Removal of users from projects

This commit is contained in:
neviyn 2021-03-31 10:59:20 +01:00
parent bf145aed44
commit a7e7ce7f2f
4 changed files with 32 additions and 7 deletions

View File

@ -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

View File

@ -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")

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragments :: baseHeader(~{::title})">
<title>Forbidden | Project Planner</title>
</head>
<body>
<div class="d-flex h-100 flex-column align-items-center align-content-center">
<h1 class="display-6">403 Forbidden</h1>
<p class="lead">
Sorry. You don't have access to this resource.
</p>
<a class="btn btn-primary" href="/">Go to Homepage</a>
</div>
</body>
</html>

View File

@ -44,11 +44,12 @@
<div class="list-group-item active">Members:</div>
<div th:each="member : ${project.members}">
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<div class="d-flex w-100 justify-content-between align-items-center">
<p th:text="${member.username}">username</p>
<a th:href="@{/{pid}/removeuser/{uid}(pid=${id},uid=${member.id})}">
<i class="bi bi-x-circle text-danger"></i>
</a>
<form class="form-floating mb-3" th:action="@{/project/{pid}/removeuser(pid=${id})}" method="post">
<input type="hidden" name="id" th:value="${member.id}">
<button class="btn btn-outline-danger btn-sm" type="submit"><i class="bi bi-x-circle text-danger"></i></button>
</form>
</div>
</div>
</div>