Skip to content

Commit

Permalink
Feature/iot 1583 move application (#265)
Browse files Browse the repository at this point in the history
* Added endpoint for application admins, to get a slimmer version of permissions.

* Cleanup

---------

Co-authored-by: Frederik Christ Vestergaard <[email protected]>
  • Loading branch information
MadsApollo and fcv-iteratorIt authored Sep 26, 2024
1 parent 7321dfd commit dcfe7c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/controllers/user-management/permission.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { OrganizationService } from "@services/user-management/organization.serv
import { Organization } from "@entities/organization.entity";
import { User } from "@entities/user.entity";
import { ApiAuth } from "@auth/swagger-auth-decorator";
import { ListAllPermissionsSlimResponseDto } from "@dto/list-all-permissions-slim-response.dto";

@UseGuards(JwtAuthGuard, RolesGuard)
@ApiAuth()
Expand Down Expand Up @@ -183,6 +184,28 @@ export class PermissionController {
return this.permissionService.getAllPermissions(query);
}

@Get("/applicationAdmin")
@ApiOperation({ summary: "Get list of all permissions for application admins" })
async getAllPermissionsWithApplicationAdmin(
@Req() req: AuthenticatedRequest,
@Query() query?: ListAllPermissionsDto
): Promise<ListAllPermissionsSlimResponseDto> {
if (!req.user.permissions.isGlobalAdmin && query.organisationId === undefined) {
const allowedOrganizations = req.user.permissions.getAllOrganizationsWithApplicationAdmin();
const permissions = await this.permissionService.getAllPermissionsInOrganizations(allowedOrganizations, query);
return {
count: permissions.count,
data: permissions.data.map(p => ({
id: p.id,
name: p.name,
automaticallyAddNewApplications: p.automaticallyAddNewApplications,
organization: p.organization,
})),
};
}
return this.permissionService.getAllPermissions(query);
}

@Get("getAllPermissionsWithoutUsers")
@ApiOperation({ summary: "Get list of all permissions without include users" })
async getAllPermissionsWithoutUsers(
Expand Down
7 changes: 7 additions & 0 deletions src/entities/dto/list-all-permissions-slim-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Permission } from "@entities/permissions/permission.entity";
import { ListAllEntitiesResponseDto } from "./list-all-entities-response.dto";

export type PermissionsSlimDto = Pick<Permission, "id" | "name" | "automaticallyAddNewApplications"> & {
organization: { id: number };
};
export class ListAllPermissionsSlimResponseDto extends ListAllEntitiesResponseDto<PermissionsSlimDto> {}

0 comments on commit dcfe7c0

Please sign in to comment.