From 54f495d7edaa463274a4d9a3bb776944b845d2cc Mon Sep 17 00:00:00 2001 From: lgdtimtou Date: Thu, 23 May 2024 10:01:11 +0200 Subject: [PATCH 01/21] Docker problemen proberen oplossen --- api/models/indiening.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/models/indiening.py b/api/models/indiening.py index 5190e4f2..0ee37e19 100644 --- a/api/models/indiening.py +++ b/api/models/indiening.py @@ -72,7 +72,9 @@ def __str__(self): return str(self.indiening_id) def save(self, *args, **kwargs): - # Update the bestand path if it's still using the temporary path + if "temp" not in self.bestand.name: + super(Indiening, self).save(*args, **kwargs) + if "temp" in self.bestand.name: old_file = self.bestand new_path = self.bestand.name.replace( @@ -95,7 +97,6 @@ def run_tests_async(instance): indiening_id = instance.indiening_id project_id = instance.groep.project.project_id result = run_tests_on(indiening_id, project_id) - with transaction.atomic(): instance.status = -1 if "FAIL" in result else 1 instance.result = result From 2706f3b22357a87388211fc0374dd3165a70bd7e Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 10:39:01 +0200 Subject: [PATCH 02/21] choose groups for students get requests with async await --- .../src/pages/groupsPage/ChooseGroup.tsx | 961 +++++++++--------- 1 file changed, 479 insertions(+), 482 deletions(-) diff --git a/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx b/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx index 84711667..1e848a98 100644 --- a/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx +++ b/frontend/frontend/src/pages/groupsPage/ChooseGroup.tsx @@ -1,11 +1,12 @@ import { Box, + CircularProgress, + Dialog, ListItem, ListItemText, + Skeleton, Stack, Typography, - Dialog, - CircularProgress, } from '@mui/material' import List from '@mui/material/List' import { useEffect, useState } from 'react' @@ -57,7 +58,7 @@ function joinLeaveButton( ) } - if (disabled){ + if (disabled) { return ( <> {t('group_full')} @@ -87,90 +88,51 @@ export function ChooseGroup() { const [userLoading, setUserLoading] = useState(true) const assignmentId = params.assignmentId + const courseid = params.courseId const handleClose = () => { setOpen(false) } useEffect(() => { - setUserLoading(true) - setLoading(true) - instance - .get('/gebruikers/me/') - .then((res) => { - setUser(res.data) - }) - .catch((err) => { - console.log(err) - }) - setUserLoading(false) - instance - .get('/projecten/' + assignmentId + '/') - .then((res) => { - setAssignment(res.data) - }) - .catch((err) => { - console.log(err) - }) - instance - .get('projecten/' + assignmentId) - .then((res) => { - instance - .get('vakken/' + res.data.vak) - .then((res) => { - //setStudenten(res.data.studenten) - for (let i = 0; i < res.data.studenten.length; i++) { - const studentid = res.data.studenten[i] - instance - .get('gebruikers/' + studentid) - .then((res) => { - setStudenten((oldstudenten) => { - return { - ...oldstudenten, - [res.data.user]: res.data, - } - }) - }) - .catch((err) => { - console.log(err) - }) - } - }) - .catch((err) => { - console.log(err) - }) - }) - .catch((err) => { - console.log(err) - }) + async function fetchData() { + setLoading(true) + setUserLoading(true) + try { + const user = await instance.get('/gebruikers/me/') + setUser(user.data) + setUserLoading(false) - instance - .get('groepen/?project=' + assignmentId) - .then((res) => { - for (let i = 0; i < res.data.length; i++) { - setGroups((oldGroups) => { - let found = false - const id = res.data[i].groep_id - for (const group of oldGroups) { - if (group.groep_id == id) { - found = true - } - } - if (found) { - return oldGroups - } else { - return [...oldGroups, res.data[i]].sort((a, b) => { - return a.groep_id - b.groep_id - }) + const assignment = await instance.get( + '/projecten/' + assignmentId + '/' + ) + setAssignment(assignment.data) + + const course = await instance.get('vakken/' + courseid) + for (let i = 0; i < course.data.studenten.length; i++) { + const studentid = course.data.studenten[i] + const student = await instance.get( + 'gebruikers/' + studentid + ) + setStudenten((oldstudenten) => { + return { + ...oldstudenten, + [student.data.user]: student.data, } }) } - }) - .catch((err) => { - console.log(err) - }) - setLoading(false) - }, []) + const groups = await instance.get( + 'groepen/?project=' + assignmentId + ) + setGroups(groups.data) + } catch (err) { + console.error(err) + } finally { + setLoading(false) + } + } + fetchData().catch((err) => console.error(err)) + }, [assignmentId, courseid]) return ( <> @@ -253,436 +215,471 @@ export function ChooseGroup() { }, }} > - {groups.map((group: Group) => { - //const group=getGroup(id) + {loading ? ( + [...Array(3)].map(() => ( + + )) + ) : ( + <> + {groups.map( + (group: Group) => { + //const group=getGroup(id) - const handleJoin = () => { - setGroups( - ( - oldGroups - ): Group[] => { - if ( - user == - undefined - ) { - return oldGroups - } - if ( - assignment == - undefined - ) { - return oldGroups - } + const handleJoin = + () => { + setGroups( + ( + oldGroups + ): Group[] => { + if ( + user == + undefined + ) { + return oldGroups + } + if ( + assignment == + undefined + ) { + return oldGroups + } - let j = 0 + let j = 0 - let edittedgroup = - undefined + let edittedgroup = + undefined - for ( - let i = 0; - i < - oldGroups.length; - i++ - ) { - if ( - oldGroups[ - i - ].studenten.includes( - user.user - ) - ) { - const newgroup1 = - { - groep_id: - oldGroups[ - i - ] - .groep_id, - project: - oldGroups[ - i - ] - .project, - studenten: - oldGroups[ - i - ].studenten.filter( - ( - student - ) => - student != + for ( + let i = 0; + i < + oldGroups.length; + i++ + ) { + if ( + oldGroups[ + i + ].studenten.includes( user.user - ), - } + ) + ) { + const newgroup1 = + { + groep_id: + oldGroups[ + i + ] + .groep_id, + project: + oldGroups[ + i + ] + .project, + studenten: + oldGroups[ + i + ].studenten.filter( + ( + student + ) => + student != + user.user + ), + } - instance - .patch( - 'groepen/' + - oldGroups[ - i - ] - .groep_id + - '/', - { - studenten: - oldGroups[ + instance + .patch( + 'groepen/' + + oldGroups[ + i + ] + .groep_id + + '/', + { + studenten: + oldGroups[ + i + ].studenten.filter( + ( + student + ) => + student != + user.user + ), + } + ) + .catch( + ( + err + ) => { + console.log( + err + ) + } + ) + j = i - ].studenten.filter( - ( - student - ) => - student != - user.user - ), - } - ) - .catch( - ( - err - ) => { - console.log( - err - ) + edittedgroup = + newgroup1 + } } - ) - j = i - edittedgroup = - newgroup1 - } - } - for ( - let i = 0; - i < - oldGroups.length; - i++ - ) { - if ( - oldGroups[i] - .groep_id == - group.groep_id - ) { - if ( - group - .studenten - .length >= - assignment.max_groep_grootte - ) { - return oldGroups - } - const newgroup = - { - groep_id: - group.groep_id, - project: - group.project, - studenten: - [ - ...group.studenten, - user.user, - ], - } - instance - .patch( - 'groepen/' + - group.groep_id + - '/', - { - studenten: - [ - ...group.studenten, - user.user, - ], - } - ) - .catch( - ( - err - ) => { - console.log( - err - ) - } - ) + for ( + let i = 0; + i < + oldGroups.length; + i++ + ) { + if ( + oldGroups[ + i + ] + .groep_id == + group.groep_id + ) { + if ( + group + .studenten + .length >= + assignment.max_groep_grootte + ) { + return oldGroups + } + const newgroup = + { + groep_id: + group.groep_id, + project: + group.project, + studenten: + [ + ...group.studenten, + user.user, + ], + } + instance + .patch( + 'groepen/' + + group.groep_id + + '/', + { + studenten: + [ + ...group.studenten, + user.user, + ], + } + ) + .catch( + ( + err + ) => { + console.log( + err + ) + } + ) - if ( - edittedgroup != - undefined - ) { - if ( - i < - j - ) { - return [ - ...oldGroups.slice( - 0, - i - ), - newgroup, - ...oldGroups.slice( - i + - 1, - j - ), - edittedgroup, - ...oldGroups.slice( - j + - 1 - ), - ].sort( - ( - a, - b - ) => { - return ( - a.groep_id - - b.groep_id + if ( + edittedgroup != + undefined + ) { + if ( + i < + j + ) { + return [ + ...oldGroups.slice( + 0, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1, + j + ), + edittedgroup, + ...oldGroups.slice( + j + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } + ) + } + return [ + ...oldGroups.slice( + 0, + j + ), + edittedgroup, + ...oldGroups.slice( + j + + 1, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } + ) + } + + return [ + ...oldGroups.slice( + 0, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } ) } - ) - } - return [ - ...oldGroups.slice( - 0, - j - ), - edittedgroup, - ...oldGroups.slice( - j + - 1, - i - ), - newgroup, - ...oldGroups.slice( - i + - 1 - ), - ].sort( - ( - a, - b - ) => { - return ( - a.groep_id - - b.groep_id - ) } - ) - } - - return [ - ...oldGroups.slice( - 0, - i - ), - newgroup, - ...oldGroups.slice( - i + - 1 - ), - ].sort( - ( - a, - b - ) => { - return ( - a.groep_id - - b.groep_id - ) + return oldGroups } ) } - } - return oldGroups - } - ) - } - const handleLeave = () => { - setGroups((oldGroups) => { - if (user == undefined) { - return oldGroups - } - for ( - let i = 0; - i < - oldGroups.length; - i++ - ) { - if ( - oldGroups[i] - .groep_id == - group.groep_id - ) { - const newgroup = - { - groep_id: - group.groep_id, - project: - group.project, - studenten: - group.studenten.filter( - ( - student - ) => - student != - user.user - ), - } - instance - .patch( - 'groepen/' + - group.groep_id + - '/', - { - studenten: - group.studenten.filter( - ( - student - ) => - student != - user.user - ), - } - ) - .catch( + const handleLeave = + () => { + setGroups( ( - err + oldGroups ) => { - console.log( - err - ) + if ( + user == + undefined + ) { + return oldGroups + } + for ( + let i = 0; + i < + oldGroups.length; + i++ + ) { + if ( + oldGroups[ + i + ] + .groep_id == + group.groep_id + ) { + const newgroup = + { + groep_id: + group.groep_id, + project: + group.project, + studenten: + group.studenten.filter( + ( + student + ) => + student != + user.user + ), + } + instance + .patch( + 'groepen/' + + group.groep_id + + '/', + { + studenten: + group.studenten.filter( + ( + student + ) => + student != + user.user + ), + } + ) + .catch( + ( + err + ) => { + console.log( + err + ) + } + ) + + return [ + ...oldGroups.slice( + 0, + i + ), + newgroup, + ...oldGroups.slice( + i + + 1 + ), + ].sort( + ( + a, + b + ) => { + return ( + a.groep_id - + b.groep_id + ) + } + ) + } + } + return oldGroups } ) + } - return [ - ...oldGroups.slice( - 0, - i - ), - newgroup, - ...oldGroups.slice( - i + 1 - ), - ].sort( - (a, b) => { - return ( - a.groep_id - - b.groep_id - ) - } - ) - } - } - return oldGroups - }) - } - - return ( - <> - - - , - + + - {loading ? ( - - {t( - 'members_loading' - )} - - ) : ( - <> - {group - .studenten - .length > - 0 ? ( - group.studenten.map( - ( - studentid - ) => { - const student = - studenten[ - studentid - ] - if ( - student - ) { - console.log( - 'Student:', - student - ) - return ( - , + + {loading ? ( + + {t( + 'members_loading' + )} + + ) : ( + <> + {group + .studenten + .length > + 0 ? ( + group.studenten.map( + ( + studentid + ) => { + const student = + studenten[ + studentid + ] + if ( + student + ) { + console.log( + 'Student:', + student + ) + return ( + + {student.first_name + + ' ' + + student.last_name} + + ) } - > - {student.first_name + - ' ' + - student.last_name} - + return null + } ) - } - return null - } - ) - ) : ( - - {t( - 'no_members_yet' - )} - - )} - - )} - , - <> - {joinLeaveButton( - user != - undefined - ? group.studenten.includes( - user.user - ) - : false, - group.studenten.length === assignment?.max_groep_grootte - && !(user != - undefined - ? group.studenten.includes( - user.user - ) - : false), - handleJoin, - handleLeave - )} - , - ]} - /> - - - ) - })} + ) : ( + + {t( + 'no_members_yet' + )} + + )} + + )} + , + <> + {joinLeaveButton( + user != + undefined + ? group.studenten.includes( + user.user + ) + : false, + group + .studenten + .length === + assignment?.max_groep_grootte && + !(user != + undefined + ? group.studenten.includes( + user.user + ) + : false), + handleJoin, + handleLeave + )} + , + ]} + /> + + + ) + } + )} + + )} Date: Thu, 23 May 2024 11:13:29 +0200 Subject: [PATCH 03/21] Kleine bugfix --- api/models/indiening.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/models/indiening.py b/api/models/indiening.py index 0ee37e19..324a86df 100644 --- a/api/models/indiening.py +++ b/api/models/indiening.py @@ -81,7 +81,6 @@ def save(self, *args, **kwargs): "temp", f"indiening_{self.indiening_id}" ) default_storage.save(new_path, ContentFile(old_file.read())) - old_file.storage.delete(old_file.name) self.bestand.name = new_path super(Indiening, self).save(*args, **kwargs) From 9bc57f7a08cff269014dece9712ba25b5f533be0 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 11:21:05 +0200 Subject: [PATCH 04/21] changed regex --- .../SubmissionListItemTeacherPage.tsx | 2 +- .../pages/submissionPage/SubmissionPage.tsx | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx index f3f748f5..7caf7e76 100644 --- a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx +++ b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx @@ -77,7 +77,7 @@ export function SubmissionListItemTeacherPage({ ) newSubmission.bestand = await instance .get( - `/indieningen/${lastSubmission.indiening_id}/indiening_bestand`, + `/indieningen/${lastSubmission.indiening_id}/indiening_bestand/`, { responseType: 'blob', } diff --git a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx index 3255e349..920a9ceb 100644 --- a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx +++ b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx @@ -135,20 +135,20 @@ export function SubmissionPage() { //Get the submission file const newSubmission: Submission = submissionResponse.data - if (newSubmission.result !== 'No tests: OK') { + if ( + newSubmission.status !== SubmissionStatus.PENDING && + newSubmission.result !== 'No tests: OK' + ) { const regex = /Testing (.*)$/ const matches = newSubmission.result.match(regex) if (matches !== null) { - matches.map((match) => { - match.replace(':', '\n') - return match - }) + newSubmission.result = matches[0] } } newSubmission.filename = submissionResponse.data.bestand.replace(/^.*[\\/]/, '') newSubmission.bestand = await instance - .get(`/indieningen/${submissionId}/indiening_bestand`, { + .get(`/indieningen/${submissionId}/indiening_bestand/`, { responseType: 'blob', }) .then((res) => { @@ -225,9 +225,11 @@ export function SubmissionPage() { } // Fetch students - fetchStudents().catch((error) => - console.error('Error fetching students data:', error) - ) + if (submission) { + fetchStudents().catch((error) => + console.error('Error fetching students data:', error) + ) + } }, [submission]) if (fetchError) { From 4db520a54b24280bbc8063c8c549554bee3c7318 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 11:51:12 +0200 Subject: [PATCH 05/21] changed regex --- .../SubmissionListItemTeacherPage.tsx | 23 +++++++++++-------- .../src/pages/groupsPage/GroupsPage.tsx | 14 +++++------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx index 7caf7e76..00b5c997 100644 --- a/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx +++ b/frontend/frontend/src/components/SubmissionListItemTeacherPage.tsx @@ -59,10 +59,13 @@ export function SubmissionListItemTeacherPage({ const submissionsResponse = await instance.get( `/indieningen/?groep=${group_id}` ) - const lastSubmission = - submissionsResponse.data[ - submissionsResponse.data.length - 1 - ] + const lastSubmission = submissionsResponse.data.sort( + (a: Submission, b: Submission) => { + return dayjs(a.tijdstip).isBefore(dayjs(b.tijdstip)) + ? -1 + : 1 + } + )[submissionsResponse.data.length - 1] if (lastSubmission) { const lastSubmissionResponse = await instance.get( `indieningen/${lastSubmission.indiening_id}/` @@ -175,12 +178,14 @@ export function SubmissionListItemTeacherPage({ + ) : submitted.status > 0 ? ( + ) : ( - submitted !== undefined && ( - - ) + )} , diff --git a/frontend/frontend/src/pages/groupsPage/GroupsPage.tsx b/frontend/frontend/src/pages/groupsPage/GroupsPage.tsx index 34b39967..5b59f141 100644 --- a/frontend/frontend/src/pages/groupsPage/GroupsPage.tsx +++ b/frontend/frontend/src/pages/groupsPage/GroupsPage.tsx @@ -220,15 +220,13 @@ export function GroupsPage() { }, [assignmentId, courseId]) useEffect(() => { - setAvailableStudents(() => - Array.from(studentNames.keys()).filter( - (student) => - !newGroups.some((group) => - group.studenten.includes(student) - ) - ) + const filteredStudents = Array.from(studentNames.keys()).filter( + (student) => + !newGroups.some((group) => group.studenten.includes(student)) ) - setFilteredStudents(availableStudents) + + setAvailableStudents(filteredStudents) + setFilteredStudents(filteredStudents) }, [newGroups, studentNames]) //Handle current group change From db28cf27edeaedc25875f2b463375770c06124cd Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 11:52:38 +0200 Subject: [PATCH 06/21] changed status --- frontend/frontend/src/components/CourseCard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/frontend/src/components/CourseCard.tsx b/frontend/frontend/src/components/CourseCard.tsx index 42a11c06..9b62b179 100644 --- a/frontend/frontend/src/components/CourseCard.tsx +++ b/frontend/frontend/src/components/CourseCard.tsx @@ -161,7 +161,7 @@ export function CourseCard({ if (!mySubmission) { return SubmissionStatus.FAIL } - + console.log('myStatus', mySubmission.status) return mySubmission.status } From 1216ea846130a591163223268f37ae2b7b514515 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 12:04:32 +0200 Subject: [PATCH 07/21] changed requested submisson homepage --- frontend/frontend/src/components/CourseCard.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/frontend/src/components/CourseCard.tsx b/frontend/frontend/src/components/CourseCard.tsx index 9b62b179..f1960930 100644 --- a/frontend/frontend/src/components/CourseCard.tsx +++ b/frontend/frontend/src/components/CourseCard.tsx @@ -97,10 +97,14 @@ export function CourseCard({ setGroups(groups) const submissionPromises = groups.map(async (group) => { - const response = await instance.get( + const response = await instance.get( `/indieningen/?project=${group.project}&groep=${group.groep_id}` ) - return response.data + return response.data.sort( + (a: Submission, b: Submission) => { + return dayjs(b.tijdstip).diff(dayjs(a.tijdstip)) + } + )[0] }) const submissions = await axios.all(submissionPromises) From d960444d7a312513f649f497570f09cfef708e90 Mon Sep 17 00:00:00 2001 From: Ben De Meurichy Date: Thu, 23 May 2024 12:20:28 +0200 Subject: [PATCH 08/21] changed requested submisson homepage --- frontend/frontend/src/components/CourseCard.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/frontend/src/components/CourseCard.tsx b/frontend/frontend/src/components/CourseCard.tsx index f1960930..c59b055b 100644 --- a/frontend/frontend/src/components/CourseCard.tsx +++ b/frontend/frontend/src/components/CourseCard.tsx @@ -159,7 +159,8 @@ export function CourseCard({ } const mySubmission = submissions.find( - (submission) => submission.groep === myGroup.groep_id + (submission) => + (submission ? submission.groep : 0) === myGroup.groep_id ) if (!mySubmission) { From 17ce0df551cf3a779172cad850bce43824ab3fe6 Mon Sep 17 00:00:00 2001 From: lgdtimtou Date: Thu, 23 May 2024 13:20:40 +0200 Subject: [PATCH 09/21] Bepaalde permissies aanpassen zodat gebruiker groep kan verlaten en ook groepen kan opvragen --- api/views/groep.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/api/views/groep.py b/api/views/groep.py index bccf1714..df73a9a3 100644 --- a/api/views/groep.py +++ b/api/views/groep.py @@ -28,10 +28,7 @@ def groep_list(request, format=None): Response: Een lijst van groepen of een nieuw aangemaakte groep. """ if request.method == "GET": - if has_permissions(request.user): - groepen = Groep.objects.all() - else: - groepen = Groep.objects.filter(studenten=request.user.id) + groepen = Groep.objects.all() if "project" in request.GET: try: @@ -78,12 +75,10 @@ def groep_detail(request, id, format=None): except Groep.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == "GET": - if has_permissions(request.user) or contains(groep.studenten, request.user): - serializer = GroepSerializer(groep) - return Response(serializer.data) - return Response(status=status.HTTP_403_FORBIDDEN) + serializer = GroepSerializer(groep) + return Response(serializer.data) - if has_permissions(request.user): + if has_permissions(request.user) or contains(groep.studenten, request.user): if request.method in ["PUT", "PATCH"]: if request.method == "PUT": serializer = GroepSerializer(groep, data=request.data) @@ -93,8 +88,9 @@ def groep_detail(request, id, format=None): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - elif request.method == "DELETE": + + if has_permissions(request.user): + if request.method == "DELETE": groep.delete() return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_403_FORBIDDEN) From 14518faa43137d06d58a90387c5f00c2d73fd188 Mon Sep 17 00:00:00 2001 From: lgdtimtou Date: Thu, 23 May 2024 13:34:48 +0200 Subject: [PATCH 10/21] Permissies aanpassen --- api/serializers/groep.py | 25 +++---------------------- api/views/groep.py | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/api/serializers/groep.py b/api/serializers/groep.py index 6262a306..b42a2337 100644 --- a/api/serializers/groep.py +++ b/api/serializers/groep.py @@ -50,10 +50,9 @@ def update(self, instance, validated_data): Groep: De bijgewerkte groep. """ students_data = validated_data.pop("studenten", instance.studenten.all()) - new_project = validated_data.get("project", instance.project) - validate_students(students_data, new_project, current_group=instance) - validate_project(instance, new_project) - validate_groep_grootte(students_data, new_project) + validated_data.pop("project", instance.project) + validate_students(students_data, instance.project, current_group=instance) + validate_groep_grootte(students_data, instance.project) super().update(instance=instance, validated_data=validated_data) instance.studenten.set(students_data) @@ -62,24 +61,6 @@ def update(self, instance, validated_data): return instance -def validate_project(instance, new_project): - """ - Valideert of het project van een groep niet kan worden aangepast. - - Args: - instance: De huidige instantie van het project. - new_project: Het nieuwe project waaraan de groep wil worden gekoppeld. - - Raises: - serializers.ValidationError: Wordt opgegooid als het project van een groep wordt aangepast. - """ - - if instance.project != new_project: - raise serializers.ValidationError( - "Het project van een groep kan niet aangepast worden" - ) - - def validate_students(students_data, project, current_group=None): """ Controleert of de opgegeven gebruikers studenten zijn en of ze al in een andere groep voor dit project zitten. diff --git a/api/views/groep.py b/api/views/groep.py index df73a9a3..411455f7 100644 --- a/api/views/groep.py +++ b/api/views/groep.py @@ -4,7 +4,7 @@ from api.models.groep import Groep from api.serializers.groep import GroepSerializer -from api.utils import has_permissions, contains +from api.utils import has_permissions @api_view(["GET", "POST"]) @@ -78,17 +78,16 @@ def groep_detail(request, id, format=None): serializer = GroepSerializer(groep) return Response(serializer.data) - if has_permissions(request.user) or contains(groep.studenten, request.user): - if request.method in ["PUT", "PATCH"]: - if request.method == "PUT": - serializer = GroepSerializer(groep, data=request.data) - else: - serializer = GroepSerializer(groep, data=request.data, partial=True) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - + if request.method in ["PUT", "PATCH"]: + if request.method == "PUT": + serializer = GroepSerializer(groep, data=request.data) + else: + serializer = GroepSerializer(groep, data=request.data, partial=True) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + if has_permissions(request.user): if request.method == "DELETE": groep.delete() From a8360a32d9bcd92696881e9fac3321f1a304b715 Mon Sep 17 00:00:00 2001 From: Gus Vanpoucke <159711661+gusvanpoucke@users.noreply.github.com> Date: Thu, 23 May 2024 13:59:03 +0200 Subject: [PATCH 11/21] kleine internationalisatie fix --- frontend/frontend/src/i18n/en.ts | 1 + frontend/frontend/src/i18n/nl.ts | 1 + frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/frontend/src/i18n/en.ts b/frontend/frontend/src/i18n/en.ts index c817851a..30ede668 100644 --- a/frontend/frontend/src/i18n/en.ts +++ b/frontend/frontend/src/i18n/en.ts @@ -139,6 +139,7 @@ const english = { add_course: 'Add course', add_project: 'Add project', no_projects: 'No projects', + may_fail: 'May fail', } export default english diff --git a/frontend/frontend/src/i18n/nl.ts b/frontend/frontend/src/i18n/nl.ts index 8091d071..8a45475f 100644 --- a/frontend/frontend/src/i18n/nl.ts +++ b/frontend/frontend/src/i18n/nl.ts @@ -139,6 +139,7 @@ const dutch = { add_course: 'Voeg vak toe', add_project: 'Voeg project toe', no_projects: 'Geen projecten', + may_fail: 'Mag falen', } export default dutch diff --git a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx index 920a9ceb..f4e7f136 100644 --- a/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx +++ b/frontend/frontend/src/pages/submissionPage/SubmissionPage.tsx @@ -442,8 +442,8 @@ export function SubmissionPage() { } > {restriction.moet_slagen - ? 'Moet slagen' - : 'Mag falen'} + ? t('may_fail') + : t('must_pass')} {restriction.artifact && ( + )