Skip to content

Commit

Permalink
feedback PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronan committed Jul 11, 2024
1 parent 185b2de commit 1877874
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion client/pyroclient/client.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
3 changes: 1 addition & 2 deletions client/pyroclient/exceptions.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.

Expand Down
2 changes: 1 addition & 1 deletion client/setup.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_e2e.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
9 changes: 3 additions & 6 deletions src/app/api/api_v1/endpoints/cameras.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.apache.org/licenses/LICENSE-2.0> for full license details.
Expand Down Expand Up @@ -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()))


Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/app/api/api_v1/endpoints/detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Check warning on line 79 in src/app/api/api_v1/endpoints/detections.py

View check run for this annotation

Codecov / codecov/patch

src/app/api/api_v1/endpoints/detections.py#L79

Added line #L79 was not covered by tests
return detection

Expand Down Expand Up @@ -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")

Check warning on line 118 in src/app/api/api_v1/endpoints/detections.py

View check run for this annotation

Codecov / codecov/patch

src/app/api/api_v1/endpoints/detections.py#L118

Added line #L118 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/api_v1/endpoints/login.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/api_v1/endpoints/users.py
Original file line number Diff line number Diff line change
@@ -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 <https://www.apache.org/licenses/LICENSE-2.0> for full license details.
Expand Down
12 changes: 0 additions & 12 deletions src/app/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion src/app/schemas/base.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion src/app/schemas/cameras.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion src/app/schemas/detections.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion src/app/schemas/login.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down
2 changes: 1 addition & 1 deletion src/app/schemas/users.py
Original file line number Diff line number Diff line change
@@ -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 <https://opensource.org/licenses/Apache-2.0> for full license details.
Expand Down

0 comments on commit 1877874

Please sign in to comment.