From 87dc0f50d44fe2db4074890d8197e47abde049c7 Mon Sep 17 00:00:00 2001 From: drieshuybens Date: Thu, 23 May 2024 12:07:40 +0200 Subject: [PATCH 1/6] publish date checks --- backend/src/project/service.py | 8 ++++++-- backend/src/subject/router.py | 6 ++++-- backend/src/user/dependencies.py | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) 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) From c237e99500390ef43e8984ec8f8741fe45e05255 Mon Sep 17 00:00:00 2001 From: drieshuybens Date: Thu, 23 May 2024 12:10:57 +0200 Subject: [PATCH 2/6] publish date checks --- backend/src/project/service.py | 7 ++----- backend/src/subject/router.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/src/project/service.py b/backend/src/project/service.py index 15dadee5..bb6b5456 100644 --- a/backend/src/project/service.py +++ b/backend/src/project/service.py @@ -33,15 +33,12 @@ 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: - now_utc = datetime.now(timezone.utc) +async def get_projects_by_user(db: AsyncSession, user_id: str) -> tuple[Sequence[Project], Sequence[Project]]: 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 5b22838f..15bd9f67 100644 --- a/backend/src/subject/router.py +++ b/backend/src/subject/router.py @@ -181,6 +181,6 @@ async def list_projects( if not await has_subject_privileges(subject_id, user, db): now = datetime.now(timezone.utc) projects.projects = [ - project for project in projects.projects if project.publish_date <= now and project.is_visible] + project for project in projects.projects if project.publish_date <= now] return projects From 5d498d60a7b96de113a89f775104d46b03be6977 Mon Sep 17 00:00:00 2001 From: drieshuybens Date: Thu, 23 May 2024 15:12:15 +0200 Subject: [PATCH 3/6] lol --- backend/src/project/service.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/project/service.py b/backend/src/project/service.py index bb6b5456..5c699e29 100644 --- a/backend/src/project/service.py +++ b/backend/src/project/service.py @@ -15,6 +15,7 @@ async def create_project(db: AsyncSession, project_in: ProjectCreate) -> Project new_project = Project( name=project_in.name, deadline=project_in.deadline, + publish_date = project_in.publish_date, subject_id=project_in.subject_id, description=project_in.description, is_visible=project_in.is_visible, From a51235c4eb7efd978a9840bc8c73234888ab351c Mon Sep 17 00:00:00 2001 From: drieshuybens Date: Thu, 23 May 2024 15:12:35 +0200 Subject: [PATCH 4/6] lol --- backend/src/project/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/project/service.py b/backend/src/project/service.py index 5c699e29..40a0b0a6 100644 --- a/backend/src/project/service.py +++ b/backend/src/project/service.py @@ -15,7 +15,7 @@ async def create_project(db: AsyncSession, project_in: ProjectCreate) -> Project new_project = Project( name=project_in.name, deadline=project_in.deadline, - publish_date = project_in.publish_date, + publish_date=project_in.publish_date, subject_id=project_in.subject_id, description=project_in.description, is_visible=project_in.is_visible, From 7c96de6990d4f09b4745258840bf8c6dfecdcc02 Mon Sep 17 00:00:00 2001 From: drieshuybens Date: Thu, 23 May 2024 16:46:26 +0200 Subject: [PATCH 5/6] extra validatie --- frontend/src/i18n/locales/en.ts | 3 +++ frontend/src/i18n/locales/nl.ts | 3 +++ frontend/src/views/CreateProjectView.vue | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts index 8212be92..0841d67e 100644 --- a/frontend/src/i18n/locales/en.ts +++ b/frontend/src/i18n/locales/en.ts @@ -97,6 +97,9 @@ export default { testfiles: "Testfiles", requirements_disclaimer: "For info on the usage of requirements please visit our", to_project: "To Project", + titlereq: "Project title is required.", + date_check: "Deadline or publish date cannot be in the past. Please correct the dates.", + publish_check: "Publish date must be before or on the deadline. Please correct the dates.", }, navigation: { home: "Home", diff --git a/frontend/src/i18n/locales/nl.ts b/frontend/src/i18n/locales/nl.ts index 652d7180..af7bb4ac 100644 --- a/frontend/src/i18n/locales/nl.ts +++ b/frontend/src/i18n/locales/nl.ts @@ -99,6 +99,9 @@ export default { testfiles: "Testbestanden", requirements_disclaimer: "Voor info over het gebruik van bestandsvereisten, bezoek onze ", to_project: "Naar project", + titlereq: "Project titel is verplicht.", + date_check: "Deadline of publiceerdatum kan niet in het verleden liggen.", + publish_check: "Publiceerdatum moet voor de deadline liggen.", }, navigation: { home: "Hoofdscherm", diff --git a/frontend/src/views/CreateProjectView.vue b/frontend/src/views/CreateProjectView.vue index 5ed5f619..2f09c4c7 100644 --- a/frontend/src/views/CreateProjectView.vue +++ b/frontend/src/views/CreateProjectView.vue @@ -15,6 +15,7 @@ :label="$t('project.assignment')" required :placeholder="$t('submit.create_title_tip')" + :rules="titleRules" /> [(v) => !!v.trim() || t("project.titlereq")]);