LibraryPanels/RBAC: Ignore old folder permission check when deleting/patching lib panel (#88422)

* LibraryPanels/RBAC: Ignore old folder permission check when deleting lib panel

* Same for patching
This commit is contained in:
kay delaney 2024-05-30 12:23:20 +01:00 committed by GitHub
parent 4f999f2b6c
commit 8f45003192
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -240,9 +240,12 @@ func (l *LibraryElementService) deleteLibraryElement(c context.Context, signedIn
return err
}
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
// nolint:staticcheck
if err := l.requireEditPermissionsOnFolder(c, signedInUser, element.FolderID); err != nil {
return err
if !l.features.IsEnabled(c, featuremgmt.FlagLibraryPanelRBAC) {
// nolint:staticcheck
if err := l.requireEditPermissionsOnFolder(c, signedInUser, element.FolderID); err != nil {
return err
}
}
// Delete any hanging/invalid connections
@ -538,17 +541,20 @@ func (l *LibraryElementService) handleFolderIDPatches(ctx context.Context, eleme
toFolderID = fromFolderID
}
// FolderID was provided in the PATCH request
if toFolderID != -1 && toFolderID != fromFolderID {
if err := l.requireEditPermissionsOnFolder(ctx, user, toFolderID); err != nil {
if !l.features.IsEnabled(ctx, featuremgmt.FlagLibraryPanelRBAC) {
// FolderID was provided in the PATCH request
if toFolderID != -1 && toFolderID != fromFolderID {
if err := l.requireEditPermissionsOnFolder(ctx, user, toFolderID); err != nil {
return err
}
}
// Always check permissions for the folder where library element resides
if err := l.requireEditPermissionsOnFolder(ctx, user, fromFolderID); err != nil {
return err
}
}
// Always check permissions for the folder where library element resides
if err := l.requireEditPermissionsOnFolder(ctx, user, fromFolderID); err != nil {
return err
}
metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc()
// nolint:staticcheck
elementToPatch.FolderID = toFolderID