Skip to content

Commit

Permalink
fix(findbyrole): find by id
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerald Baulig committed Nov 24, 2023
1 parent 44bab4d commit af2335d
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,15 +485,24 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
}
};
}

if (acsResponse.decision != Response_Decision.PERMIT) {
return { operation_status: acsResponse.operation_status };
}

const acsFilters = getACSFilters(acsResponse, 'user');
const readRequest = ReadRequest.fromPartial({
offset: request.offset, limit: request.limit,
sorts: request.sorts, filters: request.filters, fields: request.fields, locales_limiter: request.locales_limiter,
custom_arguments: request.custom_arguments, custom_queries: request.custom_queries, search: request.search
offset: request.offset,
limit: request.limit,
sorts: request.sorts,
filters: request.filters,
fields: request.fields,
locales_limiter: request.locales_limiter,
custom_arguments: request.custom_arguments,
custom_queries: request.custom_queries,
search: request.search
});

if (acsResponse?.filters && acsFilters) {
if (!readRequest.filters) {
readRequest.filters = [];
Expand All @@ -506,24 +515,15 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
readRequest.custom_arguments = acsResponse.custom_query_args[0].custom_arguments;
}

if (acsResponse.decision === Response_Decision.PERMIT) {
let users = await super.read(readRequest, context) as UserListWithRoleResponse;
let roles = await this.roleService.read(ReadRequest.fromPartial({ subject }), context);
let rolesList = roles?.items?.map(e => e.payload);
users?.items?.forEach(userObj => {
let userRoles = [];
if (userObj?.payload) {
userObj?.payload?.role_associations?.forEach(roleAssoc => {
let role = rolesList?.filter(r => r.id === roleAssoc?.role);
if (role?.length === 1) {
userRoles.push(role[0]);
}
});
userObj.payload.roles = userRoles;
}
});
return users;
}
const users = await super.read(readRequest, context) as UserListWithRoleResponse;
const roles = await this.roleService.read(ReadRequest.fromPartial({ subject }), context);
const rolesList = roles?.items?.map(e => e.payload);
users?.items?.forEach(userObj => {
userObj.payload.roles = userObj?.payload?.role_associations?.flatMap(
roleAssoc => rolesList?.filter(r => r.id === roleAssoc?.role)
);
});
return users;
}

superRead(request: ReadRequest, context): Promise<DeepPartial<UserListResponse>> {
Expand Down Expand Up @@ -2370,19 +2370,19 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
}

if (acsResponse.decision === Response_Decision.PERMIT) {
const filters = [{
filters: [{
field: 'name',
operation: Filter_Operation.eq,
value: role
},{
field: 'id',
operation: Filter_Operation.eq,
value: role
}]
}];
const result = await this.roleService.read(ReadRequest.fromPartial({
filters,
filters: [{
filters: [{
field: 'name',
operation: Filter_Operation.eq,
value: role
},{
field: 'id',
operation: Filter_Operation.eq,
value: role
}],
operator: FilterOp_Operator.or,
}],
fields: [{
name: 'id',
include: true
Expand Down

0 comments on commit af2335d

Please sign in to comment.