permission: fix bugs in validations and org manager event raised

This commit is contained in:
amalraj.manigmail.com 2019-04-12 20:28:22 +08:00
parent cc14183e06
commit 51cb1e3044
3 changed files with 27 additions and 14 deletions

View File

@ -98,10 +98,10 @@ contract OrgManager {
orgList[id].parentId = _pOrg;
orgList[id].status = _status;
if (_status == 1) {
emit OrgPendingApproval(_orgId, _pOrg, orgList[id].ultParent, orgList[id].level, 1);
emit OrgPendingApproval(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 1);
}
else {
emit OrgApproved(_orgId, _pOrg, orgList[id].ultParent, orgList[id].level, 2);
emit OrgApproved(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 2);
}
}
@ -183,7 +183,7 @@ contract OrgManager {
require(checkOrgStatus(_orgId, 2) == true, "Org not in approved state");
uint id = getOrgIndex(_orgId);
orgList[id].status = 3;
emit OrgPendingApproval(_orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 3);
emit OrgPendingApproval(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 3);
}
function revokeOrgSuspension(string memory _orgId) internal
@ -192,7 +192,7 @@ contract OrgManager {
require(checkOrgStatus(_orgId, 4) == true, "Org not in suspended state");
uint id = getOrgIndex(_orgId);
orgList[id].status = 5;
emit OrgPendingApproval(_orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 5);
emit OrgPendingApproval(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 5);
}
function approveOrg(string calldata _orgId) external
@ -201,7 +201,7 @@ contract OrgManager {
require(checkOrgStatus(_orgId, 1) == true, "Nothing to approve");
uint id = getOrgIndex(_orgId);
orgList[id].status = 2;
emit OrgApproved(_orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 2);
emit OrgApproved(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level, 2);
}
function approveOrgSuspension(string memory _orgId) internal
@ -209,7 +209,7 @@ contract OrgManager {
require(checkOrgStatus(_orgId, 3) == true, "Nothing to approve");
uint id = getOrgIndex(_orgId);
orgList[id].status = 4;
emit OrgSuspended(_orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level);
emit OrgSuspended(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level);
}
function approveOrgRevokeSuspension(string memory _orgId) internal
@ -217,7 +217,7 @@ contract OrgManager {
require(checkOrgStatus(_orgId, 5) == true, "Nothing to approve");
uint id = getOrgIndex(_orgId);
orgList[id].status = 2;
emit OrgSuspensionRevoked(_orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level);
emit OrgSuspensionRevoked(orgList[id].orgId, orgList[id].parentId, orgList[id].ultParent, orgList[id].level);
}
function checkOrgStatus(string memory _orgId, uint _orgStatus) public view returns (bool){

View File

@ -250,9 +250,11 @@ func (s *QuorumControlsAPI) isNetworkAdmin(account common.Address) bool {
return ac != nil && ac.RoleId == s.permConfig.NwAdminRole
}
//TODO (Amal) get it reviewed by Sai
func (s *QuorumControlsAPI) isOrgAdmin(account common.Address, orgId string) bool {
ac := types.AcctInfoMap.GetAccount(account)
return ac != nil && (ac.RoleId == s.permConfig.OrgAdminRole && strings.Contains(orgId, ac.OrgId))
return ac != nil && ((ac.OrgId == s.permConfig.NwAdminOrg && ac.RoleId == s.permConfig.NwAdminRole) ||
(ac.RoleId == s.permConfig.OrgAdminRole && strings.Contains(orgId, ac.OrgId)))
}
func (s *QuorumControlsAPI) validateOrg(orgId, pOrgId string) (ExecStatus, error) {

View File

@ -77,10 +77,10 @@ type AccountInfo struct {
}
type OrgDetailInfo struct {
NodeList []NodeInfo `json:"nodeList"`
RoleList []RoleInfo `json:"roleList"`
AcctList []AccountInfo `json:"acctList"`
SubOrgList []string `json:"subOrgList"`
NodeList []NodeInfo `json:"nodeList"`
RoleList []RoleInfo `json:"roleList"`
AcctList []AccountInfo `json:"acctList"`
SubOrgList []string `json:"subOrgList"`
}
type OrgStruct struct {
@ -198,8 +198,10 @@ func (o *OrgCache) UpsertOrg(orgId, parentOrg, ultimateParent string, level *big
pkey := OrgKey{OrgId: parentOrg}
if ent, ok := o.c.Get(pkey); ok {
porg := ent.(*OrgInfo)
porg.SubOrgList = append(porg.SubOrgList, key.OrgId)
o.c.Add(pkey, porg)
if !containsKey(porg.SubOrgList, key.OrgId) {
porg.SubOrgList = append(porg.SubOrgList, key.OrgId)
o.c.Add(pkey, porg)
}
}
}
@ -207,6 +209,15 @@ func (o *OrgCache) UpsertOrg(orgId, parentOrg, ultimateParent string, level *big
o.c.Add(key, norg)
}
func containsKey(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func (o *OrgCache) GetOrg(orgId string) *OrgInfo {
defer o.mux.Unlock()
o.mux.Lock()