@flusys/nestjs-auth 9.1.0-rc.1 → 9.1.1
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/README.md +18 -0
- package/config/message-keys.d.ts +2 -0
- package/controllers/company-selection.controller.d.ts +5 -3
- package/controllers/user-permission.controller.d.ts +3 -3
- package/dtos/authentication.dto.d.ts +5 -0
- package/dtos/user-permission.dto.d.ts +3 -0
- package/fesm/118.js +30 -0
- package/fesm/120.js +27 -23
- package/fesm/24.js +361 -134
- package/fesm/360.js +719 -0
- package/fesm/370.js +50 -0
- package/fesm/config/index.js +3 -1
- package/fesm/docs/index.js +8 -2
- package/fesm/helpers/index.js +139 -33
- package/fesm/index.js +26 -550
- package/fesm/interceptors/index.js +6 -2
- package/fesm/modules/index.js +4 -529
- package/fesm/services/index.js +209 -27
- package/helpers/branch-ancestry.helper.d.ts +4 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/token.helper.d.ts +2 -0
- package/interfaces/authentication.interface.d.ts +3 -0
- package/package.json +5 -5
- package/services/authentication.service.d.ts +3 -1
- package/services/branch-hierarchy-resolver.adapter.d.ts +15 -0
- package/services/branch.service.d.ts +7 -0
- package/services/company-access-resolver.adapter.d.ts +8 -0
- package/services/index.d.ts +2 -0
- package/services/user-permission.service.d.ts +1 -0
package/fesm/24.js
CHANGED
|
@@ -168,7 +168,9 @@ const COMPANY_MESSAGES = {
|
|
|
168
168
|
READONLY_DELETE_FORBIDDEN: 'company.readonly.delete.forbidden'
|
|
169
169
|
};
|
|
170
170
|
const BRANCH_MESSAGES = {
|
|
171
|
-
READONLY_DELETE_FORBIDDEN: 'branch.readonly.delete.forbidden'
|
|
171
|
+
READONLY_DELETE_FORBIDDEN: 'branch.readonly.delete.forbidden',
|
|
172
|
+
INVALID_PARENT: 'branch.invalid.parent',
|
|
173
|
+
CIRCULAR_PARENT: 'branch.circular.parent'
|
|
172
174
|
};
|
|
173
175
|
const USER_PERMISSION_MESSAGES = {
|
|
174
176
|
COMPANY_LIST_SUCCESS: 'user.permission.company.list.success',
|
|
@@ -196,7 +198,78 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
196
198
|
|
|
197
199
|
|
|
198
200
|
},
|
|
199
|
-
|
|
201
|
+
7526(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
202
|
+
/* import */ var _flusys_nestjs_shared_utils__rspack_import_0 = __webpack_require__(9216);
|
|
203
|
+
/* import */ var class_validator__rspack_import_1 = __webpack_require__(5421);
|
|
204
|
+
/* import */ var typeorm__rspack_import_2 = __webpack_require__(7158);
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
/** Every branch of the companies the given branches belong to - a parent never leaves its company. */ async function loadCompanyBranchNodes(repo, branchIds, withDeleted = false) {
|
|
209
|
+
if (!branchIds.length) return [];
|
|
210
|
+
const seeds = await repo.find({
|
|
211
|
+
where: {
|
|
212
|
+
id: (0,typeorm__rspack_import_2.In)([
|
|
213
|
+
...branchIds
|
|
214
|
+
])
|
|
215
|
+
},
|
|
216
|
+
select: [
|
|
217
|
+
'id',
|
|
218
|
+
'companyId'
|
|
219
|
+
],
|
|
220
|
+
withDeleted
|
|
221
|
+
});
|
|
222
|
+
const companyIds = [
|
|
223
|
+
...new Set(seeds.map((b)=>b.companyId))
|
|
224
|
+
];
|
|
225
|
+
if (!companyIds.length) return [];
|
|
226
|
+
return repo.find({
|
|
227
|
+
where: {
|
|
228
|
+
companyId: (0,typeorm__rspack_import_2.In)(companyIds)
|
|
229
|
+
},
|
|
230
|
+
select: [
|
|
231
|
+
'id',
|
|
232
|
+
'parentId'
|
|
233
|
+
],
|
|
234
|
+
withDeleted
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* For each listed branch, its nearest ancestor that is listed too, or null when none is - the tree parent
|
|
239
|
+
* inside a list of granted branches. The branches in between are skipped and never sent to the client.
|
|
240
|
+
*/ async function loadDisplayParentIds(repo, branchIds) {
|
|
241
|
+
const ids = (0,_flusys_nestjs_shared_utils__rspack_import_0.normalizeBranchIds)(branchIds).filter((id)=>(0,class_validator__rspack_import_1.isUUID)(id));
|
|
242
|
+
const listed = new Set(ids);
|
|
243
|
+
const nodes = await loadCompanyBranchNodes(repo, ids);
|
|
244
|
+
return new Map(ids.map((id)=>[
|
|
245
|
+
id,
|
|
246
|
+
(0,_flusys_nestjs_shared_utils__rspack_import_0.collectBranchAncestorIds)(nodes, id).find((a)=>listed.has(a)) ?? null
|
|
247
|
+
]));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
251
|
+
v: () => (loadCompanyBranchNodes),
|
|
252
|
+
x: () => (loadDisplayParentIds)
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
},
|
|
257
|
+
334(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
258
|
+
|
|
259
|
+
// EXPORTS
|
|
260
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
261
|
+
Vg: () => (/* reexport */ generateAccessToken),
|
|
262
|
+
e: () => (/* reexport */ generateTokens),
|
|
263
|
+
vR: () => (/* reexport */ branch_ancestry_helper/* .loadCompanyBranchNodes */.v),
|
|
264
|
+
xu: () => (/* reexport */ branch_ancestry_helper/* .loadDisplayParentIds */.x),
|
|
265
|
+
om: () => (/* reexport */ parseExpiryToMs),
|
|
266
|
+
XP: () => (/* reexport */ revokeUserSessions),
|
|
267
|
+
QH: () => (/* reexport */ toBranchInfo),
|
|
268
|
+
$C: () => (/* reexport */ toCompanyInfo),
|
|
269
|
+
FV: () => (/* reexport */ toUserInfo)
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/auth-response.mapper.ts
|
|
200
273
|
function toUserInfo(user) {
|
|
201
274
|
return {
|
|
202
275
|
id: user.id,
|
|
@@ -223,15 +296,12 @@ function toBranchInfo(branch) {
|
|
|
223
296
|
};
|
|
224
297
|
}
|
|
225
298
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
299
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/branch-ancestry.helper.ts
|
|
300
|
+
var branch_ancestry_helper = __webpack_require__(7526);
|
|
301
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/config/auth.constants.ts
|
|
302
|
+
var auth_constants = __webpack_require__(5588);
|
|
303
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/token.helper.ts
|
|
232
304
|
|
|
233
|
-
},
|
|
234
|
-
1379(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
235
305
|
function generateAccessToken(jwtService, authConfig, payload) {
|
|
236
306
|
return jwtService.sign({
|
|
237
307
|
...payload,
|
|
@@ -275,12 +345,15 @@ function parseExpiryToMs(expiry) {
|
|
|
275
345
|
return 7 * 24 * 60 * 60 * 1000;
|
|
276
346
|
}
|
|
277
347
|
}
|
|
348
|
+
/** Rejects every token the user holds that was issued before now: checked on refresh and, by JwtStrategy, on every request. */ async function revokeUserSessions(cache, authConfig, userId) {
|
|
349
|
+
const revokedAt = Math.floor(Date.now() / 1000);
|
|
350
|
+
await cache.set(`${auth_constants/* .TOKEN_REVOKED_PREFIX */.EV}:${userId}`, revokedAt, parseExpiryToMs(authConfig.getRefreshTokenExpiration()));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/index.ts
|
|
354
|
+
|
|
355
|
+
|
|
278
356
|
|
|
279
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
280
|
-
Vg: () => (generateAccessToken),
|
|
281
|
-
e: () => (generateTokens),
|
|
282
|
-
om: () => (parseExpiryToMs)
|
|
283
|
-
});
|
|
284
357
|
|
|
285
358
|
|
|
286
359
|
},
|
|
@@ -437,7 +510,7 @@ function readAvatarUrl(profile) {
|
|
|
437
510
|
if (typeof data !== 'object' || data === null) return null;
|
|
438
511
|
return readString(data, 'url');
|
|
439
512
|
}
|
|
440
|
-
let
|
|
513
|
+
let facebook_social_provider_FacebookSocialProvider = class FacebookSocialProvider {
|
|
441
514
|
provider = social_provider_type_enum/* .SocialProviderTypeEnum.FACEBOOK */.u.FACEBOOK;
|
|
442
515
|
defaultScopes = [
|
|
443
516
|
'email',
|
|
@@ -471,7 +544,7 @@ let FacebookSocialProvider = class FacebookSocialProvider {
|
|
|
471
544
|
};
|
|
472
545
|
}
|
|
473
546
|
};
|
|
474
|
-
const facebookSocialProvider = new
|
|
547
|
+
const facebookSocialProvider = new facebook_social_provider_FacebookSocialProvider();
|
|
475
548
|
|
|
476
549
|
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/providers/google.social-provider.ts
|
|
477
550
|
|
|
@@ -479,7 +552,7 @@ const facebookSocialProvider = new FacebookSocialProvider();
|
|
|
479
552
|
const google_social_provider_AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/v2/auth';
|
|
480
553
|
const google_social_provider_TOKEN_URL = 'https://oauth2.googleapis.com/token';
|
|
481
554
|
const USERINFO_URL = 'https://openidconnect.googleapis.com/v1/userinfo';
|
|
482
|
-
let
|
|
555
|
+
let google_social_provider_GoogleSocialProvider = class GoogleSocialProvider {
|
|
483
556
|
provider = social_provider_type_enum/* .SocialProviderTypeEnum.GOOGLE */.u.GOOGLE;
|
|
484
557
|
defaultScopes = [
|
|
485
558
|
'openid',
|
|
@@ -516,7 +589,7 @@ let GoogleSocialProvider = class GoogleSocialProvider {
|
|
|
516
589
|
};
|
|
517
590
|
}
|
|
518
591
|
};
|
|
519
|
-
const googleSocialProvider = new
|
|
592
|
+
const googleSocialProvider = new google_social_provider_GoogleSocialProvider();
|
|
520
593
|
|
|
521
594
|
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/providers/linkedin.social-provider.ts
|
|
522
595
|
|
|
@@ -524,7 +597,7 @@ const googleSocialProvider = new GoogleSocialProvider();
|
|
|
524
597
|
const linkedin_social_provider_AUTHORIZE_URL = 'https://www.linkedin.com/oauth/v2/authorization';
|
|
525
598
|
const linkedin_social_provider_TOKEN_URL = 'https://www.linkedin.com/oauth/v2/accessToken';
|
|
526
599
|
const linkedin_social_provider_USERINFO_URL = 'https://api.linkedin.com/v2/userinfo';
|
|
527
|
-
let
|
|
600
|
+
let linkedin_social_provider_LinkedInSocialProvider = class LinkedInSocialProvider {
|
|
528
601
|
provider = social_provider_type_enum/* .SocialProviderTypeEnum.LINKEDIN */.u.LINKEDIN;
|
|
529
602
|
defaultScopes = [
|
|
530
603
|
'openid',
|
|
@@ -559,7 +632,7 @@ let LinkedInSocialProvider = class LinkedInSocialProvider {
|
|
|
559
632
|
};
|
|
560
633
|
}
|
|
561
634
|
};
|
|
562
|
-
const linkedInSocialProvider = new
|
|
635
|
+
const linkedInSocialProvider = new linkedin_social_provider_LinkedInSocialProvider();
|
|
563
636
|
|
|
564
637
|
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/providers/microsoft.social-provider.ts
|
|
565
638
|
|
|
@@ -573,7 +646,7 @@ function resolveTenant(credentials) {
|
|
|
573
646
|
function endpoint(credentials, action) {
|
|
574
647
|
return `https://login.microsoftonline.com/${resolveTenant(credentials)}/oauth2/v2.0/${action}`;
|
|
575
648
|
}
|
|
576
|
-
let
|
|
649
|
+
let microsoft_social_provider_MicrosoftSocialProvider = class MicrosoftSocialProvider {
|
|
577
650
|
provider = social_provider_type_enum/* .SocialProviderTypeEnum.MICROSOFT */.u.MICROSOFT;
|
|
578
651
|
defaultScopes = [
|
|
579
652
|
'openid',
|
|
@@ -614,7 +687,7 @@ let MicrosoftSocialProvider = class MicrosoftSocialProvider {
|
|
|
614
687
|
};
|
|
615
688
|
}
|
|
616
689
|
};
|
|
617
|
-
const microsoftSocialProvider = new
|
|
690
|
+
const microsoftSocialProvider = new microsoft_social_provider_MicrosoftSocialProvider();
|
|
618
691
|
|
|
619
692
|
;// CONCATENATED MODULE: ./projects/nestjs-auth/src/providers/social-provider.registry.ts
|
|
620
693
|
|
|
@@ -1393,10 +1466,8 @@ var pending_registration_entity = __webpack_require__(9388);
|
|
|
1393
1466
|
var user_company_permission_entity = __webpack_require__(2377);
|
|
1394
1467
|
// EXTERNAL MODULE: ./projects/nestjs-auth/src/enums/user-org-permission-type.enum.ts
|
|
1395
1468
|
var user_org_permission_type_enum = __webpack_require__(5081);
|
|
1396
|
-
// EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/
|
|
1397
|
-
var
|
|
1398
|
-
// EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/auth-response.mapper.ts
|
|
1399
|
-
var auth_response_mapper = __webpack_require__(2295);
|
|
1469
|
+
// EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/index.ts + 2 modules
|
|
1470
|
+
var helpers = __webpack_require__(334);
|
|
1400
1471
|
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
|
|
1401
1472
|
var auth_config_service = __webpack_require__(6514);
|
|
1402
1473
|
// EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
|
|
@@ -1540,12 +1611,20 @@ class AuthenticationService {
|
|
|
1540
1611
|
if (!permissionRepository || !branchRepository) {
|
|
1541
1612
|
return this.generateLoginResponse(user);
|
|
1542
1613
|
}
|
|
1543
|
-
const
|
|
1614
|
+
const companyGrants = await permissionRepository.find({
|
|
1544
1615
|
where: {
|
|
1545
1616
|
userId: user.id,
|
|
1546
1617
|
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY
|
|
1547
1618
|
}
|
|
1548
1619
|
});
|
|
1620
|
+
const companyPermissions = companyGrants.filter((grant)=>grant.isActive);
|
|
1621
|
+
// A user with company grants never gets a company-less login: such a token is not filtered by company
|
|
1622
|
+
if (companyGrants.length && !companyPermissions.length) {
|
|
1623
|
+
throw new common_.ForbiddenException({
|
|
1624
|
+
message: 'User account is deactivated',
|
|
1625
|
+
messageKey: message_keys/* .AUTH_MESSAGES.LOGIN_ACCOUNT_DEACTIVATED */.mK.LOGIN_ACCOUNT_DEACTIVATED
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1549
1628
|
const companyRepository = await this.getCompanyScopedRepository(company_entity/* .Company */.C);
|
|
1550
1629
|
if (!companyRepository) {
|
|
1551
1630
|
return this.generateLoginResponse(user);
|
|
@@ -1557,6 +1636,12 @@ class AuthenticationService {
|
|
|
1557
1636
|
active: true
|
|
1558
1637
|
}).getMany() : [];
|
|
1559
1638
|
if (companies.length === 0) {
|
|
1639
|
+
if (companyGrants.length) {
|
|
1640
|
+
throw new common_.ForbiddenException({
|
|
1641
|
+
message: 'Company not found or inactive',
|
|
1642
|
+
messageKey: message_keys/* .AUTH_MESSAGES.COMPANY_NOT_FOUND */.mK.COMPANY_NOT_FOUND
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1560
1645
|
return this.generateLoginResponse(user);
|
|
1561
1646
|
}
|
|
1562
1647
|
const branchPermissions = await permissionRepository.find({
|
|
@@ -1568,13 +1653,16 @@ class AuthenticationService {
|
|
|
1568
1653
|
const branchIds = branchPermissions.map((p)=>p.targetId);
|
|
1569
1654
|
const branches = branchIds.length > 0 ? await branchRepository.createQueryBuilder('b').leftJoinAndSelect('b.company', 'company').where('b.id IN (:...ids)', {
|
|
1570
1655
|
ids: branchIds
|
|
1656
|
+
}).andWhere('b.company_id IN (:...companyIds)', {
|
|
1657
|
+
companyIds: companies.map((c)=>c.id)
|
|
1571
1658
|
}).andWhere('b.is_active = :active', {
|
|
1572
1659
|
active: true
|
|
1573
1660
|
}).getMany() : [];
|
|
1574
1661
|
if (companies.length === 1 && branches.length === 1) {
|
|
1575
1662
|
return this.generateLoginResponseWithCompany(user, companies[0], branches[0]);
|
|
1576
1663
|
}
|
|
1577
|
-
|
|
1664
|
+
const displayParentIds = await (0,helpers/* .loadDisplayParentIds */.xu)(branchRepository, branches.map((b)=>b.id));
|
|
1665
|
+
return await this.generateCompanySelectionResponse(user, companies, branches, displayParentIds);
|
|
1578
1666
|
}
|
|
1579
1667
|
async register(dto, verifyUrlBase) {
|
|
1580
1668
|
const userRepository = await this.getUserRepository();
|
|
@@ -1933,7 +2021,8 @@ class AuthenticationService {
|
|
|
1933
2021
|
where: {
|
|
1934
2022
|
userId,
|
|
1935
2023
|
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY,
|
|
1936
|
-
targetId: companyId
|
|
2024
|
+
targetId: companyId,
|
|
2025
|
+
isActive: true
|
|
1937
2026
|
}
|
|
1938
2027
|
});
|
|
1939
2028
|
if (!hasCompanyAccess) {
|
|
@@ -2035,7 +2124,8 @@ class AuthenticationService {
|
|
|
2035
2124
|
where: {
|
|
2036
2125
|
userId: user.id,
|
|
2037
2126
|
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY,
|
|
2038
|
-
targetId: payload.companyId
|
|
2127
|
+
targetId: payload.companyId,
|
|
2128
|
+
isActive: true
|
|
2039
2129
|
}
|
|
2040
2130
|
});
|
|
2041
2131
|
if (!hasCompanyAccess) {
|
|
@@ -2078,8 +2168,23 @@ class AuthenticationService {
|
|
|
2078
2168
|
}
|
|
2079
2169
|
}
|
|
2080
2170
|
}
|
|
2171
|
+
} else {
|
|
2172
|
+
// A company-less session is only for users without company grants (it is not filtered by company)
|
|
2173
|
+
const permissionRepository = await this.getCompanyScopedRepository(user_company_permission_entity/* .UserCompanyPermission */.I);
|
|
2174
|
+
const companyGrants = await permissionRepository?.count({
|
|
2175
|
+
where: {
|
|
2176
|
+
userId: user.id,
|
|
2177
|
+
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY
|
|
2178
|
+
}
|
|
2179
|
+
});
|
|
2180
|
+
if (companyGrants) {
|
|
2181
|
+
throw new common_.UnauthorizedException({
|
|
2182
|
+
message: 'Invalid refresh token',
|
|
2183
|
+
messageKey: message_keys/* .AUTH_MESSAGES.TOKEN_INVALID */.mK.TOKEN_INVALID
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2081
2186
|
}
|
|
2082
|
-
const accessToken = (0,
|
|
2187
|
+
const accessToken = (0,helpers/* .generateAccessToken */.Vg)(this.jwtService, this.authConfig, {
|
|
2083
2188
|
id: user.id,
|
|
2084
2189
|
email: user.email,
|
|
2085
2190
|
type: 'access',
|
|
@@ -2133,11 +2238,7 @@ class AuthenticationService {
|
|
|
2133
2238
|
messageKey: message_keys/* .AUTH_MESSAGES.LOGOUT_SERVICE_UNAVAILABLE */.mK.LOGOUT_SERVICE_UNAVAILABLE
|
|
2134
2239
|
});
|
|
2135
2240
|
}
|
|
2136
|
-
|
|
2137
|
-
const cacheKey = `${auth_constants/* .TOKEN_REVOKED_PREFIX */.EV}:${userId}`;
|
|
2138
|
-
const refreshTokenExpiry = this.authConfig.getRefreshTokenExpiration();
|
|
2139
|
-
const ttlMs = (0,token_helper/* .parseExpiryToMs */.om)(refreshTokenExpiry);
|
|
2140
|
-
await this.cacheManager.set(cacheKey, revokedAt, ttlMs);
|
|
2241
|
+
await (0,helpers/* .revokeUserSessions */.XP)(this.cacheManager, this.authConfig, userId);
|
|
2141
2242
|
await (0,classes_.publishDomainEvent)({
|
|
2142
2243
|
module: (/* inlined export .AUTH_EVENT_MODULE */"auth"),
|
|
2143
2244
|
entity: event_actions/* .AUTH_EVENT_ENTITIES.SESSION */.g.SESSION,
|
|
@@ -2177,7 +2278,8 @@ class AuthenticationService {
|
|
|
2177
2278
|
const permissions = await permissionRepository.find({
|
|
2178
2279
|
where: {
|
|
2179
2280
|
userId,
|
|
2180
|
-
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY
|
|
2281
|
+
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY,
|
|
2282
|
+
isActive: true
|
|
2181
2283
|
}
|
|
2182
2284
|
});
|
|
2183
2285
|
const companyIds = permissions.map((p)=>p.targetId);
|
|
@@ -2190,6 +2292,7 @@ class AuthenticationService {
|
|
|
2190
2292
|
}
|
|
2191
2293
|
async getUserBranches(userId, companyId) {
|
|
2192
2294
|
this.ensureCompanyFeatureEnabled();
|
|
2295
|
+
if (!companyId) return [];
|
|
2193
2296
|
const permissionRepository = await this.getCompanyScopedRepository(user_company_permission_entity/* .UserCompanyPermission */.I);
|
|
2194
2297
|
const branchRepository = await this.getCompanyScopedRepository(company_branch_entity/* .CompanyBranch */.A);
|
|
2195
2298
|
if (!permissionRepository || !branchRepository) {
|
|
@@ -2205,7 +2308,8 @@ class AuthenticationService {
|
|
|
2205
2308
|
where: {
|
|
2206
2309
|
userId,
|
|
2207
2310
|
permissionType: user_org_permission_type_enum/* .PermissionType.COMPANY */.e.COMPANY,
|
|
2208
|
-
targetId: companyId
|
|
2311
|
+
targetId: companyId,
|
|
2312
|
+
isActive: true
|
|
2209
2313
|
}
|
|
2210
2314
|
});
|
|
2211
2315
|
if (!companyPermission) {
|
|
@@ -2222,13 +2326,19 @@ class AuthenticationService {
|
|
|
2222
2326
|
});
|
|
2223
2327
|
const branchIds = branchPermissions.map((p)=>p.targetId);
|
|
2224
2328
|
if (branchIds.length === 0) return [];
|
|
2225
|
-
|
|
2329
|
+
const branches = await branchRepository.createQueryBuilder('b').innerJoin('b.company', 'c', 'c.is_active = :companyActive', {
|
|
2330
|
+
companyActive: true
|
|
2331
|
+
}).where('b.id IN (:...ids)', {
|
|
2226
2332
|
ids: branchIds
|
|
2227
2333
|
}).andWhere('b.company_id = :companyId', {
|
|
2228
2334
|
companyId
|
|
2229
2335
|
}).andWhere('b.is_active = :active', {
|
|
2230
2336
|
active: true
|
|
2231
2337
|
}).orderBy('b.serial', 'ASC').addOrderBy('b.name', 'ASC').getMany();
|
|
2338
|
+
const displayParentIds = await (0,helpers/* .loadDisplayParentIds */.xu)(branchRepository, branches.map((b)=>b.id));
|
|
2339
|
+
return branches.map((branch)=>Object.assign(branch, {
|
|
2340
|
+
displayParentId: displayParentIds.get(branch.id) ?? null
|
|
2341
|
+
}));
|
|
2232
2342
|
}
|
|
2233
2343
|
async getCompanyById(companyId) {
|
|
2234
2344
|
const companyRepository = await this.getCompanyScopedRepository(company_entity/* .Company */.C);
|
|
@@ -2264,7 +2374,7 @@ class AuthenticationService {
|
|
|
2264
2374
|
messageKey: message_keys/* .USER_MESSAGES.NOT_FOUND */.ny.NOT_FOUND
|
|
2265
2375
|
});
|
|
2266
2376
|
const response = {
|
|
2267
|
-
user: (0,
|
|
2377
|
+
user: (0,helpers/* .toUserInfo */.FV)(user)
|
|
2268
2378
|
};
|
|
2269
2379
|
if (this.isCompanyFeatureEnabled()) {
|
|
2270
2380
|
if (!companyId) {
|
|
@@ -2278,14 +2388,14 @@ class AuthenticationService {
|
|
|
2278
2388
|
message: 'Company not found.',
|
|
2279
2389
|
messageKey: message_keys/* .AUTH_MESSAGES.COMPANY_NOT_FOUND */.mK.COMPANY_NOT_FOUND
|
|
2280
2390
|
});
|
|
2281
|
-
response.company = (0,
|
|
2391
|
+
response.company = (0,helpers/* .toCompanyInfo */.$C)(company);
|
|
2282
2392
|
if (branchId) {
|
|
2283
2393
|
const branch = await this.getBranchById(branchId);
|
|
2284
2394
|
if (!branch) throw new common_.UnauthorizedException({
|
|
2285
2395
|
message: 'Branch not found.',
|
|
2286
2396
|
messageKey: message_keys/* .AUTH_MESSAGES.BRANCH_NOT_FOUND */.mK.BRANCH_NOT_FOUND
|
|
2287
2397
|
});
|
|
2288
|
-
response.branch = (0,
|
|
2398
|
+
response.branch = (0,helpers/* .toBranchInfo */.QH)(branch);
|
|
2289
2399
|
}
|
|
2290
2400
|
}
|
|
2291
2401
|
return response;
|
|
@@ -2316,7 +2426,7 @@ class AuthenticationService {
|
|
|
2316
2426
|
return user;
|
|
2317
2427
|
}
|
|
2318
2428
|
generateLoginResponse(user) {
|
|
2319
|
-
const { accessToken, refreshToken } = (0,
|
|
2429
|
+
const { accessToken, refreshToken } = (0,helpers/* .generateTokens */.e)(this.jwtService, this.authConfig, {
|
|
2320
2430
|
id: user.id,
|
|
2321
2431
|
email: user.email,
|
|
2322
2432
|
type: 'access'
|
|
@@ -2326,11 +2436,11 @@ class AuthenticationService {
|
|
|
2326
2436
|
return {
|
|
2327
2437
|
accessToken,
|
|
2328
2438
|
refreshToken,
|
|
2329
|
-
user: (0,
|
|
2439
|
+
user: (0,helpers/* .toUserInfo */.FV)(user)
|
|
2330
2440
|
};
|
|
2331
2441
|
}
|
|
2332
2442
|
generateLoginResponseWithCompany(user, company, branch) {
|
|
2333
|
-
const { accessToken, refreshToken } = (0,
|
|
2443
|
+
const { accessToken, refreshToken } = (0,helpers/* .generateTokens */.e)(this.jwtService, this.authConfig, {
|
|
2334
2444
|
id: user.id,
|
|
2335
2445
|
email: user.email,
|
|
2336
2446
|
type: 'access',
|
|
@@ -2345,9 +2455,9 @@ class AuthenticationService {
|
|
|
2345
2455
|
return {
|
|
2346
2456
|
accessToken,
|
|
2347
2457
|
refreshToken,
|
|
2348
|
-
user: (0,
|
|
2349
|
-
company: (0,
|
|
2350
|
-
branch: branch ? (0,
|
|
2458
|
+
user: (0,helpers/* .toUserInfo */.FV)(user),
|
|
2459
|
+
company: (0,helpers/* .toCompanyInfo */.$C)(company),
|
|
2460
|
+
branch: branch ? (0,helpers/* .toBranchInfo */.QH)(branch) : undefined
|
|
2351
2461
|
};
|
|
2352
2462
|
}
|
|
2353
2463
|
sendLoginNotification(userId, companyId) {
|
|
@@ -2363,7 +2473,7 @@ class AuthenticationService {
|
|
|
2363
2473
|
// Silent failure - notification is non-critical
|
|
2364
2474
|
});
|
|
2365
2475
|
}
|
|
2366
|
-
async generateCompanySelectionResponse(user, companies, branches) {
|
|
2476
|
+
async generateCompanySelectionResponse(user, companies, branches, displayParentIds) {
|
|
2367
2477
|
if (!this.sessionService) {
|
|
2368
2478
|
throw new common_.BadRequestException({
|
|
2369
2479
|
message: 'Session service not available',
|
|
@@ -2372,10 +2482,13 @@ class AuthenticationService {
|
|
|
2372
2482
|
}
|
|
2373
2483
|
const sessionId = await this.sessionService.createSession(user.id);
|
|
2374
2484
|
const companiesWithBranches = companies.map((company)=>({
|
|
2375
|
-
...(0,
|
|
2485
|
+
...(0,helpers/* .toCompanyInfo */.$C)(company),
|
|
2376
2486
|
isActive: company.isActive,
|
|
2377
2487
|
branches: branches.filter((b)=>b.companyId === company.id).map((b)=>({
|
|
2378
|
-
...(0,
|
|
2488
|
+
...(0,helpers/* .toBranchInfo */.QH)(b),
|
|
2489
|
+
parentId: b.parentId ?? null,
|
|
2490
|
+
serial: b.serial ?? null,
|
|
2491
|
+
displayParentId: displayParentIds.get(b.id) ?? null,
|
|
2379
2492
|
isActive: b.isActive
|
|
2380
2493
|
}))
|
|
2381
2494
|
}));
|
|
@@ -2383,7 +2496,7 @@ class AuthenticationService {
|
|
|
2383
2496
|
requiresSelection: true,
|
|
2384
2497
|
sessionId,
|
|
2385
2498
|
expiresAt: new Date(Date.now() + 5 * 60 * 1000),
|
|
2386
|
-
user: (0,
|
|
2499
|
+
user: (0,helpers/* .toUserInfo */.FV)(user),
|
|
2387
2500
|
companies: companiesWithBranches
|
|
2388
2501
|
};
|
|
2389
2502
|
}
|
|
@@ -2564,13 +2677,15 @@ AuthenticationService = _ts_decorate([
|
|
|
2564
2677
|
/* import */ var _flusys_nestjs_shared_modules__rspack_import_2 = __webpack_require__(1236);
|
|
2565
2678
|
/* import */ var _flusys_nestjs_shared_utils__rspack_import_3 = __webpack_require__(9216);
|
|
2566
2679
|
/* import */ var _nestjs_common__rspack_import_4 = __webpack_require__(6157);
|
|
2567
|
-
/* import */ var
|
|
2568
|
-
/* import */ var
|
|
2569
|
-
/* import */ var
|
|
2570
|
-
/* import */ var
|
|
2571
|
-
/* import */ var
|
|
2572
|
-
/* import */ var
|
|
2573
|
-
/* import */ var
|
|
2680
|
+
/* import */ var class_validator__rspack_import_5 = __webpack_require__(5421);
|
|
2681
|
+
/* import */ var typeorm__rspack_import_6 = __webpack_require__(7158);
|
|
2682
|
+
/* import */ var _config_index_js__rspack_import_12 = __webpack_require__(7987);
|
|
2683
|
+
/* import */ var _config_index_js__rspack_import_13 = __webpack_require__(5363);
|
|
2684
|
+
/* import */ var _entities_company_branch_entity_js__rspack_import_7 = __webpack_require__(1923);
|
|
2685
|
+
/* import */ var _helpers_branch_ancestry_helper_js__rspack_import_8 = __webpack_require__(7526);
|
|
2686
|
+
/* import */ var _entities_user_company_permission_entity_js__rspack_import_9 = __webpack_require__(2377);
|
|
2687
|
+
/* import */ var _auth_config_service_js__rspack_import_10 = __webpack_require__(6514);
|
|
2688
|
+
/* import */ var _auth_datasource_provider_js__rspack_import_11 = __webpack_require__(2732);
|
|
2574
2689
|
function _ts_decorate(decorators, target, key, desc) {
|
|
2575
2690
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2576
2691
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -2605,45 +2720,121 @@ function _ts_param(paramIndex, decorator) {
|
|
|
2605
2720
|
|
|
2606
2721
|
|
|
2607
2722
|
|
|
2723
|
+
|
|
2724
|
+
|
|
2608
2725
|
class BranchService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiService {
|
|
2609
2726
|
cacheManager;
|
|
2610
2727
|
utilsService;
|
|
2611
2728
|
authConfig;
|
|
2612
2729
|
permissionSyncAdapter;
|
|
2613
2730
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, permissionSyncAdapter){
|
|
2614
|
-
super(
|
|
2731
|
+
super(_config_index_js__rspack_import_12/* .AUTH_EVENT_ENTITIES.COMPANY_BRANCH */.g.COMPANY_BRANCH, cacheManager, utilsService, BranchService.name, true, (/* inlined export .AUTH_EVENT_MODULE */"auth"), dataSourceProvider, _entities_company_branch_entity_js__rspack_import_7/* .CompanyBranch */.A), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig, this.permissionSyncAdapter = permissionSyncAdapter;
|
|
2732
|
+
}
|
|
2733
|
+
async beforeInsertOperation(dto, _user, queryRunner) {
|
|
2734
|
+
for (const d of Array.isArray(dto) ? dto : [
|
|
2735
|
+
dto
|
|
2736
|
+
]){
|
|
2737
|
+
if (d.parentId) await this.validateParent(null, d.parentId, d.companyId, queryRunner);
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
async beforeUpdateOperation(dto, _user, queryRunner) {
|
|
2741
|
+
const repo = queryRunner.manager.getRepository(_entities_company_branch_entity_js__rspack_import_7/* .CompanyBranch */.A);
|
|
2742
|
+
for (const d of Array.isArray(dto) ? dto : [
|
|
2743
|
+
dto
|
|
2744
|
+
]){
|
|
2745
|
+
if (!d.id || d.parentId === undefined && d.companyId === undefined) continue;
|
|
2746
|
+
const existing = await repo.findOne({
|
|
2747
|
+
where: {
|
|
2748
|
+
id: d.id
|
|
2749
|
+
},
|
|
2750
|
+
select: [
|
|
2751
|
+
'id',
|
|
2752
|
+
'companyId',
|
|
2753
|
+
'parentId'
|
|
2754
|
+
]
|
|
2755
|
+
});
|
|
2756
|
+
if (!existing) continue;
|
|
2757
|
+
const parentId = d.parentId === undefined ? existing.parentId : d.parentId;
|
|
2758
|
+
if (!parentId) continue;
|
|
2759
|
+
await this.validateParent(d.id, parentId, d.companyId ?? existing.companyId, queryRunner);
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
async validateParent(branchId, parentId, companyId, queryRunner) {
|
|
2763
|
+
const repo = queryRunner.manager.getRepository(_entities_company_branch_entity_js__rspack_import_7/* .CompanyBranch */.A);
|
|
2764
|
+
const parent = await repo.findOne({
|
|
2765
|
+
where: {
|
|
2766
|
+
id: parentId,
|
|
2767
|
+
deletedAt: (0,typeorm__rspack_import_6.IsNull)()
|
|
2768
|
+
},
|
|
2769
|
+
select: [
|
|
2770
|
+
'id',
|
|
2771
|
+
'companyId',
|
|
2772
|
+
'parentId'
|
|
2773
|
+
]
|
|
2774
|
+
});
|
|
2775
|
+
if (!parent || parent.companyId !== companyId) {
|
|
2776
|
+
throw new _nestjs_common__rspack_import_4.BadRequestException({
|
|
2777
|
+
message: 'Parent branch must belong to the same company',
|
|
2778
|
+
messageKey: _config_index_js__rspack_import_13/* .BRANCH_MESSAGES.INVALID_PARENT */.W1.INVALID_PARENT
|
|
2779
|
+
});
|
|
2780
|
+
}
|
|
2781
|
+
if (!branchId) return;
|
|
2782
|
+
const visited = new Set();
|
|
2783
|
+
let current = parent;
|
|
2784
|
+
while(current){
|
|
2785
|
+
if (current.id === branchId || visited.has(current.id)) {
|
|
2786
|
+
throw new _nestjs_common__rspack_import_4.BadRequestException({
|
|
2787
|
+
message: 'A branch cannot be moved under itself or its descendants',
|
|
2788
|
+
messageKey: _config_index_js__rspack_import_13/* .BRANCH_MESSAGES.CIRCULAR_PARENT */.W1.CIRCULAR_PARENT
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
visited.add(current.id);
|
|
2792
|
+
current = current.parentId ? await repo.findOne({
|
|
2793
|
+
where: {
|
|
2794
|
+
id: current.parentId
|
|
2795
|
+
},
|
|
2796
|
+
select: [
|
|
2797
|
+
'id',
|
|
2798
|
+
'parentId'
|
|
2799
|
+
]
|
|
2800
|
+
}) : null;
|
|
2801
|
+
}
|
|
2615
2802
|
}
|
|
2616
2803
|
async beforeDeleteOperation(dto, user, queryRunner) {
|
|
2617
|
-
const
|
|
2804
|
+
const requestedIds = Array.isArray(dto.id) ? dto.id : [
|
|
2618
2805
|
dto.id
|
|
2619
2806
|
];
|
|
2807
|
+
const branchIds = dto.type === 'restore' ? requestedIds : (0,_flusys_nestjs_shared_utils__rspack_import_3.collectBranchDescendantIds)(await (0,_helpers_branch_ancestry_helper_js__rspack_import_8/* .loadCompanyBranchNodes */.v)(queryRunner.manager.getRepository(_entities_company_branch_entity_js__rspack_import_7/* .CompanyBranch */.A), requestedIds, dto.type === 'permanent'), requestedIds, {
|
|
2808
|
+
includeSelf: true
|
|
2809
|
+
});
|
|
2810
|
+
dto.id = branchIds;
|
|
2620
2811
|
await this.ensureDataSourceRepository();
|
|
2621
2812
|
const readonlyBranches = await this.repository.find({
|
|
2622
2813
|
where: {
|
|
2623
|
-
id: (0,
|
|
2814
|
+
id: (0,typeorm__rspack_import_6.In)(branchIds),
|
|
2624
2815
|
readOnly: true,
|
|
2625
|
-
deletedAt: (0,
|
|
2816
|
+
deletedAt: (0,typeorm__rspack_import_6.IsNull)()
|
|
2626
2817
|
}
|
|
2627
2818
|
});
|
|
2628
2819
|
if (readonlyBranches.length > 0) {
|
|
2629
2820
|
const names = readonlyBranches.map((b)=>b.name).join(', ');
|
|
2630
2821
|
throw new _nestjs_common__rspack_import_4.ForbiddenException({
|
|
2631
2822
|
message: `Cannot delete readonly branch(es): ${names}`,
|
|
2632
|
-
messageKey:
|
|
2823
|
+
messageKey: _config_index_js__rspack_import_13/* .BRANCH_MESSAGES.READONLY_DELETE_FORBIDDEN */.W1.READONLY_DELETE_FORBIDDEN,
|
|
2633
2824
|
messageVariables: {
|
|
2634
2825
|
names
|
|
2635
2826
|
}
|
|
2636
2827
|
});
|
|
2637
2828
|
}
|
|
2638
|
-
await queryRunner.manager.getRepository(
|
|
2639
|
-
targetId: (0,
|
|
2829
|
+
await queryRunner.manager.getRepository(_entities_user_company_permission_entity_js__rspack_import_9/* .UserCompanyPermission */.I).delete({
|
|
2830
|
+
targetId: (0,typeorm__rspack_import_6.In)(branchIds)
|
|
2640
2831
|
});
|
|
2641
2832
|
if (!this.permissionSyncAdapter?.onBranchDeleted) {
|
|
2642
2833
|
return;
|
|
2643
2834
|
}
|
|
2644
|
-
const rows = await queryRunner.manager.getRepository(
|
|
2835
|
+
const rows = await queryRunner.manager.getRepository(_entities_company_branch_entity_js__rspack_import_7/* .CompanyBranch */.A).find({
|
|
2645
2836
|
where: {
|
|
2646
|
-
id: (0,
|
|
2837
|
+
id: (0,typeorm__rspack_import_6.In)(branchIds)
|
|
2647
2838
|
},
|
|
2648
2839
|
select: [
|
|
2649
2840
|
'id',
|
|
@@ -2652,6 +2843,30 @@ class BranchService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiSe
|
|
|
2652
2843
|
});
|
|
2653
2844
|
await Promise.all(rows.map((row)=>this.permissionSyncAdapter.onBranchDeleted(row.id, row.companyId)));
|
|
2654
2845
|
}
|
|
2846
|
+
// Hierarchy - ids that are empty or not UUIDs match no branch (and never reach a uuid column)
|
|
2847
|
+
async getDescendantIds(branchIds, options = {}) {
|
|
2848
|
+
const ids = (0,_flusys_nestjs_shared_utils__rspack_import_3.normalizeBranchIds)(branchIds).filter((id)=>(0,class_validator__rspack_import_5.isUUID)(id));
|
|
2849
|
+
if (!ids.length) return [];
|
|
2850
|
+
await this.ensureDataSourceRepository();
|
|
2851
|
+
const nodes = await (0,_helpers_branch_ancestry_helper_js__rspack_import_8/* .loadCompanyBranchNodes */.v)(this.repository, ids);
|
|
2852
|
+
const known = new Set(nodes.map((b)=>b.id));
|
|
2853
|
+
return (0,_flusys_nestjs_shared_utils__rspack_import_3.collectBranchDescendantIds)(nodes, ids.filter((id)=>known.has(id)), options);
|
|
2854
|
+
}
|
|
2855
|
+
async getAncestorIds(branchId, options = {}) {
|
|
2856
|
+
if (!branchId || !(0,class_validator__rspack_import_5.isUUID)(branchId)) return [];
|
|
2857
|
+
await this.ensureDataSourceRepository();
|
|
2858
|
+
const nodes = await (0,_helpers_branch_ancestry_helper_js__rspack_import_8/* .loadCompanyBranchNodes */.v)(this.repository, [
|
|
2859
|
+
branchId
|
|
2860
|
+
]);
|
|
2861
|
+
if (!nodes.some((b)=>b.id === branchId)) return [];
|
|
2862
|
+
return (0,_flusys_nestjs_shared_utils__rspack_import_3.collectBranchAncestorIds)(nodes, branchId, options);
|
|
2863
|
+
}
|
|
2864
|
+
async isWithinBranch(branchId, ancestorId) {
|
|
2865
|
+
if (!ancestorId) return false;
|
|
2866
|
+
return (await this.getAncestorIds(branchId, {
|
|
2867
|
+
includeSelf: true
|
|
2868
|
+
})).includes(ancestorId);
|
|
2869
|
+
}
|
|
2655
2870
|
// Query Customization
|
|
2656
2871
|
async getSelectQuery(query, _user, select) {
|
|
2657
2872
|
if (!select?.length) {
|
|
@@ -2661,6 +2876,8 @@ class BranchService extends _flusys_nestjs_shared_classes__rspack_import_0.ApiSe
|
|
|
2661
2876
|
'slug',
|
|
2662
2877
|
'email',
|
|
2663
2878
|
'phone',
|
|
2879
|
+
'parentId',
|
|
2880
|
+
'serial',
|
|
2664
2881
|
'isActive',
|
|
2665
2882
|
'readOnly',
|
|
2666
2883
|
'createdAt'
|
|
@@ -2701,16 +2918,16 @@ BranchService = _ts_decorate([
|
|
|
2701
2918
|
}),
|
|
2702
2919
|
_ts_param(0, (0,_nestjs_common__rspack_import_4.Inject)('CACHE_INSTANCE')),
|
|
2703
2920
|
_ts_param(1, (0,_nestjs_common__rspack_import_4.Inject)(_flusys_nestjs_shared_modules__rspack_import_2.UtilsService)),
|
|
2704
|
-
_ts_param(2, (0,_nestjs_common__rspack_import_4.Inject)(
|
|
2705
|
-
_ts_param(3, (0,_nestjs_common__rspack_import_4.Inject)(
|
|
2921
|
+
_ts_param(2, (0,_nestjs_common__rspack_import_4.Inject)(_auth_datasource_provider_js__rspack_import_11/* .AuthDataSourceProvider */.v)),
|
|
2922
|
+
_ts_param(3, (0,_nestjs_common__rspack_import_4.Inject)(_auth_config_service_js__rspack_import_10/* .AuthConfigService */.W)),
|
|
2706
2923
|
_ts_param(4, (0,_nestjs_common__rspack_import_4.Optional)()),
|
|
2707
2924
|
_ts_param(4, (0,_nestjs_common__rspack_import_4.Inject)(_flusys_nestjs_shared_interfaces__rspack_import_1.PERMISSION_SYNC_ADAPTER)),
|
|
2708
2925
|
_ts_metadata("design:type", Function),
|
|
2709
2926
|
_ts_metadata("design:paramtypes", [
|
|
2710
2927
|
typeof _flusys_nestjs_shared_classes__rspack_import_0.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_0.HybridCache,
|
|
2711
2928
|
typeof _flusys_nestjs_shared_modules__rspack_import_2.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_2.UtilsService,
|
|
2712
|
-
typeof
|
|
2713
|
-
typeof
|
|
2929
|
+
typeof _auth_datasource_provider_js__rspack_import_11/* .AuthDataSourceProvider */.v === "undefined" ? Object : _auth_datasource_provider_js__rspack_import_11/* .AuthDataSourceProvider */.v,
|
|
2930
|
+
typeof _auth_config_service_js__rspack_import_10/* .AuthConfigService */.W === "undefined" ? Object : _auth_config_service_js__rspack_import_10/* .AuthConfigService */.W,
|
|
2714
2931
|
typeof IPermissionSyncAdapter === "undefined" ? Object : IPermissionSyncAdapter
|
|
2715
2932
|
])
|
|
2716
2933
|
], BranchService);
|
|
@@ -3420,11 +3637,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3420
3637
|
/* import */ var _flusys_nestjs_shared_classes__rspack_import_1 = __webpack_require__(6937);
|
|
3421
3638
|
/* import */ var _flusys_nestjs_shared_interfaces__rspack_import_2 = __webpack_require__(5103);
|
|
3422
3639
|
/* import */ var _nestjs_common__rspack_import_3 = __webpack_require__(6157);
|
|
3423
|
-
/* import */ var
|
|
3424
|
-
/* import */ var
|
|
3425
|
-
/* import */ var
|
|
3426
|
-
/* import */ var
|
|
3427
|
-
/* import */ var
|
|
3640
|
+
/* import */ var _config_index_js__rspack_import_9 = __webpack_require__(5363);
|
|
3641
|
+
/* import */ var _config_index_js__rspack_import_10 = __webpack_require__(7987);
|
|
3642
|
+
/* import */ var _entities_company_branch_entity_js__rspack_import_4 = __webpack_require__(1923);
|
|
3643
|
+
/* import */ var _entities_user_company_permission_entity_js__rspack_import_5 = __webpack_require__(2377);
|
|
3644
|
+
/* import */ var _helpers_branch_ancestry_helper_js__rspack_import_6 = __webpack_require__(7526);
|
|
3645
|
+
/* import */ var _auth_config_service_js__rspack_import_7 = __webpack_require__(6514);
|
|
3646
|
+
/* import */ var _auth_datasource_provider_js__rspack_import_8 = __webpack_require__(2732);
|
|
3428
3647
|
function _ts_decorate(decorators, target, key, desc) {
|
|
3429
3648
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3430
3649
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -3456,6 +3675,8 @@ function _ts_param(paramIndex, decorator) {
|
|
|
3456
3675
|
|
|
3457
3676
|
|
|
3458
3677
|
|
|
3678
|
+
|
|
3679
|
+
|
|
3459
3680
|
class UserPermissionService {
|
|
3460
3681
|
dataSourceProvider;
|
|
3461
3682
|
authConfig;
|
|
@@ -3471,7 +3692,7 @@ class UserPermissionService {
|
|
|
3471
3692
|
* for a company or branch outside their own company.
|
|
3472
3693
|
*/ async getRepository() {
|
|
3473
3694
|
if (!this._repository) {
|
|
3474
|
-
this._repository = await this.dataSourceProvider.getRepository(
|
|
3695
|
+
this._repository = await this.dataSourceProvider.getRepository(_entities_user_company_permission_entity_js__rspack_import_5/* .UserCompanyPermission */.I);
|
|
3475
3696
|
}
|
|
3476
3697
|
return this._repository;
|
|
3477
3698
|
}
|
|
@@ -3484,7 +3705,7 @@ class UserPermissionService {
|
|
|
3484
3705
|
permissionType: type
|
|
3485
3706
|
},
|
|
3486
3707
|
relations: [
|
|
3487
|
-
type ===
|
|
3708
|
+
type === _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY ? 'company' : 'branch'
|
|
3488
3709
|
],
|
|
3489
3710
|
order: {
|
|
3490
3711
|
createdAt: 'DESC'
|
|
@@ -3493,7 +3714,7 @@ class UserPermissionService {
|
|
|
3493
3714
|
}
|
|
3494
3715
|
/** Assign permission to user */ async assignPermission(userId, targetId, type) {
|
|
3495
3716
|
const repository = await this.getRepository();
|
|
3496
|
-
const typeName = type ===
|
|
3717
|
+
const typeName = type === _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY ? 'company' : 'branch';
|
|
3497
3718
|
const existing = await repository.findOne({
|
|
3498
3719
|
where: {
|
|
3499
3720
|
userId,
|
|
@@ -3504,7 +3725,7 @@ class UserPermissionService {
|
|
|
3504
3725
|
if (existing) {
|
|
3505
3726
|
throw new _nestjs_common__rspack_import_3.ConflictException({
|
|
3506
3727
|
message: `User already assigned to this ${typeName}`,
|
|
3507
|
-
messageKey:
|
|
3728
|
+
messageKey: _config_index_js__rspack_import_9/* .USER_PERMISSION_MESSAGES.ALREADY_ASSIGNED */.jz.ALREADY_ASSIGNED,
|
|
3508
3729
|
messageVariables: {
|
|
3509
3730
|
type: typeName
|
|
3510
3731
|
}
|
|
@@ -3521,7 +3742,7 @@ class UserPermissionService {
|
|
|
3521
3742
|
if (err?.code === 'ER_DUP_ENTRY' || String(err?.message).includes('Duplicate entry')) {
|
|
3522
3743
|
throw new _nestjs_common__rspack_import_3.ConflictException({
|
|
3523
3744
|
message: `User already assigned to this ${typeName}. Please refresh and try again.`,
|
|
3524
|
-
messageKey:
|
|
3745
|
+
messageKey: _config_index_js__rspack_import_9/* .USER_PERMISSION_MESSAGES.ALREADY_ASSIGNED */.jz.ALREADY_ASSIGNED,
|
|
3525
3746
|
messageVariables: {
|
|
3526
3747
|
type: typeName
|
|
3527
3748
|
}
|
|
@@ -3529,11 +3750,11 @@ class UserPermissionService {
|
|
|
3529
3750
|
}
|
|
3530
3751
|
throw error;
|
|
3531
3752
|
}
|
|
3532
|
-
await this.publishPermissionEvent(
|
|
3753
|
+
await this.publishPermissionEvent(_config_index_js__rspack_import_10/* .AUTH_EVENT_ACTIONS.PERMISSION_GRANTED */.o.PERMISSION_GRANTED, userId, targetId, type);
|
|
3533
3754
|
}
|
|
3534
3755
|
async revokePermission(userId, targetId, type) {
|
|
3535
3756
|
const repository = await this.getRepository();
|
|
3536
|
-
const typeName = type ===
|
|
3757
|
+
const typeName = type === _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY ? 'company' : 'branch';
|
|
3537
3758
|
const permission = await repository.findOne({
|
|
3538
3759
|
where: {
|
|
3539
3760
|
userId,
|
|
@@ -3541,33 +3762,33 @@ class UserPermissionService {
|
|
|
3541
3762
|
permissionType: type
|
|
3542
3763
|
},
|
|
3543
3764
|
relations: [
|
|
3544
|
-
type ===
|
|
3765
|
+
type === _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.BRANCH */.e.BRANCH ? 'branch' : 'company'
|
|
3545
3766
|
]
|
|
3546
3767
|
});
|
|
3547
3768
|
if (!permission) {
|
|
3548
3769
|
throw new _nestjs_common__rspack_import_3.NotFoundException({
|
|
3549
3770
|
message: `${typeName.charAt(0).toUpperCase() + typeName.slice(1)} permission not found`,
|
|
3550
|
-
messageKey:
|
|
3771
|
+
messageKey: _config_index_js__rspack_import_9/* .USER_PERMISSION_MESSAGES.PERMISSION_NOT_FOUND */.jz.PERMISSION_NOT_FOUND,
|
|
3551
3772
|
messageVariables: {
|
|
3552
3773
|
type: typeName.charAt(0).toUpperCase() + typeName.slice(1)
|
|
3553
3774
|
}
|
|
3554
3775
|
});
|
|
3555
3776
|
}
|
|
3556
|
-
const companyId = type ===
|
|
3777
|
+
const companyId = type === _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY ? targetId : permission.branch?.companyId;
|
|
3557
3778
|
await repository.remove(permission);
|
|
3558
|
-
if (type ===
|
|
3779
|
+
if (type === _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY) {
|
|
3559
3780
|
const revokedBranchIds = await this.revokeBranchPermissionsForCompany(repository, userId, targetId);
|
|
3560
3781
|
await this.permissionSyncAdapter?.onUserCompanyAccessRevoked?.(userId, targetId);
|
|
3561
3782
|
await Promise.all(revokedBranchIds.map((branchId)=>this.permissionSyncAdapter?.onUserBranchAccessRevoked?.(userId, branchId, targetId)));
|
|
3562
3783
|
} else {
|
|
3563
3784
|
if (companyId) await this.permissionSyncAdapter?.onUserBranchAccessRevoked?.(userId, targetId, companyId);
|
|
3564
3785
|
}
|
|
3565
|
-
await this.publishPermissionEvent(
|
|
3786
|
+
await this.publishPermissionEvent(_config_index_js__rspack_import_10/* .AUTH_EVENT_ACTIONS.PERMISSION_REVOKED */.o.PERMISSION_REVOKED, userId, targetId, type, companyId);
|
|
3566
3787
|
}
|
|
3567
3788
|
async publishPermissionEvent(action, userId, targetId, type, companyId) {
|
|
3568
3789
|
await (0,_flusys_nestjs_shared_classes__rspack_import_1.publishDomainEvent)({
|
|
3569
3790
|
module: (/* inlined export .AUTH_EVENT_MODULE */"auth"),
|
|
3570
|
-
entity:
|
|
3791
|
+
entity: _config_index_js__rspack_import_10/* .AUTH_EVENT_ENTITIES.USER_PERMISSION */.g.USER_PERMISSION,
|
|
3571
3792
|
action,
|
|
3572
3793
|
ids: [
|
|
3573
3794
|
targetId
|
|
@@ -3585,7 +3806,7 @@ class UserPermissionService {
|
|
|
3585
3806
|
const branchPermissions = await repository.createQueryBuilder('permission').innerJoin('permission.branch', 'branch').where('permission.userId = :userId', {
|
|
3586
3807
|
userId
|
|
3587
3808
|
}).andWhere('permission.permissionType = :type', {
|
|
3588
|
-
type:
|
|
3809
|
+
type: _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.BRANCH */.e.BRANCH
|
|
3589
3810
|
}).andWhere('branch.companyId = :companyId', {
|
|
3590
3811
|
companyId
|
|
3591
3812
|
}).getMany();
|
|
@@ -3596,13 +3817,13 @@ class UserPermissionService {
|
|
|
3596
3817
|
return branchPermissions.map((permission)=>permission.targetId);
|
|
3597
3818
|
}
|
|
3598
3819
|
// Convenience Methods
|
|
3599
|
-
findUserCompanies = (userId)=>this.findUserPermissions(userId,
|
|
3820
|
+
findUserCompanies = (userId)=>this.findUserPermissions(userId, _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY);
|
|
3600
3821
|
/** Find user branch permissions with optional company filter */ async findUserBranches(userId, companyId) {
|
|
3601
3822
|
const repository = await this.getRepository();
|
|
3602
3823
|
const queryBuilder = repository.createQueryBuilder('permission').leftJoinAndSelect('permission.branch', 'branch').where('permission.userId = :userId', {
|
|
3603
3824
|
userId
|
|
3604
3825
|
}).andWhere('permission.permissionType = :type', {
|
|
3605
|
-
type:
|
|
3826
|
+
type: _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.BRANCH */.e.BRANCH
|
|
3606
3827
|
}).orderBy('permission.createdAt', 'DESC');
|
|
3607
3828
|
if (companyId) {
|
|
3608
3829
|
queryBuilder.andWhere('branch.companyId = :companyId', {
|
|
@@ -3611,13 +3832,16 @@ class UserPermissionService {
|
|
|
3611
3832
|
}
|
|
3612
3833
|
return queryBuilder.getMany();
|
|
3613
3834
|
}
|
|
3835
|
+
async findDisplayParentIds(branchIds) {
|
|
3836
|
+
return (0,_helpers_branch_ancestry_helper_js__rspack_import_6/* .loadDisplayParentIds */.x)(await this.dataSourceProvider.getRepository(_entities_company_branch_entity_js__rspack_import_4/* .CompanyBranch */.A), branchIds);
|
|
3837
|
+
}
|
|
3614
3838
|
// Reverse Lookups (target -> users)
|
|
3615
3839
|
/** Find all users permitted for a given company */ async findUsersForCompany(companyId) {
|
|
3616
3840
|
const repository = await this.getRepository();
|
|
3617
3841
|
return repository.find({
|
|
3618
3842
|
where: {
|
|
3619
3843
|
targetId: companyId,
|
|
3620
|
-
permissionType:
|
|
3844
|
+
permissionType: _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.COMPANY */.e.COMPANY
|
|
3621
3845
|
},
|
|
3622
3846
|
relations: [
|
|
3623
3847
|
'user'
|
|
@@ -3632,7 +3856,7 @@ class UserPermissionService {
|
|
|
3632
3856
|
return repository.find({
|
|
3633
3857
|
where: {
|
|
3634
3858
|
targetId: branchId,
|
|
3635
|
-
permissionType:
|
|
3859
|
+
permissionType: _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType.BRANCH */.e.BRANCH
|
|
3636
3860
|
},
|
|
3637
3861
|
relations: [
|
|
3638
3862
|
'user'
|
|
@@ -3652,7 +3876,7 @@ _ts_decorate([
|
|
|
3652
3876
|
_ts_metadata("design:paramtypes", [
|
|
3653
3877
|
String,
|
|
3654
3878
|
String,
|
|
3655
|
-
typeof
|
|
3879
|
+
typeof _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType */.e === "undefined" ? Object : _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType */.e
|
|
3656
3880
|
]),
|
|
3657
3881
|
_ts_metadata("design:returntype", Promise)
|
|
3658
3882
|
], UserPermissionService.prototype, "assignPermission", null);
|
|
@@ -3665,7 +3889,7 @@ _ts_decorate([
|
|
|
3665
3889
|
_ts_metadata("design:paramtypes", [
|
|
3666
3890
|
String,
|
|
3667
3891
|
String,
|
|
3668
|
-
typeof
|
|
3892
|
+
typeof _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType */.e === "undefined" ? Object : _entities_user_company_permission_entity_js__rspack_import_5/* .PermissionType */.e
|
|
3669
3893
|
]),
|
|
3670
3894
|
_ts_metadata("design:returntype", Promise)
|
|
3671
3895
|
], UserPermissionService.prototype, "revokePermission", null);
|
|
@@ -3673,14 +3897,14 @@ UserPermissionService = _ts_decorate([
|
|
|
3673
3897
|
(0,_nestjs_common__rspack_import_3.Injectable)({
|
|
3674
3898
|
scope: _nestjs_common__rspack_import_3.Scope.REQUEST
|
|
3675
3899
|
}),
|
|
3676
|
-
_ts_param(0, (0,_nestjs_common__rspack_import_3.Inject)(
|
|
3677
|
-
_ts_param(1, (0,_nestjs_common__rspack_import_3.Inject)(
|
|
3900
|
+
_ts_param(0, (0,_nestjs_common__rspack_import_3.Inject)(_auth_datasource_provider_js__rspack_import_8/* .AuthDataSourceProvider */.v)),
|
|
3901
|
+
_ts_param(1, (0,_nestjs_common__rspack_import_3.Inject)(_auth_config_service_js__rspack_import_7/* .AuthConfigService */.W)),
|
|
3678
3902
|
_ts_param(2, (0,_nestjs_common__rspack_import_3.Optional)()),
|
|
3679
3903
|
_ts_param(2, (0,_nestjs_common__rspack_import_3.Inject)(_flusys_nestjs_shared_interfaces__rspack_import_2.PERMISSION_SYNC_ADAPTER)),
|
|
3680
3904
|
_ts_metadata("design:type", Function),
|
|
3681
3905
|
_ts_metadata("design:paramtypes", [
|
|
3682
|
-
typeof
|
|
3683
|
-
typeof
|
|
3906
|
+
typeof _auth_datasource_provider_js__rspack_import_8/* .AuthDataSourceProvider */.v === "undefined" ? Object : _auth_datasource_provider_js__rspack_import_8/* .AuthDataSourceProvider */.v,
|
|
3907
|
+
typeof _auth_config_service_js__rspack_import_7/* .AuthConfigService */.W === "undefined" ? Object : _auth_config_service_js__rspack_import_7/* .AuthConfigService */.W,
|
|
3684
3908
|
typeof IPermissionSyncAdapter === "undefined" ? Object : IPermissionSyncAdapter
|
|
3685
3909
|
])
|
|
3686
3910
|
], UserPermissionService);
|
|
@@ -3698,15 +3922,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
3698
3922
|
/* import */ var _flusys_nestjs_shared_modules__rspack_import_3 = __webpack_require__(1236);
|
|
3699
3923
|
/* import */ var _nestjs_common__rspack_import_4 = __webpack_require__(6157);
|
|
3700
3924
|
/* import */ var bcrypt__rspack_import_5 = __webpack_require__(7176);
|
|
3701
|
-
/* import */ var
|
|
3702
|
-
/* import */ var
|
|
3703
|
-
/* import */ var
|
|
3704
|
-
/* import */ var
|
|
3705
|
-
/* import */ var
|
|
3706
|
-
/* import */ var
|
|
3707
|
-
/* import */ var
|
|
3708
|
-
/* import */ var
|
|
3709
|
-
/* import */ var
|
|
3925
|
+
/* import */ var _config_index_js__rspack_import_12 = __webpack_require__(7987);
|
|
3926
|
+
/* import */ var _config_index_js__rspack_import_13 = __webpack_require__(5363);
|
|
3927
|
+
/* import */ var _config_index_js__rspack_import_15 = __webpack_require__(5588);
|
|
3928
|
+
/* import */ var _helpers_index_js__rspack_import_6 = __webpack_require__(334);
|
|
3929
|
+
/* import */ var _dtos_user_dto_js__rspack_import_7 = __webpack_require__(7265);
|
|
3930
|
+
/* import */ var _entities_app_user_entity_js__rspack_import_8 = __webpack_require__(4758);
|
|
3931
|
+
/* import */ var _entities_user_company_permission_entity_js__rspack_import_9 = __webpack_require__(2377);
|
|
3932
|
+
/* import */ var _enums_index_js__rspack_import_14 = __webpack_require__(5081);
|
|
3933
|
+
/* import */ var _auth_config_service_js__rspack_import_10 = __webpack_require__(6514);
|
|
3934
|
+
/* import */ var _auth_datasource_provider_js__rspack_import_11 = __webpack_require__(2732);
|
|
3710
3935
|
function _ts_decorate(decorators, target, key, desc) {
|
|
3711
3936
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3712
3937
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
@@ -3743,6 +3968,7 @@ function _ts_param(paramIndex, decorator) {
|
|
|
3743
3968
|
|
|
3744
3969
|
|
|
3745
3970
|
|
|
3971
|
+
|
|
3746
3972
|
class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiService {
|
|
3747
3973
|
cacheManager;
|
|
3748
3974
|
utilsService;
|
|
@@ -3752,14 +3978,14 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
3752
3978
|
dataSource;
|
|
3753
3979
|
logAdapter = (0,_flusys_nestjs_shared_classes__rspack_import_1.createModuleLogger)('auth');
|
|
3754
3980
|
constructor(cacheManager, utilsService, dataSourceProvider, authConfig, userEnricher){
|
|
3755
|
-
super(
|
|
3981
|
+
super(_config_index_js__rspack_import_12/* .AUTH_EVENT_ENTITIES.USER */.g.USER, cacheManager, utilsService, UserService.name, true, (/* inlined export .AUTH_EVENT_MODULE */"auth"), dataSourceProvider, _entities_app_user_entity_js__rspack_import_8/* .AppUser */.$), this.cacheManager = cacheManager, this.utilsService = utilsService, this.authConfig = authConfig, this.userEnricher = userEnricher;
|
|
3756
3982
|
}
|
|
3757
3983
|
async ensureDataSourceRepository() {
|
|
3758
3984
|
await super.ensureDataSourceRepository();
|
|
3759
3985
|
const isCompanyFeatureEnabled = this.authConfig.isCompanyFeatureEnabled();
|
|
3760
3986
|
if (isCompanyFeatureEnabled && !this.permissionRepository) {
|
|
3761
3987
|
[this.permissionRepository] = await this.resolveRepositories([
|
|
3762
|
-
|
|
3988
|
+
_entities_user_company_permission_entity_js__rspack_import_9/* .UserCompanyPermission */.I
|
|
3763
3989
|
]);
|
|
3764
3990
|
}
|
|
3765
3991
|
if (!this.dataSource) {
|
|
@@ -3770,7 +3996,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
3770
3996
|
if (userId !== user.id) {
|
|
3771
3997
|
throw new _nestjs_common__rspack_import_4.ForbiddenException({
|
|
3772
3998
|
message: "Cannot access another user's profile",
|
|
3773
|
-
messageKey:
|
|
3999
|
+
messageKey: _config_index_js__rspack_import_13/* .AUTH_MESSAGES.PROFILE_ACCESS_DENIED */.mK.PROFILE_ACCESS_DENIED
|
|
3774
4000
|
});
|
|
3775
4001
|
}
|
|
3776
4002
|
await this.ensureDataSourceRepository();
|
|
@@ -3782,7 +4008,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
3782
4008
|
if (!userEntity) {
|
|
3783
4009
|
throw new _nestjs_common__rspack_import_4.NotFoundException({
|
|
3784
4010
|
message: 'User not found',
|
|
3785
|
-
messageKey:
|
|
4011
|
+
messageKey: _config_index_js__rspack_import_13/* .USER_MESSAGES.NOT_FOUND */.ny.NOT_FOUND
|
|
3786
4012
|
});
|
|
3787
4013
|
}
|
|
3788
4014
|
return userEntity;
|
|
@@ -3822,14 +4048,14 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
3822
4048
|
const permission = await this.permissionRepository.findOne({
|
|
3823
4049
|
where: {
|
|
3824
4050
|
userId: id,
|
|
3825
|
-
permissionType:
|
|
4051
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.COMPANY */.e.COMPANY,
|
|
3826
4052
|
targetId: user.companyId
|
|
3827
4053
|
}
|
|
3828
4054
|
});
|
|
3829
4055
|
if (!permission) {
|
|
3830
4056
|
throw new _nestjs_common__rspack_import_4.NotFoundException({
|
|
3831
4057
|
message: 'User company permission not found',
|
|
3832
|
-
messageKey:
|
|
4058
|
+
messageKey: _config_index_js__rspack_import_13/* .USER_PERMISSION_MESSAGES.PERMISSION_NOT_FOUND */.jz.PERMISSION_NOT_FOUND,
|
|
3833
4059
|
messageVariables: {
|
|
3834
4060
|
type: 'User company'
|
|
3835
4061
|
}
|
|
@@ -3842,6 +4068,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
3842
4068
|
isActive
|
|
3843
4069
|
});
|
|
3844
4070
|
}
|
|
4071
|
+
if (!isActive) await (0,_helpers_index_js__rspack_import_6/* .revokeUserSessions */.XP)(this.cacheManager, this.authConfig, id);
|
|
3845
4072
|
await Promise.all([
|
|
3846
4073
|
this.clearCacheForAll(),
|
|
3847
4074
|
this.clearCacheForId([
|
|
@@ -3993,7 +4220,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
3993
4220
|
AND perm.permission_type = :permissionType
|
|
3994
4221
|
AND perm.target_id = :companyId
|
|
3995
4222
|
LIMIT 1)`, 'appuser_companyIsActive');
|
|
3996
|
-
query.setParameter('permissionType',
|
|
4223
|
+
query.setParameter('permissionType', _enums_index_js__rspack_import_14/* .PermissionType.COMPANY */.e.COMPANY);
|
|
3997
4224
|
query.setParameter('companyId', user.companyId);
|
|
3998
4225
|
// Filter by isActive within the company if requested
|
|
3999
4226
|
if (filter?.isActive !== undefined) {
|
|
@@ -4004,7 +4231,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4004
4231
|
AND perm.target_id = :companyId
|
|
4005
4232
|
AND perm.is_active = :isActiveValue
|
|
4006
4233
|
)`, {
|
|
4007
|
-
permissionType:
|
|
4234
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.COMPANY */.e.COMPANY,
|
|
4008
4235
|
companyId: user.companyId,
|
|
4009
4236
|
isActiveValue: filter.isActive
|
|
4010
4237
|
});
|
|
@@ -4016,7 +4243,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4016
4243
|
AND perm.permission_type = :permissionType
|
|
4017
4244
|
AND perm.target_id = :companyId
|
|
4018
4245
|
)`, {
|
|
4019
|
-
permissionType:
|
|
4246
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.COMPANY */.e.COMPANY,
|
|
4020
4247
|
companyId: user.companyId
|
|
4021
4248
|
});
|
|
4022
4249
|
return {
|
|
@@ -4038,14 +4265,14 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4038
4265
|
const existingPermission = await queryRunner.manager.findOne(this.permissionRepository.target, {
|
|
4039
4266
|
where: {
|
|
4040
4267
|
userId: savedUser.id,
|
|
4041
|
-
permissionType:
|
|
4268
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.COMPANY */.e.COMPANY,
|
|
4042
4269
|
targetId: user.companyId
|
|
4043
4270
|
}
|
|
4044
4271
|
});
|
|
4045
4272
|
if (!existingPermission) {
|
|
4046
4273
|
const permission = queryRunner.manager.create(this.permissionRepository.target, {
|
|
4047
4274
|
userId: savedUser.id,
|
|
4048
|
-
permissionType:
|
|
4275
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.COMPANY */.e.COMPANY,
|
|
4049
4276
|
targetId: user.companyId,
|
|
4050
4277
|
isActive: dto.isActive ?? true
|
|
4051
4278
|
});
|
|
@@ -4055,14 +4282,14 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4055
4282
|
const existingBranchPermission = await queryRunner.manager.findOne(this.permissionRepository.target, {
|
|
4056
4283
|
where: {
|
|
4057
4284
|
userId: savedUser.id,
|
|
4058
|
-
permissionType:
|
|
4285
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.BRANCH */.e.BRANCH,
|
|
4059
4286
|
targetId: user.branchId
|
|
4060
4287
|
}
|
|
4061
4288
|
});
|
|
4062
4289
|
if (!existingBranchPermission) {
|
|
4063
4290
|
const branchPermission = queryRunner.manager.create(this.permissionRepository.target, {
|
|
4064
4291
|
userId: savedUser.id,
|
|
4065
|
-
permissionType:
|
|
4292
|
+
permissionType: _enums_index_js__rspack_import_14/* .PermissionType.BRANCH */.e.BRANCH,
|
|
4066
4293
|
targetId: user.branchId,
|
|
4067
4294
|
isActive: dto.isActive ?? true
|
|
4068
4295
|
});
|
|
@@ -4134,7 +4361,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4134
4361
|
if (!this.userEnricher?.updateProfileSection) {
|
|
4135
4362
|
throw new _nestjs_common__rspack_import_4.BadRequestException({
|
|
4136
4363
|
message: 'Profile sections not supported',
|
|
4137
|
-
messageKey:
|
|
4364
|
+
messageKey: _config_index_js__rspack_import_13/* .AUTH_MESSAGES.PROFILE_SECTIONS_NOT_SUPPORTED */.mK.PROFILE_SECTIONS_NOT_SUPPORTED
|
|
4138
4365
|
});
|
|
4139
4366
|
}
|
|
4140
4367
|
const queryRunner = this.dataSource.createQueryRunner();
|
|
@@ -4187,7 +4414,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4187
4414
|
if (!findUser) {
|
|
4188
4415
|
throw new _nestjs_common__rspack_import_4.NotFoundException({
|
|
4189
4416
|
message: 'User not found',
|
|
4190
|
-
messageKey:
|
|
4417
|
+
messageKey: _config_index_js__rspack_import_13/* .USER_MESSAGES.NOT_FOUND */.ny.NOT_FOUND
|
|
4191
4418
|
});
|
|
4192
4419
|
}
|
|
4193
4420
|
if (dto.password) {
|
|
@@ -4196,14 +4423,14 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
|
|
|
4196
4423
|
if (!dto.oldPassword) {
|
|
4197
4424
|
throw new _nestjs_common__rspack_import_4.BadRequestException({
|
|
4198
4425
|
message: 'Current password is required to change your password',
|
|
4199
|
-
messageKey:
|
|
4426
|
+
messageKey: _config_index_js__rspack_import_13/* .AUTH_MESSAGES.PASSWORD_CHANGE_CURRENT_REQUIRED */.mK.PASSWORD_CHANGE_CURRENT_REQUIRED
|
|
4200
4427
|
});
|
|
4201
4428
|
}
|
|
4202
4429
|
const isPasswordValid = await bcrypt__rspack_import_5.compare(dto.oldPassword, findUser.password);
|
|
4203
4430
|
if (!isPasswordValid) {
|
|
4204
4431
|
throw new _nestjs_common__rspack_import_4.BadRequestException({
|
|
4205
4432
|
message: 'Current password is incorrect',
|
|
4206
|
-
messageKey:
|
|
4433
|
+
messageKey: _config_index_js__rspack_import_13/* .AUTH_MESSAGES.PASSWORD_CHANGE_INVALID_CURRENT */.mK.PASSWORD_CHANGE_INVALID_CURRENT
|
|
4207
4434
|
});
|
|
4208
4435
|
}
|
|
4209
4436
|
}
|
|
@@ -4274,7 +4501,7 @@ _ts_decorate([
|
|
|
4274
4501
|
}),
|
|
4275
4502
|
_ts_metadata("design:type", Function),
|
|
4276
4503
|
_ts_metadata("design:paramtypes", [
|
|
4277
|
-
typeof
|
|
4504
|
+
typeof _dtos_user_dto_js__rspack_import_7/* .CreateUserDto */.TG === "undefined" ? Object : _dtos_user_dto_js__rspack_import_7/* .CreateUserDto */.TG,
|
|
4278
4505
|
Object
|
|
4279
4506
|
]),
|
|
4280
4507
|
_ts_metadata("design:returntype", Promise)
|
|
@@ -4313,16 +4540,16 @@ UserService = _ts_decorate([
|
|
|
4313
4540
|
}),
|
|
4314
4541
|
_ts_param(0, (0,_nestjs_common__rspack_import_4.Inject)('CACHE_INSTANCE')),
|
|
4315
4542
|
_ts_param(1, (0,_nestjs_common__rspack_import_4.Inject)(_flusys_nestjs_shared_modules__rspack_import_3.UtilsService)),
|
|
4316
|
-
_ts_param(2, (0,_nestjs_common__rspack_import_4.Inject)(
|
|
4317
|
-
_ts_param(3, (0,_nestjs_common__rspack_import_4.Inject)(
|
|
4543
|
+
_ts_param(2, (0,_nestjs_common__rspack_import_4.Inject)(_auth_datasource_provider_js__rspack_import_11/* .AuthDataSourceProvider */.v)),
|
|
4544
|
+
_ts_param(3, (0,_nestjs_common__rspack_import_4.Inject)(_auth_config_service_js__rspack_import_10/* .AuthConfigService */.W)),
|
|
4318
4545
|
_ts_param(4, (0,_nestjs_common__rspack_import_4.Optional)()),
|
|
4319
|
-
_ts_param(4, (0,_nestjs_common__rspack_import_4.Inject)(
|
|
4546
|
+
_ts_param(4, (0,_nestjs_common__rspack_import_4.Inject)(_config_index_js__rspack_import_15/* .USER_ENRICHER */.jt)),
|
|
4320
4547
|
_ts_metadata("design:type", Function),
|
|
4321
4548
|
_ts_metadata("design:paramtypes", [
|
|
4322
4549
|
typeof _flusys_nestjs_shared_classes__rspack_import_1.HybridCache === "undefined" ? Object : _flusys_nestjs_shared_classes__rspack_import_1.HybridCache,
|
|
4323
4550
|
typeof _flusys_nestjs_shared_modules__rspack_import_3.UtilsService === "undefined" ? Object : _flusys_nestjs_shared_modules__rspack_import_3.UtilsService,
|
|
4324
|
-
typeof
|
|
4325
|
-
typeof
|
|
4551
|
+
typeof _auth_datasource_provider_js__rspack_import_11/* .AuthDataSourceProvider */.v === "undefined" ? Object : _auth_datasource_provider_js__rspack_import_11/* .AuthDataSourceProvider */.v,
|
|
4552
|
+
typeof _auth_config_service_js__rspack_import_10/* .AuthConfigService */.W === "undefined" ? Object : _auth_config_service_js__rspack_import_10/* .AuthConfigService */.W,
|
|
4326
4553
|
typeof IUserEnricher === "undefined" ? Object : IUserEnricher
|
|
4327
4554
|
])
|
|
4328
4555
|
], UserService);
|