Skip to content

Commit

Permalink
Merge branch 'main' of github.com:hotosm/drone-tm into feat/view-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
suzit-10 committed Aug 1, 2024
2 parents dd8047c + 9eb923d commit 6e5ff8d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
16 changes: 6 additions & 10 deletions src/backend/app/tasks/task_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 user(project creator)."""
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
19 changes: 14 additions & 5 deletions src/backend/app/tasks/task_routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."""
"""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})

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
8 changes: 4 additions & 4 deletions src/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e5ff8d

Please sign in to comment.