Skip to content

Commit

Permalink
feat: system env as url (#106)
Browse files Browse the repository at this point in the history
* feat: add system variable to menuitem url

* fix: add system variable to menuitem url

* fix: add system variable to menuitem url

* fix: add tests to url system env

* fix: remove logs adjust UserMenuMapper

* fix: formatter

* fix: docs added

* feat: add homePage to WorkspaceWrapper external

* feat: add disabled to Export import

* feat: add interpolate test userMenu url

* fix: format

* fix: docs

---------

Co-authored-by: Andrej Petras <[email protected]>
  • Loading branch information
jsteenke and andrejpetras authored Jul 17, 2024
1 parent 16433d0 commit bc1721b
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,62 @@ h| Version
| tkit-quarkus-data-import

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-data-import.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.28.0

| tkit-quarkus-jpa

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.28.0

| tkit-quarkus-log-cdi

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.28.0

| tkit-quarkus-log-rs

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.28.0

| tkit-quarkus-log-json

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.28.0

| tkit-quarkus-rest

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.27.0

| quarkus-oidc

| https://quarkus.io/guides/security-oidc-bearer-token-authentication-tutorial[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc.adoc[Link]
| 3.12.2
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.28.0

| onecx-tenant

| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-tenant.html[Link]
| https://github.com/onecx/onecx-quarkus/blob/0.22.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link]
| 0.22.0
| https://github.com/onecx/onecx-quarkus/blob/0.24.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link]
| 0.24.0

| tkit-quarkus-jpa-tenant

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa-tenant.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link]
| 2.28.0

| tkit-quarkus-rest-context

| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest-context.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.28.0

| quarkus-oidc

| https://quarkus.io/guides/security-oidc-bearer-token-authentication-tutorial[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-oidc.adoc[Link]
| 3.12.2
| quarkus-arc
Expand Down Expand Up @@ -137,14 +137,14 @@ h| Version
| tkit-quarkus-security
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.28.0
| onecx-core
| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link]
|
| 0.22.0
| 0.24.0
| quarkus-container-image-docker
Expand All @@ -157,7 +157,7 @@ h| Version
|
|
| 0.22.0
| 0.24.0
|===
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
<groupId>org.tkit.onecx.quarkus</groupId>
<artifactId>onecx-security</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-oidc</artifactId>
</dependency>

<!-- TENANT -->
<dependency>
Expand Down Expand Up @@ -323,6 +319,7 @@
<child6>interpolated6</child6>
<child7>interpolated7</child7>
<child8>interpolated8</child8>
<menuItem1>testItem1</menuItem1>
</environmentVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ default Map<String, EximWorkspaceDTOV1> map(Map<String, Workspace> data, Map<Str
return map;
}

