Skip to content

Commit

Permalink
feat: added userAssignments and splitted user permissions and roles (#42
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JordenReuter authored Jun 7, 2024
1 parent eafb70c commit 7c4f896
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import org.tkit.onecx.permission.bff.rs.mappers.UserMapper;

import gen.org.tkit.onecx.permission.bff.rs.internal.UserApiService;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesAndPermissionsCriteriaDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesAndPermissionsPageResultDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserCriteriaDTO;
import gen.org.tkit.onecx.permission.client.api.AssignmentInternalApi;
import gen.org.tkit.onecx.permission.client.api.PermissionInternalApi;
import gen.org.tkit.onecx.permission.client.api.RoleInternalApi;
import gen.org.tkit.onecx.permission.client.model.PermissionPageResult;
import gen.org.tkit.onecx.permission.client.model.RolePageResult;
import gen.org.tkit.onecx.permission.client.model.UserAssignmentPageResult;

public class UserRestController implements UserApiService {

Expand All @@ -35,22 +36,41 @@ public class UserRestController implements UserApiService {
@RestClient
PermissionInternalApi permissionClient;

@Inject
@RestClient
AssignmentInternalApi assignmentClient;

@Inject
HttpHeaders headers;

@Override
public Response getUserRolesAndPermissions(UserRolesAndPermissionsCriteriaDTO userRolesAndPermissionsCriteriaDTO) {
UserRolesAndPermissionsPageResultDTO resultDTO;
public Response getUserRoles(UserCriteriaDTO userCriteriaDTO) {
var token = headers.getHeaderString(AUTHORIZATION);
try (Response roleResponse = roleClient
.getUserRoles(userMapper.mapRoleRequest(userRolesAndPermissionsCriteriaDTO, token))) {
try (Response permissionResponse = permissionClient
.getUsersPermissions(userMapper.mapPermissionRequest(userRolesAndPermissionsCriteriaDTO, token))) {
resultDTO = userMapper.map(roleResponse.readEntity(RolePageResult.class),
permissionResponse.readEntity(PermissionPageResult.class));
}
.getUserRoles(userMapper.mapUserRoleRequest(userCriteriaDTO, token))) {
return Response.status(Response.Status.OK)
.entity(userMapper.map(roleResponse.readEntity(RolePageResult.class))).build();
}
}

@Override
public Response getUserPermissions(UserCriteriaDTO userCriteriaDTO) {
var token = headers.getHeaderString(AUTHORIZATION);
try (Response permissionResponse = permissionClient
.getUsersPermissions(userMapper.mapUserPermissionRequest(userCriteriaDTO, token))) {
return Response.status(Response.Status.OK).entity(userMapper.map(
permissionResponse.readEntity(PermissionPageResult.class))).build();
}
}

@Override
public Response getUserAssignments(UserCriteriaDTO userCriteriaDTO) {
var token = headers.getHeaderString(AUTHORIZATION);
try (Response assignmentResponse = assignmentClient
.getUserAssignments(userMapper.mapUserAssignmentRequest(userCriteriaDTO, token))) {
return Response.status(Response.Status.OK).entity(userMapper.map(
assignmentResponse.readEntity(UserAssignmentPageResult.class))).build();
}
return Response.status(Response.Status.OK).entity(resultDTO).build();
}

@ServerExceptionMapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@
import org.mapstruct.Mapping;
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper;

import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesAndPermissionsCriteriaDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesAndPermissionsPageResultDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesAndPermissionsPageResultPermissionsDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesAndPermissionsPageResultRolesDTO;
import gen.org.tkit.onecx.permission.client.model.PermissionPageResult;
import gen.org.tkit.onecx.permission.client.model.PermissionRequest;
import gen.org.tkit.onecx.permission.client.model.RolePageResult;
import gen.org.tkit.onecx.permission.client.model.RoleRequest;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserAssignmentPageResultDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserCriteriaDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserPermissionsPageResultDTO;
import gen.org.tkit.onecx.permission.bff.rs.internal.model.UserRolesPageResultDTO;
import gen.org.tkit.onecx.permission.client.model.*;

@Mapper(uses = { OffsetDateTimeMapper.class })
public interface UserMapper {

@Mapping(target = "pageSize", source = "userRolesAndPermissionsCriteriaDTO.rolesPageSize")
@Mapping(target = "pageNumber", source = "userRolesAndPermissionsCriteriaDTO.rolesPageNumber")
RoleRequest mapRoleRequest(UserRolesAndPermissionsCriteriaDTO userRolesAndPermissionsCriteriaDTO, String token);
RoleRequest mapUserRoleRequest(UserCriteriaDTO userCriteriaDTO, String token);

@Mapping(target = "pageSize", source = "userRolesAndPermissionsCriteriaDTO.permissionsPageSize")
@Mapping(target = "pageNumber", source = "userRolesAndPermissionsCriteriaDTO.permissionsPageNumber")
PermissionRequest mapPermissionRequest(UserRolesAndPermissionsCriteriaDTO userRolesAndPermissionsCriteriaDTO, String token);
PermissionRequest mapUserPermissionRequest(UserCriteriaDTO userCriteriaDTO, String token);

@Mapping(target = "roles", source = "rolePageResult")
@Mapping(target = "permissions", source = "permissionPageResult")
UserRolesAndPermissionsPageResultDTO map(RolePageResult rolePageResult, PermissionPageResult permissionPageResult);
AssignmentRequest mapUserAssignmentRequest(UserCriteriaDTO userCriteriaDTO, String token);

@Mapping(target = "removeStreamItem", ignore = true)
UserRolesAndPermissionsPageResultRolesDTO map(RolePageResult rolePageResult);
UserPermissionsPageResultDTO map(PermissionPageResult permissionPageResult);

@Mapping(target = "removeStreamItem", ignore = true)
UserRolesAndPermissionsPageResultPermissionsDTO map(PermissionPageResult permissionPageResult);
UserRolesPageResultDTO map(RolePageResult rolePageResult);

@Mapping(target = "removeStreamItem", ignore = true)
UserAssignmentPageResultDTO map(UserAssignmentPageResult pageResult);

}
181 changes: 135 additions & 46 deletions src/main/openapi/openapi-bff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -657,31 +657,123 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/WorkspaceDetails'
/user/me:
/user/permissions:
post:
x-onecx:
permissions:
permission:
- read
tags:
- user
description: get user roles and permissions
operationId: getUserRolesAndPermissions
description: get user permissions
operationId: getUserPermissions
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserRolesAndPermissionsCriteria'
$ref: '#/components/schemas/UserCriteria'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/UserRolesAndPermissionsPageResult'
$ref: '#/components/schemas/UserPermissionsPageResult'
/user/roles:
post:
x-onecx:
permissions:
role:
- read
tags:
- user
description: get user roles
operationId: getUserRoles
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserCriteria'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/UserRolesPageResult'
/user/assignments:
post:
x-onecx:
permissions:
assignment:
- read
tags:
- user
description: get user assignments
operationId: getUserAssignments
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserCriteria'
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/UserAssignmentPageResult'
components:
schemas:
UserCriteria:
type: object
properties:
pageNumber:
format: int32
description: The number of page.
default: 0
type: integer
pageSize:
format: int32
description: The size of page
default: 100
type: integer
UserAssignmentPageResult:
type: object
properties:
totalElements:
format: int64
description: The total elements in the resource.
type: integer
number:
format: int32
type: integer
size:
format: int32
type: integer
totalPages:
format: int64
type: integer
stream:
type: array
items:
$ref: '#/components/schemas/UserAssignment'
UserAssignment:
type: object
properties:
roleName:
type: string
productName:
type: string
applicationId:
type: string
resource:
type: string
action:
type: string
UserRolesAndPermissionsCriteria:
type: object
properties:
Expand All @@ -705,49 +797,46 @@ components:
description: The size of page
default: 100
type: integer
UserRolesAndPermissionsPageResult:
UserPermissionsPageResult:
type: object
properties:
roles:
type: object
properties:
totalElements:
format: int64
description: The total elements in the resource.
type: integer
number:
format: int32
type: integer
size:
format: int32
type: integer
totalPages:
format: int64
type: integer
stream:
type: array
items:
$ref: '#/components/schemas/Role'
permissions:
type: object
properties:
totalElements:
format: int64
description: The total elements in the resource.
type: integer
number:
format: int32
type: integer
size:
format: int32
type: integer
totalPages:
format: int64
type: integer
stream:
type: array
items:
$ref: '#/components/schemas/Permission'
totalElements:
format: int64
description: The total elements in the resource.
type: integer
number:
format: int32
type: integer
size:
format: int32
type: integer
totalPages:
format: int64
type: integer
stream:
type: array
items:
$ref: '#/components/schemas/Permission'
UserRolesPageResult:
type: object
properties:
totalElements:
format: int64
description: The total elements in the resource.
type: integer
number:
format: int32
type: integer
size:
format: int32
type: integer
totalPages:
format: int64
type: integer
stream:
type: array
items:
$ref: '#/components/schemas/Role'
CreateRolesRequest:
type: object
properties:
Expand Down
Loading

0 comments on commit 7c4f896

Please sign in to comment.