Bugfixing
This commit is contained in:
@@ -59,7 +59,7 @@ class PhotoMutation:
|
|||||||
@error_logging
|
@error_logging
|
||||||
@authenticated_user_only()
|
@authenticated_user_only()
|
||||||
async def edit_photo(self, info, id: int, input: EditPhotoInput) -> Photo:
|
async def edit_photo(self, info, id: int, input: EditPhotoInput) -> Photo:
|
||||||
return await PhotoMutationResolver().update(id, input, info.context.user_id)
|
return await PhotoMutationResolver().update(info.context, id, input, info.context.user_id)
|
||||||
|
|
||||||
@strawberry.mutation()
|
@strawberry.mutation()
|
||||||
@error_logging
|
@error_logging
|
||||||
@@ -87,4 +87,4 @@ class PhotoMutation:
|
|||||||
if info.context.user_id is None and not copilot_upload_token:
|
if info.context.user_id is None and not copilot_upload_token:
|
||||||
raise_unauthorized()
|
raise_unauthorized()
|
||||||
|
|
||||||
return await PhotoMutationResolver().delete(user_id=info.context.user_id, id=id)
|
return await PhotoMutationResolver().delete(info.context, id=id)
|
||||||
|
|||||||
@@ -2,8 +2,13 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import pymysql.err
|
||||||
|
import sqlalchemy
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from graphql import GraphQLError
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from pymysql.err import IntegrityError
|
||||||
from sqlalchemy import delete, insert, select
|
from sqlalchemy import delete, insert, select
|
||||||
from background_jobs.elevation import add_terrain_elevation_to_photo
|
from background_jobs.elevation import add_terrain_elevation_to_photo
|
||||||
from background_jobs.photo import generate_thumbnail, resize_photo
|
from background_jobs.photo import generate_thumbnail, resize_photo
|
||||||
@@ -61,7 +66,7 @@ class PhotoQueryResolver(BaseQueryResolver):
|
|||||||
|
|
||||||
class PhotoDetailInfo(BaseModel):
|
class PhotoDetailInfo(BaseModel):
|
||||||
filename: str
|
filename: str
|
||||||
original_filename: str
|
original_filename: str | None
|
||||||
path: str
|
path: str
|
||||||
flight_id: int
|
flight_id: int
|
||||||
|
|
||||||
@@ -78,7 +83,7 @@ class PhotoMutationResolver(BaseMutationResolver):
|
|||||||
|
|
||||||
return original_filename
|
return original_filename
|
||||||
|
|
||||||
async def _get_photo_details(self, id: int, user_id: int, copilot_token: Optional[str]):
|
async def _get_photo_details(self, id: int, user_id: int, copilot_token: str | None, copy_original: bool = True):
|
||||||
async with get_session() as db:
|
async with get_session() as db:
|
||||||
if not copilot_token:
|
if not copilot_token:
|
||||||
photo = await self._get_one(db, id, created_by_id=user_id)
|
photo = await self._get_one(db, id, created_by_id=user_id)
|
||||||
@@ -89,11 +94,16 @@ class PhotoMutationResolver(BaseMutationResolver):
|
|||||||
filename = photo.filename + "." + photo.filename_extension
|
filename = photo.filename + "." + photo.filename_extension
|
||||||
|
|
||||||
path = get_photo_basepath(flight_id)
|
path = get_photo_basepath(flight_id)
|
||||||
|
|
||||||
|
original_filename = None
|
||||||
|
if copy_original:
|
||||||
|
original_filename = self._copy_original(path, filename)
|
||||||
|
|
||||||
return PhotoDetailInfo(
|
return PhotoDetailInfo(
|
||||||
flight_id=flight_id,
|
flight_id=flight_id,
|
||||||
path=path,
|
path=path,
|
||||||
filename=filename,
|
filename=filename,
|
||||||
original_filename=self._copy_original(path, filename) # TODO: tohle nedelat v getteru!
|
original_filename=original_filename
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -165,23 +175,23 @@ class PhotoMutationResolver(BaseMutationResolver):
|
|||||||
|
|
||||||
return photo
|
return photo
|
||||||
|
|
||||||
async def update(self, id: int, input: EditPhotoInput, user_id: int) -> Photo:
|
async def update(self, context, id: int, data: EditPhotoInput, user_id: int) -> Photo:
|
||||||
data = input.to_dict()
|
data = data.to_dict()
|
||||||
|
|
||||||
async with get_session() as db:
|
async with get_session() as db:
|
||||||
photo = await self._get_one(db, id, created_by_id=user_id)
|
photo = await self._get_one(db, id, created_by_id=user_id)
|
||||||
if input.point_of_interest:
|
if data.point_of_interest:
|
||||||
data['point_of_interest_id'] = await handle_combobox_save(
|
data['point_of_interest_id'] = await handle_combobox_save(
|
||||||
db,
|
db,
|
||||||
models.PointOfInterest,
|
models.PointOfInterest,
|
||||||
input.point_of_interest,
|
data.point_of_interest,
|
||||||
user_id,
|
user_id,
|
||||||
extra_data={"description": ""}
|
extra_data={"description": ""}
|
||||||
)
|
)
|
||||||
|
|
||||||
if input.copilots is not None:
|
if data.copilots is not None:
|
||||||
await db.execute(delete(models.copilot_has_photo).filter_by(photo_id=id))
|
await db.execute(delete(models.copilot_has_photo).filter_by(photo_id=id))
|
||||||
for copilot in input.copilots:
|
for copilot in data.copilots:
|
||||||
await db.execute(insert(models.copilot_has_photo).values(photo_id=id, copilot_id=copilot.id))
|
await db.execute(insert(models.copilot_has_photo).values(photo_id=id, copilot_id=copilot.id))
|
||||||
|
|
||||||
return await self._do_update(db, obj=photo, data=data)
|
return await self._do_update(db, obj=photo, data=data)
|
||||||
@@ -261,12 +271,15 @@ class PhotoMutationResolver(BaseMutationResolver):
|
|||||||
"cache_key": int(time())
|
"cache_key": int(time())
|
||||||
})
|
})
|
||||||
|
|
||||||
async def delete(self, user_id: int, id: int, **kwargs) -> Photo:
|
async def delete(self, context, id: int, **kwargs) -> Photo:
|
||||||
copilot_upload_token = kwargs.get("copilot_upload_token")
|
copilot_upload_token = kwargs.get("copilot_upload_token")
|
||||||
await self._get_photo_details(id, user_id, copilot_upload_token)
|
await self._get_photo_details(id, context.user_id, copilot_upload_token, copy_original=False)
|
||||||
# ^^ pokud neexistuje, vyhodi vyjimku
|
|
||||||
|
try:
|
||||||
|
photo = await super().delete(context, id)
|
||||||
|
except (IntegrityError, sqlalchemy.exc.IntegrityError):
|
||||||
|
raise GraphQLError("Nelze smazat titulni fotku")
|
||||||
|
|
||||||
photo = await super().delete(user_id, id)
|
|
||||||
base_path = get_photo_basepath(photo.flight_id)
|
base_path = get_photo_basepath(photo.flight_id)
|
||||||
|
|
||||||
files_to_delete = [
|
files_to_delete = [
|
||||||
|
|||||||
Reference in New Issue
Block a user