Skip to content

Commit

Permalink
feat: search assignments by roles (#101)
Browse files Browse the repository at this point in the history
* feat: search assignments by roles

* fix: code smelss

* fix: sonar issue
  • Loading branch information
JordenReuter authored Oct 21, 2024
1 parent 685d4f0 commit fdb58ad
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,158 +12,158 @@ h| Version

| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link]
|
| 0.30.0
| 0.33.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.30.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link]
| 0.30.0
| https://github.com/onecx/onecx-quarkus/blob/0.33.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link]
| 0.33.0

| 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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.36.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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.36.0

| quarkus-arc

| https://quarkus.io/guides/cdi-reference[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-arc.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-liquibase
| https://quarkus.io/guides/liquibase[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-liquibase.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-smallrye-health
| https://quarkus.io/guides/smallrye-health[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-health.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-micrometer-registry-prometheus
| https://quarkus.io/guides/telemetry-micrometer[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-micrometer-registry-prometheus.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-hibernate-orm
| https://quarkus.io/guides/hibernate-orm[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-orm.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-rest
| https://quarkus.io/guides/rest[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-rest.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-rest-jackson
| https://quarkus.io/guides/rest-json[Link]
|
| 3.14.4
| 3.15.1
| quarkus-jdbc-postgresql
| https://quarkus.io/guides/datasource[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-jdbc-postgresql.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-smallrye-openapi
| https://quarkus.io/guides/openapi-swaggerui[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-smallrye-openapi.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-hibernate-validator
| https://quarkus.io/guides/validation[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-hibernate-validator.adoc[Link]
| 3.14.4
| 3.15.1
| quarkus-opentelemetry
| https://quarkus.io/guides/opentelemetry[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-opentelemetry.adoc[Link]
| 3.14.4
| 3.15.1
| 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.14.4
| 3.15.1
| 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.32.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.32.0
| https://github.com/1000kit/tkit-quarkus/blob/2.36.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.36.0
| quarkus-container-image-docker
| https://quarkus.io/guides/container-image[Link]
| https://github.com/quarkusio/quarkusio.github.io/blob/develop/_generated-doc/latest/config/quarkus-container-image-docker.adoc[Link]
| 3.14.4
| 3.15.1
| onecx-security
|
|
| 0.30.0
| 0.33.0
| quarkus-smallrye-context-propagation
|
|
| 3.14.4
| 3.15.1
|===
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ h|[.header-title]##Configuration property##
h|Type
h|Default

a| [[onecx-permission-svc_onecx-permission-token-verified]] [.property-path]##`onecx.permission.token.verified`##
a| [[onecx-permission-svc_onecx-permission-token-verified]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-verified[`onecx.permission.token.verified`]##

[.description]
--
Expand All @@ -25,7 +25,7 @@ endif::add-copy-button-to-env-var[]
|boolean
|`false`

a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-suffix]] [.property-path]##`onecx.permission.token.issuer.public-key-location.suffix`##
a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-suffix]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-issuer-public-key-location-suffix[`onecx.permission.token.issuer.public-key-location.suffix`]##

[.description]
--
Expand All @@ -42,7 +42,7 @@ endif::add-copy-button-to-env-var[]
|string
|`/protocol/openid-connect/certs`

