RBACWithAdmin.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. pragma solidity ^0.4.23;
  2. import "../ownership/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. * @dev like ROLE_ADMIN below, to avoid typos.
  8. * @dev
  9. * @dev NOTE: RBACWithAdmin is probably too expansive and powerful for your
  10. * @dev application; an admin is actually able to change any address to any role
  11. * @dev which is a very large API surface. It's recommended that you follow a strategy
  12. * @dev of strictly defining the abilities of your roles
  13. * @dev and the API-surface of your contract.
  14. * @dev This is just an example for example's sake.
  15. */
  16. contract RBACWithAdmin is RBAC {
  17. /**
  18. * A constant role name for indicating admins.
  19. */
  20. string public constant ROLE_ADMIN = "admin";
  21. /**
  22. * @dev modifier to scope access to admins
  23. * // reverts
  24. */
  25. modifier onlyAdmin()
  26. {
  27. checkRole(msg.sender, ROLE_ADMIN);
  28. _;
  29. }
  30. /**
  31. * @dev constructor. Sets msg.sender as admin by default
  32. */
  33. constructor()
  34. public
  35. {
  36. addRole(msg.sender, ROLE_ADMIN);
  37. }
  38. /**
  39. * @dev add a role to an address
  40. * @param addr address
  41. * @param roleName the name of the role
  42. */
  43. function adminAddRole(address addr, string roleName)
  44. onlyAdmin
  45. public
  46. {
  47. addRole(addr, roleName);
  48. }
  49. /**
  50. * @dev remove a role from an address
  51. * @param addr address
  52. * @param roleName the name of the role
  53. */
  54. function adminRemoveRole(address addr, string roleName)
  55. onlyAdmin
  56. public
  57. {
  58. removeRole(addr, roleName);
  59. }
  60. }