From a6bef4479068976778acd75d46ccda3aac47a8d2 Mon Sep 17 00:00:00 2001 From: Matt Condon Date: Tue, 3 Apr 2018 16:56:31 -0300 Subject: [PATCH] fix: remove admin functionality from RBAC.sol fixes #802 (#836) - splits the admin part of RBAC.sol into RBACWithAdmin.sol --- .../distribution/RefundableCrowdsale.sol | 4 +- contracts/mocks/RBACMock.sol | 4 +- contracts/ownership/rbac/RBAC.sol | 52 +--------------- contracts/ownership/rbac/RBACWithAdmin.sol | 60 +++++++++++++++++++ 4 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 contracts/ownership/rbac/RBACWithAdmin.sol diff --git a/contracts/crowdsale/distribution/RefundableCrowdsale.sol b/contracts/crowdsale/distribution/RefundableCrowdsale.sol index de1e08d13..5c6796ca3 100644 --- a/contracts/crowdsale/distribution/RefundableCrowdsale.sol +++ b/contracts/crowdsale/distribution/RefundableCrowdsale.sol @@ -22,7 +22,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { RefundVault public vault; /** - * @dev Constructor, creates RefundVault. + * @dev Constructor, creates RefundVault. * @param _goal Funding goal */ function RefundableCrowdsale(uint256 _goal) public { @@ -42,7 +42,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { } /** - * @dev Checks whether funding goal was reached. + * @dev Checks whether funding goal was reached. * @return Whether funding goal was reached */ function goalReached() public view returns (bool) { diff --git a/contracts/mocks/RBACMock.sol b/contracts/mocks/RBACMock.sol index f81e5ffc6..81435b85e 100644 --- a/contracts/mocks/RBACMock.sol +++ b/contracts/mocks/RBACMock.sol @@ -1,9 +1,9 @@ pragma solidity ^0.4.8; -import "../ownership/rbac/RBAC.sol"; +import "../ownership/rbac/RBACWithAdmin.sol"; -contract RBACMock is RBAC { +contract RBACMock is RBACWithAdmin { string constant ROLE_ADVISOR = "advisor"; diff --git a/contracts/ownership/rbac/RBAC.sol b/contracts/ownership/rbac/RBAC.sol index 16ff0d512..f030737d4 100644 --- a/contracts/ownership/rbac/RBAC.sol +++ b/contracts/ownership/rbac/RBAC.sol @@ -7,8 +7,8 @@ import "./Roles.sol"; * @title RBAC (Role-Based Access Control) * @author Matt Condon (@Shrugs) * @dev Stores and provides setters and getters for roles and addresses. - * Supports unlimited numbers of roles and addresses. - * See //contracts/mocks/RBACMock.sol for an example of usage. + * @dev Supports unlimited numbers of roles and addresses. + * @dev See //contracts/mocks/RBACMock.sol for an example of usage. * This RBAC method uses strings to key roles. It may be beneficial * for you to write your own implementation of this interface using Enums or similar. * It's also recommended that you define constants in the contract, like ROLE_ADMIN below, @@ -22,20 +22,6 @@ contract RBAC { event RoleAdded(address addr, string roleName); event RoleRemoved(address addr, string roleName); - /** - * A constant role name for indicating admins. - */ - string public constant ROLE_ADMIN = "admin"; - - /** - * @dev constructor. Sets msg.sender as admin by default - */ - function RBAC() - public - { - addRole(msg.sender, ROLE_ADMIN); - } - /** * @dev reverts if addr does not have role * @param addr address @@ -63,30 +49,6 @@ contract RBAC { return roles[roleName].has(addr); } - /** - * @dev add a role to an address - * @param addr address - * @param roleName the name of the role - */ - function adminAddRole(address addr, string roleName) - onlyAdmin - public - { - addRole(addr, roleName); - } - - /** - * @dev remove a role from an address - * @param addr address - * @param roleName the name of the role - */ - function adminRemoveRole(address addr, string roleName) - onlyAdmin - public - { - removeRole(addr, roleName); - } - /** * @dev add a role to an address * @param addr address @@ -122,16 +84,6 @@ contract RBAC { _; } - /** - * @dev modifier to scope access to admins - * // reverts - */ - modifier onlyAdmin() - { - checkRole(msg.sender, ROLE_ADMIN); - _; - } - /** * @dev modifier to scope access to a set of roles (uses msg.sender as addr) * @param roleNames the names of the roles to scope access to diff --git a/contracts/ownership/rbac/RBACWithAdmin.sol b/contracts/ownership/rbac/RBACWithAdmin.sol new file mode 100644 index 000000000..c0ac408f7 --- /dev/null +++ b/contracts/ownership/rbac/RBACWithAdmin.sol @@ -0,0 +1,60 @@ +pragma solidity ^0.4.18; + +import "./RBAC.sol"; + + +/** + * @title RBACWithAdmin + * @author Matt Condon (@Shrugs) + * @dev It's recommended that you define constants in the contract, + * @dev like ROLE_ADMIN below, to avoid typos. + */ +contract RBACWithAdmin is RBAC { + /** + * A constant role name for indicating admins. + */ + string public constant ROLE_ADMIN = "admin"; + + /** + * @dev modifier to scope access to admins + * // reverts + */ + modifier onlyAdmin() + { + checkRole(msg.sender, ROLE_ADMIN); + _; + } + + /** + * @dev constructor. Sets msg.sender as admin by default + */ + function RBACWithAdmin() + public + { + addRole(msg.sender, ROLE_ADMIN); + } + + /** + * @dev add a role to an address + * @param addr address + * @param roleName the name of the role + */ + function adminAddRole(address addr, string roleName) + onlyAdmin + public + { + addRole(addr, roleName); + } + + /** + * @dev remove a role from an address + * @param addr address + * @param roleName the name of the role + */ + function adminRemoveRole(address addr, string roleName) + onlyAdmin + public + { + removeRole(addr, roleName); + } +}