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