@@ -17,7 +17,7 @@ and shortly after calls the delete method for the root folder too, it would try
1717whole folder tree and delete all folders & files again. To prevent that there is an map variable
1818that should prevent the user from calling this method multiple times concurrently.
1919*/
20- func DeleteFolders (folderValidation * models.FoldersDeleteValidation , userID uint ) (status int , err error ) {
20+ func DeleteFolders (folderValidation * models.FoldersDeleteValidation , userID uint , isAdmin bool ) (status int , err error ) {
2121
2222 if helpers .UserRequestAsyncObj .Blocked (userID ) {
2323 return http .StatusTooManyRequests , errors .New ("wait until the previous delete request finished" )
@@ -38,10 +38,13 @@ func DeleteFolders(folderValidation *models.FoldersDeleteValidation, userID uint
3838 reqFolderIdDeleteList := []uint {}
3939 var parentFolderID uint = 0
4040 for i , FolderValidation := range folderValidation .FolderIDs {
41- var dbFolder = models.Folder {
42- UserID : userID ,
41+ query := inits .DB .Model (& models.Folder {})
42+ if ! isAdmin {
43+ query = query .Where ("user_id = ?" , userID )
4344 }
44- if res := inits .DB .First (& dbFolder , FolderValidation .FolderID ); res .Error != nil {
45+
46+ var dbFolder models.Folder
47+ if res := query .First (& dbFolder , FolderValidation .FolderID ); res .Error != nil {
4548 return http .StatusBadRequest , fmt .Errorf ("FolderID (%d) doesn't exist" , FolderValidation .FolderID )
4649 }
4750 // check if has same parent folder
@@ -83,7 +86,7 @@ func DeleteFolders(folderValidation *models.FoldersDeleteValidation, userID uint
8386 if len (files ) > 0 {
8487 if status , err := DeleteFiles (& models.LinksDeleteValidation {
8588 LinkIDs : files ,
86- }, userID ); err != nil {
89+ }, userID , isAdmin ); err != nil {
8790 return status , fmt .Errorf ("failed to delete all files from folders: %v" , err )
8891 }
8992 }
0 commit comments