AccessControl

Unauthorized

error Unauthorized(address operator)

Emitted when msg.sender is not authorized to operate the contract.

InvalidRoleId

error InvalidRoleId(uint256 roleId)

Emitted when roleId is invalid.

AuthorizePersonnel

event AuthorizePersonnel(uint256 roleId, address authorizedAddress, bool isAuthorized)

Emitted when a new address is added to an roleId.

AuthorizeOperator

event AuthorizeOperator(bytes4 interfaceId, uint256 roleId, bool isAuthorized)

Emitted when an roleId is added as an operator of a function in the contract.

onlyOperator

modifier onlyOperator(bytes4 _interfaceId, uint256 _roleId, address _operator)

Modifier to check if msg.sender is authorized to operate a given interfaceId from one of the contract's function.

onlyOwner

modifier onlyOwner()

Modifier to check if msg.sender is the owner of the contract.

constructor

constructor() internal

Initializes the contract setting the deployer as the initial owner.

owner

function owner() public view virtual returns (address)

Returns the address of the current owner.

setRole

function setRole(uint256 _roleId, address _authorizedAddress, bool _isAuthorized) public virtual

This function sets a role for an address.

Emits an {AuthorizePersonnel} event.

Requirements:

  • msg.sender must be the owner of the contract.

  • _roleId must not be 0.

setOperator

function setOperator(bytes4 _interfaceId, uint256 _roleId, bool _isAuthorized) public virtual

This function sets an authorized role as the operator of a given interface id.

Emits an {AuthorizeOperator} event.

Requirements:

  • msg.sender must be the owner of the contract.

  • _roleId must not be 0.

hasRole

function hasRole(uint256 _roleId, address _address) public view virtual returns (bool)

_This function checks if an address holds a given roleId.

NOTE

The owner of the contract is always authorized.

isOperator

function isOperator(bytes4 _interfaceId, uint256 _roleId) public view virtual returns (bool)

This function checks if an authorizedId is allowed to operate a given _interfaceId.

NOTE

The owner of the contract is always authorized.


AccessControl Summarize

The Access Control feature in the smart contract is designed to manage the permissions and roles within the Web3Task. It uses a combination of role-based access control and attribute-based access control to ensure that only authorized users can perform certain operations.

  • Role-Based Access Control: This feature allows the contract owner to assign roles to addresses. Each role is represented by a unique role ID, and an address can be assigned to multiple roles. The contract owner can also set an address as an operator for a given interface ID, which allows the address to operate a given interface ID.

  • Attribute-Based Access Control: This feature allows the contract owner to assign attributes to addresses. Each attribute is represented by a unique attribute ID, and an address can be assigned to multiple attributes. The contract owner can also set an address as an operator for a given interface ID, which allows the address to operate a given interface ID.

  • Modifiers: The contract includes two modifiers, onlyOperator and onlyOwner, which are used to restrict access to certain functions. The onlyOperator modifier checks if the sender is an operator for a given interface ID and role ID, and the onlyOwner modifier checks if the sender is the owner of the contract.

  • Events: The contract emits events when an address is authorized or deauthorized for a role or an interface ID, and when an address is authorized or deauthorized as an operator for an interface ID.

  • Functions: The contract includes functions to set a role for an address, set an operator for an interface ID, check if an address holds a given role, and check if an address is an operator for a given interface ID.

Last updated