1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

fix: messed up on merge-conflicts

This commit is contained in:
Gastón Fournier 2024-08-14 11:55:08 +02:00
parent 8a57b2b6a4
commit 38bc2068aa
No known key found for this signature in database
GPG Key ID: AF45428626E17A8E
2 changed files with 35 additions and 31 deletions

View File

@ -520,22 +520,30 @@ export default class UserAdminController extends Controller {
? Number(rootRole)
: (rootRole as RoleName);
const { createdUser, inviteLink, emailSent } =
await this.userService.createUserWithEmail(
{
username,
email,
name,
password,
rootRole: normalizedRootRole,
},
sendEmail,
req.audit,
);
const createdUser = await this.userService.createUser(
{
username,
email,
name,
password,
rootRole: normalizedRootRole,
},
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 = {
...serializeDates(createdUser),
inviteLink: inviteLink,
inviteLink,
emailSent,
rootRole: normalizedRootRole,
};

View File

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