RBACWithAdmin.sol 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. pragma solidity ^0.4.24;
  2. import "../access/rbac/RBAC.sol";
  3. /**
  4. * @title RBACWithAdmin
  5. * @author Matt Condon (@Shrugs)
  6. * @dev It's recommended that you define constants in the contract,
  7. * like ROLE_ADMIN below, to avoid typos.
  8. * @notice RBACWithAdmin is probably too expansive and powerful for your
  9. * application; an admin is actually able to change any address to any role
  10. * which is a very large API surface. It's recommended that you follow a strategy
  11. * of strictly defining the abilities of your roles
  12. * and the API-surface of your contract.
  13. * This is just an example for example's sake.
  14. */
  15. contract RBACWithAdmin is RBAC {
  16. /**
  17. * A constant role name for indicating admins.
  18. */
  19. string private constant ROLE_ADMIN = "admin";
  20. /**
  21. * @dev modifier to scope access to admins
  22. * // reverts
  23. */
  24. modifier onlyAdmin()
  25. {
  26. checkRole(msg.sender, ROLE_ADMIN);
  27. _;
  28. }
  29. /**
  30. * @dev constructor. Sets msg.sender as admin by default
  31. */
  32. constructor()
  33. public
  34. {
  35. _addRole(msg.sender, ROLE_ADMIN);
  36. }
  37. /**
  38. * @return true if the account is admin, false otherwise.
  39. */
  40. function isAdmin(address _account) public view returns(bool) {
  41. return hasRole(_account, ROLE_ADMIN);
  42. }
  43. /**
  44. * @dev add a role to an account
  45. * @param _account the account that will have the role
  46. * @param _roleName the name of the role
  47. */
  48. function adminAddRole(address _account, string _roleName)
  49. public
  50. onlyAdmin
  51. {
  52. _addRole(_account, _roleName);
  53. }
  54. /**
  55. * @dev remove a role from an account
  56. * @param _account the account that will no longer have the role
  57. * @param _roleName the name of the role
  58. */
  59. function adminRemoveRole(address _account, string _roleName)
  60. public
  61. onlyAdmin
  62. {
  63. _removeRole(_account, _roleName);
  64. }
  65. }