Skip to content

Commit cea9973

Browse files
committed
sqsdqd
1 parent e362d29 commit cea9973

3 files changed

Lines changed: 14 additions & 28 deletions

File tree

core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def get_client_ip(request: HttpRequest) -> str | None:
210210
return None
211211

212212

213-
Filterable = models.Model | models.QuerySet | models.Manager
213+
Filterable = type[models.Model] | models.QuerySet | models.Manager
214214
ListFilter = dict[str, list | tuple | set]
215215

216216

sas/api.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from django.conf import settings
44
from django.core.exceptions import ValidationError
5-
from django.shortcuts import get_list_or_404
65
from django.urls import reverse
76
from ninja import Body, Query, UploadedFile
87
from 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")
120115
class 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()

sas/schemas.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,10 @@ class Meta:
2626
class AlbumSchema(ModelSchema):
2727
class Meta:
2828
model = Album
29-
fields = ["id", "name", "is_moderated"]
29+
fields = ["id", "name", "is_moderated", "thumbnail"]
3030

31-
thumbnail: str | None
3231
sas_url: str
3332

34-
@staticmethod
35-
def resolve_thumbnail(obj: Album) -> str | None:
36-
# Album thumbnails aren't stored in `Album.thumbnail` but in `Album.file`
37-
# Don't ask me why.
38-
if not obj.file:
39-
return None
40-
return obj.get_download_url()
41-
4233
@staticmethod
4334
def resolve_sas_url(obj: Album) -> str:
4435
return obj.get_absolute_url()

0 commit comments

Comments
 (0)