Unverified Commit a6bef447 by Matt Condon Committed by GitHub

fix: remove admin functionality from RBAC.sol fixes #802 (#836)

- splits the admin part of RBAC.sol into RBACWithAdmin.sol
parent a9c777fa
...@@ -22,7 +22,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { ...@@ -22,7 +22,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale {
RefundVault public vault; RefundVault public vault;
/** /**
* @dev Constructor, creates RefundVault. * @dev Constructor, creates RefundVault.
* @param _goal Funding goal * @param _goal Funding goal
*/ */
function RefundableCrowdsale(uint256 _goal) public { function RefundableCrowdsale(uint256 _goal) public {
...@@ -42,7 +42,7 @@ contract RefundableCrowdsale is FinalizableCrowdsale { ...@@ -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 * @return Whether funding goal was reached
*/ */
function goalReached() public view returns (bool) { function goalReached() public view returns (bool) {
......
pragma solidity ^0.4.8; 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"; string constant ROLE_ADVISOR = "advisor";
......
...@@ -7,8 +7,8 @@ import "./Roles.sol"; ...@@ -7,8 +7,8 @@ import "./Roles.sol";
* @title RBAC (Role-Based Access Control) * @title RBAC (Role-Based Access Control)
* @author Matt Condon (@Shrugs) * @author Matt Condon (@Shrugs)
* @dev Stores and provides setters and getters for roles and addresses. * @dev Stores and provides setters and getters for roles and addresses.
* Supports unlimited numbers of roles and addresses. * @dev Supports unlimited numbers of roles and addresses.
* See //contracts/mocks/RBACMock.sol for an example of usage. * @dev See //contracts/mocks/RBACMock.sol for an example of usage.
* This RBAC method uses strings to key roles. It may be beneficial * 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. * 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, * It's also recommended that you define constants in the contract, like ROLE_ADMIN below,
...@@ -23,20 +23,6 @@ contract RBAC { ...@@ -23,20 +23,6 @@ contract RBAC {
event RoleRemoved(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 * @dev reverts if addr does not have role
* @param addr address * @param addr address
* @param roleName the name of the role * @param roleName the name of the role
...@@ -68,30 +54,6 @@ contract RBAC { ...@@ -68,30 +54,6 @@ contract RBAC {
* @param addr address * @param addr address
* @param roleName the name of the role * @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
* @param roleName the name of the role
*/
function addRole(address addr, string roleName) function addRole(address addr, string roleName)
internal internal
{ {
...@@ -123,16 +85,6 @@ contract RBAC { ...@@ -123,16 +85,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) * @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 * @param roleNames the names of the roles to scope access to
* // reverts * // reverts
......
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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment