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

fix: add user to all users group on user creation

This commit is contained in:
2023-02-03 16:47:18 +05:00
parent b243e62ece
commit 2bae52e307
2 changed files with 14 additions and 7 deletions

View File

@@ -21,9 +21,9 @@ import {
getUserAutoExec, getUserAutoExec,
updateUserAutoExec, updateUserAutoExec,
ModeType, ModeType,
AuthProviderType ALL_USERS_GROUP
} from '../utils' } from '../utils'
import { GroupResponse } from './group' import { GroupController, GroupResponse } from './group'
export interface UserResponse { export interface UserResponse {
id: number id: number
@@ -237,6 +237,13 @@ const createUser = async (data: UserPayload): Promise<UserDetailsResponse> => {
const savedUser = await user.save() const savedUser = await user.save()
const groupController = new GroupController()
const allUsersGroup = await groupController.getGroupByGroupName(
ALL_USERS_GROUP.name
)
await groupController.addUserToGroup(allUsersGroup.groupId, savedUser.id)
return { return {
id: savedUser.id, id: savedUser.id,
displayName: savedUser.displayName, displayName: savedUser.displayName,

View File

@@ -23,12 +23,12 @@ export const seedDB = async (): Promise<ConfigurationType> => {
} }
// Checking if 'AllUsers' Group is already in the database // Checking if 'AllUsers' Group is already in the database
let groupExist = await Group.findOne({ name: GROUP.name }) let groupExist = await Group.findOne({ name: ALL_USERS_GROUP.name })
if (!groupExist) { if (!groupExist) {
const group = new Group(GROUP) const group = new Group(ALL_USERS_GROUP)
groupExist = await group.save() groupExist = await group.save()
process.logger.success(`DB Seed - Group created: ${GROUP.name}`) process.logger.success(`DB Seed - Group created: ${ALL_USERS_GROUP.name}`)
} }
// Checking if 'Public' Group is already in the database // Checking if 'Public' Group is already in the database
@@ -54,7 +54,7 @@ export const seedDB = async (): Promise<ConfigurationType> => {
if (!groupExist.hasUser(usernameExist)) { if (!groupExist.hasUser(usernameExist)) {
groupExist.addUser(usernameExist) groupExist.addUser(usernameExist)
process.logger.success( process.logger.success(
`DB Seed - admin account '${ADMIN_USER.username}' added to Group '${GROUP.name}'` `DB Seed - admin account '${ADMIN_USER.username}' added to Group '${ALL_USERS_GROUP.name}'`
) )
} }
@@ -75,7 +75,7 @@ export const seedDB = async (): Promise<ConfigurationType> => {
} }
} }
const GROUP = { export const ALL_USERS_GROUP = {
name: 'AllUsers', name: 'AllUsers',
description: 'Group contains all users' description: 'Group contains all users'
} }