feat: RBAC authentication contract and role library
This commit is contained in:
68
test/helpers/RBACMock.sol
Normal file
68
test/helpers/RBACMock.sol
Normal file
@ -0,0 +1,68 @@
|
||||
pragma solidity ^0.4.8;
|
||||
|
||||
import '../../contracts/ownership/rbac/RBAC.sol';
|
||||
|
||||
|
||||
contract RBACMock is RBAC {
|
||||
|
||||
modifier onlyOwnerOrAdvisor()
|
||||
{
|
||||
require(
|
||||
hasRole(msg.sender, "owner") ||
|
||||
hasRole(msg.sender, "advisor")
|
||||
);
|
||||
_;
|
||||
}
|
||||
|
||||
function RBACMock(address[] _advisors)
|
||||
public
|
||||
{
|
||||
addRole(msg.sender, "owner");
|
||||
addRole(msg.sender, "advisor");
|
||||
|
||||
for (uint256 i = 0; i < _advisors.length; i++) {
|
||||
addRole(_advisors[i], "advisor");
|
||||
}
|
||||
}
|
||||
|
||||
function onlyOwnersCanDoThis()
|
||||
onlyRole("owner")
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
function onlyAdvisorsCanDoThis()
|
||||
onlyRole("advisor")
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
function eitherOwnerOrAdvisorCanDoThis()
|
||||
onlyOwnerOrAdvisor
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
function nobodyCanDoThis()
|
||||
onlyRole("unknown")
|
||||
view
|
||||
external
|
||||
{
|
||||
}
|
||||
|
||||
// owners can remove advisor's role
|
||||
function removeAdvisor(address _addr)
|
||||
onlyRole("owner")
|
||||
public
|
||||
{
|
||||
// revert if the user isn't an advisor
|
||||
// (perhaps you want to soft-fail here instead?)
|
||||
checkRole(_addr, "advisor");
|
||||
|
||||
// remove the advisor's role
|
||||
removeRole(_addr, "advisor");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user