Skip to content

Commit

Permalink
fix: slove task locking and validation error in project creator (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradip-p authored Dec 5, 2024
1 parent 90ae194 commit 93c126c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
22 changes: 14 additions & 8 deletions src/backend/app/tasks/task_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ async def get_task_stats(db: Connection, user_data: AuthUser):
%(role)s = 'DRONE_PILOT'
AND te.user_id = %(user_id)s
)
OR
(%(role)s = 'PROJECT_CREATOR' AND te.project_id IN (
OR
(
%(role)s = 'PROJECT_CREATOR'
AND (
te.project_id IN (
SELECT p.id
FROM projects p
WHERE p.author_id = %(user_id)s
))
)
OR te.user_id = %(user_id)s -- Grant permissions equivalent to DRONE_PILOT
))
ORDER BY te.task_id, te.created_at DESC
) AS te;
"""
Expand Down Expand Up @@ -284,11 +289,12 @@ async def handle_event(
case EventType.REQUESTS:
# Determine the appropriate state and message
is_author = project["author_id"] == user_id
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.",
)
# NOTE:
# 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.",
# )

requires_approval = project["requires_approval_from_manager_for_locking"]

Expand Down
13 changes: 8 additions & 5 deletions src/backend/app/tasks/task_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,15 @@ 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.author_id = %(user_id)s
)
OR task_events.user_id = %(user_id)s
)
)
ORDER BY
tasks.id, task_events.created_at DESC
OFFSET %(skip)s
Expand All @@ -228,13 +231,13 @@ class TaskDetailsOut(BaseModel):
task_area: float
outline: Outline
created_at: datetime
updated_at: datetime
updated_at: Optional[datetime] = None
state: State
project_name: str
project_task_index: int
front_overlap: float
side_overlap: float
gsd_cm_px: float
front_overlap: Optional[float] = None
side_overlap: Optional[float] = None
gsd_cm_px: Optional[float] = None
gimble_angles_degrees: Optional[int] = None

@field_validator("state", mode="after")
Expand Down

0 comments on commit 93c126c

Please sign in to comment.