1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-10 01:16:39 +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)
: (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

@ -259,20 +259,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,
@ -282,20 +272,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,
);
@ -312,7 +308,7 @@ class UserService {
);
}
return { createdUser, inviteLink, emailSent };
return emailSent;
}
async updateUser(