easywork-common-lib 1.0.1021 → 1.0.1022

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.
Files changed (66) hide show
  1. package/dist/grpc/drive/drive.proto +290 -290
  2. package/dist/grpc/drive/leads.proto +114 -114
  3. package/dist/modules/index.d.ts +0 -1
  4. package/dist/modules/index.js +0 -1
  5. package/dist/modules/index.js.map +1 -1
  6. package/package.json +54 -54
  7. package/dist/modules/authorization/authorization.module.d.ts +0 -26
  8. package/dist/modules/authorization/authorization.module.js +0 -105
  9. package/dist/modules/authorization/authorization.module.js.map +0 -1
  10. package/dist/modules/authorization/config/resource-configurations.d.ts +0 -12
  11. package/dist/modules/authorization/config/resource-configurations.js +0 -124
  12. package/dist/modules/authorization/config/resource-configurations.js.map +0 -1
  13. package/dist/modules/authorization/decorators/contact-permissions.decorator.d.ts +0 -13
  14. package/dist/modules/authorization/decorators/contact-permissions.decorator.js +0 -101
  15. package/dist/modules/authorization/decorators/contact-permissions.decorator.js.map +0 -1
  16. package/dist/modules/authorization/decorators/permissions.decorator.d.ts +0 -51
  17. package/dist/modules/authorization/decorators/permissions.decorator.js +0 -144
  18. package/dist/modules/authorization/decorators/permissions.decorator.js.map +0 -1
  19. package/dist/modules/authorization/factories/resource-authorization.factory.d.ts +0 -55
  20. package/dist/modules/authorization/factories/resource-authorization.factory.js +0 -184
  21. package/dist/modules/authorization/factories/resource-authorization.factory.js.map +0 -1
  22. package/dist/modules/authorization/index.d.ts +0 -7
  23. package/dist/modules/authorization/index.js +0 -24
  24. package/dist/modules/authorization/index.js.map +0 -1
  25. package/dist/modules/authorization/interfaces/authorization.interface.d.ts +0 -23
  26. package/dist/modules/authorization/interfaces/authorization.interface.js +0 -3
  27. package/dist/modules/authorization/interfaces/authorization.interface.js.map +0 -1
  28. package/dist/modules/authorization/services/authorization.service.d.ts +0 -25
  29. package/dist/modules/authorization/services/authorization.service.js +0 -139
  30. package/dist/modules/authorization/services/authorization.service.js.map +0 -1
  31. package/dist/modules/authorization/services/dynamic-filter.service.d.ts +0 -9
  32. package/dist/modules/authorization/services/dynamic-filter.service.js +0 -238
  33. package/dist/modules/authorization/services/dynamic-filter.service.js.map +0 -1
  34. package/dist/modules/authorization/services/index.d.ts +0 -7
  35. package/dist/modules/authorization/services/index.js +0 -24
  36. package/dist/modules/authorization/services/index.js.map +0 -1
  37. package/dist/modules/authorization/services/modules/contact-authorization.service.d.ts +0 -29
  38. package/dist/modules/authorization/services/modules/contact-authorization.service.js +0 -105
  39. package/dist/modules/authorization/services/modules/contact-authorization.service.js.map +0 -1
  40. package/dist/modules/authorization/services/modules/index.d.ts +0 -4
  41. package/dist/modules/authorization/services/modules/index.js +0 -21
  42. package/dist/modules/authorization/services/modules/index.js.map +0 -1
  43. package/dist/modules/authorization/services/modules/lead-authorization.service.d.ts +0 -27
  44. package/dist/modules/authorization/services/modules/lead-authorization.service.js +0 -96
  45. package/dist/modules/authorization/services/modules/lead-authorization.service.js.map +0 -1
  46. package/dist/modules/authorization/services/modules/policy-authorization.service.d.ts +0 -28
  47. package/dist/modules/authorization/services/modules/policy-authorization.service.js +0 -100
  48. package/dist/modules/authorization/services/modules/policy-authorization.service.js.map +0 -1
  49. package/dist/modules/authorization/services/modules/task-authorization.service.d.ts +0 -28
  50. package/dist/modules/authorization/services/modules/task-authorization.service.js +0 -100
  51. package/dist/modules/authorization/services/modules/task-authorization.service.js.map +0 -1
  52. package/dist/modules/authorization/services/permission-cache.service.d.ts +0 -10
  53. package/dist/modules/authorization/services/permission-cache.service.js +0 -48
  54. package/dist/modules/authorization/services/permission-cache.service.js.map +0 -1
  55. package/dist/modules/authorization/services/permission-evaluator.service.d.ts +0 -26
  56. package/dist/modules/authorization/services/permission-evaluator.service.js +0 -349
  57. package/dist/modules/authorization/services/permission-evaluator.service.js.map +0 -1
  58. package/dist/modules/authorization/services/resource-access-filter.service.d.ts +0 -20
  59. package/dist/modules/authorization/services/resource-access-filter.service.js +0 -406
  60. package/dist/modules/authorization/services/resource-access-filter.service.js.map +0 -1
  61. package/dist/modules/authorization/services/resource-authorization.service.d.ts +0 -47
  62. package/dist/modules/authorization/services/resource-authorization.service.js +0 -192
  63. package/dist/modules/authorization/services/resource-authorization.service.js.map +0 -1
  64. package/dist/modules/authorization/usage-example.d.ts +0 -35
  65. package/dist/modules/authorization/usage-example.js +0 -180
  66. package/dist/modules/authorization/usage-example.js.map +0 -1
