1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- pragma solidity ^0.4.23;
- import "./Ownable.sol";
- import "./rbac/RBAC.sol";
- /**
- * @title Superuser
- * @dev The Superuser contract defines a single superuser who can transfer the ownership
- * @dev of a contract to a new address, even if he is not the owner.
- * @dev A superuser can transfer his role to a new address.
- */
- contract Superuser is Ownable, RBAC {
- string public constant ROLE_SUPERUSER = "superuser";
- constructor () public {
- addRole(msg.sender, ROLE_SUPERUSER);
- }
- /**
- * @dev Throws if called by any account that's not a superuser.
- */
- modifier onlySuperuser() {
- checkRole(msg.sender, ROLE_SUPERUSER);
- _;
- }
- modifier onlyOwnerOrSuperuser() {
- require(msg.sender == owner || isSuperuser(msg.sender));
- _;
- }
- /**
- * @dev getter to determine if address has superuser role
- */
- function isSuperuser(address _addr)
- public
- view
- returns (bool)
- {
- return hasRole(_addr, ROLE_SUPERUSER);
- }
- /**
- * @dev Allows the current superuser to transfer his role to a newSuperuser.
- * @param _newSuperuser The address to transfer ownership to.
- */
- function transferSuperuser(address _newSuperuser) public onlySuperuser {
- require(_newSuperuser != address(0));
- removeRole(msg.sender, ROLE_SUPERUSER);
- addRole(_newSuperuser, ROLE_SUPERUSER);
- }
- /**
- * @dev Allows the current superuser or owner to transfer control of the contract to a newOwner.
- * @param _newOwner The address to transfer ownership to.
- */
- function transferOwnership(address _newOwner) public onlyOwnerOrSuperuser {
- _transferOwnership(_newOwner);
- }
- }
|