@forklaunch/implementation-iam-base 0.2.3 → 0.3.0
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/lib/schemas/index.d.mts +474 -0
- package/lib/schemas/index.d.ts +474 -5
- package/lib/schemas/index.js +339 -4
- package/lib/schemas/index.mjs +369 -0
- package/lib/services/index.d.mts +203 -0
- package/lib/services/index.d.ts +203 -5
- package/lib/services/index.js +666 -4
- package/lib/services/index.mjs +652 -0
- package/package.json +6 -5
- package/lib/__test__/schemaEquality.test.d.ts +0 -2
- package/lib/__test__/schemaEquality.test.d.ts.map +0 -1
- package/lib/__test__/schemaEquality.test.js +0 -283
- package/lib/jest.config.d.ts +0 -4
- package/lib/jest.config.d.ts.map +0 -1
- package/lib/jest.config.js +0 -19
- package/lib/schemas/index.d.ts.map +0 -1
- package/lib/schemas/organization.schema.d.ts +0 -423
- package/lib/schemas/organization.schema.d.ts.map +0 -1
- package/lib/schemas/organization.schema.js +0 -7
- package/lib/schemas/permission.schema.d.ts +0 -104
- package/lib/schemas/permission.schema.d.ts.map +0 -1
- package/lib/schemas/permission.schema.js +0 -7
- package/lib/schemas/role.schema.d.ts +0 -163
- package/lib/schemas/role.schema.d.ts.map +0 -1
- package/lib/schemas/role.schema.js +0 -7
- package/lib/schemas/typebox/organization.schema.d.ts +0 -382
- package/lib/schemas/typebox/organization.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/organization.schema.js +0 -44
- package/lib/schemas/typebox/permission.schema.d.ts +0 -123
- package/lib/schemas/typebox/permission.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/permission.schema.js +0 -32
- package/lib/schemas/typebox/role.schema.d.ts +0 -183
- package/lib/schemas/typebox/role.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/role.schema.js +0 -33
- package/lib/schemas/typebox/user.schema.d.ts +0 -315
- package/lib/schemas/typebox/user.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/user.schema.js +0 -49
- package/lib/schemas/user.schema.d.ts +0 -298
- package/lib/schemas/user.schema.d.ts.map +0 -1
- package/lib/schemas/user.schema.js +0 -7
- package/lib/schemas/zod/organization.schema.d.ts +0 -418
- package/lib/schemas/zod/organization.schema.d.ts.map +0 -1
- package/lib/schemas/zod/organization.schema.js +0 -44
- package/lib/schemas/zod/permission.schema.d.ts +0 -71
- package/lib/schemas/zod/permission.schema.d.ts.map +0 -1
- package/lib/schemas/zod/permission.schema.js +0 -32
- package/lib/schemas/zod/role.schema.d.ts +0 -129
- package/lib/schemas/zod/role.schema.d.ts.map +0 -1
- package/lib/schemas/zod/role.schema.js +0 -33
- package/lib/schemas/zod/user.schema.d.ts +0 -249
- package/lib/schemas/zod/user.schema.d.ts.map +0 -1
- package/lib/schemas/zod/user.schema.js +0 -49
- package/lib/services/index.d.ts.map +0 -1
- package/lib/services/organization.service.d.ts +0 -123
- package/lib/services/organization.service.d.ts.map +0 -1
- package/lib/services/organization.service.js +0 -88
- package/lib/services/permission.service.d.ts +0 -149
- package/lib/services/permission.service.d.ts.map +0 -1
- package/lib/services/permission.service.js +0 -264
- package/lib/services/role.service.d.ts +0 -123
- package/lib/services/role.service.d.ts.map +0 -1
- package/lib/services/role.service.js +0 -139
- package/lib/services/user.service.d.ts +0 -134
- package/lib/services/user.service.d.ts.map +0 -1
- package/lib/services/user.service.js +0 -185
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OrganizationService,
|
|
3
|
-
RoleService,
|
|
4
|
-
UserService
|
|
5
|
-
} from '@forklaunch/interfaces-iam/interfaces';
|
|
6
|
-
import { IdDto, IdsDto } from '@forklaunch/common';
|
|
7
|
-
import {
|
|
8
|
-
MetricsDefinition,
|
|
9
|
-
OpenTelemetryCollector,
|
|
10
|
-
TelemetryOptions
|
|
11
|
-
} from '@forklaunch/core/http';
|
|
12
|
-
import {
|
|
13
|
-
RequestDtoMapperConstructor,
|
|
14
|
-
ResponseDtoMapperConstructor
|
|
15
|
-
} from '@forklaunch/core/mappers';
|
|
16
|
-
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
17
|
-
import {
|
|
18
|
-
CreateUserDto,
|
|
19
|
-
UpdateUserDto,
|
|
20
|
-
UserDto
|
|
21
|
-
} from '@forklaunch/interfaces-iam/types';
|
|
22
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
23
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
24
|
-
export declare class BaseUserService<
|
|
25
|
-
SchemaValidator extends AnySchemaValidator,
|
|
26
|
-
OrganizationStatus,
|
|
27
|
-
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
28
|
-
Dto extends {
|
|
29
|
-
UserDtoMapper: UserDto;
|
|
30
|
-
CreateUserDtoMapper: CreateUserDto;
|
|
31
|
-
UpdateUserDtoMapper: UpdateUserDto;
|
|
32
|
-
} = {
|
|
33
|
-
UserDtoMapper: UserDto;
|
|
34
|
-
CreateUserDtoMapper: CreateUserDto;
|
|
35
|
-
UpdateUserDtoMapper: UpdateUserDto;
|
|
36
|
-
},
|
|
37
|
-
Entities extends {
|
|
38
|
-
UserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
39
|
-
CreateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
40
|
-
UpdateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
41
|
-
} = {
|
|
42
|
-
UserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
43
|
-
CreateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
44
|
-
UpdateUserDtoMapper: MapNestedDtoArraysToCollections<UserDto, 'roles'>;
|
|
45
|
-
}
|
|
46
|
-
> implements UserService
|
|
47
|
-
{
|
|
48
|
-
#private;
|
|
49
|
-
em: EntityManager;
|
|
50
|
-
protected passwordEncryptionPublicKeyPath: string;
|
|
51
|
-
protected roleServiceFactory: () => RoleService;
|
|
52
|
-
protected organizationServiceFactory: () => OrganizationService<OrganizationStatus>;
|
|
53
|
-
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
54
|
-
protected schemaValidator: SchemaValidator;
|
|
55
|
-
protected mappers: {
|
|
56
|
-
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
57
|
-
SchemaValidator,
|
|
58
|
-
Dto['UserDtoMapper'],
|
|
59
|
-
Entities['UserDtoMapper']
|
|
60
|
-
>;
|
|
61
|
-
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
62
|
-
SchemaValidator,
|
|
63
|
-
Dto['CreateUserDtoMapper'],
|
|
64
|
-
Entities['CreateUserDtoMapper']
|
|
65
|
-
>;
|
|
66
|
-
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
67
|
-
SchemaValidator,
|
|
68
|
-
Dto['UpdateUserDtoMapper'],
|
|
69
|
-
Entities['UpdateUserDtoMapper']
|
|
70
|
-
>;
|
|
71
|
-
};
|
|
72
|
-
readonly options?:
|
|
73
|
-
| {
|
|
74
|
-
telemetry?: TelemetryOptions;
|
|
75
|
-
}
|
|
76
|
-
| undefined;
|
|
77
|
-
private evaluatedTelemetryOptions;
|
|
78
|
-
constructor(
|
|
79
|
-
em: EntityManager,
|
|
80
|
-
passwordEncryptionPublicKeyPath: string,
|
|
81
|
-
roleServiceFactory: () => RoleService,
|
|
82
|
-
organizationServiceFactory: () => OrganizationService<OrganizationStatus>,
|
|
83
|
-
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
84
|
-
schemaValidator: SchemaValidator,
|
|
85
|
-
mappers: {
|
|
86
|
-
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
87
|
-
SchemaValidator,
|
|
88
|
-
Dto['UserDtoMapper'],
|
|
89
|
-
Entities['UserDtoMapper']
|
|
90
|
-
>;
|
|
91
|
-
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
92
|
-
SchemaValidator,
|
|
93
|
-
Dto['CreateUserDtoMapper'],
|
|
94
|
-
Entities['CreateUserDtoMapper']
|
|
95
|
-
>;
|
|
96
|
-
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
97
|
-
SchemaValidator,
|
|
98
|
-
Dto['UpdateUserDtoMapper'],
|
|
99
|
-
Entities['UpdateUserDtoMapper']
|
|
100
|
-
>;
|
|
101
|
-
},
|
|
102
|
-
options?:
|
|
103
|
-
| {
|
|
104
|
-
telemetry?: TelemetryOptions;
|
|
105
|
-
}
|
|
106
|
-
| undefined
|
|
107
|
-
);
|
|
108
|
-
createUser(
|
|
109
|
-
userDto: Dto['CreateUserDtoMapper'],
|
|
110
|
-
em?: EntityManager
|
|
111
|
-
): Promise<Dto['UserDtoMapper']>;
|
|
112
|
-
createBatchUsers(
|
|
113
|
-
userDtos: Dto['CreateUserDtoMapper'][],
|
|
114
|
-
em?: EntityManager
|
|
115
|
-
): Promise<Dto['UserDtoMapper'][]>;
|
|
116
|
-
getUser(idDto: IdDto, em?: EntityManager): Promise<Dto['UserDtoMapper']>;
|
|
117
|
-
getBatchUsers(
|
|
118
|
-
idsDto: IdsDto,
|
|
119
|
-
em?: EntityManager
|
|
120
|
-
): Promise<Dto['UserDtoMapper'][]>;
|
|
121
|
-
updateUser(
|
|
122
|
-
userDto: Dto['UpdateUserDtoMapper'],
|
|
123
|
-
em?: EntityManager
|
|
124
|
-
): Promise<Dto['UserDtoMapper']>;
|
|
125
|
-
updateBatchUsers(
|
|
126
|
-
userDtos: UpdateUserDto[],
|
|
127
|
-
em?: EntityManager
|
|
128
|
-
): Promise<Dto['UserDtoMapper'][]>;
|
|
129
|
-
deleteUser(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
130
|
-
deleteBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<void>;
|
|
131
|
-
verifyHasRole(idDto: IdDto, roleId: string): Promise<void>;
|
|
132
|
-
verifyHasPermission(idDto: IdDto, permissionId: string): Promise<void>;
|
|
133
|
-
}
|
|
134
|
-
//# sourceMappingURL=user.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../services/user.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACZ,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAsB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EACL,aAAa,EACb,aAAa,EACb,OAAO,EACR,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,qBAAa,eAAe,CAC1B,eAAe,SAAS,kBAAkB,EAC1C,kBAAkB,EAClB,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EACrD,GAAG,SAAS;IACV,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,aAAa,CAAC;IACnC,mBAAmB,EAAE,aAAa,CAAC;CACpC,GAAG;IACF,aAAa,EAAE,OAAO,CAAC;IACvB,mBAAmB,EAAE,aAAa,CAAC;IACnC,mBAAmB,EAAE,aAAa,CAAC;CACpC,EACD,QAAQ,SAAS;IACf,aAAa,EAAE,+BAA+B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjE,mBAAmB,EAAE,+BAA+B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvE,mBAAmB,EAA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G,CAAC,eAAe,CAAC,EAAE,CAAC;IA2B5B,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3D,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnE,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB1D,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmB7E"}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
2
|
-
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
3
|
-
export class BaseUserService {
|
|
4
|
-
em;
|
|
5
|
-
passwordEncryptionPublicKeyPath;
|
|
6
|
-
roleServiceFactory;
|
|
7
|
-
organizationServiceFactory;
|
|
8
|
-
openTelemetryCollector;
|
|
9
|
-
schemaValidator;
|
|
10
|
-
mappers;
|
|
11
|
-
options;
|
|
12
|
-
#mappers;
|
|
13
|
-
evaluatedTelemetryOptions;
|
|
14
|
-
constructor(
|
|
15
|
-
em,
|
|
16
|
-
passwordEncryptionPublicKeyPath,
|
|
17
|
-
roleServiceFactory,
|
|
18
|
-
organizationServiceFactory,
|
|
19
|
-
openTelemetryCollector,
|
|
20
|
-
schemaValidator,
|
|
21
|
-
mappers,
|
|
22
|
-
options
|
|
23
|
-
) {
|
|
24
|
-
this.em = em;
|
|
25
|
-
this.passwordEncryptionPublicKeyPath = passwordEncryptionPublicKeyPath;
|
|
26
|
-
this.roleServiceFactory = roleServiceFactory;
|
|
27
|
-
this.organizationServiceFactory = organizationServiceFactory;
|
|
28
|
-
this.openTelemetryCollector = openTelemetryCollector;
|
|
29
|
-
this.schemaValidator = schemaValidator;
|
|
30
|
-
this.mappers = mappers;
|
|
31
|
-
this.options = options;
|
|
32
|
-
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
33
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
34
|
-
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
35
|
-
: {
|
|
36
|
-
logging: false,
|
|
37
|
-
metrics: false,
|
|
38
|
-
tracing: false
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
async createUser(userDto, em) {
|
|
42
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
43
|
-
this.openTelemetryCollector.info('Creating user', userDto);
|
|
44
|
-
}
|
|
45
|
-
const user = await this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
46
|
-
userDto,
|
|
47
|
-
em ?? this.em
|
|
48
|
-
);
|
|
49
|
-
if (em) {
|
|
50
|
-
await em.persist(user);
|
|
51
|
-
} else {
|
|
52
|
-
await this.em.persistAndFlush(user);
|
|
53
|
-
}
|
|
54
|
-
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
55
|
-
}
|
|
56
|
-
async createBatchUsers(userDtos, em) {
|
|
57
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
58
|
-
this.openTelemetryCollector.info('Creating batch users', userDtos);
|
|
59
|
-
}
|
|
60
|
-
const users = await Promise.all(
|
|
61
|
-
userDtos.map(async (createUserDto) =>
|
|
62
|
-
this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
63
|
-
createUserDto,
|
|
64
|
-
em ?? this.em
|
|
65
|
-
)
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
if (em) {
|
|
69
|
-
await em.persist(users);
|
|
70
|
-
} else {
|
|
71
|
-
await this.em.persistAndFlush(users);
|
|
72
|
-
}
|
|
73
|
-
return Promise.all(
|
|
74
|
-
users.map((user) =>
|
|
75
|
-
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
76
|
-
)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
async getUser(idDto, em) {
|
|
80
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
81
|
-
this.openTelemetryCollector.info('Getting user', idDto);
|
|
82
|
-
}
|
|
83
|
-
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
84
|
-
populate: ['id', '*']
|
|
85
|
-
});
|
|
86
|
-
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
87
|
-
}
|
|
88
|
-
async getBatchUsers(idsDto, em) {
|
|
89
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
90
|
-
this.openTelemetryCollector.info('Getting batch users', idsDto);
|
|
91
|
-
}
|
|
92
|
-
return Promise.all(
|
|
93
|
-
(
|
|
94
|
-
await (em ?? this.em).find('User', idsDto, {
|
|
95
|
-
populate: ['id', '*']
|
|
96
|
-
})
|
|
97
|
-
).map((user) => this.#mappers.UserDtoMapper.serializeEntityToDto(user))
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
async updateUser(userDto, em) {
|
|
101
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
102
|
-
this.openTelemetryCollector.info('Updating user', userDto);
|
|
103
|
-
}
|
|
104
|
-
const user = await this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
105
|
-
userDto,
|
|
106
|
-
em ?? this.em
|
|
107
|
-
);
|
|
108
|
-
if (em) {
|
|
109
|
-
await em.persist(user);
|
|
110
|
-
} else {
|
|
111
|
-
await this.em.persistAndFlush(user);
|
|
112
|
-
}
|
|
113
|
-
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
114
|
-
}
|
|
115
|
-
async updateBatchUsers(userDtos, em) {
|
|
116
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
117
|
-
this.openTelemetryCollector.info('Updating batch users', userDtos);
|
|
118
|
-
}
|
|
119
|
-
const users = await Promise.all(
|
|
120
|
-
userDtos.map(async (updateUserDto) =>
|
|
121
|
-
this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
122
|
-
updateUserDto,
|
|
123
|
-
em ?? this.em
|
|
124
|
-
)
|
|
125
|
-
)
|
|
126
|
-
);
|
|
127
|
-
if (em) {
|
|
128
|
-
await em.persist(users);
|
|
129
|
-
} else {
|
|
130
|
-
await this.em.persistAndFlush(users);
|
|
131
|
-
}
|
|
132
|
-
return Promise.all(
|
|
133
|
-
users.map((user) =>
|
|
134
|
-
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
135
|
-
)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
async deleteUser(idDto, em) {
|
|
139
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
140
|
-
this.openTelemetryCollector.info('Deleting user', idDto);
|
|
141
|
-
}
|
|
142
|
-
await (em ?? this.em).nativeDelete('User', idDto);
|
|
143
|
-
}
|
|
144
|
-
async deleteBatchUsers(idsDto, em) {
|
|
145
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
146
|
-
this.openTelemetryCollector.info('Deleting batch users', idsDto);
|
|
147
|
-
}
|
|
148
|
-
await (em ?? this.em).nativeDelete('User', idsDto);
|
|
149
|
-
}
|
|
150
|
-
async verifyHasRole(idDto, roleId) {
|
|
151
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
152
|
-
this.openTelemetryCollector.info('Verifying user has role', {
|
|
153
|
-
idDto,
|
|
154
|
-
roleId
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
const user = await this.getUser(idDto);
|
|
158
|
-
if (
|
|
159
|
-
user.roles.filter((role) => {
|
|
160
|
-
return roleId == role.id;
|
|
161
|
-
}).length === 0
|
|
162
|
-
) {
|
|
163
|
-
throw new Error(`User ${idDto.id} does not have role ${roleId}`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
async verifyHasPermission(idDto, permissionId) {
|
|
167
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
168
|
-
this.openTelemetryCollector.info('Verifying user has permission', {
|
|
169
|
-
idDto,
|
|
170
|
-
permissionId
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
const user = await this.getUser(idDto);
|
|
174
|
-
if (
|
|
175
|
-
user.roles
|
|
176
|
-
.map((role) => role.permissions.map((permission) => permission.id))
|
|
177
|
-
.flat()
|
|
178
|
-
.filter((id) => id == permissionId).length === 0
|
|
179
|
-
) {
|
|
180
|
-
throw new Error(
|
|
181
|
-
`User ${idDto.id} does not have permission ${permissionId}`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|