fix error code for delete folder (#42470) (#42519)

(cherry picked from commit e13e6a7bd7)

Co-authored-by: ying-jeanne <74549700+ying-jeanne@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2021-11-30 14:21:31 +01:00
committed by GitHub
co-authored by ying-jeanne
parent e4a85fb951
commit 9d6491be4f
2 changed files with 12 additions and 0 deletions
+6
View File
@@ -692,9 +692,15 @@ func (l *LibraryElementService) deleteLibraryElementsInFolderUID(c context.Conte
if err != nil {
return err
}
if len(folderUIDs) == 0 {
return models.ErrFolderNotFound
}
if len(folderUIDs) != 1 {
return fmt.Errorf("found %d folders, while expecting at most one", len(folderUIDs))
}
folderID := folderUIDs[0].ID
if err := l.requirePermissionsOnFolder(c, signedInUser, folderID); err != nil {
@@ -65,6 +65,12 @@ func TestDeleteLibraryPanelsInFolder(t *testing.T) {
require.EqualError(t, err, ErrFolderHasConnectedLibraryElements.Error())
})
scenarioWithPanel(t, "When an admin tries to delete a folder uid that doesn't exist, it should fail",
func(t *testing.T, sc scenarioContext) {
err := sc.service.DeleteLibraryElementsInFolder(sc.reqContext.Req.Context(), sc.reqContext.SignedInUser, sc.folder.Uid+"xxxx")
require.EqualError(t, err, models.ErrFolderNotFound.Error())
})
scenarioWithPanel(t, "When an admin tries to delete a folder that contains disconnected elements, it should delete all disconnected elements too",
func(t *testing.T, sc scenarioContext) {
command := getCreateVariableCommand(sc.folder.Id, "query0")