RBACMock.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. pragma solidity ^0.4.24;
  2. import "../examples/RBACWithAdmin.sol";
  3. contract RBACMock is RBACWithAdmin {
  4. string internal constant ROLE_ADVISOR = "advisor";
  5. modifier onlyAdminOrAdvisor()
  6. {
  7. require(
  8. hasRole(msg.sender, ROLE_ADMIN) ||
  9. hasRole(msg.sender, ROLE_ADVISOR)
  10. );
  11. _;
  12. }
  13. constructor(address[] _advisors)
  14. public
  15. {
  16. addRole(msg.sender, ROLE_ADVISOR);
  17. for (uint256 i = 0; i < _advisors.length; i++) {
  18. addRole(_advisors[i], ROLE_ADVISOR);
  19. }
  20. }
  21. function onlyAdminsCanDoThis()
  22. external
  23. onlyAdmin
  24. view
  25. {
  26. }
  27. function onlyAdvisorsCanDoThis()
  28. external
  29. onlyRole(ROLE_ADVISOR)
  30. view
  31. {
  32. }
  33. function eitherAdminOrAdvisorCanDoThis()
  34. external
  35. onlyAdminOrAdvisor
  36. view
  37. {
  38. }
  39. function nobodyCanDoThis()
  40. external
  41. onlyRole("unknown")
  42. view
  43. {
  44. }
  45. // admins can remove advisor's role
  46. function removeAdvisor(address _account)
  47. public
  48. onlyAdmin
  49. {
  50. // revert if the user isn't an advisor
  51. // (perhaps you want to soft-fail here instead?)
  52. checkRole(_account, ROLE_ADVISOR);
  53. // remove the advisor's role
  54. removeRole(_account, ROLE_ADVISOR);
  55. }
  56. }