1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

fix: update permission response

This commit is contained in:
2022-07-02 01:03:53 +05:00
parent f3dfc7083f
commit e516b7716d
7 changed files with 94 additions and 15 deletions

View File

@@ -171,7 +171,7 @@ components:
user:
$ref: '#/components/schemas/UserResponse'
group:
$ref: '#/components/schemas/GroupResponse'
$ref: '#/components/schemas/GroupDetailsResponse'
required:
- permissionId
- uri
@@ -1008,7 +1008,7 @@ paths:
type: array
examples:
'Example 1':
value: [{permissionId: 123, uri: /SASjsApi/code/execute, setting: Grant, user: {id: 1, username: johnSnow01, displayName: 'John Snow', isAdmin: false}}, {permissionId: 124, uri: /SASjsApi/code/execute, setting: Grant, group: {groupId: 1, name: DCGroup, description: 'This group represents Data Controller Users'}}]
value: [{permissionId: 123, uri: /SASjsApi/code/execute, setting: Grant, user: {id: 1, username: johnSnow01, displayName: 'John Snow', isAdmin: false}}, {permissionId: 124, uri: /SASjsApi/code/execute, setting: Grant, group: {groupId: 1, name: DCGroup, description: 'This group represents Data Controller Users', isActive: true, users: []}}]
summary: 'Get list of all permissions (uri, setting and userDetail).'
tags:
- Permission

View File

@@ -20,7 +20,7 @@ export interface GroupResponse {
description: string
}
interface GroupDetailsResponse {
export interface GroupDetailsResponse {
groupId: number
name: string
description: string

View File

@@ -15,7 +15,7 @@ import Permission from '../model/Permission'
import User from '../model/User'
import Group from '../model/Group'
import { UserResponse } from './user'
import { GroupResponse } from './group'
import { GroupDetailsResponse } from './group'
export enum PrincipalType {
user = 'user',
@@ -63,7 +63,7 @@ export interface PermissionDetailsResponse {
uri: string
setting: string
user?: UserResponse
group?: GroupResponse
group?: GroupDetailsResponse
}
@Security('bearerAuth')
@@ -93,7 +93,9 @@ export class PermissionController {
group: {
groupId: 1,
name: 'DCGroup',
description: 'This group represents Data Controller Users'
description: 'This group represents Data Controller Users',
isActive: true,
users: []
}
}
])
@@ -170,7 +172,12 @@ const getAllPermissions = async (): Promise<PermissionDetailsResponse[]> =>
.populate({ path: 'user', select: 'id username displayName isAdmin -_id' })
.populate({
path: 'group',
select: 'groupId name description -_id'
select: 'groupId name description -_id',
populate: {
path: 'users',
select: 'id username displayName isAdmin -_id',
options: { limit: 15 }
}
})) as unknown as PermissionDetailsResponse[]
const createPermission = async ({
@@ -185,7 +192,7 @@ const createPermission = async ({
})
let user: UserResponse | undefined
let group: GroupResponse | undefined
let group: GroupDetailsResponse | undefined
switch (principalType) {
case PrincipalType.user: {
@@ -251,7 +258,13 @@ const createPermission = async ({
group = {
groupId: groupInDB.groupId,
name: groupInDB.name,
description: groupInDB.description
description: groupInDB.description,
isActive: groupInDB.isActive,
users: groupInDB.populate({
path: 'users',
select: 'id username displayName isAdmin -_id',
options: { limit: 15 }
}) as unknown as UserResponse[]
}
break
}