Skip to content

Commit 0c668c5

Browse files
Feature/display application permissons (#216)
* Fixed permission fetching * Added permissions to application fetch * Cleaned up get permissions query
1 parent 7b2e0f3 commit 0c668c5

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/controllers/user-management/permission.controller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,14 @@ export class PermissionController {
222222
@Req() req: AuthenticatedRequest,
223223
@Query() query?: ListAllPermissionsDto
224224
): Promise<ListAllPermissionsResponseDto> {
225-
if (req.user.permissions.isGlobalAdmin) {
226-
return this.permissionService.getAllPermissions(query);
227-
} else {
225+
if (!req.user.permissions.isGlobalAdmin && query.organisationId === undefined) {
228226
const allowedOrganizations = req.user.permissions.getAllOrganizationsWithUserAdmin();
229227
return this.permissionService.getAllPermissionsInOrganizations(
230228
allowedOrganizations,
231229
query
232230
);
233231
}
232+
return this.permissionService.getAllPermissions(query);
234233
}
235234

236235
@Get(":id")

src/entities/dto/list-all-permissions.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export class ListAllPermissionsDto extends ListAllEntitiesDto {
66
organisationId?: number;
77

88
@ApiProperty({ type: String, required: false })
9-
userId?: number;
9+
userId?: string;
1010
}

src/services/device-management/application.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export class ApplicationService {
171171
"belongsTo",
172172
nameof<Application>("controlledProperties"),
173173
nameof<Application>("deviceTypes"),
174+
"permissions",
174175
],
175176
loadRelationIds: {
176177
relations: ["createdBy", "updatedBy"],

src/services/user-management/permission.service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,13 @@ export class PermissionService {
275275
.skip(query?.offset ? +query.offset : 0)
276276
.orderBy(orderBy, order);
277277

278-
if (query?.userId) {
279-
qb = qb.where("user.id = :userId", { userId: +query.userId });
280-
} else if (orgs) {
281-
qb.where({ organization: In(orgs) });
278+
if (query?.userId !== undefined && query.userId !== "undefined") {
279+
qb = qb.andWhere("user.id = :userId", { userId: +query.userId });
280+
}
281+
if (orgs) {
282+
qb = qb.andWhere({ organization: In(orgs) });
282283
} else if (query?.organisationId) {
283-
qb = qb.where("org.id = :orgId", { orgId: +query.organisationId });
284+
qb = qb.andWhere("org.id = :orgId", { orgId: +query.organisationId });
284285
}
285286

286287
const [data, count] = await qb.getManyAndCount();

0 commit comments

Comments
 (0)