From 54b49fa4c973bbda67a961d63bd41b8f8de767e3 Mon Sep 17 00:00:00 2001 From: Jannik Steenken Date: Mon, 8 Apr 2024 16:29:11 +0200 Subject: [PATCH 1/4] feat: add roleId to search --- .../onecx/permission/bff/rs/mappers/AssignmentMapper.java | 2 +- src/main/openapi/openapi-bff.yaml | 2 ++ .../onecx/permission/rs/AssignmentRestControllerTest.java | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/tkit/onecx/permission/bff/rs/mappers/AssignmentMapper.java b/src/main/java/org/tkit/onecx/permission/bff/rs/mappers/AssignmentMapper.java index 422101a..350baa5 100644 --- a/src/main/java/org/tkit/onecx/permission/bff/rs/mappers/AssignmentMapper.java +++ b/src/main/java/org/tkit/onecx/permission/bff/rs/mappers/AssignmentMapper.java @@ -13,7 +13,7 @@ public interface AssignmentMapper { AssignmentDTO map(Assignment assignment); - @Mapping(target = "appId", source = "appIds") + @Mapping(target = "appIds", source = "appIds") AssignmentSearchCriteria map(AssignmentSearchCriteriaDTO assignmentSearchCriteriaDTO); @Mapping(target = "removeStreamItem", ignore = true) diff --git a/src/main/openapi/openapi-bff.yaml b/src/main/openapi/openapi-bff.yaml index 3c1ddef..d9deb1b 100644 --- a/src/main/openapi/openapi-bff.yaml +++ b/src/main/openapi/openapi-bff.yaml @@ -668,6 +668,8 @@ components: type: array items: type: string + roleId: + type: string pageNumber: format: int32 description: The number of page. diff --git a/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java index 0d7170e..ca777c4 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java @@ -105,7 +105,7 @@ void createAssignmentEmptyBodyTest() { @Test void searchAssignmentByCriteriaTest() { AssignmentSearchCriteria criteria = new AssignmentSearchCriteria(); - criteria.pageNumber(1).pageSize(1).appId(List.of("app1")); + criteria.pageNumber(1).pageSize(1).roleId("role1").appIds(List.of("app1")); AssignmentPageResult pageResult = new AssignmentPageResult(); Assignment assignment = new Assignment(); @@ -121,7 +121,7 @@ void searchAssignmentByCriteriaTest() { .withBody(JsonBody.json(pageResult))); AssignmentSearchCriteriaDTO criteriaDTO = new AssignmentSearchCriteriaDTO(); - criteriaDTO.pageNumber(1).appIds(List.of("app1")).pageSize(1); + criteriaDTO.pageNumber(1).roleId("role1").appIds(List.of("app1")).pageSize(1); var output = given() .when() From ccff4567b0758d0fd88adb6bcc784455168449cf Mon Sep 17 00:00:00 2001 From: Jannik Steenken Date: Mon, 8 Apr 2024 16:50:08 +0200 Subject: [PATCH 2/4] feat: grant and revoke assignment by appId --- pom.xml | 2 +- .../bff/rs/controllers/AssignmentRestController.java | 4 ++-- src/main/openapi/openapi-bff.yaml | 9 ++++++--- .../permission/rs/AssignmentRestControllerTest.java | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 62f5dd4..62af911 100644 --- a/pom.xml +++ b/pom.xml @@ -170,7 +170,7 @@ wget - https://raw.githubusercontent.com/onecx/onecx-permission-svc/main/src/main/openapi/onecx-permission-internal-openapi.yaml + https://raw.githubusercontent.com/jsteenke/onecx-permission-svc/main/src/main/openapi/onecx-permission-internal-openapi.yaml target/tmp/openapi onecx-permission-svc.yaml true diff --git a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java index c1f91df..bf91cba 100644 --- a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java +++ b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java @@ -45,8 +45,8 @@ public Response createAssignment(CreateAssignmentRequestDTO createAssignmentRequ } @Override - public Response createProductAssignments(CreateProductAssignmentsRequestDTO createProductAssignmentsRequestDTO) { - try (Response response = assignmentClient.createProductAssignment(mapper.map(createProductAssignmentsRequestDTO))) { + public Response grantAssignment(CreateProductAssignmentsRequestDTO createProductAssignmentsRequestDTO) { + try (Response response = assignmentClient.grantAssignment(mapper.map(createProductAssignmentsRequestDTO))) { return Response.status(response.getStatus()).build(); } } diff --git a/src/main/openapi/openapi-bff.yaml b/src/main/openapi/openapi-bff.yaml index d9deb1b..34108b5 100644 --- a/src/main/openapi/openapi-bff.yaml +++ b/src/main/openapi/openapi-bff.yaml @@ -274,7 +274,7 @@ paths: application/json: schema: $ref: '#/components/schemas/ProblemDetailResponse' - /assignments/product: + /assignments/grant: post: x-onecx: permissions: @@ -283,7 +283,7 @@ paths: tags: - assignment description: Create new assignments for products - operationId: createProductAssignments + operationId: grantAssignment requestBody: required: true content: @@ -714,10 +714,11 @@ components: type: object required: - roleId - - productNames properties: roleId: type: string + appId: + type: string productNames: type: array items: @@ -729,6 +730,8 @@ components: properties: roleId: type: string + appId: + type: string permissionId: type: string productNames: diff --git a/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java b/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java index ca777c4..595b221 100644 --- a/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java +++ b/src/test/java/org/tkit/onecx/permission/rs/AssignmentRestControllerTest.java @@ -257,7 +257,7 @@ void createProductAssignmentsTest() { request.setProductNames(List.of("product1")); // create mock rest endpoint - mockServerClient.when(request().withPath("/internal/assignments/product").withMethod(HttpMethod.POST) + mockServerClient.when(request().withPath("/internal/assignments/grant").withMethod(HttpMethod.POST) .withBody(JsonBody.json(request))) .withId(MOCKID) .respond(httpRequest -> response().withStatusCode(Response.Status.CREATED.getStatusCode()) @@ -272,7 +272,7 @@ void createProductAssignmentsTest() { .header(APM_HEADER_PARAM, ADMIN) .contentType(APPLICATION_JSON) .body(requestDTO) - .post("/product") + .post("/grant") .then() .statusCode(Response.Status.CREATED.getStatusCode()); } From 34ed97a90d0d95624ebb325b97731bc74b4b4c04 Mon Sep 17 00:00:00 2001 From: Jannik Steenken Date: Mon, 8 Apr 2024 16:50:46 +0200 Subject: [PATCH 3/4] fix: grant and revoke assignment by appId --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 62af911..62f5dd4 100644 --- a/pom.xml +++ b/pom.xml @@ -170,7 +170,7 @@ wget - https://raw.githubusercontent.com/jsteenke/onecx-permission-svc/main/src/main/openapi/onecx-permission-internal-openapi.yaml + https://raw.githubusercontent.com/onecx/onecx-permission-svc/main/src/main/openapi/onecx-permission-internal-openapi.yaml target/tmp/openapi onecx-permission-svc.yaml true From 762f04231a74705837927bc1cf0d52b10768744f Mon Sep 17 00:00:00 2001 From: Jannik Steenken Date: Tue, 9 Apr 2024 11:49:42 +0200 Subject: [PATCH 4/4] fix: openapi fix --- .../bff/rs/controllers/AssignmentRestController.java | 2 +- src/main/openapi/openapi-bff.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java index bf91cba..f4fa508 100644 --- a/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java +++ b/src/main/java/org/tkit/onecx/permission/bff/rs/controllers/AssignmentRestController.java @@ -45,7 +45,7 @@ public Response createAssignment(CreateAssignmentRequestDTO createAssignmentRequ } @Override - public Response grantAssignment(CreateProductAssignmentsRequestDTO createProductAssignmentsRequestDTO) { + public Response grantAssignments(CreateProductAssignmentsRequestDTO createProductAssignmentsRequestDTO) { try (Response response = assignmentClient.grantAssignment(mapper.map(createProductAssignmentsRequestDTO))) { return Response.status(response.getStatus()).build(); } diff --git a/src/main/openapi/openapi-bff.yaml b/src/main/openapi/openapi-bff.yaml index 34108b5..28d60d8 100644 --- a/src/main/openapi/openapi-bff.yaml +++ b/src/main/openapi/openapi-bff.yaml @@ -282,8 +282,8 @@ paths: - write tags: - assignment - description: Create new assignments for products - operationId: grantAssignment + description: Create new assignments by criteria + operationId: grantAssignments requestBody: required: true content: @@ -292,7 +292,7 @@ paths: $ref: '#/components/schemas/CreateProductAssignmentsRequest' responses: 201: - description: New assignment created + description: New assignments created 400: description: Bad request content: