Refactoring Superuser contract to allow Owners to transfer ownership … (#978)
* Refactoring Superuser contract to allow Owners to transfer ownership when they are not superusers #50 * Refactoring tests to create a contract instance for each of them #50
This commit is contained in:
committed by
Francisco Giordano
parent
5db0d7d1a0
commit
7fb84b42d5
@ -33,16 +33,6 @@ contract Ownable {
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current owner to transfer control of the contract to a newOwner.
|
||||
* @param newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function transferOwnership(address newOwner) public onlyOwner {
|
||||
require(newOwner != address(0));
|
||||
emit OwnershipTransferred(owner, newOwner);
|
||||
owner = newOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current owner to relinquish control of the contract.
|
||||
*/
|
||||
@ -50,4 +40,22 @@ contract Ownable {
|
||||
emit OwnershipRenounced(owner);
|
||||
owner = address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current owner to transfer control of the contract to a newOwner.
|
||||
* @param _newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function transferOwnership(address _newOwner) public onlyOwner {
|
||||
_transferOwnership(_newOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers control of the contract to a newOwner.
|
||||
* @param _newOwner The address to transfer ownership to.
|
||||
*/
|
||||
function _transferOwnership(address _newOwner) internal {
|
||||
require(_newOwner != address(0));
|
||||
emit OwnershipTransferred(owner, _newOwner);
|
||||
owner = _newOwner;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,11 @@ contract Superuser is Ownable, RBAC {
|
||||
_;
|
||||
}
|
||||
|
||||
modifier onlyOwnerOrSuperuser() {
|
||||
require(msg.sender == owner || isSuperuser(msg.sender));
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev getter to determine if address has superuser role
|
||||
*/
|
||||
@ -41,22 +46,17 @@ contract Superuser is Ownable, RBAC {
|
||||
* @dev Allows the current superuser to transfer his role to a newSuperuser.
|
||||
* @param _newSuperuser The address to transfer ownership to.
|
||||
*/
|
||||
function transferSuperuser(address _newSuperuser)
|
||||
onlySuperuser
|
||||
public
|
||||
{
|
||||
function transferSuperuser(address _newSuperuser) public onlySuperuser {
|
||||
require(_newSuperuser != address(0));
|
||||
removeRole(msg.sender, ROLE_SUPERUSER);
|
||||
addRole(_newSuperuser, ROLE_SUPERUSER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allows the current superuser to transfer control of the contract to a newOwner.
|
||||
* @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 onlySuperuser {
|
||||
require(_newOwner != address(0));
|
||||
owner = _newOwner;
|
||||
emit OwnershipTransferred(owner, _newOwner);
|
||||
function transferOwnership(address _newOwner) public onlyOwnerOrSuperuser {
|
||||
_transferOwnership(_newOwner);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user