mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 19:44:35 +00:00
feat: add api endpoint for deleting permission
This commit is contained in:
@@ -1448,7 +1448,7 @@ paths:
|
|||||||
examples:
|
examples:
|
||||||
'Example 1':
|
'Example 1':
|
||||||
value: {permissionId: 123, uri: /SASjsApi/code/execute, setting: Grant, user: {id: 1, username: johnSnow01, displayName: 'John Snow'}}
|
value: {permissionId: 123, uri: /SASjsApi/code/execute, setting: Grant, user: {id: 1, username: johnSnow01, displayName: 'John Snow'}}
|
||||||
summary: 'Update permission setting.'
|
summary: 'Update permission setting. Admin only'
|
||||||
tags:
|
tags:
|
||||||
- Permission
|
- Permission
|
||||||
security:
|
security:
|
||||||
@@ -1463,12 +1463,34 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
format: double
|
format: double
|
||||||
type: number
|
type: number
|
||||||
|
example: 1234
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/UpdatePermissionPayload'
|
$ref: '#/components/schemas/UpdatePermissionPayload'
|
||||||
|
delete:
|
||||||
|
operationId: DeletePermission
|
||||||
|
responses:
|
||||||
|
'204':
|
||||||
|
description: 'No content'
|
||||||
|
summary: 'Delete a permission. Admin only.'
|
||||||
|
tags:
|
||||||
|
- Permission
|
||||||
|
security:
|
||||||
|
-
|
||||||
|
bearerAuth: []
|
||||||
|
parameters:
|
||||||
|
-
|
||||||
|
description: 'The user''s identifier'
|
||||||
|
in: path
|
||||||
|
name: permissionId
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
format: double
|
||||||
|
type: number
|
||||||
|
example: 1234
|
||||||
servers:
|
servers:
|
||||||
-
|
-
|
||||||
url: /
|
url: /
|
||||||
|
|||||||
@@ -113,9 +113,9 @@ export class PermissionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Update permission setting.
|
* @summary Update permission setting. Admin only
|
||||||
* @param permissionId The permission's identifier
|
* @param permissionId The permission's identifier
|
||||||
* @example userId "1234"
|
* @example permissionId 1234
|
||||||
*/
|
*/
|
||||||
@Example<PermissionDetailsResponse>({
|
@Example<PermissionDetailsResponse>({
|
||||||
permissionId: 123,
|
permissionId: 123,
|
||||||
@@ -130,6 +130,16 @@ export class PermissionController {
|
|||||||
): Promise<PermissionDetailsResponse> {
|
): Promise<PermissionDetailsResponse> {
|
||||||
return updatePermission(permissionId, body)
|
return updatePermission(permissionId, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @summary Delete a permission. Admin only.
|
||||||
|
* @param permissionId The user's identifier
|
||||||
|
* @example permissionId 1234
|
||||||
|
*/
|
||||||
|
@Delete('{permissionId}')
|
||||||
|
public async deletePermission(@Path() permissionId: number) {
|
||||||
|
return deletePermission(permissionId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAllPermissions = async (): Promise<PermissionDetailsResponse[]> =>
|
const getAllPermissions = async (): Promise<PermissionDetailsResponse[]> =>
|
||||||
@@ -233,3 +243,9 @@ const updatePermission = async (
|
|||||||
|
|
||||||
return updatedPermission
|
return updatedPermission
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deletePermission = async (id: number) => {
|
||||||
|
const permission = await Permission.findOne({ id })
|
||||||
|
if (!permission) throw new Error('Permission is not found.')
|
||||||
|
await Permission.deleteOne({ id })
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,4 +53,20 @@ permissionRouter.patch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
permissionRouter.delete(
|
||||||
|
'/:permissionId',
|
||||||
|
authenticateAccessToken,
|
||||||
|
verifyAdmin,
|
||||||
|
async (req: any, res) => {
|
||||||
|
const { permissionId } = req.params
|
||||||
|
|
||||||
|
try {
|
||||||
|
await controller.deletePermission(permissionId)
|
||||||
|
res.status(200).send('Permission Deleted!')
|
||||||
|
} catch (err: any) {
|
||||||
|
res.status(403).send(err.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
export default permissionRouter
|
export default permissionRouter
|
||||||
|
|||||||
Reference in New Issue
Block a user