Skip to content

Commit

Permalink
PR(ACP): Rename Registering Document Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzadlone committed Mar 18, 2024
1 parent 87ccd7e commit f3b1a8c
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion acp/acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type ACPModule interface {
resourceName string,
) error

// RegisterDocCreation registers the document (object) to have access control.
// RegisterDocObject registers the document (object) to have access control.
// No error is returned upon successful registering of a document.
//
// Note(s):
Expand Down
2 changes: 1 addition & 1 deletion acp/acp_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (l *ACPLocal) ValidateResourceExistsOnValidDPI(
return nil
}

func (l *ACPLocal) RegisterDocCreation(
func (l *ACPLocal) RegisterDocObject(
ctx context.Context,
actorID string,
policyID string,
Expand Down
6 changes: 3 additions & 3 deletions db/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ func (c *collection) create(
return err
}

return c.registerDocCreation(ctx, identity, doc.ID().String())
return c.registerDocWithACP(ctx, identity, doc.ID().String())
}

// Update an existing document with the new values.
Expand Down Expand Up @@ -1429,7 +1429,7 @@ func (c *collection) update(
doc *client.Document,
) error {
// Stop the update if the correct permissions aren't there.
canUpdate, err := c.checkDocPermissionedAccess(
canUpdate, err := c.checkAccessOfDocWithACP(
ctx,
identity,
acp.WritePermission,
Expand Down Expand Up @@ -1780,7 +1780,7 @@ func (c *collection) exists(
txn datastore.Txn,
primaryKey core.PrimaryDataStoreKey,
) (exists bool, isDeleted bool, err error) {
canRead, err := c.checkDocPermissionedAccess(
canRead, err := c.checkAccessOfDocWithACP(
ctx,
identity,
acp.ReadPermission,
Expand Down
12 changes: 6 additions & 6 deletions db/collection_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@ import (
"github.com/sourcenetwork/defradb/db/permission"
)

func (c *collection) registerDocCreation(
func (c *collection) registerDocWithACP(
ctx context.Context,
identity immutable.Option[string],
docID string,
) error {
return permission.RegisterDocCreationOnCollection(
return permission.RegisterDocOnCollectionWithACP(
ctx,
identity,
c.db.ACPModule(),
c.db.acp,
c,
docID,
)
}

func (c *collection) checkDocPermissionedAccess(
func (c *collection) checkAccessOfDocWithACP(
ctx context.Context,
identity immutable.Option[string],
dpiPermission acp.DPIPermission,
docID string,
) (bool, error) {
return permission.CheckDocPermissionedAccessOnCollection(
return permission.CheckAccessOfDocOnCollectionWithACP(
ctx,
identity,
c.db.ACPModule(),
c.db.acp,
c,
dpiPermission,
docID,
Expand Down
2 changes: 1 addition & 1 deletion db/collection_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (c *collection) applyDelete(
}

// Stop deletion of document if the correct permissions aren't there.
canDelete, err := c.checkDocPermissionedAccess(
canDelete, err := c.checkAccessOfDocWithACP(
ctx,
identity,
acp.WritePermission,
Expand Down
4 changes: 0 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ func (db *db) LensRegistry() client.LensRegistry {
return db.lensRegistry
}

func (db *db) ACPModule() immutable.Option[acp.ACPModule] {
return db.acp
}

// Initialize is called when a database is first run and creates all the db global meta data
// like Collection ID counters.
func (db *db) initialize(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion db/fetcher/fetcher_acp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// or not, according to our access logic based on weather (1) the request is permissioned,
// (2) the collection is permissioned (has a policy), (3) acp module exists.
func (df *DocumentFetcher) runDocReadPermissionCheck(ctx context.Context) error {
hasPermission, err := permission.CheckDocPermissionedAccessOnCollection(
hasPermission, err := permission.CheckAccessOfDocOnCollectionWithACP(
ctx,
df.identity,
df.acp,
Expand Down
6 changes: 3 additions & 3 deletions db/permission/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"github.com/sourcenetwork/defradb/client"
)

// CheckDocPermissionedAccessOnCollection handles the check, which tells us if access to the target
// CheckAccessOfDocOnCollectionWithACP handles the check, which tells us if access to the target
// document is valid, with respect to the permission type, and the specified collection.
//
// According to our access logic we have these components to worry about:
// (1) the request is permissioned (has an identity signature),
// (1) the request is permissioned (has an identity),
// (2) the collection is permissioned (has a policy),
// (3) acp module exists (acp is enabled).
//
Expand All @@ -32,7 +32,7 @@ import (
// - Document is public (unregistered), whether signatured request or not, doesn't matter.
//
// Otherwise, check with acp module to verify signature has the appropriate access.
func CheckDocPermissionedAccessOnCollection(
func CheckAccessOfDocOnCollectionWithACP(
ctx context.Context,
identityOptional immutable.Option[string],
acpModuleOptional immutable.Option[acp.ACPModule],
Expand Down
9 changes: 3 additions & 6 deletions db/permission/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import (
"github.com/sourcenetwork/defradb/client"
)

// The document is only registered with ACP if all (1) (2) and (3) are true.
// In all other cases, nothing is registered with ACP.

// RegisterDocCreationOnCollection handles the registration of the document with acp module.
// RegisterDocOnCollectionWithACP handles the registration of the document with acp module.
// The registering is done at document creation on the collection.
//
// According to our access logic we have these components to worry about:
Expand All @@ -33,7 +30,7 @@ import (
// The document is only registered if all (1) (2) and (3) are true.
//
// Otherwise, nothing is registered on the acp module.
func RegisterDocCreationOnCollection(
func RegisterDocOnCollectionWithACP(
ctx context.Context,
identity immutable.Option[string],
acpModule immutable.Option[acp.ACPModule],
Expand All @@ -44,7 +41,7 @@ func RegisterDocCreationOnCollection(
if acpModule.HasValue() && identity.HasValue() {
// And collection has policy.
if policyID, resourceName, hasPolicy := IsPermissioned(collection); hasPolicy {
return acpModule.Value().RegisterDocCreation(
return acpModule.Value().RegisterDocObject(
ctx,
identity.Value(),
policyID,
Expand Down

0 comments on commit f3b1a8c

Please sign in to comment.