1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-06 22:20:06 +00:00

Merge pull request #337 from sasjs/issue-336

fix: add user to all users group on user creation
This commit is contained in:
Allan Bowe
2023-02-03 13:44:46 +00:00
committed by GitHub
3 changed files with 17 additions and 8 deletions

View File

@@ -159,7 +159,7 @@ const updatePassword = async (
) => { ) => {
const { currentPassword, newPassword } = data const { currentPassword, newPassword } = data
const userId = req.user?.userId const userId = req.user?.userId
const dbUser = await User.findOne({ userId }) const dbUser = await User.findOne({ id: userId })
if (!dbUser) if (!dbUser)
throw { throw {

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,15 @@ 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)
.catch(() => {})
if (allUsersGroup) {
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'
} }