mirror of
https://github.com/sasjs/server.git
synced 2025-12-11 03:34:35 +00:00
chore: add isAdmin field in user response
This commit is contained in:
@@ -314,10 +314,13 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
displayName:
|
displayName:
|
||||||
type: string
|
type: string
|
||||||
|
isAdmin:
|
||||||
|
type: boolean
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- username
|
- username
|
||||||
- displayName
|
- displayName
|
||||||
|
- isAdmin
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
GroupResponse:
|
GroupResponse:
|
||||||
@@ -535,24 +538,6 @@ components:
|
|||||||
- setting
|
- setting
|
||||||
type: object
|
type: object
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
SessionResponse:
|
|
||||||
properties:
|
|
||||||
id:
|
|
||||||
type: number
|
|
||||||
format: double
|
|
||||||
username:
|
|
||||||
type: string
|
|
||||||
displayName:
|
|
||||||
type: string
|
|
||||||
isAdmin:
|
|
||||||
type: boolean
|
|
||||||
required:
|
|
||||||
- id
|
|
||||||
- username
|
|
||||||
- displayName
|
|
||||||
- isAdmin
|
|
||||||
type: object
|
|
||||||
additionalProperties: false
|
|
||||||
ExecuteReturnJsonPayload:
|
ExecuteReturnJsonPayload:
|
||||||
properties:
|
properties:
|
||||||
_program:
|
_program:
|
||||||
@@ -1066,7 +1051,7 @@ paths:
|
|||||||
type: array
|
type: array
|
||||||
examples:
|
examples:
|
||||||
'Example 1':
|
'Example 1':
|
||||||
value: [{id: 123, username: johnusername, displayName: John}, {id: 456, username: starkusername, displayName: Stark}]
|
value: [{id: 123, username: johnusername, displayName: John, isAdmin: false}, {id: 456, username: starkusername, displayName: Stark, isAdmin: true}]
|
||||||
summary: 'Get list of all users (username, displayname). All users can request this.'
|
summary: 'Get list of all users (username, displayname). All users can request this.'
|
||||||
tags:
|
tags:
|
||||||
- User
|
- User
|
||||||
@@ -1509,7 +1494,7 @@ paths:
|
|||||||
type: array
|
type: array
|
||||||
examples:
|
examples:
|
||||||
'Example 1':
|
'Example 1':
|
||||||
value: [{permissionId: 123, uri: /SASjsApi/code/execute, setting: Grant, user: {id: 1, username: johnSnow01, displayName: 'John Snow'}}, {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'}}]
|
||||||
summary: 'Get list of all permissions (uri, setting and userDetail).'
|
summary: 'Get list of all permissions (uri, setting and userDetail).'
|
||||||
tags:
|
tags:
|
||||||
- Permission
|
- Permission
|
||||||
@@ -1528,7 +1513,7 @@ paths:
|
|||||||
$ref: '#/components/schemas/PermissionDetailsResponse'
|
$ref: '#/components/schemas/PermissionDetailsResponse'
|
||||||
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', isAdmin: false}}
|
||||||
summary: 'Create a new permission. Admin only.'
|
summary: 'Create a new permission. Admin only.'
|
||||||
tags:
|
tags:
|
||||||
- Permission
|
- Permission
|
||||||
@@ -1554,7 +1539,7 @@ paths:
|
|||||||
$ref: '#/components/schemas/PermissionDetailsResponse'
|
$ref: '#/components/schemas/PermissionDetailsResponse'
|
||||||
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', isAdmin: false}}
|
||||||
summary: 'Update permission setting. Admin only'
|
summary: 'Update permission setting. Admin only'
|
||||||
tags:
|
tags:
|
||||||
- Permission
|
- Permission
|
||||||
@@ -1607,7 +1592,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/SessionResponse'
|
$ref: '#/components/schemas/UserResponse'
|
||||||
examples:
|
examples:
|
||||||
'Example 1':
|
'Example 1':
|
||||||
value: {id: 123, username: johnusername, displayName: John, isAdmin: false}
|
value: {id: 123, username: johnusername, displayName: John, isAdmin: false}
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ const getGroup = async (findBy: GetGroupBy): Promise<GroupDetailsResponse> => {
|
|||||||
'groupId name description isActive users -_id'
|
'groupId name description isActive users -_id'
|
||||||
).populate(
|
).populate(
|
||||||
'users',
|
'users',
|
||||||
'id username displayName -_id'
|
'id username displayName isAdmin -_id'
|
||||||
)) as unknown as GroupDetailsResponse
|
)) as unknown as GroupDetailsResponse
|
||||||
if (!group)
|
if (!group)
|
||||||
throw {
|
throw {
|
||||||
|
|||||||
@@ -69,7 +69,12 @@ export class PermissionController {
|
|||||||
permissionId: 123,
|
permissionId: 123,
|
||||||
uri: '/SASjsApi/code/execute',
|
uri: '/SASjsApi/code/execute',
|
||||||
setting: 'Grant',
|
setting: 'Grant',
|
||||||
user: { id: 1, username: 'johnSnow01', displayName: 'John Snow' }
|
user: {
|
||||||
|
id: 1,
|
||||||
|
username: 'johnSnow01',
|
||||||
|
displayName: 'John Snow',
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
permissionId: 124,
|
permissionId: 124,
|
||||||
@@ -95,7 +100,12 @@ export class PermissionController {
|
|||||||
permissionId: 123,
|
permissionId: 123,
|
||||||
uri: '/SASjsApi/code/execute',
|
uri: '/SASjsApi/code/execute',
|
||||||
setting: 'Grant',
|
setting: 'Grant',
|
||||||
user: { id: 1, username: 'johnSnow01', displayName: 'John Snow' }
|
user: {
|
||||||
|
id: 1,
|
||||||
|
username: 'johnSnow01',
|
||||||
|
displayName: 'John Snow',
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
@Post('/')
|
@Post('/')
|
||||||
public async createPermission(
|
public async createPermission(
|
||||||
@@ -113,7 +123,12 @@ export class PermissionController {
|
|||||||
permissionId: 123,
|
permissionId: 123,
|
||||||
uri: '/SASjsApi/code/execute',
|
uri: '/SASjsApi/code/execute',
|
||||||
setting: 'Grant',
|
setting: 'Grant',
|
||||||
user: { id: 1, username: 'johnSnow01', displayName: 'John Snow' }
|
user: {
|
||||||
|
id: 1,
|
||||||
|
username: 'johnSnow01',
|
||||||
|
displayName: 'John Snow',
|
||||||
|
isAdmin: false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
@Patch('{permissionId}')
|
@Patch('{permissionId}')
|
||||||
public async updatePermission(
|
public async updatePermission(
|
||||||
@@ -142,7 +157,7 @@ const getAllPermissions = async (): Promise<PermissionDetailsResponse[]> =>
|
|||||||
uri: 1,
|
uri: 1,
|
||||||
setting: 1
|
setting: 1
|
||||||
})
|
})
|
||||||
.populate({ path: 'user', select: 'id username displayName -_id' })
|
.populate({ path: 'user', select: 'id username displayName isAdmin -_id' })
|
||||||
.populate({
|
.populate({
|
||||||
path: 'group',
|
path: 'group',
|
||||||
select: 'groupId name description -_id'
|
select: 'groupId name description -_id'
|
||||||
@@ -183,7 +198,8 @@ const createPermission = async ({
|
|||||||
user = {
|
user = {
|
||||||
id: userInDB.id,
|
id: userInDB.id,
|
||||||
username: userInDB.username,
|
username: userInDB.username,
|
||||||
displayName: userInDB.displayName
|
displayName: userInDB.displayName,
|
||||||
|
isAdmin: userInDB.isAdmin
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -241,7 +257,7 @@ const updatePermission = async (
|
|||||||
uri: 1,
|
uri: 1,
|
||||||
setting: 1
|
setting: 1
|
||||||
})
|
})
|
||||||
.populate({ path: 'user', select: 'id username displayName -_id' })
|
.populate({ path: 'user', select: 'id username displayName isAdmin -_id' })
|
||||||
.populate({
|
.populate({
|
||||||
path: 'group',
|
path: 'group',
|
||||||
select: 'groupId name description -_id'
|
select: 'groupId name description -_id'
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import express from 'express'
|
|||||||
import { Request, Security, Route, Tags, Example, Get } from 'tsoa'
|
import { Request, Security, Route, Tags, Example, Get } from 'tsoa'
|
||||||
import { UserResponse } from './user'
|
import { UserResponse } from './user'
|
||||||
|
|
||||||
interface SessionResponse extends UserResponse {
|
|
||||||
isAdmin: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
@Security('bearerAuth')
|
@Security('bearerAuth')
|
||||||
@Route('SASjsApi/session')
|
@Route('SASjsApi/session')
|
||||||
@Tags('Session')
|
@Tags('Session')
|
||||||
@@ -14,7 +10,7 @@ export class SessionController {
|
|||||||
* @summary Get session info (username).
|
* @summary Get session info (username).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Example<SessionResponse>({
|
@Example<UserResponse>({
|
||||||
id: 123,
|
id: 123,
|
||||||
username: 'johnusername',
|
username: 'johnusername',
|
||||||
displayName: 'John',
|
displayName: 'John',
|
||||||
@@ -23,7 +19,7 @@ export class SessionController {
|
|||||||
@Get('/')
|
@Get('/')
|
||||||
public async session(
|
public async session(
|
||||||
@Request() request: express.Request
|
@Request() request: express.Request
|
||||||
): Promise<SessionResponse> {
|
): Promise<UserResponse> {
|
||||||
return session(request)
|
return session(request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export interface UserResponse {
|
|||||||
id: number
|
id: number
|
||||||
username: string
|
username: string
|
||||||
displayName: string
|
displayName: string
|
||||||
|
isAdmin: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserDetailsResponse {
|
export interface UserDetailsResponse {
|
||||||
@@ -48,12 +49,14 @@ export class UserController {
|
|||||||
{
|
{
|
||||||
id: 123,
|
id: 123,
|
||||||
username: 'johnusername',
|
username: 'johnusername',
|
||||||
displayName: 'John'
|
displayName: 'John',
|
||||||
|
isAdmin: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 456,
|
id: 456,
|
||||||
username: 'starkusername',
|
username: 'starkusername',
|
||||||
displayName: 'Stark'
|
displayName: 'Stark',
|
||||||
|
isAdmin: true
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
@Get('/')
|
@Get('/')
|
||||||
@@ -200,7 +203,7 @@ export class UserController {
|
|||||||
|
|
||||||
const getAllUsers = async (): Promise<UserResponse[]> =>
|
const getAllUsers = async (): Promise<UserResponse[]> =>
|
||||||
await User.find({})
|
await User.find({})
|
||||||
.select({ _id: 0, id: 1, username: 1, displayName: 1 })
|
.select({ _id: 0, id: 1, username: 1, displayName: 1, isAdmin: 1 })
|
||||||
.exec()
|
.exec()
|
||||||
|
|
||||||
const createUser = async (data: UserPayload): Promise<UserDetailsResponse> => {
|
const createUser = async (data: UserPayload): Promise<UserDetailsResponse> => {
|
||||||
|
|||||||
@@ -770,12 +770,14 @@ describe('user', () => {
|
|||||||
{
|
{
|
||||||
id: expect.anything(),
|
id: expect.anything(),
|
||||||
username: adminUser.username,
|
username: adminUser.username,
|
||||||
displayName: adminUser.displayName
|
displayName: adminUser.displayName,
|
||||||
|
isAdmin: adminUser.isAdmin
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: expect.anything(),
|
id: expect.anything(),
|
||||||
username: user.username,
|
username: user.username,
|
||||||
displayName: user.displayName
|
displayName: user.displayName,
|
||||||
|
isAdmin: user.isAdmin
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@@ -796,12 +798,14 @@ describe('user', () => {
|
|||||||
{
|
{
|
||||||
id: expect.anything(),
|
id: expect.anything(),
|
||||||
username: adminUser.username,
|
username: adminUser.username,
|
||||||
displayName: adminUser.displayName
|
displayName: adminUser.displayName,
|
||||||
|
isAdmin: adminUser.isAdmin
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: expect.anything(),
|
id: expect.anything(),
|
||||||
username: 'randomUser',
|
username: 'randomUser',
|
||||||
displayName: user.displayName
|
displayName: user.displayName,
|
||||||
|
isAdmin: user.isAdmin
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user