diff --git a/pom.xml b/pom.xml index 16673c5cc032c2aa962877fba8f11f293497241d..a36bcae41e7632e98055bc508e431e61620fb842 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ <parent> <groupId>de.ozgcloud.common</groupId> <artifactId>ozgcloud-common-parent</artifactId> - <version>4.9.0</version> + <version>4.11.0-SNAPSHOT</version> <relativePath /> </parent> diff --git a/src/main/helm/templates/deployment.yaml b/src/main/helm/templates/deployment.yaml index 58ff6b8aeeff343f7af013e6c3ff8e22c31d326b..7131cc9d9630c7d8d5964a3abcf2512e42b3dc87 100644 --- a/src/main/helm/templates/deployment.yaml +++ b/src/main/helm/templates/deployment.yaml @@ -70,6 +70,10 @@ spec: value: {{ include "app.ssoClientName" . }} - name: ozgcloud_oauth2_auth-server-url value: {{ include "app.ssoServerUrl" . }} + {{- if (((.Values.ozgcloud).user_assistance).documentation).url }} + - name: ozgcloud_user-assistance_documentation_url + value: {{ .Values.ozgcloud.user_assistance.documentation.url }} + {{- end }} {{- if not (.Values.database).useExternal }} - name: spring_data_mongodb_uri valueFrom: diff --git a/src/main/java/de/ozgcloud/admin/DocumentationProperties.java b/src/main/java/de/ozgcloud/admin/DocumentationProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..fb90234e4bb9a4e5da39cc53d956b8ab09c0dd7b --- /dev/null +++ b/src/main/java/de/ozgcloud/admin/DocumentationProperties.java @@ -0,0 +1,23 @@ +package de.ozgcloud.admin; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@Configuration +@ConfigurationProperties(prefix = DocumentationProperties.DOCUMENTATION_PROPERTIES_PREFIX) +public class DocumentationProperties { + + static final String DOCUMENTATION_PROPERTIES_PREFIX = "ozgcloud.user-assistance.documentation"; + + /* + * Url pointing to the documentation (Benutzerleitfaden fuer die + * Administration). + */ + private String url; + +} diff --git a/src/main/java/de/ozgcloud/admin/RootModelAssembler.java b/src/main/java/de/ozgcloud/admin/RootModelAssembler.java index 3b564cf37f4483a8b793e1f5c845fdfce4c9ad69..6e19dd7823bc0d84a1f7fdebe2c217debcd1f624 100644 --- a/src/main/java/de/ozgcloud/admin/RootModelAssembler.java +++ b/src/main/java/de/ozgcloud/admin/RootModelAssembler.java @@ -23,8 +23,7 @@ */ package de.ozgcloud.admin; -import java.util.ArrayList; -import java.util.List; +import java.util.Objects; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties; import org.springframework.hateoas.EntityModel; @@ -40,24 +39,23 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class RootModelAssembler implements RepresentationModelAssembler<Root, EntityModel<Root>> { static final String REL_CONFIGURATION = "configuration"; + static final String REL_DOCUMENTATIONS = "documentations"; private final RepositoryRestProperties restProperties; private final CurrentUserService currentUserService; + private final DocumentationProperties documentationProperties; @Override public EntityModel<Root> toModel(Root root) { - List<Link> links = buildRootModelLinks(); - return EntityModel.of(root, links); + var rootModel = EntityModel.of(root); + addLinks(rootModel); + return rootModel; } - List<Link> buildRootModelLinks() { - List<Link> links = new ArrayList<>(); - var rootLinkBuilder = WebMvcLinkBuilder.linkTo(RootController.class); - links.add(rootLinkBuilder.withSelfRel()); - if (currentUserService.hasConfigurationPermission()) { - links.add(buildConfigLink()); - } - return links; + private void addLinks(EntityModel<Root> rootModel) { + rootModel.add(WebMvcLinkBuilder.linkTo(RootController.class).withSelfRel()); + rootModel.addIf(currentUserService.hasConfigurationPermission(), this::buildConfigLink); + rootModel.addIf(Objects.nonNull(documentationProperties.getUrl()), () -> Link.of(documentationProperties.getUrl(), REL_DOCUMENTATIONS)); } private Link buildConfigLink() { diff --git a/src/test/helm/deployment_env_test.yaml b/src/test/helm/deployment_env_test.yaml index dfa90b4d8fc3d5de9b00838c86eca7ed504e4fa8..f6c863d20d3b9c29cf8227d9aaa5a494223df359 100644 --- a/src/test/helm/deployment_env_test.yaml +++ b/src/test/helm/deployment_env_test.yaml @@ -54,5 +54,15 @@ tests: content: name: ozgcloud_administration_sync_organisationseinheiten_cron value: "*/15 * * * *" - - + - it: should have user assistance documentation url + set: + ozgcloud: + user_assistance: + documentation: + url: http://hier/geht/es/zum/benutzerleitfaden.de + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: ozgcloud_user-assistance_documentation_url + value: http://hier/geht/es/zum/benutzerleitfaden.de diff --git a/src/test/java/de/ozgcloud/admin/RootModelAssemblerTest.java b/src/test/java/de/ozgcloud/admin/RootModelAssemblerTest.java index d3933e7611bc6c2682d105a3bd92f022f14421a2..c7d0c03d343ea978117768878198ebb9ddb943ae 100644 --- a/src/test/java/de/ozgcloud/admin/RootModelAssemblerTest.java +++ b/src/test/java/de/ozgcloud/admin/RootModelAssemblerTest.java @@ -27,8 +27,6 @@ import static de.ozgcloud.admin.RootModelAssembler.*; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import java.util.List; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -37,8 +35,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.springframework.boot.autoconfigure.data.rest.RepositoryRestProperties; +import org.springframework.hateoas.IanaLinkRelations; import org.springframework.hateoas.Link; +import com.thedeanda.lorem.LoremIpsum; + import de.ozgcloud.admin.common.user.CurrentUserService; class RootModelAssemblerTest { @@ -53,82 +54,116 @@ class RootModelAssemblerTest { private RepositoryRestProperties restProperties; @Mock private CurrentUserService currentUserService; + @Mock + private DocumentationProperties documentationProperties; @DisplayName("Entity Model") @Nested - class TestEntityModel { - - private final List<Link> links = List.of(Link.of(RootController.PATH)); + class TestToModel { - @BeforeEach - void beforeEach() { - doReturn(links).when(modelAssembler).buildRootModelLinks(); - } + private final Root root = RootTestFactory.create(); @Test - void shouldHaveRoot() { - var givenRoot = RootTestFactory.create(); - - var resultRoot = modelAssembler.toModel(givenRoot).getContent(); + void shouldHaveRootContent() { + var resultRoot = modelAssembler.toModel(root).getContent(); - assertThat(resultRoot).isEqualTo(givenRoot); + assertThat(resultRoot).isEqualTo(root); } @Test - void shouldHaveLinks() { - var modelLinks = modelAssembler.toModel(RootTestFactory.create()).getLinks(); + void shouldHaveSelfLink() { + var model = modelAssembler.toModel(root); - assertThat(modelLinks).containsAll(links); + assertThat(model.getLink(IanaLinkRelations.SELF)).get().extracting(Link::getHref).isEqualTo(RootController.PATH); } - } - @DisplayName("Root Model Links") - @Nested - class TestBuildRootModelLinks { + @Nested + class TestConfigurationLink { - @Test - void shouldCheckConfigurationPermission() { - modelAssembler.buildRootModelLinks(); + @Test + void shouldCallHasConfigurationPermission() { + modelAssembler.toModel(root); - verify(currentUserService).hasConfigurationPermission(); - } + verify(currentUserService).hasConfigurationPermission(); + } - @Nested - class TestOnHasConfigurationPermission { + @Nested + class TestOnHasConfigurationPermission { + + @BeforeEach + void mock() { + when(currentUserService.hasConfigurationPermission()).thenReturn(true); + when(restProperties.getBasePath()).thenReturn(BASE_PATH); + } + + @Test + void shouldHaveHrefToConfiguration() { + var model = modelAssembler.toModel(root); - @BeforeEach - void hasConfigurationPermission() { - when(currentUserService.hasConfigurationPermission()).thenReturn(true); - when(restProperties.getBasePath()).thenReturn(BASE_PATH); + assertThat(model.getLink(REL_CONFIGURATION)).get().extracting(Link::getHref).isEqualTo(BASE_PATH); + } } - @Test - void shouldHaveHrefToConfiguration() { - var links = modelAssembler.buildRootModelLinks(); + @Nested + class TestOnHasNotConfigurationPermission { + + @BeforeEach + void mock() { + when(currentUserService.hasConfigurationPermission()).thenReturn(false); + } - assertThat(links).containsExactly( - Link.of(RootController.PATH), - Link.of(BASE_PATH, REL_CONFIGURATION)); + @Test + void shouldNotHaveConfigurationLink() { + var model = modelAssembler.toModel(root); + + assertThat(model.getLink(REL_CONFIGURATION)).isEmpty(); + } } } @Nested - class TestOnNotHasConfigurationPermission { + class TestDocumentationLink { + + @Test + void shouldGetDocumentationUrl() { + modelAssembler.toModel(root); - @BeforeEach - void hasNotConfigurationPermission() { - when(currentUserService.hasConfigurationPermission()).thenReturn(false); + verify(documentationProperties).getUrl(); } - @Test - void shouldHaveOnlySelfLink() { - var links = modelAssembler.buildRootModelLinks(); + @Nested + class TestOnDocumentationUrlGiven { + + private final String documentationUrl = LoremIpsum.getInstance().getUrl(); + + @BeforeEach + void mock() { + when(documentationProperties.getUrl()).thenReturn(documentationUrl); + } - assertThat(links).containsExactly( - Link.of(RootController.PATH)); + @Test + void shouldHaveDocumentationLink() { + var model = modelAssembler.toModel(root); + + assertThat(model.getLink(REL_DOCUMENTATIONS)).get().extracting(Link::getHref).isEqualTo(documentationUrl); + } } - } - } + @Nested + class TestOnDocumentationUrlNotGiven { + + @BeforeEach + void mock() { + when(documentationProperties.getUrl()).thenReturn(null); + } + @Test + void shouldNotHaveDocumentationLink() { + var model = modelAssembler.toModel(root); + + assertThat(model.getLink(REL_DOCUMENTATIONS)).isEmpty(); + } + } + } + } } \ No newline at end of file