fix(project): hide unavailable create action
This commit is contained in:
+3
-1
@@ -30,7 +30,9 @@ public class ProjectController {
|
||||
|
||||
@GetMapping
|
||||
public String list(Principal principal, Model model) {
|
||||
model.addAttribute("projects", pages.listVisible(actorId(principal)));
|
||||
var actor = pages.authenticatedActor(principal.getName());
|
||||
model.addAttribute("projects", pages.listVisible(actor.userId()));
|
||||
model.addAttribute("canCreateProject", "MENTOR".equals(actor.role()));
|
||||
return "projects/list";
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<body>
|
||||
<main>
|
||||
<h1>Projects</h1>
|
||||
<a href="/projects/new">Create Project</a>
|
||||
<a th:if="${canCreateProject}" href="/projects/new">Create Project</a>
|
||||
<p th:if="${#lists.isEmpty(projects)}">No authorized Projects.</p>
|
||||
<table th:unless="${#lists.isEmpty(projects)}">
|
||||
<caption>Authorized Projects</caption>
|
||||
|
||||
+18
-2
@@ -44,7 +44,8 @@ class ProjectControllerTest {
|
||||
@Test
|
||||
@WithMockUser(username = "mentor@example.test")
|
||||
void listsOnlyTheAuthenticatedUsersAuthorizedProjects() throws Exception {
|
||||
when(pages.authenticatedUserId("mentor@example.test")).thenReturn(10L);
|
||||
when(pages.authenticatedActor("mentor@example.test"))
|
||||
.thenReturn(new ProjectActorView(10L, "MENTOR"));
|
||||
when(pages.listVisible(10L)).thenReturn(List.of(new ProjectSummary(
|
||||
30L,
|
||||
"Intern Portal Refresh",
|
||||
@@ -55,11 +56,26 @@ class ProjectControllerTest {
|
||||
mvc.perform(get("/projects"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("projects/list"))
|
||||
.andExpect(model().attributeExists("projects"));
|
||||
.andExpect(model().attributeExists("projects"))
|
||||
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content()
|
||||
.string(containsString("Create Project")));
|
||||
|
||||
verify(pages).listVisible(10L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser(username = "member@example.test")
|
||||
void nonMentorProjectListOmitsTheCreateLink() throws Exception {
|
||||
when(pages.authenticatedActor("member@example.test"))
|
||||
.thenReturn(new ProjectActorView(20L, "INTERN"));
|
||||
when(pages.listVisible(20L)).thenReturn(List.of());
|
||||
|
||||
mvc.perform(get("/projects"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content()
|
||||
.string(not(containsString("Create Project"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockUser(username = "member@example.test")
|
||||
void guessedProjectIdReturnsTheSameNotFoundResponseAsAMissingProject() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user