@@ -1,25 +0,0 @@
1
- import { PermissionContextType, PermissionResult } from "../../../common/";
2
- import { IAuthorizationService } from "../interfaces/authorization.interface";
3
- import { PermissionEvaluatorService } from "./permission-evaluator.service";
4
- import { ResourceAccessFilterService } from "./resource-access-filter.service";
5
- import { PermissionCacheService } from "./permission-cache.service";
6
- export declare class AuthorizationService implements IAuthorizationService {
7
- private readonly permissionEvaluator;
8
- private readonly accessFilter;
9
- private readonly permissionCache;
10
- private readonly logger;
11
- constructor(permissionEvaluator: PermissionEvaluatorService, accessFilter: ResourceAccessFilterService, permissionCache: PermissionCacheService);
12
- canAccess(context: PermissionContextType): Promise<PermissionResult>;
13
- filterQuery(queryBuilder: any, context: PermissionContextType): Promise<any>;
14
- validateAccess(context: PermissionContextType): Promise<void>;
15
- canCreate(user: any, resource: string, targetEntity?: any): Promise<PermissionResult>;
16
- canRead(user: any, resource: string, targetEntity?: any): Promise<PermissionResult>;
17
- canUpdate(user: any, resource: string, targetEntity: any): Promise<PermissionResult>;
18
- canDelete(user: any, resource: string, targetEntity: any): Promise<PermissionResult>;
19
- canManage(user: any, resource: string, targetEntity?: any): Promise<PermissionResult>;
20
- canAccessMultiple(contexts: PermissionContextType[]): Promise<{
21
- [key: string]: PermissionResult;
22
- }>;
23
- clearUserCache(userId: string): Promise<void>;
24
- private buildCacheKey;
25
- }
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var AuthorizationService_1;
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.AuthorizationService = void 0;
14
- const common_1 = require("@nestjs/common");
15
- const common_2 = require("../../../common/");
16
- const permission_evaluator_service_1 = require("./permission-evaluator.service");
17
- const resource_access_filter_service_1 = require("./resource-access-filter.service");
18
- const permission_cache_service_1 = require("./permission-cache.service");
19
- let AuthorizationService = AuthorizationService_1 = class AuthorizationService {
20
- permissionEvaluator;
21
- accessFilter;
22
- permissionCache;
23
- logger = new common_1.Logger(AuthorizationService_1.name);
24
- constructor(permissionEvaluator, accessFilter, permissionCache) {
25
- this.permissionEvaluator = permissionEvaluator;
26
- this.accessFilter = accessFilter;
27
- this.permissionCache = permissionCache;
28
- }
29
- async canAccess(context) {
30
- const cacheKey = this.buildCacheKey(context);
31
- try {
32
- const cachedResult = await this.permissionCache.get(cacheKey);
33
- if (cachedResult && cachedResult.timestamp) {
34
- const now = Date.now();
35
- const ttl = cachedResult.allowed ? 300000 : 60000;
36
- if (now - cachedResult.timestamp < ttl) {
37
- return cachedResult;
38
- }
39
- }
40
- const result = await this.permissionEvaluator.evaluate(context);
41
- const resultWithTimestamp = {
42
- ...result,
43
- timestamp: Date.now(),
44
- };
45
- const ttl = result.allowed ? 300 : 60;
46
- await this.permissionCache.set(cacheKey, resultWithTimestamp, ttl);
47
- return result;
48
- }
49
- catch (error) {
50
- this.logger.error(`Permission evaluation failed: ${error.message}`, error.stack);
51
- throw new common_1.ForbiddenException("Permission evaluation failed");
52
- }
53
- }
54
- async filterQuery(queryBuilder, context) {
55
- const result = await this.canAccess(context);
56
- if (!result.allowed) {
57
- throw new common_1.ForbiddenException(`Access denied for ${context.action} on ${context.resource}`);
58
- }
59
- if (result.filters && Object.keys(result.filters).length > 0) {
60
- return this.accessFilter.applyFilters(queryBuilder, {
61
- ...context,
62
- additionalContext: { permissionFilters: result.filters },
63
- });
64
- }
65
- return queryBuilder;
66
- }
67
- async validateAccess(context) {
68
- const result = await this.canAccess(context);
69
- if (!result.allowed) {
70
- throw new common_1.ForbiddenException(result.reason ||
71
- `Access denied for ${context.action} on ${context.resource}`);
72
- }
73
- }
74
- async canCreate(user, resource, targetEntity) {
75
- return this.canAccess({
76
- user,
77
- resource,
78
- action: common_2.PermissionAction.CREATE,
79
- targetEntity,
80
- });
81
- }
82
- async canRead(user, resource, targetEntity) {
83
- return this.canAccess({
84
- user,
85
- resource,
86
- action: common_2.PermissionAction.READ,
87
- targetEntity,
88
- });
89
- }
90
- async canUpdate(user, resource, targetEntity) {
91
- return this.canAccess({
92
- user,
93
- resource,
94
- action: common_2.PermissionAction.UPDATE,
95
- targetEntity,
96
- });
97
- }
98
- async canDelete(user, resource, targetEntity) {
99
- return this.canAccess({
100
- user,
101
- resource,
102
- action: common_2.PermissionAction.DELETE,
103
- targetEntity,
104
- });
105
- }
106
- async canManage(user, resource, targetEntity) {
107
- return this.canAccess({
108
- user,
109
- resource,
110
- action: common_2.PermissionAction.MANAGE,
111
- targetEntity,
112
- });
113
- }
114
- async canAccessMultiple(contexts) {
115
- const results = {};
116
- const promises = contexts.map(async (context) => {
117
- const result = await this.canAccess(context);
118
- const key = `${context.resource}.${context.action}`;
119
- results[key] = result;
120
- });
121
- await Promise.all(promises);
122
- return results;
123
- }
124
- async clearUserCache(userId) {
125
- return this.permissionCache.clear(`user:${userId}:*`);
126
- }
127
- buildCacheKey(context) {
128
- const entityId = context.targetEntity?.id || "null";
129
- return `user:${context.user.id}:${context.resource}:${context.action}:${entityId}`;
130
- }
131
- };
132
- exports.AuthorizationService = AuthorizationService;
133
- exports.AuthorizationService = AuthorizationService = AuthorizationService_1 = __decorate([
134
- (0, common_1.Injectable)(),
135
- __metadata("design:paramtypes", [permission_evaluator_service_1.PermissionEvaluatorService,
136
- resource_access_filter_service_1.ResourceAccessFilterService,
137
- permission_cache_service_1.PermissionCacheService])
138
- ], AuthorizationService);
139
- //# sourceMappingURL=authorization.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorization.service.js","sourceRoot":"","sources":["../../../../src/modules/authorization/services/authorization.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAwE;AACxE,6CAI0B;AAE1B,iFAA4E;AAC5E,qFAA+E;AAC/E,yEAAoE;AAG7D,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAIZ;IACA;IACA;IALF,MAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAEhE,YACmB,mBAA+C,EAC/C,YAAyC,EACzC,eAAuC;QAFvC,wBAAmB,GAAnB,mBAAmB,CAA4B;QAC/C,iBAAY,GAAZ,YAAY,CAA6B;QACzC,oBAAe,GAAf,eAAe,CAAwB;IACvD,CAAC;IAEJ,KAAK,CAAC,SAAS,CAAC,OAA8B;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE7C,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAE9D,IAAI,YAAY,IAAI,YAAY,CAAC,SAAS,EAAE,CAAC;gBAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACvB,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;gBAClD,IAAI,GAAG,GAAG,YAAY,CAAC,SAAS,GAAG,GAAG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AChB,YAAkB;QAElB,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,IAAI;YACJ,QAAQ;YACR,MAAM,EAAE,yBAAgB,CAAC,MAAM;YAC/B,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAGD,KAAK,CAAC,iBAAiB,CACrB,QAAiC;QAEjC,MAAM,OAAO,GAAwC,EAAE,CAAC;QAExD,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC7C,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpD,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QACxB,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5B,OAAO,OAAO,CAAC;IACjB,CAAC;IAGD,KAAK,CAAC,cAAc,CAAC,MAAc;QACjC,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,MAAM,IAAI,CAAC,CAAC;IACxD,CAAC;IAEO,aAAa,CAAC,OAA8B;QAClD,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,EAAE,EAAE,IAAI,MAAM,CAAC;QACpD,OAAO,QAAQ,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;IACrF,CAAC;CACF,CAAA;AAzKY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAK6B,yDAA0B;QACjC,4DAA2B;QACxB,iDAAsB;GAN/C,oBAAoB,CAyKhC"}
@@ -1,9 +0,0 @@
1
- import { FilterCriteria, PermissionContextType } from "../../../common/";
2
- export declare class DynamicFilterService {
3
- private readonly logger;
4
- buildFiltersFromCriteria(criteria: FilterCriteria, context: PermissionContextType, assistantIds?: string[]): Promise<Record<string, any>>;
5
- private applyFieldCondition;
6
- mergeFilters(...filterObjects: Record<string, any>[]): Record<string, any>;
7
- private getColumnMapping;
8
- private mapFieldName;
9
- }
@@ -1,238 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var DynamicFilterService_1;
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.DynamicFilterService = void 0;
11
- const common_1 = require("@nestjs/common");
12
- const resource_configurations_1 = require("../config/resource-configurations");
13
- let DynamicFilterService = DynamicFilterService_1 = class DynamicFilterService {
14
- logger = new common_1.Logger(DynamicFilterService_1.name);
15
- async buildFiltersFromCriteria(criteria, context, assistantIds = []) {
16
- const filters = {};
17
- const { user } = context;
18
- if (criteria.fields && criteria.fields.length > 0) {
19
- for (const fieldCondition of criteria.fields) {
20
- this.applyFieldCondition(filters, fieldCondition);
21
- }
22
- }
23
- const userBasedConditions = [];
24
- const ruleConditions = context.additionalContext?.ruleConditions || [];
25
- const hasParticipantCondition = ruleConditions.includes("participant");
26
- const includeParticipants = hasParticipantCondition || criteria.includeParticipants;
27
- if (criteria.includeOwn) {
28
- const createdByField = this.mapFieldName(context.resource, "createdBy");
29
- userBasedConditions.push({ [createdByField]: user.id });
30
- }
31
- if (criteria.includeAssigned) {
32
- const assignedToField = this.mapFieldName(context.resource, "assignedTo");
33
- userBasedConditions.push({ [assignedToField]: user.id });
34
- }
35
- if (criteria.includeObserved) {
36
- const observersField = this.mapFieldName(context.resource, "observers");
37
- const mapping = this.getColumnMapping(context.resource);
38
- if (mapping.observers === "observer" ||
39
- mapping.observers === "observerId") {
40
- userBasedConditions.push({ [observersField]: user.id });
41
- }
42
- else {
43
- userBasedConditions.push({ [observersField]: { contains: [user.id] } });
44
- }
45
- }
46
- if (includeParticipants) {
47
- const participantsField = this.mapFieldName(context.resource, "participants");
48
- const mapping = this.getColumnMapping(context.resource);
49
- if (mapping.participants) {
50
- userBasedConditions.push({
51
- [participantsField]: { contains: [user.id] },
52
- });
53
- }
54
- }
55
- if (criteria.includeTeam) {
56
- const teamMemberIds = assistantIds && assistantIds.length > 0 ? assistantIds : [];
57
- if (teamMemberIds.length > 0) {
58
- const createdByField = this.mapFieldName(context.resource, "createdBy");
59
- const assignedToField = this.mapFieldName(context.resource, "assignedTo");
60
- const observersField = this.mapFieldName(context.resource, "observers");
61
- const mapping = this.getColumnMapping(context.resource);
62
- userBasedConditions.push({ [createdByField]: { in: teamMemberIds } });
63
- userBasedConditions.push({ [assignedToField]: { in: teamMemberIds } });
64
- if (mapping.observers === "observer" ||
65
- mapping.observers === "observerId") {
66
- userBasedConditions.push({ [observersField]: { in: teamMemberIds } });
67
- }
68
- else {
69
- userBasedConditions.push({
70
- [observersField]: { contains: teamMemberIds },
71
- });
72
- }
73
- if (mapping.participants &&
74
- (criteria.includeTeam ||
75
- hasParticipantCondition ||
76
- criteria.includeParticipants)) {
77
- const participantsField = this.mapFieldName(context.resource, "participants");
78
- userBasedConditions.push({
79
- [participantsField]: { contains: teamMemberIds },
80
- });
81
- }
82
- }
83
- }
84
- if (criteria.includeGroup) {
85
- const groupIds = (user.groups || []).map((g) => g.id);
86
- if (groupIds.length > 0) {
87
- userBasedConditions.push({ groupId: { in: groupIds } });
88
- }
89
- }
90
- if (criteria.includeSupervised && assistantIds.length > 0) {
91
- const createdByField = this.mapFieldName(context.resource, "createdBy");
92
- const assignedToField = this.mapFieldName(context.resource, "assignedTo");
93
- const observersField = this.mapFieldName(context.resource, "observers");
94
- const mapping = this.getColumnMapping(context.resource);
95
- userBasedConditions.push({ [createdByField]: { in: assistantIds } }, { [assignedToField]: { in: assistantIds } });
96
- if (mapping.observers === "observer" ||
97
- mapping.observers === "observerId") {
98
- userBasedConditions.push({ [observersField]: { in: assistantIds } });
99
- }
100
- else {
101
- userBasedConditions.push({
102
- [observersField]: { contains: assistantIds },
103
- });
104
- }
105
- }
106
- if (userBasedConditions.length > 0) {
107
- if (filters.or) {
108
- filters.or.push(...userBasedConditions);
109
- }
110
- else {
111
- filters.or = userBasedConditions;
112
- }
113
- }
114
- if (criteria.orConditions && criteria.orConditions.length > 0) {
115
- const orFilters = await Promise.all(criteria.orConditions.map(async (orCriteria) => this.buildFiltersFromCriteria(orCriteria, context, assistantIds)));
116
- const flattenedOrFilters = orFilters
117
- .flatMap((filter) => (filter.or ? filter.or : [filter]))
118
- .filter((f) => Object.keys(f).length > 0);
119
- if (flattenedOrFilters.length > 0) {
120
- if (filters.or) {
121
- filters.or.push(...flattenedOrFilters);
122
- }
123
- else {
124
- filters.or = flattenedOrFilters;
125
- }
126
- }
127
- }
128
- if (criteria.andConditions && criteria.andConditions.length > 0) {
129
- for (const andCriteria of criteria.andConditions) {
130
- const andFilter = await this.buildFiltersFromCriteria(andCriteria, context, assistantIds);
131
- if (Object.keys(andFilter).length > 0) {
132
- Object.assign(filters, andFilter);
133
- }
134
- }
135
- }
136
- return filters;
137
- }
138
- applyFieldCondition(filters, condition) {
139
- const { field, operator, value, values } = condition;
140
- switch (operator) {
141
- case "equals":
142
- filters[field] = value;
143
- break;
144
- case "in":
145
- if (values && values.length > 0) {
146
- filters[field] = { in: values };
147
- }
148
- break;
149
- case "contains":
150
- if (values && values.length > 0) {
151
- filters[field] = { contains: values };
152
- }
153
- else if (value !== undefined) {
154
- filters[field] = { contains: [value] };
155
- }
156
- break;
157
- case "not_in":
158
- if (values && values.length > 0) {
159
- filters[field] = { notIn: values };
160
- }
161
- break;
162
- case "is_null":
163
- filters[field] = { isNull: true };
164
- break;
165
- case "is_not_null":
166
- filters[field] = { isNull: false };
167
- break;
168
- case "like":
169
- filters[field] = { like: value };
170
- break;
171
- case "gt":
172
- filters[field] = { gt: value };
173
- break;
174
- case "gte":
175
- filters[field] = { gte: value };
176
- break;
177
- case "lt":
178
- filters[field] = { lt: value };
179
- break;
180
- case "lte":
181
- filters[field] = { lte: value };
182
- break;
183
- default:
184
- this.logger.warn(`Unknown filter operator: ${operator}`);
185
- }
186
- }
187
- mergeFilters(...filterObjects) {
188
- const merged = {};
189
- for (const filters of filterObjects) {
190
- for (const [key, value] of Object.entries(filters)) {
191
- if (key === "or") {
192
- if (merged.or) {
193
- merged.or.push(...(Array.isArray(value) ? value : [value]));
194
- }
195
- else {
196
- merged.or = Array.isArray(value) ? [...value] : [value];
197
- }
198
- }
199
- else if (key === "and") {
200
- if (merged.and) {
201
- merged.and.push(...(Array.isArray(value) ? value : [value]));
202
- }
203
- else {
204
- merged.and = Array.isArray(value) ? [...value] : [value];
205
- }
206
- }
207
- else {
208
- merged[key] = value;
209
- }
210
- }
211
- }
212
- return merged;
213
- }
214
- getColumnMapping(resource) {
215
- try {
216
- const config = (0, resource_configurations_1.getResourceConfig)(resource);
217
- return config.columnMappings;
218
- }
219
- catch (error) {
220
- this.logger.warn(`Resource configuration not found for: ${resource}, using default mapping`);
221
- return {
222
- assignedTo: "assignedById",
223
- observers: "observers",
224
- createdBy: "createdBy",
225
- groupId: "groupId",
226
- };
227
- }
228
- }
229
- mapFieldName(resource, logicalField) {
230
- const mapping = this.getColumnMapping(resource);
231
- return mapping[logicalField] || logicalField;
232
- }
233
- };
234
- exports.DynamicFilterService = DynamicFilterService;
235
- exports.DynamicFilterService = DynamicFilterService = DynamicFilterService_1 = __decorate([
236
- (0, common_1.Injectable)()
237
- ], DynamicFilterService);
238
- //# sourceMappingURL=dynamic-filter.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamic-filter.service.js","sourceRoot":"","sources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H,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAKO,gBAAgB,CAAC,QAAgB;QACvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAA,2CAAiB,EAAC,QAAQ,CAAC,CAAC;YAC3C,OAAO,MAAM,CAAC,cAAc,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEf,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,yCAAyC,QAAQ,yBAAyB,CAC3E,CAAC;YACF,OAAO;gBACL,UAAU,EAAE,cAAc;gBAC1B,SAAS,EAAE,WAAW;gBACtB,SAAS,EAAE,WAAW;gBACtB,OAAO,EAAE,SAAS;aACnB,CAAC;QACJ,CAAC;IACH,CAAC;IAKO,YAAY,CAAC,QAAgB,EAAE,YAAoB;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAChD,OAAO,OAAO,CAAC,YAAoC,CAAC,IAAI,YAAY,CAAC;IACvE,CAAC;CACF,CAAA;AAvUY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;GACA,oBAAoB,CAuUhC"}
@@ -1,7 +0,0 @@
1
- export * from "./authorization.service";
2
- export * from "./permission-evaluator.service";
3
- export * from "./resource-authorization.service";
4
- export * from "./permission-cache.service";
5
- export * from "./resource-access-filter.service";
6
- export * from "./dynamic-filter.service";
7
- export * from "./modules";
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./authorization.service"), exports);
18
- __exportStar(require("./permission-evaluator.service"), exports);
19
- __exportStar(require("./resource-authorization.service"), exports);
20
- __exportStar(require("./permission-cache.service"), exports);
21
- __exportStar(require("./resource-access-filter.service"), exports);
22
- __exportStar(require("./dynamic-filter.service"), exports);
23
- __exportStar(require("./modules"), exports);
24
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/authorization/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAuC;AACvC,iEAA8C;AAC9C,mEAAgD;AAChD,6DAA0C;AAC1C,mEAAgD;AAChD,2DAAwC;AACxC,4CAAyB"}
@@ -1,29 +0,0 @@
1
- import { Repository, SelectQueryBuilder } from "typeorm";
2
- import { SubGroup, User } from "../../../../entities";
3
- import { PermissionAction, PermissionResult } from "../../../../common/";
4
- import { ResourceAuthorizationFactory } from "../../factories/resource-authorization.factory";
5
- export declare class ContactAuthorizationService {
6
- private readonly authFactory;
7
- private readonly logger;
8
- private contactAuth?;
9
- constructor(authFactory: ResourceAuthorizationFactory);
10
- private getContactAuth;
11
- applyContactPermissionFilters(queryBuilder: SelectQueryBuilder<any>, user: User, options?: {
12
- getAll?: boolean;
13
- action?: PermissionAction;
14
- subGroupRepository?: Repository<SubGroup>;
15
- }): Promise<SelectQueryBuilder<any>>;
16
- canPerformContactAction(user: any, action: PermissionAction, targetContact?: any, subGroupRepository?: Repository<SubGroup>): Promise<PermissionResult>;
17
- validateContactAccess(user: any, action: PermissionAction, targetContact: any, subGroupRepository?: Repository<SubGroup>): Promise<void>;
18
- getAssistantIds(user: User, subGroupRepository: Repository<SubGroup>): Promise<string[]>;
19
- getUserSubGroupMembers(user: User, subGroupRepository: Repository<SubGroup>): Promise<string[]>;
20
- hasHighLevelPermissions(user: any): boolean;
21
- private getUserMaxRoleLevel;
22
- canCreateContact(user: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
23
- canReadContact(user: any, contact?: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
24
- canUpdateContact(user: any, contact: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
25
- canDeleteContact(user: any, contact: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
26
- canMergeContacts(user: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
27
- canImportContacts(user: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
28
- canExportContacts(user: any, subGroupRepository?: Repository<SubGroup>): Promise<boolean>;
29
- }
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var ContactAuthorizationService_1;
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ContactAuthorizationService = void 0;
14
- const common_1 = require("@nestjs/common");
15
- const resource_authorization_factory_1 = require("../../factories/resource-authorization.factory");
16
- let ContactAuthorizationService = ContactAuthorizationService_1 = class ContactAuthorizationService {
17
- authFactory;
18
- logger = new common_1.Logger(ContactAuthorizationService_1.name);
19
- contactAuth;
20
- constructor(authFactory) {
21
- this.authFactory = authFactory;
22
- }
23
- getContactAuth(subGroupRepository) {
24
- if (!this.contactAuth && subGroupRepository) {
25
- this.contactAuth = this.authFactory.forContact(subGroupRepository);
26
- }
27
- return (this.contactAuth ||
28
- this.authFactory.createBuilder().forResource("contact").build());
29
- }
30
- async applyContactPermissionFilters(queryBuilder, user, options = {}) {
31
- const { subGroupRepository, ...restOptions } = options;
32
- try {
33
- const contactAuth = this.getContactAuth(subGroupRepository);
34
- const assistantIds = await contactAuth.getSubGroupMembers(user);
35
- return await contactAuth.applyPermissionFilters(queryBuilder, user, {
36
- ...restOptions,
37
- assistantIds,
38
- });
39
- }
40
- catch (error) {
41
- this.logger.error(`Error applying contact permission filters: ${error instanceof Error ? error.message : "Unknown error"}`);
42
- queryBuilder.where("1 = 0");
43
- return queryBuilder;
44
- }
45
- }
46
- async canPerformContactAction(user, action, targetContact, subGroupRepository) {
47
- const contactAuth = this.getContactAuth(subGroupRepository);
48
- return contactAuth.canPerformAction(user, action, targetContact);
49
- }
50
- async validateContactAccess(user, action, targetContact, subGroupRepository) {
51
- const contactAuth = this.getContactAuth(subGroupRepository);
52
- return contactAuth.validateAccess(user, action, targetContact);
53
- }
54
- async getAssistantIds(user, subGroupRepository) {
55
- const contactAuth = this.getContactAuth(subGroupRepository);
56
- return contactAuth.getAssistantIds(user);
57
- }
58
- async getUserSubGroupMembers(user, subGroupRepository) {
59
- const contactAuth = this.getContactAuth(subGroupRepository);
60
- return contactAuth.getSubGroupMembers(user);
61
- }
62
- hasHighLevelPermissions(user) {
63
- const userMaxRoleLevel = this.getUserMaxRoleLevel(user.roles || []);
64
- return userMaxRoleLevel <= 2;
65
- }
66
- getUserMaxRoleLevel(roles) {
67
- if (!roles || roles.length === 0)
68
- return 999;
69
- return Math.min(...roles.map((role) => role.level || 999));
70
- }
71
- async canCreateContact(user, subGroupRepository) {
72
- const contactAuth = this.getContactAuth(subGroupRepository);
73
- return contactAuth.canCreate(user);
74
- }
75
- async canReadContact(user, contact, subGroupRepository) {
76
- const contactAuth = this.getContactAuth(subGroupRepository);
77
- return contactAuth.canRead(user, contact);
78
- }
79
- async canUpdateContact(user, contact, subGroupRepository) {
80
- const contactAuth = this.getContactAuth(subGroupRepository);
81
- return contactAuth.canUpdate(user, contact);
82
- }
83
- async canDeleteContact(user, contact, subGroupRepository) {
84
- const contactAuth = this.getContactAuth(subGroupRepository);
85
- return contactAuth.canDelete(user, contact);
86
- }
87
- async canMergeContacts(user, subGroupRepository) {
88
- const contactAuth = this.getContactAuth(subGroupRepository);
89
- return contactAuth.canManage(user);
90
- }
91
- async canImportContacts(user, subGroupRepository) {
92
- const contactAuth = this.getContactAuth(subGroupRepository);
93
- return contactAuth.canImport(user);
94
- }
95
- async canExportContacts(user, subGroupRepository) {
96
- const contactAuth = this.getContactAuth(subGroupRepository);
97
- return contactAuth.canExport(user);
98
- }
99
- };
100
- exports.ContactAuthorizationService = ContactAuthorizationService;
101
- exports.ContactAuthorizationService = ContactAuthorizationService = ContactAuthorizationService_1 = __decorate([
102
- (0, common_1.Injectable)(),
103
- __metadata("design:paramtypes", [resource_authorization_factory_1.ResourceAuthorizationFactory])
104
- ], ContactAuthorizationService);
105
- //# sourceMappingURL=contact-authorization.service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contact-authorization.service.js","sourceRoot":"","sources":["../../../../../src/modules/authorization/services/modules/contact-authorization.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AAIpD,mGAGwD;AAUjD,IAAM,2BAA2B,mCAAjC,MAAM,2BAA2B;IAIT;IAHZ,MAAM,GAAG,IAAI,eAAM,CAAC,6BAA2B,CAAC,IAAI,CAAC,CAAC;IAC/D,WAAW,CAAmC;IAEtD,YAA6B,WAAyC;QAAzC,gBAAW,GAAX,WAAW,CAA8B;IAAG,CAAC;IAKlE,cAAc,CACpB,kBAAyC;QAEzC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,kBAAkB,EAAE,CAAC;YAC5C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CA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@ -1,4 +0,0 @@
1
- export * from "./contact-authorization.service";
2
- export * from "./lead-authorization.service";
3
- export * from "./policy-authorization.service";
4
- export * from "./task-authorization.service";