Removal of users from projects
This commit is contained in:
parent
bf145aed44
commit
a7e7ce7f2f
@ -44,6 +44,11 @@ class Project(
|
|||||||
members.add(member)
|
members.add(member)
|
||||||
member.projects.add(this)
|
member.projects.add(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeMember(member: User){
|
||||||
|
members.remove(member)
|
||||||
|
member.projects.remove(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ModelAttribute
|
|||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
import org.springframework.web.bind.annotation.RequestBody
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
import javax.persistence.EntityManager
|
import javax.persistence.EntityManager
|
||||||
import javax.transaction.Transactional
|
import javax.transaction.Transactional
|
||||||
|
|
||||||
@ -128,11 +129,14 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep
|
|||||||
|
|
||||||
@PostMapping("/removeuser")
|
@PostMapping("/removeuser")
|
||||||
@PreAuthorize("hasPermission(#id, 'Long', '')")
|
@PreAuthorize("hasPermission(#id, 'Long', '')")
|
||||||
fun removeUserFromProject(@PathVariable id: Long, @RequestBody u: UserID) {
|
fun removeUserFromProject(@PathVariable id: Long, @RequestParam("id") uid: Long, model: Model) : String{
|
||||||
val user = userRepository.findById(u.id).get()
|
|
||||||
val project = projectRepository.findById(id).get()
|
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)
|
projectRepository.save(project)
|
||||||
|
return "redirect:/project/$id"
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/addevent")
|
@PostMapping("/addevent")
|
||||||
|
15
src/main/resources/templates/error/403.html
Normal file
15
src/main/resources/templates/error/403.html
Normal 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>
|
@ -44,11 +44,12 @@
|
|||||||
<div class="list-group-item active">Members:</div>
|
<div class="list-group-item active">Members:</div>
|
||||||
<div th:each="member : ${project.members}">
|
<div th:each="member : ${project.members}">
|
||||||
<div class="list-group-item">
|
<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>
|
<p th:text="${member.username}">username</p>
|
||||||
<a th:href="@{/{pid}/removeuser/{uid}(pid=${id},uid=${member.id})}">
|
<form class="form-floating mb-3" th:action="@{/project/{pid}/removeuser(pid=${id})}" method="post">
|
||||||
<i class="bi bi-x-circle text-danger"></i>
|
<input type="hidden" name="id" th:value="${member.id}">
|
||||||
</a>
|
<button class="btn btn-outline-danger btn-sm" type="submit"><i class="bi bi-x-circle text-danger"></i></button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user