forked from CMTA/CMTAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessControlModule.sol
More file actions
51 lines (46 loc) · 2.01 KB
/
AccessControlModule.sol
File metadata and controls
51 lines (46 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//SPDX-License-Identifier: MPL-2.0
pragma solidity ^0.8.20;
/* ==== OpenZeppelin === */
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
abstract contract AccessControlModule is AccessControlUpgradeable {
error CMTAT_AccessControlModule_AddressZeroNotAllowed();
/* ============ Initializer Function ============ */
/**
* @notice Internal initializer that sets the provided address as the default admin.
* @dev
* - MUST be called only during initialization (`onlyInitializing`).
* - Reverts if `admin` is the zero address.
* - Grants `DEFAULT_ADMIN_ROLE` to `admin`.
* The return value of `_grantRole` is intentionally ignored, as it returns `false`
* only when the role was already assigned.
*
* @param admin The address that will receive the `DEFAULT_ADMIN_ROLE`.
*/
function __AccessControlModule_init_unchained(address admin)
internal onlyInitializing {
if(admin == address(0)){
revert CMTAT_AccessControlModule_AddressZeroNotAllowed();
}
// we don't check the return value
// _grantRole attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
// return false only if the admin has already the role
_grantRole(DEFAULT_ADMIN_ROLE, admin);
}
/*//////////////////////////////////////////////////////////////
PUBLIC/EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(
bytes32 role,
address account
) public view virtual override(AccessControlUpgradeable) returns (bool) {
// The Default Admin has all roles
if (AccessControlUpgradeable.hasRole(DEFAULT_ADMIN_ROLE, account)) {
return true;
} else {
return AccessControlUpgradeable.hasRole(role, account);
}
}
}