From 18b3767b449085bcad5807a77448ba274301a5d0 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Tue, 21 May 2024 17:49:30 +0200 Subject: [PATCH 01/13] fix: invalid redirect after create project --- frontend/src/views/CreateProjectView.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/views/CreateProjectView.vue b/frontend/src/views/CreateProjectView.vue index 211f8b3c..9779ebf7 100644 --- a/frontend/src/views/CreateProjectView.vue +++ b/frontend/src/views/CreateProjectView.vue @@ -309,7 +309,7 @@ async function submitForm() { console.error("Error during project or group creation or file upload:", error); setErrorAlert("An unexpected error occurred. Please try again."); } - navigateToProject(projectId.value); + navigateToProject(projectData.project_id); } function formatProjectData() { From d36726c4cee8f379f4b263a1a0d2698453d0139a Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Tue, 21 May 2024 19:03:48 +0200 Subject: [PATCH 02/13] frontend fix: joining group when automatically now works --- frontend/src/queries/Group.ts | 23 +---------------------- frontend/src/views/CreateProjectView.vue | 2 -- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/frontend/src/queries/Group.ts b/frontend/src/queries/Group.ts index 0cdbf151..af7badb3 100644 --- a/frontend/src/queries/Group.ts +++ b/frontend/src/queries/Group.ts @@ -154,35 +154,14 @@ export function useAddToGroupMutation(): UseMutationReturnType< void, Error, { groupId: number; uid: string }, - { previousGroup: Group } + void > { const queryClient = useQueryClient(); return useMutation({ mutationFn: ({ groupId, uid }) => addToGroup(groupId, uid), - onMutate: ({ groupId, uid }) => { - const previousGroup = queryClient.getQueryData(GROUP_QUERY_KEY(groupId)); - // TODO: this is a placeholder and should be replaced with the - // actual user data, but query structure does not support this - // currently - const newGroup = { ...previousGroup! }; - newGroup.members.push({ - uid, - given_name: "placeholder", - surname: "placeholder", - mail: "placeholder", - is_teacher: false, - is_admin: false, - }); - queryClient.setQueryData(GROUP_QUERY_KEY(groupId), newGroup); - return { previousGroup: previousGroup! }; - }, onSuccess: (_, { groupId }) => { queryClient.invalidateQueries({ queryKey: GROUP_QUERY_KEY(groupId) }); }, - onError: (_, { groupId }, ctx) => { - queryClient.setQueryData(GROUP_QUERY_KEY(groupId), ctx!.previousGroup); - alert("Could not join group. Please try again."); - }, }); } diff --git a/frontend/src/views/CreateProjectView.vue b/frontend/src/views/CreateProjectView.vue index 9779ebf7..974f4287 100644 --- a/frontend/src/views/CreateProjectView.vue +++ b/frontend/src/views/CreateProjectView.vue @@ -351,7 +351,6 @@ async function handleGroupCreation(projectId) { const groupsToCreate = groups.map((_, i) => ({ project_id: projectId, score: 0, - team_name: "Group " + (i + 1), })); const createdGroups = await createGroupsMutation.mutateAsync({ projectId: projectId, @@ -381,7 +380,6 @@ function generateEmptyGroups(projectId: number) { emptyGroups.push({ project_id: projectId, score: 0, - team_name: `Group ${i + 1}`, }); } return emptyGroups; From bbaef5e98888f21f7dab193baced792cb46ad391 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Wed, 22 May 2024 13:56:49 +0200 Subject: [PATCH 03/13] fix: register to subject both as student and instructor --- backend/src/subject/router.py | 4 ++++ 1 file changed, 4 insertions(+) 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) From 9e7883d3d42ca91872f36539f4a0fc667be91850 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Wed, 22 May 2024 14:49:24 +0200 Subject: [PATCH 04/13] fix submect mail is null --- backend/src/subject/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 802254762a331579e9c83a52318b47a6160f1690 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Wed, 22 May 2024 14:58:08 +0200 Subject: [PATCH 05/13] fix #185 --- backend/src/group/dependencies.py | 6 +++++- backend/src/group/exceptions.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/group/dependencies.py b/backend/src/group/dependencies.py index 4d916835..d9db5073 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..c5d247d2 100644 --- a/backend/src/group/exceptions.py +++ b/backend/src/group/exceptions.py @@ -17,3 +17,8 @@ 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") From 800d52d41b7d5443fe6fb201196b383ba4fc64d6 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Wed, 22 May 2024 15:06:53 +0200 Subject: [PATCH 06/13] fix weird groups styling --- frontend/src/components/groups/GroupCard.vue | 48 ++++++++++---------- frontend/src/views/GroupsView.vue | 4 +- 2 files changed, 27 insertions(+), 25 deletions(-) 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/views/GroupsView.vue b/frontend/src/views/GroupsView.vue index 140c0061..95cbdda5 100644 --- a/frontend/src/views/GroupsView.vue +++ b/frontend/src/views/GroupsView.vue @@ -7,7 +7,7 @@

{{ "Project: " + project!.name }}

-
+ {{ $t("group.groups") }} {{ $t("group.members") }} @@ -22,7 +22,7 @@ :isTeacher="isTeacher!" class="group-card" /> -
+
{{ $t("group.not_found2") }} From 9c4cd8c1ca8d3c7ac65cff295e71dff5eca05456 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Wed, 22 May 2024 15:22:23 +0200 Subject: [PATCH 07/13] fix broken router push --- .../src/components/home/listcontent/DeadlineItem.vue | 11 ++++------- .../src/components/home/listcontent/SubjectItem.vue | 10 ++++------ 2 files changed, 8 insertions(+), 13 deletions(-) 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 @@