Skip to main content

ARBACGroupable

Overview​

License: MIT​

abstract contract ARBACGroupable is IRBACGroupable, ARBAC

The Role Based Access Control (RBAC) module

This contract is an extension for the RBAC contract to provide the ability to organize roles into groups and assign users to them.

The contract also supports default groups that all users may be in by default.

The RBAC structure becomes the following:

((PERMISSION >- RESOURCE) >- ROLE) >- GROUP

Where ROLE and GROUP are assignable to users

Structs info​

ARBACGroupableStorage​

struct ARBACGroupableStorage {
uint256 defaultGroupEnabled;
mapping(address => DynamicSet.StringSet) userGroups;
mapping(string => DynamicSet.StringSet) groupRoles;
}

Errors info​

EmptyGroups​

error EmptyGroups()

Functions info​

addUserToGroups (0xfcddfd4a)​

function addUserToGroups(
address who_,
string[] memory groupsToAddTo_
) public virtual override onlyPermission(RBAC_RESOURCE, CREATE_PERMISSION)

The function to assign the user to groups

Parameters:

NameTypeDescription
who_addressthe user to be assigned
groupsToAddTo_string[]the list of groups to assign the user to

removeUserFromGroups (0x9a9aa8d4)​

function removeUserFromGroups(
address who_,
string[] memory groupsToRemoveFrom_
) public virtual override onlyPermission(RBAC_RESOURCE, DELETE_PERMISSION)

The function to remove the user from groups

Parameters:

NameTypeDescription
who_addressthe user to be removed from groups
groupsToRemoveFrom_string[]the list of groups to remove the user from

grantGroupRoles (0xf1c7d41b)​

function grantGroupRoles(
string memory groupTo_,
string[] memory rolesToGrant_
) public virtual override onlyPermission(RBAC_RESOURCE, CREATE_PERMISSION)

The function to grant roles to the group

Parameters:

NameTypeDescription
groupTo_stringthe group to grant roles to
rolesToGrant_string[]the list of roles to grant

revokeGroupRoles (0x30cae168)​

function revokeGroupRoles(
string memory groupFrom_,
string[] memory rolesToRevoke_
) public virtual override onlyPermission(RBAC_RESOURCE, DELETE_PERMISSION)

The function to revoke roles from the group

Parameters:

NameTypeDescription
groupFrom_stringthe group to revoke roles from
rolesToRevoke_string[]the list of roles to revoke

toggleDefaultGroup (0xd41de127)​

function toggleDefaultGroup()
public
virtual
override
onlyPermission(RBAC_RESOURCE, UPDATE_PERMISSION)

The function to toggle the default group state. When defaultGroupEnabled is set to true, the default group is enabled, otherwise it is disabled

getUserGroups (0x3da04e4a)​

function getUserGroups(
address who_
) public view override returns (string[] memory groups_)

The function to get the list of user groups

Parameters:

NameTypeDescription
who_addressthe user

Return values:

NameTypeDescription
groups_string[]the list of user groups

getGroupRoles (0x8e5cc2b7)​

function getGroupRoles(
string memory group_
) public view override returns (string[] memory roles_)

The function to get the list of groups roles

Parameters:

NameTypeDescription
group_stringthe group

Return values:

NameTypeDescription
roles_string[]the list of group roles

getDefaultGroupEnabled (0x0b441407)​

function getDefaultGroupEnabled()
public
view
returns (bool defaultGroupEnabled_)

The function to get the current state of the default group

Return values:

NameTypeDescription
defaultGroupEnabled_boolthe boolean indicating whether the default group is enabled

hasPermission (0x7951c6da)​

function hasPermission(
address who_,
string memory resource_,
string memory permission_
) public view virtual override returns (bool isAllowed_)

The function to check the user's possession of the role. Unlike the base method, this method also looks up the required permission in the user's groups

DO NOT call super.hasPermission(...) in derived contracts, because this method handles not 2 but 3 states: NO PERMISSION, ALLOWED, DISALLOWED

Parameters:

NameTypeDescription
who_addressthe user
resource_stringthe resource the user has to have the permission of
permission_stringthe permission the user has to have

Return values:

NameTypeDescription
isAllowed_booltrue if the user has the permission, false otherwise