diff --git a/backend/src/project/service.py b/backend/src/project/service.py index 5ba96760..15dadee5 100644 --- a/backend/src/project/service.py +++ b/backend/src/project/service.py @@ -4,6 +4,7 @@ from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.future import select from src.subject.models import InstructorSubject, StudentSubject, Subject +from datetime import datetime, timezone from .exceptions import ProjectNotFound from .models import Project, Requirement @@ -32,12 +33,15 @@ async def get_project(db: AsyncSession, project_id: int) -> Project: return result.scalars().first() -async def get_projects_by_user(db: AsyncSession, user_id: str) -> tuple[Sequence[Project], Sequence[Project]]: +async def get_projects_by_user(db: AsyncSession, user_id: str) -> tuple: + now_utc = datetime.now(timezone.utc) student_result = await db.execute( select(Project) .join(Subject, Project.subject_id == Subject.id) .join(StudentSubject, StudentSubject.c.subject_id == Subject.id) - .where(StudentSubject.c.uid == user_id) + .where( + (StudentSubject.c.uid == user_id) + ) ) instructor_result = await db.execute( select(Project) diff --git a/backend/src/subject/router.py b/backend/src/subject/router.py index f5edb649..5b22838f 100644 --- a/backend/src/subject/router.py +++ b/backend/src/subject/router.py @@ -8,6 +8,7 @@ from src.user.dependencies import get_authenticated_user, retrieve_user, teacher_or_admin_user_validation from src.user.schemas import User from src.subject.utils import has_subject_privileges +from datetime import datetime, timezone from . import service from .dependencies import ( @@ -177,8 +178,9 @@ async def list_projects( user: User = Depends(get_authenticated_user) ) -> ProjectList: projects = await get_projects_for_subject(db, subject_id) - if not await has_subject_privileges(subject_id, user, db): - projects.projects = list(filter(lambda x: x.is_visible, projects.projects)) + now = datetime.now(timezone.utc) + projects.projects = [ + project for project in projects.projects if project.publish_date <= now and project.is_visible] return projects diff --git a/backend/src/user/dependencies.py b/backend/src/user/dependencies.py index 2ce069d1..ae631624 100644 --- a/backend/src/user/dependencies.py +++ b/backend/src/user/dependencies.py @@ -2,6 +2,7 @@ import src.project.service as project_service import src.subject.service as subject_service import src.user.service as user_service +from datetime import datetime, timezone from fastapi import Depends from sqlalchemy.ext.asyncio import AsyncSession from src.auth.dependencies import jwt_token_validation @@ -81,4 +82,10 @@ async def retrieve_projects( student_projects, instructor_projects = await project_service.get_projects_by_user( db, user.uid ) + now = datetime.now(timezone.utc) + student_projects = [ + project for project in student_projects + if project.publish_date <= now and project.is_visible + ] + return UserProjectList(as_student=student_projects, as_instructor=instructor_projects)