permission: allow sub orgs to be added to orgs

This commit is contained in:
amalraj.manigmail.com 2019-04-04 18:25:43 +08:00
parent 2bd92a2622
commit 5f5c222246
3 changed files with 88 additions and 55 deletions

View File

@ -7,13 +7,17 @@ contract OrgManager {
PermissionsUpgradable private permUpgradable;
// checks if first time network boot up has happened or not
bool private networkBoot = false;
uint private DEPTH_LIMIT = 4;
uint private BREADTH_LIMIT = 5;
// enum OrgStatus {0- NotInList, 1- Proposed, 2- Approved, 3- PendingSuspension, 4- Suspended, 5- RevokeSuspension}
struct OrgDetails {
string orgId;
uint status;
string parentId;
string fullOrgId;
uint pindex;
uint level;
uint [] subOrgIndexList;
}
OrgDetails [] private orgList;
@ -63,6 +67,8 @@ contract OrgManager {
{
bytes32 pid = "";
bytes32 oid = "";
uint parentIndex = 0;
if (_level == 1) {//root
oid = keccak256(abi.encodePacked(_orgId));
} else {
@ -75,9 +81,22 @@ contract OrgManager {
if (_level == 1) {
orgList[id].level = _level;
orgList[id].pindex = 0;
orgList[id].fullOrgId = _orgId;
} else {
orgList[id].level = orgList[OrgIndex[pid]-1].level + 1;
orgList[id].pindex = OrgIndex[pid];
parentIndex = OrgIndex[pid] - 1;
uint newLevel = orgList[parentIndex].level;
uint breadth = orgList[parentIndex].subOrgIndexList.length;
require(breadth < BREADTH_LIMIT, "breadth level exceeded");
require(newLevel < DEPTH_LIMIT, "depth level exceeded");
orgList[id].level = newLevel + 1;
orgList[id].pindex = parentIndex;
uint subOrgId = orgList[parentIndex].subOrgIndexList.length++;
orgList[parentIndex].subOrgIndexList[subOrgId] = id;
orgList[id].fullOrgId = string(abi.encodePacked(_pOrg, ".", _orgId));
}
orgList[id].orgId = _orgId;
orgList[id].parentId = _pOrg;
@ -219,8 +238,22 @@ contract OrgManager {
}
// returns org and master org details based on org index
function getOrgInfo(uint _orgIndex) external view returns (string memory, uint, uint, string memory, uint)
function getOrgInfo(uint _orgIndex) external view returns (string memory, string memory, uint, uint, string memory, uint, uint[] memory)
{
return (orgList[_orgIndex].parentId, orgList[_orgIndex].pindex,orgList[_orgIndex].level, orgList[_orgIndex].orgId, orgList[_orgIndex].status);
return (orgList[_orgIndex].fullOrgId, orgList[_orgIndex].parentId, orgList[_orgIndex].pindex,orgList[_orgIndex].level, orgList[_orgIndex].orgId, orgList[_orgIndex].status, orgList[_orgIndex].subOrgIndexList);
}
function getSubOrgInfo(uint _orgIndex) external view returns (uint[] memory)
{
return orgList[_orgIndex].subOrgIndexList;
}
function getSubOrgIndexLength(uint _orgIndex) external view returns (uint)
{
return orgList[_orgIndex].subOrgIndexList.length;
}
function getSubOrgIndexLength(uint _orgIndex, uint _subOrgIndex) external view returns (uint)
{
return orgList[_orgIndex].subOrgIndexList[_subOrgIndex];
}
}

View File

@ -44,7 +44,7 @@ contract PermissionsImplementation {
}
modifier orgAdmin(address _account, string memory _orgId) {
//require(isOrgAdmin(_account, _orgId) == true, "Not an org admin");
require(isOrgAdmin(_account, _orgId) == true, "Not an org admin");
_;
}
@ -150,7 +150,7 @@ contract PermissionsImplementation {
nodes.addNode(_enodeId, pid);
}
function approveOrg(string calldata _orgId, string calldata _enodeId, address _caller) external
function approveOrgImpl(string memory _orgId, string memory _enodeId, address _caller) internal
onlyProxy
networkAdmin(_caller)
{
@ -162,17 +162,14 @@ contract PermissionsImplementation {
}
}
function approveSubOrg(string calldata _pOrg, string calldata _orgId, string calldata _enodeId, address _caller) external
onlyProxy
networkAdmin(_caller)
function approveOrg(string calldata _orgId, string calldata _enodeId, address _caller) external
{
string memory pid = string(abi.encodePacked(_pOrg, ".", _orgId));
require(checkOrgStatus(pid, 1) == true, "Nothing to approve");
if ((processVote(adminOrg, _caller, 1))) {
org.approveOrg(pid);
roles.addRole(orgAdminRole, pid, fullAccess, true);
nodes.approveNode(_enodeId, pid);
}
approveOrgImpl(_orgId, _enodeId, _caller);
}
function approveSubOrg(string calldata _pOrg, string calldata _orgId, string calldata _enodeId, address _caller) external
{
approveOrgImpl(string(abi.encodePacked(_pOrg, ".", _orgId)), _enodeId, _caller);
}
function updateOrgStatus(string calldata _orgId, uint _status, address _caller) external
@ -204,15 +201,15 @@ contract PermissionsImplementation {
}
}
// returns org and master org details based on org index
function getOrgInfo(uint _orgIndex) external view
/* function getOrgInfo(uint _orgIndex) external view
returns (string memory, uint, uint, string memory, uint)
{
return org.getOrgInfo(_orgIndex);
}
}*/
// Role related functions
/*function addNewRole(string calldata _roleId, string calldata _orgId, uint _access, bool _voter, address _caller) external
function addNewRole(string calldata _roleId, string calldata _orgId, uint _access, bool _voter, address _caller) external
onlyProxy
orgApproved(_orgId)
orgAdmin(_caller, _orgId)
@ -227,39 +224,39 @@ contract PermissionsImplementation {
orgAdmin(_caller, _orgId)
{
roles.removeRole(_roleId, _orgId);
}*/
}
function getRoleDetails(string calldata _roleId, string calldata _orgId) external view
/*function getRoleDetails(string calldata _roleId, string calldata _orgId) external view
returns (string memory, string memory, uint, bool, bool)
{
return roles.getRoleDetails(_roleId, _orgId);
}
}*/
// Org voter related functions
function getNumberOfVoters(string calldata _orgId) external view
/*function getNumberOfVoters(string calldata _orgId) external view
returns (uint){
return voter.getNumberOfValidVoters(_orgId);
}
}*/
function checkIfVoterExists(string calldata _orgId, address _acct) external view
/*function checkIfVoterExists(string calldata _orgId, address _acct) external view
returns (bool)
{
return voter.checkIfVoterExists(_orgId, _acct);
}
}*/
function getVoteCount(string calldata _orgId) external view returns (uint, uint)
/*function getVoteCount(string calldata _orgId) external view returns (uint, uint)
{
return voter.getVoteCount(_orgId);
}
}*/
function getPendingOp(string calldata _orgId) external view
/*function getPendingOp(string calldata _orgId) external view
returns (string memory, string memory, address, uint)
{
return voter.getPendingOpDetails(_orgId);
}
}*/
function assignOrgAdminAccount(string calldata _orgId, address _account, address _caller) external
onlyProxy
@ -285,7 +282,7 @@ contract PermissionsImplementation {
}
/* function assignAccountRole(address _acct, string memory _orgId, string memory _roleId, address _caller) public
function assignAccountRole(address _acct, string memory _orgId, string memory _roleId, address _caller) public
onlyProxy
orgAdmin(_caller, _orgId)
orgApproved(_orgId)
@ -319,7 +316,7 @@ contract PermissionsImplementation {
}
}
accounts.assignAccountRole(_acct, _orgId, _roleId);
}*/
}
function addNode(string calldata _orgId, string calldata _enodeId, address _caller) external
onlyProxy
@ -327,15 +324,17 @@ contract PermissionsImplementation {
orgAdmin(_caller, _orgId)
{
// check that the node is not part of another org
require(getNodeStatus(_enodeId) == 0, "Node present already");
require(nodes.getNodeStatus(_enodeId) == 0, "Node present already");
nodes.addOrgNode(_enodeId, _orgId);
}
function getNodeStatus(string memory _enodeId) public view
/* function getNodeStatus(string memory _enodeId) public view
returns (uint)
{
return (nodes.getNodeStatus(_enodeId));
}
}*/
function isNetworkAdmin(address _account) public view
returns (bool)
@ -343,7 +342,7 @@ contract PermissionsImplementation {
return (keccak256(abi.encodePacked(accounts.getAccountRole(_account))) == keccak256(abi.encodePacked(adminRole)));
}
/*function isOrgAdmin(address _account, string memory _orgId) public view
function isOrgAdmin(address _account, string memory _orgId) public view
returns (bool)
{
return (accounts.checkOrgAdmin(_account, _orgId));
@ -353,7 +352,7 @@ contract PermissionsImplementation {
returns (bool)
{
return (accounts.valAcctAccessChange(_account, _orgId));
}*/
}
function checkOrgExists(string memory _orgId) internal view
returns (bool)

View File

@ -96,13 +96,13 @@ contract PermissionsInterface {
permImplementation.approveOrgStatus(_orgId, _status, msg.sender);
}
// returns org and master org details based on org index
function getOrgInfo(uint _orgIndex) external view returns (string memory, uint, uint, string memory, uint)
/* function getOrgInfo(uint _orgIndex) external view returns (string memory, uint, uint, string memory, uint)
{
return permImplementation.getOrgInfo(_orgIndex);
}
}*/
// Role related functions
/*function addNewRole(string calldata _roleId, string calldata _orgId, uint _access, bool _voter) external
function addNewRole(string calldata _roleId, string calldata _orgId, uint _access, bool _voter) external
{
permImplementation.addNewRole(_roleId, _orgId, _access, _voter, msg.sender);
}
@ -110,35 +110,37 @@ contract PermissionsInterface {
function removeRole(string calldata _roleId, string calldata _orgId) external
{
permImplementation.removeRole(_roleId, _orgId, msg.sender);
}*/
function getRoleDetails(string calldata _roleId, string calldata _orgId) external view returns (string memory, string memory, uint, bool, bool)
{
return permImplementation.getRoleDetails(_roleId, _orgId);
}
/* function getRoleDetails(string calldata _roleId, string calldata _orgId) external view returns (string memory, string memory, uint, bool, bool)
{
return permImplementation.getRoleDetails(_roleId, _orgId);
}*/
// Org voter related functions
/*
function getNumberOfVoters(string calldata _orgId) external view returns (uint)
{
return permImplementation.getNumberOfVoters(_orgId);
}
*/
function checkIfVoterExists(string calldata _orgId, address _acct) external view returns (bool)
/* function checkIfVoterExists(string calldata _orgId, address _acct) external view returns (bool)
{
return permImplementation.checkIfVoterExists(_orgId, _acct);
}
}*/
function getVoteCount(string calldata _orgId) external view returns (uint, uint)
/* function getVoteCount(string calldata _orgId) external view returns (uint, uint)
{
return permImplementation.getVoteCount(_orgId);
}
}*/
function getPendingOp(string calldata _orgId) external view returns (string memory, string memory, address, uint)
/* function getPendingOp(string calldata _orgId) external view returns (string memory, string memory, address, uint)
{
return permImplementation.getPendingOp(_orgId);
}
}*/
function assignOrgAdminAccount(string calldata _orgId, address _account) external
{
@ -152,12 +154,11 @@ contract PermissionsInterface {
}
/*function assignAccountRole(address _acct, string memory _orgId, string memory _roleId) public
function assignAccountRole(address _acct, string memory _orgId, string memory _roleId) public
{
permImplementation.assignAccountRole(_acct, _orgId, _roleId, msg.sender);
}
*/
function addNode(string calldata _orgId, string calldata _enodeId) external
{
permImplementation.addNode(_orgId, _enodeId, msg.sender);
@ -169,10 +170,10 @@ contract PermissionsInterface {
permImplementation.updateNodeStatus(_orgId, _enodeId, _status, msg.sender);
}
function getNodeStatus(string memory _enodeId) public view returns (uint)
/* function getNodeStatus(string memory _enodeId) public view returns (uint)
{
return permImplementation.getNodeStatus(_enodeId);
}
}*/
/*function isNetworkAdmin(address _account) public view returns (bool)
{