Checking Relations
Since you've now created your relation definitions and relations, we can now check them to determine access control. Below are the functions you can use to check relations.
Check if relation exists
The hasRelations
function checks if a particular relation exists. Pass in an array of AuthzRelationQuery
objects and the same objects will
be returned with a boolean set to true or false;
Check who can access a particular resource
The whoCanAccess
function takes in a resource, a relation definition, and a namespace corresponding to the relation definition and returns an array
of users with the given relation definitions to the resource.
Check what relations a resource has
The resourceRelations
function returns an array of relations for a given resource.
Check what relations a target has directly
The targetsRelations
function takes an array of targets (eg. users) and returns an array of relations that exist for the target directly.
This will NOT return relations that exist for the target implicitly, such as through a parent node with a matching relation definition.
Check what relations a target has directly and implicitly (recursive)
The whatCanTargetAccess
function is similar to the targetsRelations
function in that it takes an array of targets and returns
an array of relations that exist for it, but instead of simply including direct relations, it returns implicit ones as well,
traversing the tree of relations recursively.