diff --git a/client/pyroclient/client.py b/client/pyroclient/client.py index 4ee1c375..8356876e 100644 --- a/client/pyroclient/client.py +++ b/client/pyroclient/client.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/client/pyroclient/exceptions.py b/client/pyroclient/exceptions.py index 6f18541a..dda90320 100644 --- a/client/pyroclient/exceptions.py +++ b/client/pyroclient/exceptions.py @@ -1,5 +1,4 @@ -# Copyright (C) 2024, Pyronear. - +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/client/setup.py b/client/setup.py index c4a8c0d0..0c29bffe 100644 --- a/client/setup.py +++ b/client/setup.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/scripts/test_e2e.py b/scripts/test_e2e.py index 4677f0d7..5ddaf1d6 100644 --- a/scripts/test_e2e.py +++ b/scripts/test_e2e.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/api/api_v1/endpoints/cameras.py b/src/app/api/api_v1/endpoints/cameras.py index 0aaba1ec..c31f8ce2 100644 --- a/src/app/api/api_v1/endpoints/cameras.py +++ b/src/app/api/api_v1/endpoints/cameras.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. @@ -63,9 +63,6 @@ async def heartbeat( token_payload: TokenPayload = Security(get_jwt, scopes=[Role.CAMERA]), ) -> Camera: # telemetry_client.capture(f"camera|{token_payload.sub}", event="cameras-heartbeat", properties={"camera_id": camera_id}) - camera = cast(Camera, await cameras.get(token_payload.sub, strict=True)) - if token_payload.organization_id != camera.organization_id: - raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Access forbidden.") return await cameras.update(token_payload.sub, LastActive(last_active_at=datetime.utcnow())) @@ -76,9 +73,9 @@ async def create_camera_token( token_payload: TokenPayload = Security(get_jwt, scopes=[UserRole.ADMIN]), ) -> Token: telemetry_client.capture(token_payload.sub, event="cameras-token", properties={"camera_id": camera_id}) - await cameras.get(camera_id, strict=True) + camera = cast(Camera, await cameras.get(camera_id, strict=True)) # create access token using user user_id/user_scopes - token_data = {"sub": str(camera_id), "scopes": ["camera"], "organization_id": token_payload.organization_id} + token_data = {"sub": str(camera_id), "scopes": ["camera"], "organization_id": camera.organization_id} token = create_access_token(token_data, settings.JWT_UNLIMITED) return Token(access_token=token, token_type="bearer") # noqa S106 diff --git a/src/app/api/api_v1/endpoints/detections.py b/src/app/api/api_v1/endpoints/detections.py index 81af7a09..cd609a16 100644 --- a/src/app/api/api_v1/endpoints/detections.py +++ b/src/app/api/api_v1/endpoints/detections.py @@ -75,7 +75,7 @@ async def get_detection( return detection camera = cast(Camera, await cameras.get(detection.camera_id, strict=True)) - if token_payload.organization_id != camera.organization_id and UserRole.ADMIN not in token_payload.scopes: + if token_payload.organization_id != camera.organization_id: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Access forbidden.") return detection @@ -112,7 +112,7 @@ async def fetch_detections( if UserRole.ADMIN in token_payload.scopes: return [elt for elt in await detections.fetch_all()] - cameras_list = await cameras.get_all_by("organization_id", token_payload.organization_id, strict=True) + cameras_list = await cameras.fetch_all(("organization_id", token_payload.organization_id)) camera_ids = [camera.id for camera in cameras_list] return await detections.get_in(camera_ids, "camera_id") diff --git a/src/app/api/api_v1/endpoints/login.py b/src/app/api/api_v1/endpoints/login.py index 1e6fc840..2bf72462 100644 --- a/src/app/api/api_v1/endpoints/login.py +++ b/src/app/api/api_v1/endpoints/login.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/api/api_v1/endpoints/users.py b/src/app/api/api_v1/endpoints/users.py index 8f0075ab..1ef02444 100644 --- a/src/app/api/api_v1/endpoints/users.py +++ b/src/app/api/api_v1/endpoints/users.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/crud/base.py b/src/app/crud/base.py index ebecfa1a..8c9f8682 100644 --- a/src/app/crud/base.py +++ b/src/app/crud/base.py @@ -58,18 +58,6 @@ async def get_by(self, field_name: str, val: Union[str, int], strict: bool = Fal ) return entry - async def get_all_by(self, field_name: str, val: Union[str, int], strict: bool = False) -> List[ModelType]: - statement = select(self.model).where(getattr(self.model, field_name) == val) # type: ignore[var-annotated] - results = await self.session.exec(statement=statement) - entries = results.all() - - if strict and not entries: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND, - detail=f"Table {self.model.__name__} has no corresponding entry.", - ) - return entries - async def fetch_all(self, filter_pair: Union[Tuple[str, Any], None] = None) -> List[ModelType]: statement = select(self.model) # type: ignore[var-annotated] if isinstance(filter_pair, tuple): diff --git a/src/app/main.py b/src/app/main.py index 641013d6..976d423f 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/schemas/base.py b/src/app/schemas/base.py index 9772930d..876c125f 100644 --- a/src/app/schemas/base.py +++ b/src/app/schemas/base.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/schemas/cameras.py b/src/app/schemas/cameras.py index 16cd8be1..910f2779 100644 --- a/src/app/schemas/cameras.py +++ b/src/app/schemas/cameras.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/schemas/detections.py b/src/app/schemas/detections.py index 870bb2d9..7336a7ff 100644 --- a/src/app/schemas/detections.py +++ b/src/app/schemas/detections.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/schemas/login.py b/src/app/schemas/login.py index 2b48a9ee..bb0444b2 100644 --- a/src/app/schemas/login.py +++ b/src/app/schemas/login.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details. diff --git a/src/app/schemas/users.py b/src/app/schemas/users.py index 9446fab8..499a910a 100644 --- a/src/app/schemas/users.py +++ b/src/app/schemas/users.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024, Pyronear. +# Copyright (C) 2020-2024, Pyronear. # This program is licensed under the Apache License 2.0. # See LICENSE or go to for full license details.