mirror of
https://github.com/sasjs/server.git
synced 2026-01-06 06:10:04 +00:00
chore: add isAdmin field in user response
This commit is contained in:
@@ -198,7 +198,7 @@ const getGroup = async (findBy: GetGroupBy): Promise<GroupDetailsResponse> => {
|
||||
'groupId name description isActive users -_id'
|
||||
).populate(
|
||||
'users',
|
||||
'id username displayName -_id'
|
||||
'id username displayName isAdmin -_id'
|
||||
)) as unknown as GroupDetailsResponse
|
||||
if (!group)
|
||||
throw {
|
||||
|
||||
@@ -69,7 +69,12 @@ export class PermissionController {
|
||||
permissionId: 123,
|
||||
uri: '/SASjsApi/code/execute',
|
||||
setting: 'Grant',
|
||||
user: { id: 1, username: 'johnSnow01', displayName: 'John Snow' }
|
||||
user: {
|
||||
id: 1,
|
||||
username: 'johnSnow01',
|
||||
displayName: 'John Snow',
|
||||
isAdmin: false
|
||||
}
|
||||
},
|
||||
{
|
||||
permissionId: 124,
|
||||
@@ -95,7 +100,12 @@ export class PermissionController {
|
||||
permissionId: 123,
|
||||
uri: '/SASjsApi/code/execute',
|
||||
setting: 'Grant',
|
||||
user: { id: 1, username: 'johnSnow01', displayName: 'John Snow' }
|
||||
user: {
|
||||
id: 1,
|
||||
username: 'johnSnow01',
|
||||
displayName: 'John Snow',
|
||||
isAdmin: false
|
||||
}
|
||||
})
|
||||
@Post('/')
|
||||
public async createPermission(
|
||||
@@ -113,7 +123,12 @@ export class PermissionController {
|
||||
permissionId: 123,
|
||||
uri: '/SASjsApi/code/execute',
|
||||
setting: 'Grant',
|
||||
user: { id: 1, username: 'johnSnow01', displayName: 'John Snow' }
|
||||
user: {
|
||||
id: 1,
|
||||
username: 'johnSnow01',
|
||||
displayName: 'John Snow',
|
||||
isAdmin: false
|
||||
}
|
||||
})
|
||||
@Patch('{permissionId}')
|
||||
public async updatePermission(
|
||||
@@ -142,7 +157,7 @@ const getAllPermissions = async (): Promise<PermissionDetailsResponse[]> =>
|
||||
uri: 1,
|
||||
setting: 1
|
||||
})
|
||||
.populate({ path: 'user', select: 'id username displayName -_id' })
|
||||
.populate({ path: 'user', select: 'id username displayName isAdmin -_id' })
|
||||
.populate({
|
||||
path: 'group',
|
||||
select: 'groupId name description -_id'
|
||||
@@ -183,7 +198,8 @@ const createPermission = async ({
|
||||
user = {
|
||||
id: userInDB.id,
|
||||
username: userInDB.username,
|
||||
displayName: userInDB.displayName
|
||||
displayName: userInDB.displayName,
|
||||
isAdmin: userInDB.isAdmin
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -241,7 +257,7 @@ const updatePermission = async (
|
||||
uri: 1,
|
||||
setting: 1
|
||||
})
|
||||
.populate({ path: 'user', select: 'id username displayName -_id' })
|
||||
.populate({ path: 'user', select: 'id username displayName isAdmin -_id' })
|
||||
.populate({
|
||||
path: 'group',
|
||||
select: 'groupId name description -_id'
|
||||
|
||||
@@ -2,10 +2,6 @@ import express from 'express'
|
||||
import { Request, Security, Route, Tags, Example, Get } from 'tsoa'
|
||||
import { UserResponse } from './user'
|
||||
|
||||
interface SessionResponse extends UserResponse {
|
||||
isAdmin: boolean
|
||||
}
|
||||
|
||||
@Security('bearerAuth')
|
||||
@Route('SASjsApi/session')
|
||||
@Tags('Session')
|
||||
@@ -14,7 +10,7 @@ export class SessionController {
|
||||
* @summary Get session info (username).
|
||||
*
|
||||
*/
|
||||
@Example<SessionResponse>({
|
||||
@Example<UserResponse>({
|
||||
id: 123,
|
||||
username: 'johnusername',
|
||||
displayName: 'John',
|
||||
@@ -23,7 +19,7 @@ export class SessionController {
|
||||
@Get('/')
|
||||
public async session(
|
||||
@Request() request: express.Request
|
||||
): Promise<SessionResponse> {
|
||||
): Promise<UserResponse> {
|
||||
return session(request)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface UserResponse {
|
||||
id: number
|
||||
username: string
|
||||
displayName: string
|
||||
isAdmin: boolean
|
||||
}
|
||||
|
||||
export interface UserDetailsResponse {
|
||||
@@ -48,12 +49,14 @@ export class UserController {
|
||||
{
|
||||
id: 123,
|
||||
username: 'johnusername',
|
||||
displayName: 'John'
|
||||
displayName: 'John',
|
||||
isAdmin: false
|
||||
},
|
||||
{
|
||||
id: 456,
|
||||
username: 'starkusername',
|
||||
displayName: 'Stark'
|
||||
displayName: 'Stark',
|
||||
isAdmin: true
|
||||
}
|
||||
])
|
||||
@Get('/')
|
||||
@@ -200,7 +203,7 @@ export class UserController {
|
||||
|
||||
const getAllUsers = async (): Promise<UserResponse[]> =>
|
||||
await User.find({})
|
||||
.select({ _id: 0, id: 1, username: 1, displayName: 1 })
|
||||
.select({ _id: 0, id: 1, username: 1, displayName: 1, isAdmin: 1 })
|
||||
.exec()
|
||||
|
||||
const createUser = async (data: UserPayload): Promise<UserDetailsResponse> => {
|
||||
|
||||
Reference in New Issue
Block a user