a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-enabled]] [.property-path]##`onecx.permission.token.issuer.public-key-location.enabled`##
a| [[onecx-permission-svc_onecx-permission-token-issuer-public-key-location-enabled]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-issuer-public-key-location-enabled[`onecx.permission.token.issuer.public-key-location.enabled`]##

[.description]
--
Expand All @@ -59,7 +59,7 @@ endif::add-copy-button-to-env-var[]
|boolean
|`false`

a| [[onecx-permission-svc_onecx-permission-token-claim-separator]] [.property-path]##`onecx.permission.token.claim.separator`##
a| [[onecx-permission-svc_onecx-permission-token-claim-separator]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-claim-separator[`onecx.permission.token.claim.separator`]##

[.description]
--
Expand All @@ -76,7 +76,7 @@ endif::add-copy-button-to-env-var[]
|string
|

a| [[onecx-permission-svc_onecx-permission-token-claim-path]] [.property-path]##`onecx.permission.token.claim.path`##
a| [[onecx-permission-svc_onecx-permission-token-claim-path]] [.property-path]##link:#onecx-permission-svc_onecx-permission-token-claim-path[`onecx.permission.token.claim.path`]##

[.description]
--
Expand All @@ -93,7 +93,7 @@ endif::add-copy-button-to-env-var[]
|string
|`realm_access/roles`

a| [[onecx-permission-svc_onecx-permission-template-role-mapping-role-mapping]] [.property-path]##`onecx.permission.template.role-mapping."role-mapping"`##
a| [[onecx-permission-svc_onecx-permission-template-role-mapping-role-mapping]] [.property-path]##link:#onecx-permission-svc_onecx-permission-template-role-mapping-role-mapping[`onecx.permission.template.role-mapping."role-mapping"`]##

[.description]
--
Expand All @@ -110,7 +110,7 @@ endif::add-copy-button-to-env-var[]
|Map<String,String>
|

a| [[onecx-permission-svc_onecx-permission-template-tenants]] [.property-path]##`onecx.permission.template.tenants`##
a| [[onecx-permission-svc_onecx-permission-template-tenants]] [.property-path]##link:#onecx-permission-svc_onecx-permission-template-tenants[`onecx.permission.template.tenants`]##

[.description]
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public Response searchAssignments(AssignmentSearchCriteriaDTO assignmentSearchCr
return Response.ok(mapper.map(result)).build();
}

@Override
public Response searchAssignmentsByRoles(AssignmentRolesSearchCriteriaDTO assignmentRolesSearchCriteriaDTO) {
var page = dao.findUserAssignments(assignmentRolesSearchCriteriaDTO.getRoles(),
assignmentRolesSearchCriteriaDTO.getPageNumber(),
assignmentRolesSearchCriteriaDTO.getPageSize());
var assignments = dao.loadAssignments(page.getStream().map(TraceableEntity::getId).toList());
PageResult<Assignment> pageResult = new PageResult<>(page.getTotalElements(), assignments.stream(),
page.getNumber(), page.getSize());
return Response.ok().entity(mapper.mapUserAssignments(pageResult)).build();
}

@Override
public Response createAssignment(CreateAssignmentRequestDTO createAssignmentRequestDTO) {
var role = roleDAO.findById(createAssignmentRequestDTO.getRoleId());
Expand Down
44 changes: 44 additions & 0 deletions src/main/openapi/onecx-permission-internal-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,32 @@ paths:
responses:
204:
description: Assignment deleted
/internal/assignments/roles/search:
post:
security:
- oauth2: [ ocx-pm:all, ocx-pm:read ]
tags:
- assignmentInternal
operationId: searchAssignmentsByRoles
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AssignmentRolesSearchCriteria'
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/UserAssignmentPageResult'
400:
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetailResponse'
/internal/assignments/me:
post:
security:
Expand Down Expand Up @@ -732,6 +758,24 @@ components:
roleId:
type: string
description: The size of page
AssignmentRolesSearchCriteria:
type: object
properties:
roles:
type: array
items:
type: string
pageNumber:
format: int32
description: The number of page.
default: 0
type: integer
pageSize:
format: int32
description: The size of page
default: 100
maximum: 1000
type: integer
AssignmentPageResult:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,4 +653,22 @@ void getUsersAssignmentsTest() {

assertThat(dto).isNotNull();
}

@Test
void searchAssignmentsByRolesTest() {

var dto = given()
.auth().oauth2(getKeycloakClientToken("testClient"))
.contentType(APPLICATION_JSON)
.body(new AssignmentRolesSearchCriteriaDTO().roles(List.of("n3")).pageNumber(0).pageSize(10))
.post("/roles/search")
.then()
.log().all()
.statusCode(OK.getStatusCode())
.extract()
.body().as(UserAssignmentPageResultDTO.class);

assertThat(dto).isNotNull();
assertThat(dto.getStream()).hasSize(1);
}
}

0 comments on commit fdb58ad

Please sign in to comment.