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 47e8670..8163a69 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 @@ -24,6 +24,7 @@ import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.CourseService; import ovh.herisson.Clyde.Services.Msg.ForumService; import ovh.herisson.Clyde.Tables.Course; +import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Token; import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.Msg.Forum; @@ -46,7 +47,7 @@ public class ForumController { @GetMapping("/forums/{id}") public ResponseEntity> getForumFromCourseId(@RequestHeader("Authorization") String token, @PathVariable long id){ User u = authServ.getUserFromToken(token); - if(u != null){ + if(u == null){ return new UnauthorizedResponse<>(null); } return new ResponseEntity<>(courseRepo.findById(id).getForums(), HttpStatus.OK); @@ -56,7 +57,7 @@ public class ForumController { public ResponseEntity createForumOfCourse(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Forum data){ User u = authServ.getUserFromToken(token); Course c = courseRepo.findById(id); - if(!c.getOwner().equals(u)){ + if(!(c.getOwner().equals(u) || u.getRole() == Role.Admin)){ return new UnauthorizedResponse<>(null); } forumServ.createForum(c, data); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java index bff279c..905cd01 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/Msg/TopicRepository.java @@ -1,4 +1,4 @@ -package ovh.herisson.Clyde.EndPoints.Msg; +package ovh.herisson.Clyde.Repositories.Msg; import org.springframework.data.repository.CrudRepository; diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java index 3fbf0df..ddf5be6 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Msg/ForumService.java @@ -1,6 +1,5 @@ package ovh.herisson.Clyde.Services.Msg; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import lombok.AllArgsConstructor; 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 7fff00f..0534b0e 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Course.java @@ -24,7 +24,7 @@ public class Course { private User owner; //// Extension Messagerie ///// - @OneToMany + @OneToMany(cascade = CascadeType.ALL) private List forums; public void addForum(Forum 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 3baa406..3ca1637 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 @@ -15,7 +15,7 @@ public class Forum { @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne private Course course; private String name; diff --git a/frontend/src/Apps/Forums.vue b/frontend/src/Apps/Forums.vue index 3e777e2..5f56704 100644 --- a/frontend/src/Apps/Forums.vue +++ b/frontend/src/Apps/Forums.vue @@ -8,13 +8,18 @@ @@ -28,10 +33,11 @@ const selectedForum = ref(); +
{{ post.name }}
- +
@@ -43,10 +49,41 @@ const selectedForum = ref();
+
+
+ + +
+