@solidstarters/solid-core 1.2.59 → 1.2.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.59",
3
+ "version": "1.2.60",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -187,16 +187,7 @@ export class AuthenticationService {
187
187
  }
188
188
 
189
189
  private async handlePostSignup(user: User, roles: string[]=[], pwd: string, autoGeneratedPwd: string) {
190
- let userRoles = [];
191
- // Default Internal user role assigned
192
- userRoles.push("Internal User");
193
- if (roles) {
194
- userRoles = [...userRoles, ...roles];
195
- }
196
- userRoles = Array.from(new Set([...userRoles]));
197
- if (userRoles.length > 0) {
198
- this.userService.addRolesToUser(user.username, userRoles);
199
- }
190
+ this.userService.initializeRolesForNewUser(roles, user);
200
191
  // Tanay: Adding user password to history table
201
192
  const userPasswordHistory = new UserPasswordHistory();
202
193
  userPasswordHistory.passwordHash = pwd;
@@ -210,6 +201,7 @@ export class AuthenticationService {
210
201
  }
211
202
  }
212
203
 
204
+
213
205
  generatePassword(length: number = 8): string {
214
206
  const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
215
207
  const lowerCase = "abcdefghijklmnopqrstuvwxyz";
@@ -1,5 +1,5 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { ConfigService } from '@nestjs/config';
1
+ import { BadRequestException, Inject, Injectable } from '@nestjs/common';
2
+ import { ConfigService, ConfigType } from '@nestjs/config';
3
3
  import { DiscoveryService, ModuleRef } from "@nestjs/core";
4
4
  import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';
5
5
  import { CrudHelperService } from "src/services/crud-helper.service";
@@ -14,6 +14,7 @@ import { OauthUserDto } from '../dtos/oauth-user-dto';
14
14
  import { RoleMetadata } from '../entities/role-metadata.entity';
15
15
  import { User } from '../entities/user.entity';
16
16
  import { ActiveUserData } from '../interfaces/active-user-data.interface';
17
+ import { iamConfig } from 'src/config/iam.config';
17
18
 
18
19
  @Injectable()
19
20
  export class UserService extends CRUDService<User> {
@@ -30,8 +31,10 @@ export class UserService extends CRUDService<User> {
30
31
  readonly repo: Repository<User>,
31
32
  @InjectRepository(RoleMetadata)
32
33
  private readonly roleRepository: Repository<RoleMetadata>,
33
- readonly moduleRef: ModuleRef
34
-
34
+ readonly moduleRef: ModuleRef,
35
+ @Inject(iamConfig.KEY)
36
+ private readonly iamConfiguration: ConfigType<typeof iamConfig>,
37
+
35
38
  ) {
36
39
  super(modelMetadataService, moduleMetadataService, configService, fileService, discoveryService, crudHelperService, entityManager, repo, 'user', 'solid-core', moduleRef);
37
40
  }
@@ -195,7 +198,10 @@ export class UserService extends CRUDService<User> {
195
198
  user.googleId = oauthUserDto.providerId;
196
199
  user.googleProfilePicture = oauthUserDto.picture;
197
200
 
198
- return await this.repo.save(user);
201
+ const savedUser = await this.repo.save(user);
202
+
203
+ // Initialize the user roles
204
+ this.initializeRolesForNewUser([this.iamConfiguration.defaultRole], savedUser);
199
205
  }
200
206
  // else we update the user and store the generated code & access token.
201
207
  else {
@@ -230,4 +236,21 @@ export class UserService extends CRUDService<User> {
230
236
  const matchingPermssions = activeUser.permissions.filter((p) => query.permissionNames.includes(p));
231
237
  return matchingPermssions
232
238
  }
239
+
240
+ initializeRolesForNewUser(roles: string[], user: User) {
241
+ if (!user.id) {
242
+ throw new BadRequestException('User must exist before initializing roles');
243
+ }
244
+ let userRoles = [];
245
+ // Default Internal user role assigned
246
+ userRoles.push("Internal User");
247
+ if (roles) {
248
+ userRoles = [...userRoles, ...roles];
249
+ }
250
+ userRoles = Array.from(new Set([...userRoles]));
251
+ if (userRoles.length > 0) {
252
+ this.addRolesToUser(user.username, userRoles);
253
+ }
254
+ }
255
+
233
256
  }