mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat: RBAC (#8922)
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com> Co-authored-by: Val <68596159+valya@users.noreply.github.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in> Co-authored-by: Valya Bullions <valya@n8n.io> Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: Danny Martini <despair.blue@gmail.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Omar Ajoue <krynble@gmail.com> Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: Michael Kret <michael.k@radency.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Giulio Andreini <andreini@netseven.it> Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Ayato Hayashi <go12limchangyong@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { Container, Service } from 'typedi';
|
||||
import type { IUserSettings } from 'n8n-workflow';
|
||||
import { ApplicationError, ErrorReporterProxy as ErrorReporter } from 'n8n-workflow';
|
||||
|
||||
import { type AssignableRole, User } from '@db/entities/User';
|
||||
import type { User, AssignableRole } from '@db/entities/User';
|
||||
import { UserRepository } from '@db/repositories/user.repository';
|
||||
import type { PublicUser } from '@/Interfaces';
|
||||
import type { PostHogClient } from '@/posthog';
|
||||
@@ -23,7 +23,13 @@ export class UserService {
|
||||
) {}
|
||||
|
||||
async update(userId: string, data: Partial<User>) {
|
||||
return await this.userRepository.update(userId, data);
|
||||
const user = await this.userRepository.findOneBy({ id: userId });
|
||||
|
||||
if (user) {
|
||||
await this.userRepository.save({ ...user, ...data }, { transaction: true });
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
getManager() {
|
||||
@@ -31,9 +37,15 @@ export class UserService {
|
||||
}
|
||||
|
||||
async updateSettings(userId: string, newSettings: Partial<IUserSettings>) {
|
||||
const { settings } = await this.userRepository.findOneOrFail({ where: { id: userId } });
|
||||
const user = await this.userRepository.findOneOrFail({ where: { id: userId } });
|
||||
|
||||
return await this.userRepository.update(userId, { settings: { ...settings, ...newSettings } });
|
||||
if (user.settings) {
|
||||
Object.assign(user.settings, newSettings);
|
||||
} else {
|
||||
user.settings = newSettings;
|
||||
}
|
||||
|
||||
await this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async toPublic(
|
||||
@@ -192,8 +204,10 @@ export class UserService {
|
||||
async (transactionManager) =>
|
||||
await Promise.all(
|
||||
toCreateUsers.map(async ({ email, role }) => {
|
||||
const newUser = transactionManager.create(User, { email, role });
|
||||
const savedUser = await transactionManager.save<User>(newUser);
|
||||
const { user: savedUser } = await this.userRepository.createUserWithProject(
|
||||
{ email, role },
|
||||
transactionManager,
|
||||
);
|
||||
createdUsers.set(email, savedUser.id);
|
||||
return savedUser;
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user