Skip to content

Commit

Permalink
refac: update user task lists & added log for user role
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradip-p committed Oct 19, 2024
1 parent da594b0 commit 8172c12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/backend/app/tasks/task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from app.db import database
from app.utils import send_notification_email, render_email_template
from psycopg.rows import dict_row
from loguru import logger as log

router = APIRouter(
prefix=f"{settings.API_PREFIX}/tasks",
Expand Down Expand Up @@ -124,6 +125,7 @@ async def list_tasks(
"""Get all tasks for a all user."""
user_id = user_data.id
role = user_data.role
log.info(f"Fetching tasks for user {user_id} with role: {role}")
return await task_schemas.UserTasksStatsOut.get_tasks_by_user(
db, user_id, role, skip, limit
)
Expand Down Expand Up @@ -157,8 +159,7 @@ async def new_event(
case EventType.REQUESTS:
# Determine the appropriate state and message
is_author = project["author_id"] == user_id

if user_role != UserRole.DRONE_PILOT and not is_author:
if user_role != UserRole.DRONE_PILOT.name and not is_author:
raise HTTPException(
status_code=403,
detail="Only the project author or drone operators can request tasks for this project.",
Expand Down
13 changes: 2 additions & 11 deletions src/backend/app/tasks/task_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,10 @@ async def get_tasks_by_user(
)
OR
(
%(role)s = 'PROJECT_CREATOR'
AND task_events.project_id IN (
%(role)s = 'PROJECT_CREATOR' AND task_events.project_id IN (
SELECT p.id
FROM projects p
WHERE p.id IN (
SELECT t.project_id
FROM tasks t
WHERE t.project_id IN (
SELECT DISTINCT te2.project_id
FROM task_events te2
WHERE te2.user_id = %(user_id)s
)
)
WHERE p.author_id = %(user_id)s
)
)
ORDER BY
Expand Down

0 comments on commit 8172c12

Please sign in to comment.