Merge remote-tracking branch 'quoeng/feature/permissioning-1.8.18-suborgs' into feature/permissioning-1.8.18-suborgs

# Conflicts:
#	core/types/permissions_cache.go
This commit is contained in:
amalraj.manigmail.com 2019-04-11 17:18:48 +08:00
commit cc14183e06
2 changed files with 18 additions and 12 deletions

View File

@ -130,7 +130,8 @@ var (
ErrRoleDoesNotExist = ExecStatus{false, "Role not found for org. Add role first"} ErrRoleDoesNotExist = ExecStatus{false, "Role not found for org. Add role first"}
ErrRoleActive = ExecStatus{false, "Accounts linked to the role. Cannot be removed"} ErrRoleActive = ExecStatus{false, "Accounts linked to the role. Cannot be removed"}
ErrAdminRoles = ExecStatus{false, "Admin role cannot be removed"} ErrAdminRoles = ExecStatus{false, "Admin role cannot be removed"}
ErrInvalidOrgName = ExecStatus{false, "Org id cannot contain '.'"} ErrInvalidOrgName = ExecStatus{false, "Org id cannot contain special characters"}
ErrInvalidParentOrg = ExecStatus{false, "Invalid parent org id"}
ExecSuccess = ExecStatus{true, "Action completed successfully"} ExecSuccess = ExecStatus{true, "Action completed successfully"}
) )
@ -191,7 +192,7 @@ func (s *QuorumControlsAPI) GetOrgDetails(orgId string) types.OrgDetailInfo {
nodeList = append(nodeList, a) nodeList = append(nodeList, a)
} }
} }
return types.OrgDetailInfo{NodeList: nodeList, RoleList: roleList, AcctList: acctList} return types.OrgDetailInfo{NodeList: nodeList, RoleList: roleList, AcctList: acctList, SubOrgList: types.OrgInfoMap.GetOrg(orgId).SubOrgList}
} }
func (s *QuorumControlsAPI) AddOrg(orgId string, url string, acct common.Address, txa ethapi.SendTxArgs) ExecStatus { func (s *QuorumControlsAPI) AddOrg(orgId string, url string, acct common.Address, txa ethapi.SendTxArgs) ExecStatus {
@ -254,13 +255,17 @@ func (s *QuorumControlsAPI) isOrgAdmin(account common.Address, orgId string) boo
return ac != nil && (ac.RoleId == s.permConfig.OrgAdminRole && strings.Contains(orgId, ac.OrgId)) return ac != nil && (ac.RoleId == s.permConfig.OrgAdminRole && strings.Contains(orgId, ac.OrgId))
} }
func (s *QuorumControlsAPI) checkOrgExists(orgId, pOrgId string) bool { func (s *QuorumControlsAPI) validateOrg(orgId, pOrgId string) (ExecStatus, error) {
locOrgId := orgId // validate Parent org id
if pOrgId != "" { if pOrgId != "" && types.OrgInfoMap.GetOrg(pOrgId) == nil {
locOrgId = pOrgId + "." + locOrgId return ErrInvalidParentOrg, errors.New("invalid parent org")
} else {
locOrgId := pOrgId + "." + orgId
if types.OrgInfoMap.GetOrg(locOrgId) != nil {
return ErrOrgExists, errors.New("org exists")
}
} }
org := types.OrgInfoMap.GetOrg(locOrgId) return ExecSuccess, nil
return org != nil
} }
func (s *QuorumControlsAPI) checkNodeExists(enodeId string) bool { func (s *QuorumControlsAPI) checkNodeExists(enodeId string) bool {
@ -364,8 +369,8 @@ func (s *QuorumControlsAPI) executePermAction(action PermAction, args txArgs) Ex
return ErrPendingApprovals return ErrPendingApprovals
} }
// check if org already exists // check if org already exists
if s.checkOrgExists(args.orgId, "") { if execStatus, er := s.validateOrg(args.orgId, ""); er != nil {
return ErrOrgExists return execStatus
} }
// validate node id and // validate node id and
@ -411,8 +416,8 @@ func (s *QuorumControlsAPI) executePermAction(action PermAction, args txArgs) Ex
} }
// check if org already exists // check if org already exists
if s.checkOrgExists(args.orgId, args.porgId) { if execStatus, er := s.validateOrg(args.orgId, args.porgId); er != nil {
return ErrOrgExists return execStatus
} }
// validate node id and // validate node id and

View File

@ -80,6 +80,7 @@ type OrgDetailInfo struct {
NodeList []NodeInfo `json:"nodeList"` NodeList []NodeInfo `json:"nodeList"`
RoleList []RoleInfo `json:"roleList"` RoleList []RoleInfo `json:"roleList"`
AcctList []AccountInfo `json:"acctList"` AcctList []AccountInfo `json:"acctList"`
SubOrgList []string `json:"subOrgList"`
} }
type OrgStruct struct { type OrgStruct struct {