Skip to content

Commit

Permalink
Merge pull request #264 from aragon/issue251
Browse files Browse the repository at this point in the history
acl: Add better getters for extracting ACL info
  • Loading branch information
bingen authored Mar 27, 2018
2 parents 053fb10 + 593ad6d commit 1f167c1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
56 changes: 41 additions & 15 deletions contracts/acl/ACL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,32 @@ contract ACL is IACL, AragonApp, ACLHelpers {
_setPermissionManager(_newManager, _app, _role);
}

/**
* @notice Get parameters for permission array length
* @param _entity Address of the whitelisted entity that will be able to perform the role
* @param _app Address of the app
* @param _role Identifier for a group of actions in app
* @return Length of the array
*/
function getPermissionParamsLength(address _entity, address _app, bytes32 _role) external view returns (uint) {
return permissionParams[permissions[permissionHash(_entity, _app, _role)]].length;
}

/**
* @notice Get parameter for permission
* @param _entity Address of the whitelisted entity that will be able to perform the role
* @param _app Address of the app
* @param _role Identifier for a group of actions in app
* @param _index Index of parameter in the array
* @return Parameter (id, op, value)
*/
function getPermissionParam(address _entity, address _app, bytes32 _role, uint _index) external view returns (uint8 id, uint8 op, uint240 value) {
Param param = permissionParams[permissions[permissionHash(_entity, _app, _role)]][_index];
id = param.id;
op = param.op;
value = param.value;
}

/**
* @dev Get manager for permission
* @param _app Address of the app
Expand Down Expand Up @@ -180,6 +206,21 @@ contract ACL is IACL, AragonApp, ACLHelpers {
return hasPermission(_who, _where, _what, empty);
}

function evalParams(
bytes32 _paramsHash,
address _who,
address _where,
bytes32 _what,
uint256[] _how
) public view returns (bool)
{
if (_paramsHash == EMPTY_PARAM_HASH) {
return true;
}

return evalParam(_paramsHash, 0, _who, _where, _what, _how);
}

/**
* @dev Internal createPermission for access inside the kernel (on instantiation)
*/
Expand Down Expand Up @@ -215,21 +256,6 @@ contract ACL is IACL, AragonApp, ACLHelpers {
return paramHash;
}

function evalParams(
bytes32 _paramsHash,
address _who,
address _where,
bytes32 _what,
uint256[] _how
) internal view returns (bool)
{
if (_paramsHash == EMPTY_PARAM_HASH) {
return true;
}

return evalParam(_paramsHash, 0, _who, _where, _what, _how);
}

function evalParam(
bytes32 _paramsHash,
uint32 _paramId,
Expand Down
9 changes: 9 additions & 0 deletions test/kernel_acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ contract('Kernel ACL', accounts => {
const param = new web3.BigNumber(argId + op + value)

const r1 = await acl.grantPermissionP(accounts[3], app, role, [param], { from: granted })

// retrieve the params back with the getters
const numParams = await acl.getPermissionParamsLength(accounts[3], app, role)
assert.equal(numParams, 1, 'There should be just 1 param')
const returnedParam = await acl.getPermissionParam(accounts[3], app, role, 0)
assert.equal(returnedParam[0].valueOf(), parseInt(argId, 16), 'param id should match')
assert.equal(returnedParam[1].valueOf(), parseInt(op, 10), 'param op should match')
assert.equal(returnedParam[2].valueOf(), parseInt(value, 10), 'param value should match')

// grants again without re-saving params
const r2 = await acl.grantPermissionP(accounts[4], app, role, [param], { from: granted })

Expand Down

0 comments on commit 1f167c1

Please sign in to comment.