@@ -19,32 +19,31 @@ contract Permissions is IPermissions {
1919 return _hasRole[role][account];
2020 }
2121
22+ function hasRoleWithSwitch (bytes32 role , address account ) public view returns (bool ) {
23+ if (! _hasRole[role][address (0 )]) {
24+ return _hasRole[role][account];
25+ }
26+
27+ return true ;
28+ }
29+
2230 function getRoleAdmin (bytes32 role ) public view override returns (bytes32 ) {
2331 return _getRoleAdmin[role];
2432 }
2533
2634 function grantRole (bytes32 role , address account ) public virtual override {
2735 _checkRole (_getRoleAdmin[role], msg .sender );
28-
29- _hasRole[role][account] = true ;
30-
31- emit RoleGranted (role, account, msg .sender );
36+ _setupRole (role, account);
3237 }
3338
3439 function revokeRole (bytes32 role , address account ) public virtual override {
3540 _checkRole (_getRoleAdmin[role], msg .sender );
36-
37- delete _hasRole[role][account];
38-
39- emit RoleRevoked (role, account, msg .sender );
41+ _revokeRole (role, account);
4042 }
4143
4244 function renounceRole (bytes32 role , address account ) public virtual override {
4345 require (msg .sender == account, "Can only renounce for self " );
44-
45- delete _hasRole[role][account];
46-
47- emit RoleRevoked (role, account, msg .sender );
46+ _revokeRole (role, account);
4847 }
4948
5049 function _setRoleAdmin (bytes32 role , bytes32 adminRole ) internal virtual {
@@ -58,12 +57,32 @@ contract Permissions is IPermissions {
5857 emit RoleGranted (role, account, msg .sender );
5958 }
6059
60+ function _revokeRole (bytes32 role , address account ) internal virtual {
61+ delete _hasRole[role][account];
62+ emit RoleRevoked (role, account, msg .sender );
63+ }
64+
6165 function _checkRole (bytes32 role , address account ) internal view virtual {
6266 if (! _hasRole[role][account]) {
6367 revert (
6468 string (
6569 abi.encodePacked (
66- "AccessControl: account " ,
70+ "Permissions: account " ,
71+ Strings.toHexString (uint160 (account), 20 ),
72+ " is missing role " ,
73+ Strings.toHexString (uint256 (role), 32 )
74+ )
75+ )
76+ );
77+ }
78+ }
79+
80+ function _checkRoleWithSwitch (bytes32 role , address account ) internal view virtual {
81+ if (! hasRoleWithSwitch (role, account)) {
82+ revert (
83+ string (
84+ abi.encodePacked (
85+ "Permissions: account " ,
6786 Strings.toHexString (uint160 (account), 20 ),
6887 " is missing role " ,
6988 Strings.toHexString (uint256 (role), 32 )
0 commit comments