Skip to content
Snippets Groups Projects
Commit c86850ec authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2339 OZG-2691 myVorgaenge navigationsitem ausblenden

parent c986b586
Branches
Tags
No related merge requests found
......@@ -45,16 +45,20 @@ public class RootController {
linkTo(VorgangController.class).withRel(REL_VORGAENGE),
linkTo(methodOn(UserProfileController.class).findUsers(null)).withRel(REL_SEARCH_USER),
linkTo(DownloadTokenController.class).withRel(REL_DOWNLOAD_TOKEN),
buildVorgangListByPageLink(REL_SEARCH, Optional.empty()),
buildVorgangListByPageLink(REL_SEARCH, Optional.empty()))
.ifMatch(this::hasVerwaltungRole).addLinks(
buildVorgangListByPageLink(REL_MY_VORGAENGE, Optional.of(currentUserService.getUserId())),
buildVorgangListByPageLink(REL_SEARCH_MY_VORGAENGE, Optional.of(currentUserService.getUserId())))
.buildModel();
}
private boolean hasRole() {
boolean hasRole() {
return hasVerwaltungRole() || currentUserService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
}
boolean hasVerwaltungRole() {
return currentUserService.hasRole(UserRole.VERWALTUNG_USER)
|| currentUserService.hasRole(UserRole.VERWALTUNG_POSTSTELLE)
|| currentUserService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER);
|| currentUserService.hasRole(UserRole.VERWALTUNG_POSTSTELLE);
}
private Link buildVorgangListByPageLink(String linkRel, Optional<UserId> assignedTo) {
......
......@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.boot.info.BuildProperties;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
......@@ -24,12 +25,14 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import static org.assertj.core.api.Assertions.*;
import de.itvsh.goofy.common.user.CurrentUserService;
import de.itvsh.goofy.common.user.UserRole;
import de.itvsh.goofy.common.user.UserTestFactory;
class RootControllerTest {
private final String PATH = "/api";
@Spy
@InjectMocks // NOSONAR
private RootController controller;
@Mock
......@@ -50,13 +53,13 @@ class RootControllerTest {
@Nested
class TestLinks {
@DisplayName("with any role")
@DisplayName("with any verwaltung role")
@Nested
class TestWithAnyRole {
class TestWithVerwaltungRole {
@BeforeEach
void mockCurrentUserService() {
when(currentUserService.hasRole(anyString())).thenReturn(true);
doReturn(true).when(controller).hasVerwaltungRole();
}
@Test
......@@ -115,6 +118,32 @@ class RootControllerTest {
}
}
@DisplayName("with role " + UserRole.EINHEITLICHER_ANSPRECHPARTNER)
@Nested
class TestWithEinheitlicherAnsprechpartnerRole {
@BeforeEach
void mock() {
when(currentUserService.hasRole(UserRole.EINHEITLICHER_ANSPRECHPARTNER)).thenReturn(true);
doReturn(false).when(controller).hasVerwaltungRole();
}
@Test
void shoulNotHaveMyVorgaengeLink() {
var model = controller.getRootResource();
assertThat(model.getLink(RootController.REL_MY_VORGAENGE)).isNotPresent();
}
@Test
void shoulNotHaveSearchMyVorgaengeLink() {
var model = controller.getRootResource();
assertThat(model.getLink(RootController.REL_SEARCH_MY_VORGAENGE)).isNotPresent();
}
}
@DisplayName("with no role")
@Nested
class TestWithNoRole {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment