diff --git a/backend/src/group/dependencies.py b/backend/src/group/dependencies.py index 4d916835..cbf07a9f 100644 --- a/backend/src/group/dependencies.py +++ b/backend/src/group/dependencies.py @@ -11,7 +11,7 @@ from src.subject.utils import has_subject_privileges from . import service -from .exceptions import AlreadyInGroup, GroupNotFound, MaxCapacity +from .exceptions import AlreadyInGroup, AlreadyInGroupOfProject, GroupNotFound, MaxCapacity async def retrieve_group( @@ -79,5 +79,9 @@ async def join_group( if len(group.members) >= project.capacity: raise MaxCapacity() + groups = await retrieve_groups_by_user(user, db) + if any([group.project_id == g.project_id for g in groups]): + raise AlreadyInGroupOfProject() + await service.join_group(db, group_id, uid) return await service.get_group_by_id(db, group_id) diff --git a/backend/src/group/exceptions.py b/backend/src/group/exceptions.py index 9fda0c9e..c55c03af 100644 --- a/backend/src/group/exceptions.py +++ b/backend/src/group/exceptions.py @@ -17,3 +17,9 @@ class MaxCapacity(HTTPException): def __init__(self): """Raised when user wants to join group at max capacity""" super().__init__(status_code=403, detail="Group at max capacity") + + +class AlreadyInGroupOfProject(HTTPException): + def __init__(self): + """Raised when person is already in another group of the project""" + super().__init__(status_code=403, detail="Already in a Group for this project") diff --git a/backend/src/subject/router.py b/backend/src/subject/router.py index ca0b9eef..f5edb649 100644 --- a/backend/src/subject/router.py +++ b/backend/src/subject/router.py @@ -97,6 +97,8 @@ async def create_subject_instructor( ): if await service.is_instructor(db, subject_id, user.uid): raise AlreadyInstructor() + if await service.is_student(db, subject_id, user.uid): + raise AlreadyRegistered() await service.add_instructor_to_subject(db, subject_id, user.uid) @@ -129,6 +131,8 @@ async def add_student_to_subject( user: User = Depends(retrieve_user), db: AsyncSession = Depends(get_async_db) ) -> Subject: + if await service.is_instructor(db, subject.id, user.uid): + raise AlreadyInstructor() if await service.is_student(db, subject.id, user.uid): raise AlreadyRegistered() await service.create_subject_student(db, subject.id, user.uid) diff --git a/backend/src/subject/service.py b/backend/src/subject/service.py index 5f5e517b..5ee276f2 100644 --- a/backend/src/subject/service.py +++ b/backend/src/subject/service.py @@ -63,7 +63,7 @@ async def is_instructor(db: AsyncSession, subject_id: int, uid: str) -> bool: async def create_subject(db: AsyncSession, subject: SubjectCreate) -> Subject: db_subject = Subject( - name=subject.name, academic_year=subject.academic_year) + name=subject.name, academic_year=subject.academic_year, email=subject.email) db.add(db_subject) await db.commit() await db.refresh(db_subject) diff --git a/frontend/src/components/form_elements/FilesInput.vue b/frontend/src/components/form_elements/FilesInput.vue index a44d8405..005a7cef 100644 --- a/frontend/src/components/form_elements/FilesInput.vue +++ b/frontend/src/components/form_elements/FilesInput.vue @@ -45,9 +45,11 @@ function onAddFilesClick() { } function updateFiles(event: Event) { - // todo: check of meerdere identieke filenames aanwezig zijn const files = (event.target as HTMLInputElement).files!; - inputFiles.value.push(...files); + const unique_files = Array.from(files).filter( + (file) => !inputFiles.value.map((file) => file.name).includes(file.name) + ); + inputFiles.value.push(...unique_files); } function onDeleteClick(index: number) { diff --git a/frontend/src/components/groups/GroupCard.vue b/frontend/src/components/groups/GroupCard.vue index 46963879..7e8c9946 100644 --- a/frontend/src/components/groups/GroupCard.vue +++ b/frontend/src/components/groups/GroupCard.vue @@ -1,28 +1,30 @@ diff --git a/frontend/src/components/home/listcontent/DeadlineItem.vue b/frontend/src/components/home/listcontent/DeadlineItem.vue index e593015f..5690f59d 100644 --- a/frontend/src/components/home/listcontent/DeadlineItem.vue +++ b/frontend/src/components/home/listcontent/DeadlineItem.vue @@ -1,5 +1,5 @@