(0);
const [confirmSubmit, setConfirmSubmit] = useState(false);
+ const [accessDenied, setAccessDenied] = useState(true);
const isTitleEmpty = !title
@@ -94,7 +105,7 @@ function ProjectEditForm({project_id, add_course_id}: ProjectEditFormProps) {
}
if (project.deadline !== null) setHasDeadline(true);
}
- await getUserData().then((response) => {
+ await fetchUserData().then((response) => {
if (response.role === 3) {
setIsStudent(true);
} else {
@@ -113,7 +124,38 @@ function ProjectEditForm({project_id, add_course_id}: ProjectEditFormProps) {
} else {
setLoadingProject(false);
}
- }, [project_id, loadingTranslations, isStudent, loadingProject, isTeacher]);
+ }, [project_id, isStudent, loadingProject, isTeacher]);
+
+ useEffect(() => {
+ const fetchUser = async () => {
+ try {
+ const user = await fetchUserData();
+ setUser(user)
+ if (!loadingUser && !loadingProject && user) {
+ if (project_id !== null) {
+ if (!user.course.includes(Number(course_id))) {
+ window.location.href = `/403/`;
+ } else {
+ setAccessDenied(false);
+ }
+ } else {
+ if (!user.course.includes(Number(add_course_id))) {
+ window.location.href = `/403/`;
+ } else {
+ setAccessDenied(false);
+ }
+ }
+ }
+ } catch (error) {
+ console.error("There was an error fetching the user data:", error);
+ } finally {
+ setLoadingUser(false);
+ }
+ }
+
+ fetchUser();
+ }, [add_course_id, course_id, loadingProject, loadingUser, project_id]);
+
async function setTestFiles(project: Project) {
@@ -212,12 +254,13 @@ function ProjectEditForm({project_id, add_course_id}: ProjectEditFormProps) {
window.location.href = "/course/" + course_id + "/"
}
- if(loadingProject){
+ if(loadingProject || loadingUser){
return ;
}
return (
(!isStudent) ? (
+ !accessDenied &&
-
-
-
+
)
diff --git a/frontend/cypress/e2e/student/submission_page.cy.ts b/frontend/cypress/e2e/student/submission_page.cy.ts
index 2bc5b7f5..41e04a2a 100644
--- a/frontend/cypress/e2e/student/submission_page.cy.ts
+++ b/frontend/cypress/e2e/student/submission_page.cy.ts
@@ -8,28 +8,19 @@ describe('student project page', () => {
it ('add a submission to a project', () => {
cy.contains('Artificiële intelligentie').click();
- cy.contains('en').click();
- cy.contains('nl').click();
+ cy.contains('English').click();
+ cy.contains('Nederlands').click();
cy.contains('View').click();
cy.contains('Indiening toevoegen').click();
cy.url().should('eq', 'http://localhost:3000/nl/project/2/submit');
cy.contains('submit');
- cy.contains('Project inleveren: AI project')
- cy.contains('Bestanden');
-
- cy.contains('submit').click();
- cy.contains('Fout bij inleveren, probeer het opnieuw');
-
- cy.get('#filepicker').click();
- cy.fixture('submission.txt').then(fileContent => {
- cy.get('input[type="file"]').attachFile({
- fileContent: undefined,
- fileName: 'submission.txt',
- mimeType: 'text/plain'
- });
- });
+ cy.contains('AI project')
+ cy.contains('Upload een map');
+ cy.contains('Upload bestanden');
+
+ cy.contains('submit').should('be.disabled');
});
diff --git a/frontend/lib/api.ts b/frontend/lib/api.ts
index fe2f4c18..37cafd91 100644
--- a/frontend/lib/api.ts
+++ b/frontend/lib/api.ts
@@ -419,8 +419,12 @@ export async function getGroup(id: number): Promise {
}
export async function checkGroup(id: number) {
- let response = await axios.get(backend_url + "/projects/" + id + "/get_group/", {withCredentials: true});
- return response.status !== 404;
+ try {
+ await axios.get(backend_url + "/projects/" + id + "/get_group/", {withCredentials: true});
+ return true;
+ } catch (error) {
+ return false;
+ }
}
export async function getGroups(): Promise {
@@ -507,7 +511,7 @@ export async function getUserData(): Promise {
}
}
-async function fetchUserData() : Promise {
+export async function fetchUserData() : Promise {
try{
userData = await getRequest('/users/current');
localStorage.setItem('user', JSON.stringify({data: userData, lastcache: Date.now().toString()}));
diff --git a/frontend/locales/en/common.json b/frontend/locales/en/common.json
index b306a73e..c6fbd8e7 100644
--- a/frontend/locales/en/common.json
+++ b/frontend/locales/en/common.json
@@ -122,8 +122,8 @@
"search_teacher": "Search teacher",
"Are you sure you want to delete this user?": "Are you sure you want to delete this user?",
"delete user": "Delete user",
- "user first name": "First name of user",
- "user last name": "Last name of user",
+ "first name": "First name",
+ "last name": "Surname",
"user email": "Email of user",
"Are you sure you want to submit this course?": "Are you sure you want to submit this course?",
"ERROR_NOT_IN_GROUP": "You're not in a group",
@@ -139,5 +139,7 @@
"group_nr": "Group nr",
"join_leave": "Join/Leave",
"not_in_group": "Join a group to submit",
- "submission_all": "Submissions"
+ "edit_user_details": "Edit user details",
+ "status_button_tooltip": "Required, optional or forbidden file",
+ "no_deadline": "No deadline"
}
\ No newline at end of file
diff --git a/frontend/locales/nl/common.json b/frontend/locales/nl/common.json
index af0852b1..c9b59304 100644
--- a/frontend/locales/nl/common.json
+++ b/frontend/locales/nl/common.json
@@ -122,8 +122,8 @@
"search_teacher": "Zoek docent",
"Are you sure you want to delete this user?": "Ben je zeker dat je deze gebruiker wil verwijderen?",
"delete user": "Verwijder gebruiker",
- "user first name": "Voornaam gebruiker",
- "user last name": "Achternaam gebruiker",
+ "first name": "Voornaam",
+ "last name": "Achternaam",
"user email": "Gebruiker email",
"Are you sure you want to submit this course?": "Ben je zeker dat je deze cursus wil aanmaken?",
"year": "Jaargang",
@@ -142,5 +142,7 @@
"group_nr": "Groep nr",
"join_leave": "Toetreden/Verlaten",
"not_in_group": "Je kan niet indienen zonder in een groep te zitten",
- "submission_all": "Indieningen"
+ "edit_user_details": "Gebruiker bewerken",
+ "status_button_tooltip": "Verplicht, optioneel of verboden bestand",
+ "no_deadline": "Geen deadline"
}
\ No newline at end of file