Browse Source

Bugfix/assign admin role to first user signing up (#5914)

* Assign admin role to first user signing up

* Update changelog
pull/5918/head
Germán Martín 3 weeks ago
committed by GitHub
parent
commit
1ae3519d7f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 6
      apps/api/src/app/user/user.controller.ts
  3. 20
      apps/api/src/app/user/user.service.ts

1
CHANGELOG.md

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed the style of the safe withdrawal rate selector in the _FIRE_ section (experimental) - Fixed the style of the safe withdrawal rate selector in the _FIRE_ section (experimental)
- Assigned the `ADMIN` role to the first user signing up via a social login provider if no administrator existed
- Improved the table headers’ alignment in the platform management of the admin control panel - Improved the table headers’ alignment in the platform management of the admin control panel
- Improved the table headers’ alignment in the tag management of the admin control panel - Improved the table headers’ alignment in the tag management of the admin control panel

6
apps/api/src/app/user/user.controller.ts

@ -126,11 +126,7 @@ export class UserController {
); );
} }
const hasAdmin = await this.userService.hasAdmin(); const { accessToken, id, role } = await this.userService.createUser();
const { accessToken, id, role } = await this.userService.createUser({
data: { role: hasAdmin ? 'USER' : 'ADMIN' }
});
return { return {
accessToken, accessToken,

20
apps/api/src/app/user/user.service.ts

@ -526,15 +526,23 @@ export class UserService {
}); });
} }
public async createUser({ public async createUser(
data {
}: { data
data: Prisma.UserCreateInput; }: {
}): Promise<User> { data: Prisma.UserCreateInput;
if (!data?.provider) { } = { data: {} }
): Promise<User> {
if (!data.provider) {
data.provider = 'ANONYMOUS'; data.provider = 'ANONYMOUS';
} }
if (!data.role) {
const hasAdmin = await this.hasAdmin();
data.role = hasAdmin ? 'USER' : 'ADMIN';
}
const user = await this.prismaService.user.create({ const user = await this.prismaService.user.create({
data: { data: {
...data, ...data,

Loading…
Cancel
Save