From f14d41f04dd7a5cd9ae4e6ea5c9010bb496b118e Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 21 Apr 2024 17:42:29 +0200 Subject: [PATCH] =?UTF-8?q?je=20sais=20vraiment=20pas=20ce=20que=20j'ai=20?= =?UTF-8?q?ajout=C3=A9=20mais=20am=C3=A9lioration=20jt'e=20jure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java | 2 +- backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java | 3 ++- backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java | 3 +++ frontend/src/App.vue | 2 +- frontend/src/Apps/Forums.vue | 2 +- frontend/src/rest/courses.js | 2 -- frontend/src/rest/notifications.js | 2 +- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java index a0c74f5..d14265d 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/Msg/ForumController.java @@ -80,7 +80,7 @@ public class ForumController { public ResponseEntity postTopicToForum(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Topic data){ User u = authServ.getUserFromToken(token); Forum f = forumRepo.findById(id).orElse(null); - if(!(f.getWriters().contains(u) || u.getRole() == Role.Admin)){ + if(!(f.getWriters().contains(u) || f.getCourse().getOwner().equals(u) || u.getRole() == Role.Admin)){ return new UnauthorizedResponse<>(null); } forumServ.createTopic(f, data); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java index 369a8bc..1093052 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -28,10 +28,11 @@ public class Course { private User owner; //// Extension Messagerie ///// - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(mappedBy = "course", cascade = CascadeType.ALL) private List forums; public void addForum(Forum f){ + f.setCourse(this); forums.add(f); } /////////////////////////////// diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java index 75508aa..e03d0de 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Msg/Forum.java @@ -2,6 +2,8 @@ package ovh.herisson.Clyde.Tables.Msg; import java.util.List; +import com.fasterxml.jackson.annotation.JsonIgnore; + import jakarta.persistence.*; import lombok.Data; import ovh.herisson.Clyde.Tables.Course; @@ -16,6 +18,7 @@ public class Forum { private int id; @ManyToOne + @JsonIgnore private Course course; private String name; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index ae9caf6..2a15677 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -15,7 +15,7 @@ window.onhashchange = function() { } const Logged = ref(isLogged()); -if(Logged){ +if(Logged.value){ fetchNotifications(); } diff --git a/frontend/src/Apps/Forums.vue b/frontend/src/Apps/Forums.vue index d2004c5..2e7dd49 100644 --- a/frontend/src/Apps/Forums.vue +++ b/frontend/src/Apps/Forums.vue @@ -15,7 +15,7 @@ import { fetchedPost, fetchPost, sendAnswer } from '@/rest/forum.js' import { getSelf } from '@/rest/Users.js' const Role = (await getSelf()).role; -const courses = Role === 'Admin' || Role === 'Secretary' ? await reactive(getCourses()) : await reactive(getUserActualCourses()); +const courses = Role === 'Admin' || Role === 'Secretary' || Role === 'Teacher' ? await reactive(getCourses(Role)) : await reactive(getUserActualCourses()); const selectedCourse = ref(); const selectedForum = ref(); diff --git a/frontend/src/rest/courses.js b/frontend/src/rest/courses.js index 92677e9..3a87f5c 100644 --- a/frontend/src/rest/courses.js +++ b/frontend/src/rest/courses.js @@ -8,8 +8,6 @@ import { restGet, restPost, restDelete, restPatch } from './restConsumer.js' * Create a new course */ export async function createCourse(name, credits, owner){ - console.log(owner); - return restPost("/course", {title: name, credits: credits, owner} ) } diff --git a/frontend/src/rest/notifications.js b/frontend/src/rest/notifications.js index d2b0ccb..31d0319 100644 --- a/frontend/src/rest/notifications.js +++ b/frontend/src/rest/notifications.js @@ -1,7 +1,7 @@ import { ref } from 'vue' import { restGet, restPost } from '@/rest/restConsumer.js' -export const notifications = ref({}); +export const notifications = ref([]); export function fetchNotifications(){ restGet("/notifications").then( e => notifications.value = e );