diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt index 3ae7f0f..e24bfc0 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt @@ -44,6 +44,11 @@ class Project( members.add(member) member.projects.add(this) } + + fun removeMember(member: User){ + members.remove(member) + member.projects.remove(this) + } } @Entity diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt index 37a5671..19911b6 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ModelAttribute import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam import javax.persistence.EntityManager import javax.transaction.Transactional @@ -128,11 +129,14 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep @PostMapping("/removeuser") @PreAuthorize("hasPermission(#id, 'Long', '')") - fun removeUserFromProject(@PathVariable id: Long, @RequestBody u: UserID) { - val user = userRepository.findById(u.id).get() + fun removeUserFromProject(@PathVariable id: Long, @RequestParam("id") uid: Long, model: Model) : String{ val project = projectRepository.findById(id).get() - project.members.remove(user) + // Don't allow projects to have no members + if(project.members.size == 1) return "redirect:/project/$id" + val user = userRepository.findById(uid).get() + project.removeMember(user) projectRepository.save(project) + return "redirect:/project/$id" } @PostMapping("/addevent") diff --git a/src/main/resources/templates/error/403.html b/src/main/resources/templates/error/403.html new file mode 100644 index 0000000..8325237 --- /dev/null +++ b/src/main/resources/templates/error/403.html @@ -0,0 +1,15 @@ + + + + Forbidden | Project Planner + + +
+

403 Forbidden

+

+ Sorry. You don't have access to this resource. +

+ Go to Homepage +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/project.html b/src/main/resources/templates/project.html index 55007bd..05e9a57 100644 --- a/src/main/resources/templates/project.html +++ b/src/main/resources/templates/project.html @@ -44,11 +44,12 @@
Members:
-
+

username

- - - +
+ + +