refac: debt on role backend
This commit is contained in:
1 parent
de142f6c5f
commit
a043f7f41a
130 files changed
+3591
-512
No files matched your search
@@ -46,24 +46,15 @@ func (u *GetMyAccessUseCase) Get(account user.User) (Access, error) {
|
||||
if err != nil {
|
||||
return Access{}, err
|
||||
}
|
||||
granted, err := u.roles.ListGrants(resolved.ID)
|
||||
if err != nil {
|
||||
return Access{}, err
|
||||
}
|
||||
return Access{Role: resolved, Permissions: orderedGrants(granted)}, nil
|
||||
return Access{Role: resolved, Permissions: effectiveGrants(resolved.GrantSet())}, nil
|
||||
}
|
||||
|
||||
func orderedGrants(granted []role.Grant) []role.Grant {
|
||||
scopes := make(map[string]role.Scope, len(granted))
|
||||
for _, grant := range granted {
|
||||
scopes[grant.Key] = grant.Scope
|
||||
}
|
||||
ordered := []role.Grant{}
|
||||
func effectiveGrants(grants role.GrantSet) []role.Grant {
|
||||
effective := []role.Grant{}
|
||||
for _, permission := range role.Catalogue() {
|
||||
scope, present := scopes[permission.Key]
|
||||
if present && scope != role.ScopeNone {
|
||||
ordered = append(ordered, role.Grant{Key: permission.Key, Scope: scope})
|
||||
if scope := grants.ScopeFor(permission.Key, ""); scope != role.ScopeNone {
|
||||
effective = append(effective, role.Grant{Key: permission.Key, Scope: scope})
|
||||
}
|
||||
}
|
||||
return ordered
|
||||
return effective
|
||||
}
|
||||
Reference in new issue
Block a user