K8s/Folders: Improve k8s client implementation of get (#96434)
* Enable getting folders with kubernetes client * Add TestIntegrationFolderGetPermissions * Set full path as part of legacy get * Replace implementation for setting fullpath * Add folder get test * Escape forward slash in parent titles * Replace test for access control metadata * Add test case to TestIntegrationFolderGetPermissions * Improve fetching of access control
This commit is contained in:
@@ -286,9 +286,47 @@ func (s *Service) Get(ctx context.Context, q *folder.GetFolderQuery) (*folder.Fo
|
||||
f.FullpathUIDs = f.UID // set full path to the folder UID
|
||||
}
|
||||
|
||||
if s.features.IsEnabled(ctx, featuremgmt.FlagKubernetesFolders) {
|
||||
f, err = s.setFullpath(ctx, f, q.SignedInUser)
|
||||
}
|
||||
|
||||
return f, err
|
||||
}
|
||||
|
||||
func (s *Service) setFullpath(ctx context.Context, f *folder.Folder, user identity.Requester) (*folder.Folder, error) {
|
||||
// #TODO is some kind of intermediate conversion required as is the case with user id where
|
||||
// it gets parsed using UserIdentifier(). Also is there some kind of validation taking place as
|
||||
// part of the parsing?
|
||||
f.CreatedByUID = user.GetUID()
|
||||
f.UpdatedByUID = user.GetUID()
|
||||
|
||||
if f.ParentUID == "" {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// Fetch the parent since the permissions for fetching the newly created folder
|
||||
// are not yet present for the user--this requires a call to ClearUserPermissionCache
|
||||
parents, err := s.GetParents(ctx, folder.GetParentsQuery{
|
||||
UID: f.UID,
|
||||
OrgID: f.OrgID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// #TODO revisit setting permissions so that we can centralise the logic for escaping slashes in titles
|
||||
// Escape forward slashes in the title
|
||||
escapedSlash := "\\/"
|
||||
title := strings.Replace(f.Title, "/", escapedSlash, -1)
|
||||
f.Fullpath = title
|
||||
f.FullpathUIDs = f.UID
|
||||
for _, p := range parents {
|
||||
pt := strings.Replace(p.Title, "/", escapedSlash, -1)
|
||||
f.Fullpath = f.Fullpath + "/" + pt
|
||||
f.FullpathUIDs = f.FullpathUIDs + "/" + p.UID
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetChildren(ctx context.Context, q *folder.GetChildrenQuery) ([]*folder.Folder, error) {
|
||||
defer func(t time.Time) {
|
||||
parent := q.UID
|
||||
@@ -673,33 +711,7 @@ func (s *Service) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (
|
||||
}
|
||||
|
||||
if s.features.IsEnabled(ctx, featuremgmt.FlagKubernetesFolders) {
|
||||
// #TODO is some kind of intermediate conversion required as is the case with user id where
|
||||
// it gets parsed using UserIdentifier(). Also is there some kind of validation taking place as
|
||||
// part of the parsing?
|
||||
f.CreatedByUID = user.GetUID()
|
||||
f.UpdatedByUID = user.GetUID()
|
||||
|
||||
if f.ParentUID == "" {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// Fetch the parent since the permissions for fetching the newly created folder
|
||||
// are not yet present for the user--this requires a call to ClearUserPermissionCache
|
||||
parent, err := s.Get(ctx, &folder.GetFolderQuery{
|
||||
UID: &f.ParentUID,
|
||||
OrgID: f.OrgID,
|
||||
WithFullpath: true,
|
||||
WithFullpathUIDs: true,
|
||||
SignedInUser: user,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// #TODO revisit setting permissions so that we can centralise the logic for escaping slashes in titles
|
||||
// Escape forward slashes in the title
|
||||
title := strings.Replace(f.Title, "/", "\\/", -1)
|
||||
f.Fullpath = title + "/" + parent.Fullpath
|
||||
f.FullpathUIDs = f.UID + "/" + parent.FullpathUIDs
|
||||
f, err = s.setFullpath(ctx, f, user)
|
||||
}
|
||||
|
||||
return f, nil
|
||||
|
||||
Reference in New Issue
Block a user