@Mapping(target = "disabled", ignore = true)
@Mapping(target = "mandatory", ignore = true)
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "creationUser", ignore = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.text.StringSubstitutor;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.tkit.onecx.workspace.domain.models.MenuItem;
Expand All @@ -25,12 +26,14 @@ default UserWorkspaceMenuStructureDTO empty(String workspaceName) {
default UserWorkspaceMenuStructureDTO mapTree(Workspace workspace, Collection<MenuItem> entities,
Map<String, Set<String>> mapping, Set<String> roles, Set<String> mappingKeys) {
UserWorkspaceMenuStructureDTO dto = empty(workspace.getName());

if (entities.isEmpty()) {
return dto;
}
Set<MenuItem> items;
if (!mappingKeys.isEmpty()) {
items = entities.stream().filter(m -> m.getParentId() == null)
items = entities.stream()
.filter(m -> m.getParentId() == null)
.filter(m -> mappingKeys.contains(m.getKey()))
.collect(Collectors.toSet());
} else {
Expand All @@ -45,40 +48,46 @@ default UserWorkspaceMenuStructureDTO mapTree(Workspace workspace, Collection<Me
return dto.menu(items.stream().map(this::mapTreeItem).toList());
}

default String updateInternalUrl(String workspaceUrl, String menuItemUrl, Boolean isExternal) {
default String updateInternalUrl(String workspaceUrl, String menuItemUrl, Boolean isExternal, StringSubstitutor sub) {
if (Boolean.TRUE.equals(isExternal)) {
return menuItemUrl;
return sub.replace(menuItemUrl);
} else {
return workspaceUrl + menuItemUrl;
return sub.replace(workspaceUrl + menuItemUrl);
}
}

default Set<MenuItem> filterMenu(Set<MenuItem> items, Map<String, Set<String>> mapping, Set<String> roles,
String workspaceUrl) {
Set<MenuItem> tmp = new HashSet<>(items);
final var sub = new StringSubstitutor(System.getenv());
tmp.forEach(m -> {
var mr = mapping.get(m.getId());
var mUrl = m.getUrl();
if (mr == null || mr.stream().noneMatch(roles::contains)) {
items.remove(m);
} else {
filterChildren(m, mapping, roles, workspaceUrl);
if (mUrl != null) {
sub.replace(mUrl);
}
filterChildren(m, mapping, roles, workspaceUrl, sub);
}
});

return items;
}

default void filterChildren(MenuItem menuItem, Map<String, Set<String>> mapping, Set<String> roles, String workspaceUrl) {
default void filterChildren(MenuItem menuItem, Map<String, Set<String>> mapping, Set<String> roles, String workspaceUrl,
StringSubstitutor sub) {
Set<MenuItem> items = new HashSet<>(menuItem.getChildren());
items.forEach(child -> {
var mr = mapping.get(child.getId());
if (mr != null && mr.stream().noneMatch(roles::contains)) {
menuItem.getChildren().remove(child);
} else {
if (child.getChildren() != null && !child.getChildren().isEmpty()) {
filterChildren(child, mapping, roles, workspaceUrl);
filterChildren(child, mapping, roles, workspaceUrl, sub);
} else {
child.setUrl(updateInternalUrl(workspaceUrl, child.getUrl(), child.isExternal()));
child.setUrl(updateInternalUrl(workspaceUrl, child.getUrl(), child.isExternal(), sub));
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/main/openapi/onecx-workspace-exim-v1-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ components:
type: string
footerLabel:
type: string
disabled:
type: boolean
logoUrl:
type: string
address:
Expand Down
2 changes: 2 additions & 0 deletions src/main/openapi/onecx-workspace-v1-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ components:
type: string
baseUrl:
type: string
homePage:
type: string
theme:
type: string
products:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void exportWorkspaceTest() {
.contentType(APPLICATION_JSON)
.body(request)
.post("/export")
.then().log().all()
.then()
.statusCode(OK.getStatusCode())
.extract().as(WorkspaceSnapshotDTOV1.class);

Expand Down Expand Up @@ -69,7 +69,7 @@ void exportWorkspaceNoMenuTest() {
.contentType(APPLICATION_JSON)
.body(request)
.post("/export")
.then().log().all()
.then()
.statusCode(OK.getStatusCode())
.extract().as(WorkspaceSnapshotDTOV1.class);

Expand Down Expand Up @@ -182,6 +182,7 @@ void importWorkspaceTest() {
.putImagesItem("logo2", new ImageDTOV1().imageData(new byte[] { 1, 2, 3 }).mimeType("image/*"))
.baseUrl("/someurl")
.name("testWorkspace")
.disabled(true)
.roles(roles)
.menuItems(menuItems)
.products(products)
Expand Down Expand Up @@ -221,6 +222,7 @@ void importWorkspaceTest() {
var w = dto.getWorkspaces().get("testWorkspace");
assertThat(w).isNotNull();
assertThat(w.getName()).isEqualTo("testWorkspace");
assertThat(w.getDisabled()).isEqualTo(true);

assertThat(w.getRoles()).isNotNull().isNotEmpty().hasSize(2)
.containsExactly(
Expand Down Expand Up @@ -677,7 +679,7 @@ void importMenuToNonExistingWorkspaceTest() {
.contentType(APPLICATION_JSON)
.body(snapshot)
.post("/111111/menu/import")
.then().log().all()
.then()
.statusCode(BAD_REQUEST.getStatusCode())
.extract().as(EximProblemDetailResponseDTOV1.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void searchAssignmentTest() {
.contentType(APPLICATION_JSON)
.body(criteria2)
.post("/search")
.then().log().all()
.then()
.statusCode(OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void deleteAllMenuItemsForWorkspaceTest() {
.header(APM_HEADER_PARAM, createToken("org1"))
.body(criteria)
.post("search")
.then().log().all()
.then()
.statusCode(OK.getStatusCode())
.extract().as(MenuItemPageResultDTO.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ void modificationCountTest() {
.pathParam("id", "11-222")
.put("{id}")
.then()
.log().all()
.statusCode(BAD_REQUEST.getStatusCode())
.extract().as(ProblemDetailResponseDTO.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.tkit.onecx.workspace.rs.user.controllers;

import static io.restassured.RestAssured.given;
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
import static jakarta.ws.rs.core.Response.Status.OK;
import static org.assertj.core.api.Assertions.assertThat;
import static org.tkit.quarkus.security.test.SecurityTestUtils.getKeycloakClientToken;

import org.junit.jupiter.api.Test;
import org.tkit.onecx.workspace.test.AbstractTest;
import org.tkit.quarkus.security.test.GenerateKeycloakClient;
import org.tkit.quarkus.test.WithDBData;

import gen.org.tkit.onecx.workspace.rs.user.model.UserWorkspaceMenuRequestDTO;
import gen.org.tkit.onecx.workspace.rs.user.model.UserWorkspaceMenuStructureDTO;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@TestHTTPEndpoint(UserMenuInternalController.class)
@WithDBData(value = "data/testdata-user.xml", deleteBeforeInsert = true, deleteAfterTest = true, rinseAndRepeat = true)
@GenerateKeycloakClient(clientName = "testClient", scopes = { "ocx-ws:all", "ocx-ws:read", "ocx-ws:write" })
public class UserMenuInternalControllerInterpolateTest extends AbstractTest {

@Test
void getMenuStructure_shouldReturnSystemURL() {

var workspaceName = "test03";
var accessToken = createAccessTokenBearer(USER_BOB);
var idToken = createToken("org1");

var data = given()
.auth().oauth2(getKeycloakClientToken("testClient"))
.when()
.contentType(APPLICATION_JSON)
.header(APM_HEADER_PARAM, idToken)
.body(new UserWorkspaceMenuRequestDTO().token(accessToken))
.pathParam("workspaceName", workspaceName)
.post()
.then()
.statusCode(OK.getStatusCode())
.extract().body().as(UserWorkspaceMenuStructureDTO.class);

assertThat(data).isNotNull();
assertThat(data.getMenu().get(1).getChildren().get(0).getUrl()).isEqualTo("/company3/testItem1");
}

}
2 changes: 1 addition & 1 deletion src/test/resources/data/testdata-user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<!-- ROOT 4-2 -->
<MENU_ITEM guid="4-2" optlock="0" disabled="FALSE" key="key42" name="4-2" external="FALSE" pos="1" scope="WORKSPACE" url="" workspace="4" application_id="" tenant_id="tenant-100"/>
<!-- CHILDREN 4-2 -->
<MENU_ITEM guid="4-2-1" parent="4-2" pos="0" optlock="0" disabled="FALSE" key="key421" name="4-2-1" external="FALSE" scope="WORKSPACE" url="" workspace="4" application_id="" tenant_id="tenant-100"/>
<MENU_ITEM guid="4-2-1" parent="4-2" pos="0" optlock="0" disabled="FALSE" key="key421" name="4-2-1" external="FALSE" scope="WORKSPACE" url="/${menuItem1}" workspace="4" application_id="" tenant_id="tenant-100"/>
<MENU_ITEM guid="4-2-2" parent="4-2" pos="1" optlock="0" disabled="FALSE" key="key422" name="4-2-2" external="FALSE" scope="WORKSPACE" url="" workspace="4" application_id="" tenant_id="tenant-100"/>
<MENU_ITEM guid="4-2-3" parent="4-2" pos="2" optlock="0" disabled="FALSE" key="key423" name="4-2-3" external="FALSE" scope="WORKSPACE" url="" workspace="4" application_id="" tenant_id="tenant-100"/>
<!-- CHILDREN 4-2-3 -->
Expand Down

0 comments on commit bc1721b

Please sign in to comment.