NestedFolders: Add API endpoint for descendant count in a folder (#66550)
* Add CountInFolder to RegistryService interface * Add folder children counts api route * Update fake GetFolderChildrenCounts * Add test for getting folder children counts * Add validation to folder children counts handler * Update openapi specs * Update pkg/services/folder/folderimpl/folder.go Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> --------- Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit is contained in:
co-authored by
Sofia Papagiannaki
parent
990b3c07ab
commit
fd434cab58
@@ -623,6 +623,28 @@ func (s *Service) nestedFolderDelete(ctx context.Context, cmd *folder.DeleteFold
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetChildrenCounts(ctx context.Context, cmd *folder.GetChildrenCountsQuery) (folder.ChildrenCounts, error) {
|
||||
if cmd.SignedInUser == nil {
|
||||
return nil, folder.ErrBadRequest.Errorf("missing signed-in user")
|
||||
}
|
||||
if *cmd.UID == "" {
|
||||
return nil, folder.ErrBadRequest.Errorf("missing UID")
|
||||
}
|
||||
if cmd.OrgID < 1 {
|
||||
return nil, folder.ErrBadRequest.Errorf("invalid orgID")
|
||||
}
|
||||
|
||||
countsMap := make(folder.ChildrenCounts, len(s.registry))
|
||||
for _, v := range s.registry {
|
||||
c, err := v.CountInFolder(ctx, cmd.OrgID, *cmd.UID, cmd.SignedInUser)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
countsMap[v.Kind()] += c
|
||||
}
|
||||
return countsMap, nil
|
||||
}
|
||||
|
||||
// MakeUserAdmin is copy of DashboardServiceImpl.MakeUserAdmin
|
||||
func (s *Service) MakeUserAdmin(ctx context.Context, orgID int64, userID, folderID int64, setViewAndEditPermissions bool) error {
|
||||
rtEditor := org.RoleEditor
|
||||
|
||||
Reference in New Issue
Block a user