1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-18 01:18:23 +02:00

fix: messed up on merge-conflicts (#7873)

When fixing conflicts accidentally I've undone my changes
This commit is contained in:
Gastón Fournier 2024-08-14 12:00:57 +02:00 committed by GitHub
parent cb6ba743ac
commit cac621c450
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 31 deletions

View File

@ -520,22 +520,30 @@ export default class UserAdminController extends Controller {
? Number(rootRole) ? Number(rootRole)
: (rootRole as RoleName); : (rootRole as RoleName);
const { createdUser, inviteLink, emailSent } = const createdUser = await this.userService.createUser(
await this.userService.createUserWithEmail( {
{ username,
username, email,
email, name,
name, password,
password, rootRole: normalizedRootRole,
rootRole: normalizedRootRole, },
}, req.audit,
sendEmail, );
req.audit,
); const inviteLink = await this.userService.newUserInviteLink(
createdUser,
req.audit,
);
// send email defaults to true
const emailSent = (sendEmail !== undefined ? sendEmail : true)
? await this.userService.sendWelcomeEmail(createdUser, inviteLink)
: false;
const responseData: CreateUserResponseSchema = { const responseData: CreateUserResponseSchema = {
...serializeDates(createdUser), ...serializeDates(createdUser),
inviteLink: inviteLink, inviteLink,
emailSent, emailSent,
rootRole: normalizedRootRole, rootRole: normalizedRootRole,
}; };

View File

@ -259,20 +259,10 @@ class UserService {
return userCreated; return userCreated;
} }
async createUserWithEmail( async newUserInviteLink(
{ username, email, name, password, rootRole }: ICreateUser, user: IUserWithRootRole,
sendEmail = true,
auditUser: IAuditUser = SYSTEM_USER_AUDIT, auditUser: IAuditUser = SYSTEM_USER_AUDIT,
): Promise<{ ): Promise<string> {
createdUser: IUserWithRootRole;
inviteLink: string;
emailSent: boolean;
}> {
const createdUser = await this.createUser(
{ username, email, name, password, rootRole },
auditUser,
);
const passwordAuthSettings = const passwordAuthSettings =
await this.settingService.getWithDefault<SimpleAuthSettings>( await this.settingService.getWithDefault<SimpleAuthSettings>(
simpleAuthSettingsKey, simpleAuthSettingsKey,
@ -282,20 +272,26 @@ class UserService {
let inviteLink = this.unleashUrl; let inviteLink = this.unleashUrl;
if (!passwordAuthSettings.disabled) { if (!passwordAuthSettings.disabled) {
const inviteUrl = await this.resetTokenService.createNewUserUrl( const inviteUrl = await this.resetTokenService.createNewUserUrl(
createdUser.id, user.id,
auditUser.username, auditUser.username,
); );
inviteLink = inviteUrl.toString(); inviteLink = inviteUrl.toString();
} }
return inviteLink;
}
async sendWelcomeEmail(
user: IUserWithRootRole,
inviteLink: string,
): Promise<boolean> {
let emailSent = false; let emailSent = false;
const emailConfigured = this.emailService.configured(); const emailConfigured = this.emailService.configured();
if (emailConfigured && sendEmail && createdUser.email) { if (emailConfigured && user.email) {
try { try {
await this.emailService.sendGettingStartedMail( await this.emailService.sendGettingStartedMail(
createdUser.name || '', user.name || '',
createdUser.email, user.email,
this.unleashUrl, this.unleashUrl,
inviteLink, inviteLink,
); );
@ -312,7 +308,7 @@ class UserService {
); );
} }
return { createdUser, inviteLink, emailSent }; return emailSent;
} }
async updateUser( async updateUser(