diff --git a/goofy-server/src/main/java/de/itvsh/goofy/RootController.java b/goofy-server/src/main/java/de/itvsh/goofy/RootController.java index f394e86ca7234a76fca635adbb013a6558f16aed..97b2c40373c78b5024cc55eb7c6b5d917240e935 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/RootController.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/RootController.java @@ -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) { diff --git a/goofy-server/src/test/java/de/itvsh/goofy/RootControllerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/RootControllerTest.java index 778e0dc261ca83baefff24df794e4e346fb7c403..bd32012c381f870f397df66abc0485a793c5c0db 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/RootControllerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/RootControllerTest.java @@ -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 {