@solidstarters/solid-core 1.2.59 → 1.2.61
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/dist/commands/refresh-model.command.js +1 -1
- package/dist/commands/refresh-model.command.js.map +1 -1
- package/dist/controllers/model-metadata.controller.js +1 -1
- package/dist/controllers/model-metadata.controller.js.map +1 -1
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +1 -9
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts +2 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +27 -12
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/module-metadata.service.js +1 -1
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/services/user.service.d.ts +5 -2
- package/dist/services/user.service.d.ts.map +1 -1
- package/dist/services/user.service.js +21 -3
- package/dist/services/user.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/commands/refresh-model.command.ts +1 -1
- package/src/controllers/model-metadata.controller.ts +1 -1
- package/src/services/authentication.service.ts +2 -10
- package/src/services/model-metadata.service.ts +34 -15
- package/src/services/module-metadata.service.ts +1 -1
- package/src/services/user.service.ts +28 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidstarters/solid-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.61",
|
|
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",
|
|
@@ -33,7 +33,7 @@ export class RefreshModelCommand extends CommandRunner {
|
|
|
33
33
|
modelUserKey: options.name,
|
|
34
34
|
dryRun: options.dryRun,
|
|
35
35
|
};
|
|
36
|
-
await this.modelMetadataService.
|
|
36
|
+
await this.modelMetadataService.handleGenerateCode(codeGenerationOptions);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
@Option({
|
|
@@ -69,7 +69,7 @@ export class ModelMetadataController {
|
|
|
69
69
|
@ApiBearerAuth("jwt")
|
|
70
70
|
@Post(':id/generate-code')
|
|
71
71
|
generateCode(@Param('id', ParseIntPipe) id: number) {
|
|
72
|
-
return this.modelMetadataService.
|
|
72
|
+
return this.modelMetadataService.handleGenerateCode({ modelId: id});
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
|
|
@@ -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
|
-
|
|
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";
|
|
@@ -717,21 +717,22 @@ export class ModelMetadataService {
|
|
|
717
717
|
return this.modelMetadataRepo.remove(entity);
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
-
async
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
720
|
+
async handleGenerateCode(options: CodeGenerationOptions): Promise<string> {
|
|
721
|
+
const { model, removeFieldCodeOuput, refreshModelCodeOutput } = await this.generateCode(options);
|
|
722
|
+
|
|
723
|
+
// Generate the code for models which are linked to fields having an inverse relation
|
|
724
|
+
const coModelSingularNames = model.fields.
|
|
725
|
+
filter(field => field.type === SolidFieldType.relation && field.relationCreateInverse === true)
|
|
726
|
+
.map(field => field.relationCoModelSingularName);
|
|
727
|
+
|
|
728
|
+
for (const singularName of coModelSingularNames) {
|
|
729
|
+
const coModel = await this.findOneBySingularName(singularName);
|
|
730
|
+
const inverseOptions: CodeGenerationOptions = {
|
|
731
|
+
modelId: coModel.id,
|
|
732
|
+
dryRun: options.dryRun
|
|
733
|
+
};
|
|
734
|
+
await this.generateCode(inverseOptions);
|
|
735
|
+
}
|
|
735
736
|
|
|
736
737
|
const jsonFieldsList = model.fields.filter((field: FieldMetadata) => field.isSystem !== true);
|
|
737
738
|
|
|
@@ -876,6 +877,24 @@ export class ModelMetadataService {
|
|
|
876
877
|
return `${removeFieldCodeOuput} \n ${refreshModelCodeOutput}`;
|
|
877
878
|
}
|
|
878
879
|
|
|
880
|
+
private async generateCode(options: CodeGenerationOptions) {
|
|
881
|
+
const query = {
|
|
882
|
+
populate: ["module", "fields"]
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
const model = options.modelId
|
|
886
|
+
? await this.findOne(options.modelId, query)
|
|
887
|
+
: await this.findOneByUserKey(options.modelUserKey, query.populate);
|
|
888
|
+
|
|
889
|
+
options.fieldIdsForRemoval = model.fields
|
|
890
|
+
.filter(field => field.isMarkedForRemoval)
|
|
891
|
+
.map(field => field.id);
|
|
892
|
+
|
|
893
|
+
const refreshModelCodeOutput = await this.generateModelCode(options);
|
|
894
|
+
const removeFieldCodeOuput = await this.generateRemoveFieldsCode(options);
|
|
895
|
+
return { model, removeFieldCodeOuput, refreshModelCodeOutput };
|
|
896
|
+
}
|
|
897
|
+
|
|
879
898
|
async generateRemoveFieldsCode(options: CodeGenerationOptions): Promise<string> {
|
|
880
899
|
if (!options.modelId && !options.modelUserKey) {
|
|
881
900
|
throw new BadRequestException('Model ID or Model Name is required for generating code');
|
|
@@ -375,7 +375,7 @@ export class ModuleMetadataService {
|
|
|
375
375
|
modelId: model.id,
|
|
376
376
|
dryRun: options.dryRun,
|
|
377
377
|
};
|
|
378
|
-
const output = await this.modelMetadataService.
|
|
378
|
+
const output = await this.modelMetadataService.handleGenerateCode(codeGenerationOptions);
|
|
379
379
|
this.logger.debug(`Schematic output : ${output}`);
|
|
380
380
|
outputLines.push(output)
|
|
381
381
|
}
|
|
@@ -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
|
-
|
|
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
|
}
|