Skip to content

Commit

Permalink
fix document check when node specific
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Jan 16, 2025
1 parent 10e0f38 commit da75557
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/db/collection_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (c *collection) checkAccessOfDocWithACP(
if !c.db.acp.HasValue() {
return true, nil
}
ident := identity.FromContext(ctx)
if ident.HasValue() && c.db.nodeIdentity.HasValue() && ident.Value().DID == c.db.nodeIdentity.Value().DID {
return true, nil
}
return permission.CheckAccessOfDocOnCollectionWithACP(
ctx,
identity.FromContext(ctx),
Expand Down
3 changes: 3 additions & 0 deletions internal/db/p2p_replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/sourcenetwork/corelog"

"github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/datastore"
dbErrors "github.com/sourcenetwork/defradb/errors"
Expand Down Expand Up @@ -156,6 +157,8 @@ func (db *db) getDocsHeads(
}
defer txn.Discard(ctx)
ctx = SetContextTxn(ctx, txn)
// This is a node specific action which means the actor is the node itself.
ctx = identity.WithContext(ctx, db.nodeIdentity)
for _, col := range cols {
keysCh, err := col.GetAllDocIDs(ctx)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/db/p2p_schema_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/acp/identity"
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/event"
"github.com/sourcenetwork/defradb/internal/keys"
Expand Down Expand Up @@ -72,6 +73,8 @@ func (db *db) AddP2PCollections(ctx context.Context, collectionIDs []string) err
evt.ToAdd = append(evt.ToAdd, col.SchemaRoot())
}

// This is a node specific action which means the actor is the node itself.
ctx = identity.WithContext(ctx, db.nodeIdentity)
for _, col := range storeCollections {
keyChan, err := col.GetAllDocIDs(ctx)
if err != nil {
Expand Down Expand Up @@ -129,6 +132,8 @@ func (db *db) RemoveP2PCollections(ctx context.Context, collectionIDs []string)
evt.ToRemove = append(evt.ToRemove, col.SchemaRoot())
}

// This is a node specific action which means the actor is the node itself.
ctx = identity.WithContext(ctx, db.nodeIdentity)
for _, col := range storeCollections {
keyChan, err := col.GetAllDocIDs(ctx)
if err != nil {
Expand Down Expand Up @@ -202,6 +207,8 @@ func (db *db) loadAndPublishP2PCollections(ctx context.Context) error {
colMap[schemaRoot] = struct{}{}
}

// This is a node specific action which means the actor is the node itself.
ctx = identity.WithContext(ctx, db.nodeIdentity)
for _, col := range cols {
// If we subscribed to the collection, we skip subscribing to the collection's docIDs.
if _, ok := colMap[col.SchemaRoot()]; ok {
Expand Down

0 comments on commit da75557

Please sign in to comment.