22
33from django .conf import settings
44from django .core .exceptions import ValidationError
5- from django .shortcuts import get_list_or_404
65from django .urls import reverse
76from ninja import Body , Query , UploadedFile
87from ninja .errors import HttpError
@@ -73,7 +72,7 @@ def autocomplete_album(self, filters: Query[AlbumFilterSchema]):
7372 Album .objects .viewable_by (self .context .request .user ).order_by ("-date" )
7473 )
7574
76- @route .patch ("/parent" , permissions = [ IsAuthenticated ] )
75+ @route .patch ("/parent" )
7776 def change_album_parent (self , payload : list [MoveAlbumSchema ]):
7877 """Change parents of albums
7978
@@ -87,17 +86,19 @@ def change_album_parent(self, payload: list[MoveAlbumSchema]):
8786 )
8887 if not user .has_perm ("sas.change_album" ):
8988 unauthorized = [a .id for a in albums if not user .can_edit (a )]
90- raise PermissionDenied (
91- f"You can't move the following albums : { unauthorized } "
92- )
89+ if unauthorized :
90+ raise PermissionDenied (
91+ f"You can't move the following albums : { unauthorized } "
92+ )
9393 parents : list [Album ] = get_list_exact_or_404 (
9494 Album , pk__in = {a .new_parent_id for a in payload }
9595 )
9696 if not user .has_perm ("sas.change_album" ):
9797 unauthorized = [a .id for a in parents if not user .can_edit (a )]
98- raise PermissionDenied (
99- f"You can't move to the following albums : { unauthorized } "
100- )
98+ if unauthorized :
99+ raise PermissionDenied (
100+ f"You can't move to the following albums : { unauthorized } "
101+ )
101102 id_to_new_parent = {i .id : i .new_parent_id for i in payload }
102103 for album in albums :
103104 album .parent_id = id_to_new_parent [album .id ]
@@ -109,12 +110,6 @@ def change_album_parent(self, payload: list[MoveAlbumSchema]):
109110 # because we would then have to manage rollbacks on fail.
110111 Album .objects .bulk_update (albums , fields = ["parent_id" ])
111112
112- @route .delete ("" , permissions = [HasPerm ("sas.delete_album" )])
113- def delete_album (self , album_ids : list [int ]):
114- # known caveat : deleting an album doesn't delete the pictures on the disk.
115- # It's a db only operation.
116- albums : list [Album ] = get_list_or_404 (Album , pk__in = album_ids )
117-
118113
119114@api_controller ("/sas/picture" )
120115class PicturesController (ControllerBase ):
@@ -273,9 +268,9 @@ def delete_relation(self, relation_id: NonNegativeInt):
273268 relation = self .get_object_or_exception (PeoplePictureRelation , pk = relation_id )
274269 user : User = self .context .request .user
275270 if (
276- relation .user_id != user .id
277- and not user .is_root
278- and not user .is_in_group (pk = settings .SITH_GROUP_SAS_ADMIN_ID )
271+ relation .user_id != user .id
272+ and not user .is_root
273+ and not user .is_in_group (pk = settings .SITH_GROUP_SAS_ADMIN_ID )
279274 ):
280275 raise PermissionDenied
281276 relation .delete ()
0 commit comments