diff --git a/backend/src/project/service.py b/backend/src/project/service.py index 5ba96760..40a0b0a6 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 @@ -14,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, diff --git a/backend/src/subject/router.py b/backend/src/subject/router.py index f5edb649..15bd9f67 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] 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) diff --git a/backend/tests/test_project.py b/backend/tests/test_project.py index 559295e6..c58bc52c 100644 --- a/backend/tests/test_project.py +++ b/backend/tests/test_project.py @@ -10,6 +10,7 @@ # skeletons for basic json objects subject = {"name": "test subject"} future_date = datetime.now(timezone.utc) + timedelta(weeks=1) +past_date = datetime.now(timezone.utc) - timedelta(weeks=1) project = { "name": "test project", "subject_id": 0, # temp needs to be filled in by actual subject id @@ -18,7 +19,7 @@ "enroll_deadline": future_date.strftime("%Y-%m-%dT%H:%M:%SZ"), "capacity": 1, "requirements": [{"mandatory": "false", "value": "*.pdf"}], - "publish_date": future_date.strftime("%Y-%m-%dT%H:%M:%SZ"), + "publish_date": past_date.strftime("%Y-%m-%dT%H:%M:%SZ"), } 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")]);