Folder UID scope resolver (#46426)
This commit is contained in:
@@ -43,3 +43,23 @@ func NewNameScopeResolver(db Store) (string, ac.AttributeScopeResolveFunc) {
|
||||
}
|
||||
return prefix, resolver
|
||||
}
|
||||
|
||||
// NewUidScopeResolver provides an AttributeScopeResolver that is able to convert a scope prefixed with "folders:uid:" into an id based scope.
|
||||
func NewUidScopeResolver(db Store) (string, ac.AttributeScopeResolveFunc) {
|
||||
prefix := ScopeFoldersProvider.GetResourceScopeUID("")
|
||||
resolver := func(ctx context.Context, orgID int64, scope string) (string, error) {
|
||||
if !strings.HasPrefix(scope, prefix) {
|
||||
return "", ac.ErrInvalidScope
|
||||
}
|
||||
uid := scope[len(prefix):]
|
||||
if len(uid) == 0 {
|
||||
return "", ac.ErrInvalidScope
|
||||
}
|
||||
folder, err := db.GetFolderByUID(ctx, orgID, uid)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return ScopeFoldersProvider.GetResourceScope(strconv.FormatInt(folder.Id, 10)), nil
|
||||
}
|
||||
return prefix, resolver
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user