From 4a1aae9368f38eb657588cdd6491392b48987346 Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Thu, 1 Aug 2024 15:06:34 +0545 Subject: [PATCH 1/3] fix(hot-fix): listed pending task based on project creator --- src/backend/app/tasks/task_crud.py | 16 ++++++---------- src/backend/app/tasks/task_routes.py | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index 2ae11ff2..7670eb44 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -204,19 +204,15 @@ async def get_requested_user_id( return result["user_id"] -async def get_project_task_by_id(db: Database, project_id: uuid.UUID, user_id): - """Get all tasks associated with a specific project by project_id.""" +async def get_project_task_by_id(db: Database, user_id: str): + """Get a list of pending tasks for a specific project and user.""" raw_sql = """ - SELECT t.id AS task_id, te.event_id, te.user_id, te.comment, te.state, te.created_at + SELECT t.id AS task_id, te.event_id, te.user_id, te.project_id, te.comment, te.state, te.created_at FROM tasks t LEFT JOIN task_events te ON t.id = te.task_id - WHERE t.project_id = :project_id - AND te.user_id = :user_id - + WHERE te.user_id = :user_id + AND te.state = 'REQUEST_FOR_MAPPING' ORDER BY t.project_task_index; """ - db_tasks = await db.fetch_all( - raw_sql, {"project_id": project_id, "user_id": user_id} - ) - + db_tasks = await db.fetch_all(raw_sql, {"user_id": user_id}) return db_tasks diff --git a/src/backend/app/tasks/task_routes.py b/src/backend/app/tasks/task_routes.py index faa94bb9..13dfd718 100644 --- a/src/backend/app/tasks/task_routes.py +++ b/src/backend/app/tasks/task_routes.py @@ -1,7 +1,7 @@ import uuid from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException from app.config import settings -from app.models.enums import EventType, State +from app.models.enums import EventType, State, UserRole from app.tasks import task_schemas, task_crud from app.users.user_deps import login_required from app.users.user_schemas import AuthUser @@ -210,16 +210,25 @@ async def new_event( return True -@router.get("/requested_tasks/{project_id}/pending") +@router.get("/requested_tasks/pending") async def get_pending_tasks( - project_id: uuid.UUID, user_data: AuthUser = Depends(login_required), db: Database = Depends(database.get_db), ): """Get a list of pending tasks for a specific project and user.""" user_id = user_data.id + query = """SELECT role FROM user_profile WHERE user_id = :user_id""" + record = await db.fetch_one(query, {"user_id": user_id}) + + if not record: + raise HTTPException(status_code=404, detail="User profile not found") + + if record.role != UserRole.PROJECT_CREATOR.name: + raise HTTPException( + status_code=403, detail="Access forbidden for non-Project Creator users" + ) - pending_tasks = await task_crud.get_project_task_by_id(db, project_id, user_id) + pending_tasks = await task_crud.get_project_task_by_id(db, user_id) if pending_tasks is None: raise HTTPException(status_code=404, detail="Project not found") return pending_tasks From f090a7c9b40126bff8dfb7973272656d1b1a42f6 Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Thu, 1 Aug 2024 15:10:47 +0545 Subject: [PATCH 2/3] fix: docstring on function --- src/backend/app/tasks/task_crud.py | 2 +- src/backend/app/tasks/task_routes.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index 7670eb44..c0748760 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -205,7 +205,7 @@ async def get_requested_user_id( async def get_project_task_by_id(db: Database, user_id: str): - """Get a list of pending tasks for a specific project and user.""" + """Get a list of pending tasks for a specific user(project creator).""" raw_sql = """ SELECT t.id AS task_id, te.event_id, te.user_id, te.project_id, te.comment, te.state, te.created_at FROM tasks t diff --git a/src/backend/app/tasks/task_routes.py b/src/backend/app/tasks/task_routes.py index 13dfd718..43cc6e32 100644 --- a/src/backend/app/tasks/task_routes.py +++ b/src/backend/app/tasks/task_routes.py @@ -215,7 +215,7 @@ async def get_pending_tasks( user_data: AuthUser = Depends(login_required), db: Database = Depends(database.get_db), ): - """Get a list of pending tasks for a specific project and user.""" + """Get a list of pending tasks for a project creator.""" user_id = user_data.id query = """SELECT role FROM user_profile WHERE user_id = :user_id""" record = await db.fetch_one(query, {"user_id": user_id}) From 9eb923d4b454478b71118016cceb39321d9f87ee Mon Sep 17 00:00:00 2001 From: Nischal Shrestha Date: Thu, 1 Aug 2024 15:32:37 +0545 Subject: [PATCH 3/3] fix: frontend Dockerfile case FromAs --- src/frontend/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/frontend/Dockerfile b/src/frontend/Dockerfile index 3d3db29d..7986cf04 100644 --- a/src/frontend/Dockerfile +++ b/src/frontend/Dockerfile @@ -2,24 +2,24 @@ ARG NODE_BASE=18.16.0-bullseye-slim # Base image with frontend code -FROM node:${NODE_BASE} as base +FROM node:${NODE_BASE} AS base RUN mkdir -p /app WORKDIR /app COPY ./src/frontend /app # Run development environment -FROM base as development +FROM base AS development ENTRYPOINT ["/bin/sh", "-c", "env | tee .env ; yarn; yarn start --host 0.0.0.0;"] # Generate frontend build files -FROM base as build +FROM base AS build COPY ../.env .env RUN yarn RUN yarn build # Copy static files to minio and generated index.html to backend services -FROM docker:27.0-dind-rootless as live +FROM docker:27.0-dind-rootless AS live USER 0 RUN apk update && apk add minio-client envsubst COPY --from=build /app/dist /tmp/dist