Skip to content

Commit

Permalink
save user roles before running callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-lehnen-rc committed Jul 26, 2023
1 parent e4133bc commit 11121b4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions apps/meteor/server/services/user/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ export class UserService extends ServiceClassInternal implements IUserService {

const _id = await this.insertOne(user);

const hasAdmin = await Users.findOneByRolesAndType('admin', 'user', { projection: { _id: 1 } });
if (!roles.includes('admin') && !hasAdmin) {
roles.push('admin');
}

await addUserRolesAsync(_id, roles);

const newUser = await Users.findOne({
_id,
});
Expand All @@ -224,21 +231,16 @@ export class UserService extends ServiceClassInternal implements IUserService {
throw new Error('error-user-not-found');
}

if (!hasAdmin && roles.includes('admin') && settings.get('Show_Setup_Wizard') === 'pending') {
await Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}

if (newUser.username) {
await this.addUserToDefaultChannels(newUser, options);
await this.callAfterCreateUser(newUser);
await this.setDefaultAvatar(newUser);
}

const hasAdmin = await Users.findOneByRolesAndType('admin', 'user', { projection: { _id: 1 } });
if (!roles.includes('admin') && !hasAdmin) {
roles.push('admin');
if (settings.get('Show_Setup_Wizard') === 'pending') {
await Settings.updateValueById('Show_Setup_Wizard', 'in_progress');
}
}

await addUserRolesAsync(_id, roles);
return _id;
}

Expand Down

0 comments on commit 11121b4

Please sign in to comment.