@qrvey/assets-sharing 0.3.4-dev.2162 → 0.3.4-dev.2164
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/cjs/common/common.type.js +0 -3
- package/dist/cjs/common/common.type.js.map +0 -1
- package/dist/cjs/common/constants.js +0 -56
- package/dist/cjs/common/constants.js.map +0 -1
- package/dist/cjs/common/persistence/base.js +0 -15
- package/dist/cjs/common/persistence/base.js.map +0 -1
- package/dist/cjs/common/persistence/poolClient.js +0 -11
- package/dist/cjs/common/persistence/poolClient.js.map +0 -1
- package/dist/cjs/common/util.js +0 -12
- package/dist/cjs/common/util.js.map +0 -1
- package/dist/cjs/context.js +0 -22
- package/dist/cjs/context.js.map +0 -1
- package/dist/cjs/index.js +0 -43
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/quser/entities/types/user.type.js +0 -3
- package/dist/cjs/quser/entities/types/user.type.js.map +0 -1
- package/dist/cjs/quser/entities/user.js +0 -25
- package/dist/cjs/quser/entities/user.js.map +0 -1
- package/dist/cjs/quser/implementations/group.model.js +0 -19
- package/dist/cjs/quser/implementations/group.model.js.map +0 -1
- package/dist/cjs/quser/implementations/group.repository.js +0 -19
- package/dist/cjs/quser/implementations/group.repository.js.map +0 -1
- package/dist/cjs/quser/implementations/user.model.js +0 -24
- package/dist/cjs/quser/implementations/user.model.js.map +0 -1
- package/dist/cjs/quser/implementations/user.repository.js +0 -29
- package/dist/cjs/quser/implementations/user.repository.js.map +0 -1
- package/dist/cjs/quser/interfaces/rolesRepository.interface.js +0 -3
- package/dist/cjs/quser/interfaces/rolesRepository.interface.js.map +0 -1
- package/dist/cjs/quser/interfaces/userRepository.interface.js +0 -3
- package/dist/cjs/quser/interfaces/userRepository.interface.js.map +0 -1
- package/dist/cjs/quser/services/fromTokenToUser.js +0 -52
- package/dist/cjs/quser/services/fromTokenToUser.js.map +0 -1
- package/dist/cjs/quser/services/hasAdminRole.js +0 -48
- package/dist/cjs/quser/services/hasAdminRole.js.map +0 -1
- package/dist/cjs/sharing/entities/details.js +0 -109
- package/dist/cjs/sharing/entities/details.js.map +0 -1
- package/dist/cjs/sharing/entities/sharing.js +0 -63
- package/dist/cjs/sharing/entities/sharing.js.map +0 -1
- package/dist/cjs/sharing/entities/types/details.type.js +0 -3
- package/dist/cjs/sharing/entities/types/details.type.js.map +0 -1
- package/dist/cjs/sharing/entities/types/orgTreeResult.js +0 -3
- package/dist/cjs/sharing/entities/types/orgTreeResult.js.map +0 -1
- package/dist/cjs/sharing/entities/types/organization.type.js +0 -3
- package/dist/cjs/sharing/entities/types/organization.type.js.map +0 -1
- package/dist/cjs/sharing/entities/types/sharing.type.js +0 -3
- package/dist/cjs/sharing/entities/types/sharing.type.js.map +0 -1
- package/dist/cjs/sharing/implementations/admin.repository.js +0 -47
- package/dist/cjs/sharing/implementations/admin.repository.js.map +0 -1
- package/dist/cjs/sharing/implementations/details.model.js +0 -93
- package/dist/cjs/sharing/implementations/details.model.js.map +0 -1
- package/dist/cjs/sharing/implementations/details.repository.js +0 -114
- package/dist/cjs/sharing/implementations/details.repository.js.map +0 -1
- package/dist/cjs/sharing/implementations/dm.model.js +0 -22
- package/dist/cjs/sharing/implementations/dm.model.js.map +0 -1
- package/dist/cjs/sharing/implementations/dm.repository.js +0 -20
- package/dist/cjs/sharing/implementations/dm.repository.js.map +0 -1
- package/dist/cjs/sharing/implementations/dx.model.js +0 -30
- package/dist/cjs/sharing/implementations/dx.model.js.map +0 -1
- package/dist/cjs/sharing/implementations/dx.repository.js +0 -21
- package/dist/cjs/sharing/implementations/dx.repository.js.map +0 -1
- package/dist/cjs/sharing/implementations/organization.model.js +0 -31
- package/dist/cjs/sharing/implementations/organization.model.js.map +0 -1
- package/dist/cjs/sharing/implementations/organization.repository.js +0 -66
- package/dist/cjs/sharing/implementations/organization.repository.js.map +0 -1
- package/dist/cjs/sharing/implementations/sharing.model.js +0 -33
- package/dist/cjs/sharing/implementations/sharing.model.js.map +0 -1
- package/dist/cjs/sharing/implementations/sharing.repository.js +0 -31
- package/dist/cjs/sharing/implementations/sharing.repository.js.map +0 -1
- package/dist/cjs/sharing/interfaces/adminRepository.interface.js +0 -3
- package/dist/cjs/sharing/interfaces/adminRepository.interface.js.map +0 -1
- package/dist/cjs/sharing/interfaces/dashboardRepository.interface.js +0 -3
- package/dist/cjs/sharing/interfaces/dashboardRepository.interface.js.map +0 -1
- package/dist/cjs/sharing/interfaces/detailsRepository.interface.js +0 -3
- package/dist/cjs/sharing/interfaces/detailsRepository.interface.js.map +0 -1
- package/dist/cjs/sharing/interfaces/downloadManagerRepository.interface.js +0 -3
- package/dist/cjs/sharing/interfaces/downloadManagerRepository.interface.js.map +0 -1
- package/dist/cjs/sharing/interfaces/organizationRepository.interface.js +0 -3
- package/dist/cjs/sharing/interfaces/organizationRepository.interface.js.map +0 -1
- package/dist/cjs/sharing/interfaces/sharingRepository.interface.js +0 -3
- package/dist/cjs/sharing/interfaces/sharingRepository.interface.js.map +0 -1
- package/dist/cjs/sharing/services/checkAppPermissions.js +0 -45
- package/dist/cjs/sharing/services/checkAppPermissions.js.map +0 -1
- package/dist/cjs/sharing/services/checkOrgPermissions.js +0 -32
- package/dist/cjs/sharing/services/checkOrgPermissions.js.map +0 -1
- package/dist/cjs/sharing/services/checkUserAccessLevel.js +0 -58
- package/dist/cjs/sharing/services/checkUserAccessLevel.js.map +0 -1
- package/dist/cjs/sharing/services/delete.js +0 -32
- package/dist/cjs/sharing/services/delete.js.map +0 -1
- package/dist/cjs/sharing/services/getOrgTree.js +0 -26
- package/dist/cjs/sharing/services/getOrgTree.js.map +0 -1
- package/dist/cjs/sharing/services/list.js +0 -44
- package/dist/cjs/sharing/services/list.js.map +0 -1
- package/dist/cjs/sharing/services/upsert.js +0 -135
- package/dist/cjs/sharing/services/upsert.js.map +0 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist/esm/index.mjs +0 -1198
- package/dist/esm/index.mjs.map +0 -1
- package/dist/types/index.d.ts +0 -167
package/dist/esm/index.mjs
DELETED
|
@@ -1,1198 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { container, injectable, inject } from 'tsyringe';
|
|
3
|
-
import { CrudSchema, CrudService, buildFilter, getDbPool } from '@qrvey/data-persistence';
|
|
4
|
-
import { getAttribute } from '@qrvey/utils';
|
|
5
|
-
import { getId } from '@qrvey/id-generator';
|
|
6
|
-
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __defProps = Object.defineProperties;
|
|
9
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
11
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
12
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
14
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
-
var __spreadValues = (a, b) => {
|
|
16
|
-
for (var prop in b || (b = {}))
|
|
17
|
-
if (__hasOwnProp.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
if (__getOwnPropSymbols)
|
|
20
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
21
|
-
if (__propIsEnum.call(b, prop))
|
|
22
|
-
__defNormalProp(a, prop, b[prop]);
|
|
23
|
-
}
|
|
24
|
-
return a;
|
|
25
|
-
};
|
|
26
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
28
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
29
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
30
|
-
if (decorator = decorators[i])
|
|
31
|
-
result = (decorator(result)) || result;
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
35
|
-
|
|
36
|
-
// src/common/constants.ts
|
|
37
|
-
var ENVIRONMENT = {
|
|
38
|
-
SERVER_PREFIX: process.env.SERVER_PREFIX,
|
|
39
|
-
TABLE_PREFIX: process.env.TABLE_PREFIX,
|
|
40
|
-
DOMAIN: process.env.DOMAIN,
|
|
41
|
-
API_KEY: process.env.API_KEY
|
|
42
|
-
};
|
|
43
|
-
var DATABASE_INFO = {
|
|
44
|
-
DATA_PERSISTENCE_SCHEMA: "admin",
|
|
45
|
-
SERVER_PREFIX: ENVIRONMENT.SERVER_PREFIX,
|
|
46
|
-
TABLE_PREFIX: ENVIRONMENT.TABLE_PREFIX
|
|
47
|
-
};
|
|
48
|
-
var ORGANIZATION_QRVEY = "org:0";
|
|
49
|
-
var ORGANIZATION_ANONYMOUS = "anonymous";
|
|
50
|
-
var ASSET_TYPE = /* @__PURE__ */ ((ASSET_TYPE2) => {
|
|
51
|
-
ASSET_TYPE2["DX"] = "DX";
|
|
52
|
-
ASSET_TYPE2["DM"] = "DM";
|
|
53
|
-
return ASSET_TYPE2;
|
|
54
|
-
})(ASSET_TYPE || {});
|
|
55
|
-
var SHARED_ORIGIN = /* @__PURE__ */ ((SHARED_ORIGIN3) => {
|
|
56
|
-
SHARED_ORIGIN3["INTERNAL"] = "INTERNAL";
|
|
57
|
-
SHARED_ORIGIN3["EXTERNAL"] = "EXTERNAL";
|
|
58
|
-
SHARED_ORIGIN3["UNKNOWN"] = "UNKNOWN";
|
|
59
|
-
return SHARED_ORIGIN3;
|
|
60
|
-
})(SHARED_ORIGIN || {});
|
|
61
|
-
var SHARE_TYPE = /* @__PURE__ */ ((SHARE_TYPE3) => {
|
|
62
|
-
SHARE_TYPE3["USER"] = "USER";
|
|
63
|
-
SHARE_TYPE3["ROLE"] = "ROLE";
|
|
64
|
-
SHARE_TYPE3["ORGANIZATION"] = "ORGANIZATION";
|
|
65
|
-
return SHARE_TYPE3;
|
|
66
|
-
})(SHARE_TYPE || {});
|
|
67
|
-
var ACCESS_LEVEL = /* @__PURE__ */ ((ACCESS_LEVEL3) => {
|
|
68
|
-
ACCESS_LEVEL3[ACCESS_LEVEL3["NONE"] = 0] = "NONE";
|
|
69
|
-
ACCESS_LEVEL3[ACCESS_LEVEL3["CAN_USE"] = 1] = "CAN_USE";
|
|
70
|
-
ACCESS_LEVEL3[ACCESS_LEVEL3["CAN_EDIT"] = 2] = "CAN_EDIT";
|
|
71
|
-
ACCESS_LEVEL3[ACCESS_LEVEL3["ADMIN"] = 4] = "ADMIN";
|
|
72
|
-
return ACCESS_LEVEL3;
|
|
73
|
-
})(ACCESS_LEVEL || {});
|
|
74
|
-
var APP_SHARING_STATUS = /* @__PURE__ */ ((APP_SHARING_STATUS2) => {
|
|
75
|
-
APP_SHARING_STATUS2["PUBLIC"] = "public";
|
|
76
|
-
APP_SHARING_STATUS2["PRIVATE"] = "private";
|
|
77
|
-
return APP_SHARING_STATUS2;
|
|
78
|
-
})(APP_SHARING_STATUS || {});
|
|
79
|
-
var LIMIT_PER_PAGE = 10;
|
|
80
|
-
|
|
81
|
-
// src/quser/implementations/group.model.ts
|
|
82
|
-
var GroupModel = class extends CrudSchema {
|
|
83
|
-
};
|
|
84
|
-
GroupModel.table = {
|
|
85
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}Groups`,
|
|
86
|
-
alias: "qv_groups"
|
|
87
|
-
};
|
|
88
|
-
GroupModel.columns = {
|
|
89
|
-
groupid: {
|
|
90
|
-
type: "string"
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
GroupModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
94
|
-
var poolClient;
|
|
95
|
-
function getPoolClient() {
|
|
96
|
-
if (!poolClient) poolClient = getDbPool();
|
|
97
|
-
return poolClient;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// src/common/persistence/base.ts
|
|
101
|
-
var BaseRepository = class extends CrudService {
|
|
102
|
-
constructor(schema) {
|
|
103
|
-
super(schema, getPoolClient());
|
|
104
|
-
}
|
|
105
|
-
filter(attribute, value, operator) {
|
|
106
|
-
return buildFilter(attribute, value, operator);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// src/quser/implementations/group.repository.ts
|
|
111
|
-
var GroupRepository = class extends BaseRepository {
|
|
112
|
-
constructor() {
|
|
113
|
-
super(GroupModel);
|
|
114
|
-
}
|
|
115
|
-
async getOne(identifier) {
|
|
116
|
-
const params = {
|
|
117
|
-
filters: [this.filter("groupid", identifier)]
|
|
118
|
-
};
|
|
119
|
-
const response = await super.findItem(params);
|
|
120
|
-
return response;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var UserModel = class extends CrudSchema {
|
|
124
|
-
};
|
|
125
|
-
UserModel.table = {
|
|
126
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}Users`,
|
|
127
|
-
alias: "qv_users"
|
|
128
|
-
};
|
|
129
|
-
UserModel.columns = {
|
|
130
|
-
userid: {
|
|
131
|
-
type: "string",
|
|
132
|
-
primary: true,
|
|
133
|
-
columnId: true
|
|
134
|
-
},
|
|
135
|
-
groups: {
|
|
136
|
-
type: "array"
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
UserModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
140
|
-
|
|
141
|
-
// src/quser/implementations/user.repository.ts
|
|
142
|
-
var UserRepository = class extends BaseRepository {
|
|
143
|
-
constructor() {
|
|
144
|
-
super(UserModel);
|
|
145
|
-
}
|
|
146
|
-
async getOne(identifier) {
|
|
147
|
-
const params = {
|
|
148
|
-
filters: [this.filter("userid", identifier)]
|
|
149
|
-
};
|
|
150
|
-
const response = await super.findItem(params);
|
|
151
|
-
return response;
|
|
152
|
-
}
|
|
153
|
-
async getList(options) {
|
|
154
|
-
const params = {
|
|
155
|
-
filters: [
|
|
156
|
-
this.filter("userid", options.data.identifier),
|
|
157
|
-
this.filter("groups", options.data.role, "CONTAINS")
|
|
158
|
-
]
|
|
159
|
-
};
|
|
160
|
-
const response = await super.find(params);
|
|
161
|
-
return response;
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var AdminRepository = class {
|
|
165
|
-
async getApplicationInfo(body) {
|
|
166
|
-
var _a;
|
|
167
|
-
const url = `${ENVIRONMENT.DOMAIN}/devapi/v4/user/${body.userId}/app/${body.appId}`;
|
|
168
|
-
const headers = {
|
|
169
|
-
"x-api-key": ENVIRONMENT.API_KEY
|
|
170
|
-
};
|
|
171
|
-
const requestOptions = {
|
|
172
|
-
method: "GET",
|
|
173
|
-
headers
|
|
174
|
-
};
|
|
175
|
-
const response = await fetch(url, requestOptions);
|
|
176
|
-
const data = await response.json();
|
|
177
|
-
return {
|
|
178
|
-
status: response.status,
|
|
179
|
-
data: {
|
|
180
|
-
userId: (_a = data == null ? void 0 : data.userid) != null ? _a : body.userId,
|
|
181
|
-
appId: getAttribute(data, "appId"),
|
|
182
|
-
userEmail: getAttribute(data, "userEmail")
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
async getPlatformConfiguration() {
|
|
187
|
-
var _a, _b, _c;
|
|
188
|
-
const url = `${ENVIRONMENT.DOMAIN}/admin/api/v5/customization/features/platform`;
|
|
189
|
-
const headers = {
|
|
190
|
-
"x-api-key": ENVIRONMENT.API_KEY
|
|
191
|
-
};
|
|
192
|
-
const requestOptions = {
|
|
193
|
-
method: "GET",
|
|
194
|
-
headers
|
|
195
|
-
};
|
|
196
|
-
const response = await fetch(url, requestOptions);
|
|
197
|
-
const data = await response.json();
|
|
198
|
-
return {
|
|
199
|
-
status: response.status,
|
|
200
|
-
legacyMode: (_c = (_b = (_a = data == null ? void 0 : data.Item) == null ? void 0 : _a.settings) == null ? void 0 : _b.legacyMode) != null ? _c : true
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var SharingDetailsModel = class extends CrudSchema {
|
|
205
|
-
};
|
|
206
|
-
SharingDetailsModel.table = {
|
|
207
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}_sharing_details`,
|
|
208
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_sharing_details`
|
|
209
|
-
};
|
|
210
|
-
SharingDetailsModel.columns = {
|
|
211
|
-
sharing_details_id: { type: "string", primary: true },
|
|
212
|
-
asset_id: { type: "string" },
|
|
213
|
-
access_level: { type: "numeric" },
|
|
214
|
-
org_id: { type: "string" },
|
|
215
|
-
shared_with: { type: "string" },
|
|
216
|
-
shared_type: { type: "string" },
|
|
217
|
-
shared_email: { type: "string" },
|
|
218
|
-
share_origin: { type: "string" },
|
|
219
|
-
created_at: { type: "date" },
|
|
220
|
-
updated_at: { type: "date" },
|
|
221
|
-
deleted_at: { type: "date" }
|
|
222
|
-
};
|
|
223
|
-
SharingDetailsModel.indexes = {
|
|
224
|
-
sharingDetailsOrgId: {
|
|
225
|
-
name: "sharing_details_org_id_index",
|
|
226
|
-
columns: [
|
|
227
|
-
"org_id",
|
|
228
|
-
"asset_id",
|
|
229
|
-
"sharing_details_id",
|
|
230
|
-
"shared_with",
|
|
231
|
-
"shared_type",
|
|
232
|
-
"shared_email",
|
|
233
|
-
"share_origin"
|
|
234
|
-
]
|
|
235
|
-
},
|
|
236
|
-
sharingDetailsSharedWithAccessLevel: {
|
|
237
|
-
name: "sharing_details_shared_with_access_level_index",
|
|
238
|
-
columns: [
|
|
239
|
-
"shared_with",
|
|
240
|
-
"access_level",
|
|
241
|
-
"asset_id",
|
|
242
|
-
"sharing_details_id",
|
|
243
|
-
"org_id",
|
|
244
|
-
"shared_type",
|
|
245
|
-
"shared_email",
|
|
246
|
-
"share_origin"
|
|
247
|
-
]
|
|
248
|
-
},
|
|
249
|
-
sharingDetailsAccessLevelSharedWithOrgId: {
|
|
250
|
-
name: "sharing_details_access_level_shared_with_org_id_index",
|
|
251
|
-
columns: [
|
|
252
|
-
"access_level",
|
|
253
|
-
"shared_with",
|
|
254
|
-
"org_id",
|
|
255
|
-
"asset_id",
|
|
256
|
-
"sharing_details_id",
|
|
257
|
-
"shared_type",
|
|
258
|
-
"shared_email",
|
|
259
|
-
"share_origin"
|
|
260
|
-
]
|
|
261
|
-
},
|
|
262
|
-
sharingDetailsAccessLevelOrgId: {
|
|
263
|
-
name: "sharing_details_access_level_org_id_index",
|
|
264
|
-
columns: [
|
|
265
|
-
"access_level",
|
|
266
|
-
"org_id",
|
|
267
|
-
"asset_id",
|
|
268
|
-
"sharing_details_id",
|
|
269
|
-
"shared_with",
|
|
270
|
-
"shared_type",
|
|
271
|
-
"shared_email",
|
|
272
|
-
"share_origin"
|
|
273
|
-
]
|
|
274
|
-
},
|
|
275
|
-
sharingDetailsAssetId: {
|
|
276
|
-
name: "sharing_details_asset_id_index",
|
|
277
|
-
columns: [
|
|
278
|
-
"asset_id",
|
|
279
|
-
"sharing_details_id",
|
|
280
|
-
"org_id",
|
|
281
|
-
"shared_with",
|
|
282
|
-
"shared_type",
|
|
283
|
-
"shared_email",
|
|
284
|
-
"share_origin"
|
|
285
|
-
]
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
SharingDetailsModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
289
|
-
SharingDetailsModel.usePool = true;
|
|
290
|
-
|
|
291
|
-
// src/sharing/implementations/details.repository.ts
|
|
292
|
-
var SharingDetailsRepository = class extends BaseRepository {
|
|
293
|
-
constructor() {
|
|
294
|
-
super(SharingDetailsModel);
|
|
295
|
-
}
|
|
296
|
-
async getOne(sharingDetailId) {
|
|
297
|
-
const params = {
|
|
298
|
-
filters: [this.filter("sharing_details_id", sharingDetailId)]
|
|
299
|
-
};
|
|
300
|
-
const response = await super.findItem(params);
|
|
301
|
-
return response;
|
|
302
|
-
}
|
|
303
|
-
async getBySharedWith(assetId, sharedWith) {
|
|
304
|
-
const filterList = [
|
|
305
|
-
this.filter("asset_id", assetId),
|
|
306
|
-
this.filter("shared_with", sharedWith)
|
|
307
|
-
];
|
|
308
|
-
const params = {
|
|
309
|
-
filters: filterList
|
|
310
|
-
};
|
|
311
|
-
const response = await super.findItem(params);
|
|
312
|
-
return response;
|
|
313
|
-
}
|
|
314
|
-
async getList(options) {
|
|
315
|
-
const assetIndex = SharingDetailsModel.indexes.sharingDetailsAssetId;
|
|
316
|
-
const pagination = this.getPagination(options.pagination);
|
|
317
|
-
const params = {
|
|
318
|
-
pagination,
|
|
319
|
-
index: {
|
|
320
|
-
indexName: assetIndex.name,
|
|
321
|
-
columns: assetIndex.columns
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
const filterList = [this.filter("asset_id", options.data.assetId)];
|
|
325
|
-
if (options.filters) {
|
|
326
|
-
options.filters.forEach((filter) => {
|
|
327
|
-
filterList.push(this.filter(filter.column, filter.value));
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
params.filters = filterList;
|
|
331
|
-
if (options.data.user) {
|
|
332
|
-
const currentFilter = this.getUserFilter(
|
|
333
|
-
options.data.user,
|
|
334
|
-
filterList
|
|
335
|
-
);
|
|
336
|
-
params.filters = currentFilter;
|
|
337
|
-
}
|
|
338
|
-
if (options.sorting) params.sorting = options.sorting;
|
|
339
|
-
const response = await super.find(params);
|
|
340
|
-
return response;
|
|
341
|
-
}
|
|
342
|
-
async create(details) {
|
|
343
|
-
const response = await super.create(details);
|
|
344
|
-
return response;
|
|
345
|
-
}
|
|
346
|
-
async patch(sharingDetailId, details) {
|
|
347
|
-
await super.update(
|
|
348
|
-
[this.filter("sharing_details_id", sharingDetailId)],
|
|
349
|
-
details
|
|
350
|
-
);
|
|
351
|
-
return true;
|
|
352
|
-
}
|
|
353
|
-
async delete(sharingDetailId) {
|
|
354
|
-
await super.remove([
|
|
355
|
-
this.filter("sharing_details_id", sharingDetailId)
|
|
356
|
-
]);
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
getPagination(options) {
|
|
360
|
-
var _a, _b;
|
|
361
|
-
return {
|
|
362
|
-
limit: (_a = options == null ? void 0 : options.limit) != null ? _a : LIMIT_PER_PAGE,
|
|
363
|
-
from: (_b = options == null ? void 0 : options.from) != null ? _b : void 0
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
getUserFilter(user, currentFilters) {
|
|
367
|
-
const { userId, roles } = user;
|
|
368
|
-
const orgId = user.orgId === "" ? ORGANIZATION_QRVEY : user.orgId;
|
|
369
|
-
const sharing = {
|
|
370
|
-
OR: [
|
|
371
|
-
{
|
|
372
|
-
AND: [
|
|
373
|
-
this.buildFilter("shared_with", userId),
|
|
374
|
-
this.buildFilter("shared_type", "USER"),
|
|
375
|
-
this.buildFilter("org_id", orgId)
|
|
376
|
-
]
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
AND: [
|
|
380
|
-
this.buildFilter("shared_with", orgId),
|
|
381
|
-
this.buildFilter("shared_type", "ORGANIZATION"),
|
|
382
|
-
this.buildFilter("org_id", orgId)
|
|
383
|
-
]
|
|
384
|
-
}
|
|
385
|
-
]
|
|
386
|
-
};
|
|
387
|
-
if (roles && (roles == null ? void 0 : roles.length) > 0) {
|
|
388
|
-
sharing.OR.push({
|
|
389
|
-
AND: [
|
|
390
|
-
this.buildFilter("shared_with", roles, "IN"),
|
|
391
|
-
this.buildFilter("shared_type", "ROLE"),
|
|
392
|
-
this.buildFilter("org_id", orgId)
|
|
393
|
-
]
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
const filter = [];
|
|
397
|
-
if (currentFilters) filter.push(...currentFilters);
|
|
398
|
-
filter.push(sharing);
|
|
399
|
-
return { AND: filter };
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
var DownloadManagerSchema = class extends CrudSchema {
|
|
403
|
-
};
|
|
404
|
-
DownloadManagerSchema.table = {
|
|
405
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}DownloadManager`,
|
|
406
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_download_manager`
|
|
407
|
-
};
|
|
408
|
-
DownloadManagerSchema.columns = {
|
|
409
|
-
downloadManagerId: {
|
|
410
|
-
primary: true,
|
|
411
|
-
type: "String",
|
|
412
|
-
columnId: true
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
DownloadManagerSchema.schema = "exports";
|
|
416
|
-
DownloadManagerSchema.usePool = true;
|
|
417
|
-
|
|
418
|
-
// src/sharing/implementations/dm.repository.ts
|
|
419
|
-
var DownloadManagerRepository = class extends BaseRepository {
|
|
420
|
-
constructor() {
|
|
421
|
-
super(DownloadManagerSchema);
|
|
422
|
-
}
|
|
423
|
-
async get(identifier) {
|
|
424
|
-
const filterList = [this.filter("downloadManagerId", identifier)];
|
|
425
|
-
const params = {
|
|
426
|
-
filters: filterList
|
|
427
|
-
};
|
|
428
|
-
const response = await super.findItem(params);
|
|
429
|
-
return response;
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
var DashboardSchema = class extends CrudSchema {
|
|
433
|
-
};
|
|
434
|
-
DashboardSchema.table = {
|
|
435
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}_dx_dashboard`,
|
|
436
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_dashboard`
|
|
437
|
-
};
|
|
438
|
-
DashboardSchema.columns = {
|
|
439
|
-
ResourceUID: { type: "string", primary: true },
|
|
440
|
-
dashboardId: { type: "string" },
|
|
441
|
-
contentId: { type: "string" },
|
|
442
|
-
userId: { type: "string" },
|
|
443
|
-
ownerId: { type: "string" },
|
|
444
|
-
appId: { type: "string" },
|
|
445
|
-
qvAttributes: { type: "object" }
|
|
446
|
-
};
|
|
447
|
-
DashboardSchema.indexes = {
|
|
448
|
-
ResourceUID: {
|
|
449
|
-
name: "MetadataByResource",
|
|
450
|
-
columns: ["Metadata", "ResourceUID"]
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
DashboardSchema.schema = "dashboard_x";
|
|
454
|
-
DashboardSchema.usePool = true;
|
|
455
|
-
|
|
456
|
-
// src/sharing/implementations/dx.repository.ts
|
|
457
|
-
var DashboardRepository = class extends BaseRepository {
|
|
458
|
-
constructor() {
|
|
459
|
-
super(DashboardSchema);
|
|
460
|
-
}
|
|
461
|
-
async get(identifier) {
|
|
462
|
-
const uid = `DASHBOARD=${identifier}&BRANCH=MAIN`;
|
|
463
|
-
const filterList = [this.filter("ResourceUID", uid)];
|
|
464
|
-
const params = {
|
|
465
|
-
filters: filterList
|
|
466
|
-
};
|
|
467
|
-
const response = await super.findItem(params);
|
|
468
|
-
return response;
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
var OrganizationModel = class extends CrudSchema {
|
|
472
|
-
};
|
|
473
|
-
OrganizationModel.table = {
|
|
474
|
-
name: "qv_organization",
|
|
475
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_organization`
|
|
476
|
-
};
|
|
477
|
-
OrganizationModel.columns = {
|
|
478
|
-
org_id: { type: "string", primary: true },
|
|
479
|
-
name: { type: "string" },
|
|
480
|
-
parent_org_id: { type: "string" },
|
|
481
|
-
org_path: { type: "string" },
|
|
482
|
-
content_privacy: { type: "boolean" },
|
|
483
|
-
effective_content_privacy: { type: "boolean" },
|
|
484
|
-
created_at: { type: "string" },
|
|
485
|
-
updated_at: { type: "string" }
|
|
486
|
-
};
|
|
487
|
-
OrganizationModel.indexes = {
|
|
488
|
-
org_path: { name: "idx_qv_orgs_org_path_gist", columns: ["org_path"] },
|
|
489
|
-
parent_org_id: {
|
|
490
|
-
name: "idx_qv_orgs_parent",
|
|
491
|
-
columns: ["parent_org_id"]
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
OrganizationModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
495
|
-
OrganizationModel.usePool = true;
|
|
496
|
-
|
|
497
|
-
// src/sharing/implementations/organization.repository.ts
|
|
498
|
-
var OrganizationRepository = class extends BaseRepository {
|
|
499
|
-
constructor() {
|
|
500
|
-
super(OrganizationModel);
|
|
501
|
-
}
|
|
502
|
-
async getOne(orgId) {
|
|
503
|
-
const params = {
|
|
504
|
-
filters: [this.filter("org_id", orgId)]
|
|
505
|
-
};
|
|
506
|
-
const response = await super.findItem(params);
|
|
507
|
-
return response;
|
|
508
|
-
}
|
|
509
|
-
async getOrgTree(orgId, contentSharing) {
|
|
510
|
-
const cte = `WITH target AS (SELECT org_path FROM admin.qv_organization WHERE org_id = '${orgId}')`;
|
|
511
|
-
let selectClause = "";
|
|
512
|
-
let whereClause = `
|
|
513
|
-
FROM admin.qv_organization, target
|
|
514
|
-
WHERE (
|
|
515
|
-
admin.qv_organization.org_path <@ target.org_path
|
|
516
|
-
OR
|
|
517
|
-
admin.qv_organization.org_path @> target.org_path
|
|
518
|
-
)
|
|
519
|
-
AND org_id != '${orgId}'
|
|
520
|
-
`;
|
|
521
|
-
if (contentSharing === void 0) {
|
|
522
|
-
selectClause = `
|
|
523
|
-
SELECT
|
|
524
|
-
COALESCE(ARRAY_AGG(org_id) FILTER (WHERE effective_content_privacy = true), '{}') as db_private,
|
|
525
|
-
COALESCE(ARRAY_AGG(org_id) FILTER (WHERE effective_content_privacy = false), '{}') as db_public
|
|
526
|
-
`;
|
|
527
|
-
} else {
|
|
528
|
-
selectClause = `SELECT COALESCE(ARRAY_AGG(org_id), '{}') as db_specific`;
|
|
529
|
-
whereClause += ` AND effective_content_privacy = ${contentSharing}`;
|
|
530
|
-
}
|
|
531
|
-
const fullSql = `${cte} ${selectClause} ${whereClause};`;
|
|
532
|
-
const result = await super.runRawQuery(fullSql, []);
|
|
533
|
-
const row = result == null ? void 0 : result.rows[0];
|
|
534
|
-
if (!row)
|
|
535
|
-
return {
|
|
536
|
-
privateIds: [],
|
|
537
|
-
publicIds: []
|
|
538
|
-
};
|
|
539
|
-
if (contentSharing === void 0) {
|
|
540
|
-
return {
|
|
541
|
-
privateIds: row.db_private,
|
|
542
|
-
publicIds: row.db_public
|
|
543
|
-
};
|
|
544
|
-
} else {
|
|
545
|
-
return {
|
|
546
|
-
privateIds: contentSharing ? row.db_specific : [],
|
|
547
|
-
publicIds: contentSharing ? [] : row.db_specific
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
var SharingModel = class extends CrudSchema {
|
|
553
|
-
};
|
|
554
|
-
SharingModel.table = {
|
|
555
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}_sharing`,
|
|
556
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_sharing`
|
|
557
|
-
};
|
|
558
|
-
SharingModel.columns = {
|
|
559
|
-
asset_id: { type: "string", primary: true },
|
|
560
|
-
asset_type: { type: "string" },
|
|
561
|
-
created_at: { type: "date" },
|
|
562
|
-
updated_at: { type: "date" },
|
|
563
|
-
deleted_at: { type: "date" },
|
|
564
|
-
qvAttributes: { type: "object" }
|
|
565
|
-
};
|
|
566
|
-
SharingModel.indexes = {
|
|
567
|
-
sharingAssetIdAssetType: {
|
|
568
|
-
name: "sharing_asset_id_asset_type_index",
|
|
569
|
-
columns: ["asset_id", "asset_type"]
|
|
570
|
-
},
|
|
571
|
-
sharingAssetType: {
|
|
572
|
-
name: "sharing_asset_type_index",
|
|
573
|
-
columns: ["asset_type"]
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
SharingModel.schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
577
|
-
SharingModel.usePool = true;
|
|
578
|
-
|
|
579
|
-
// src/sharing/implementations/sharing.repository.ts
|
|
580
|
-
var SharingRepository = class extends BaseRepository {
|
|
581
|
-
constructor() {
|
|
582
|
-
super(SharingModel);
|
|
583
|
-
}
|
|
584
|
-
async getOne(assetId) {
|
|
585
|
-
const params = {
|
|
586
|
-
filters: [this.filter("asset_id", assetId)]
|
|
587
|
-
};
|
|
588
|
-
const response = await super.findItem(params);
|
|
589
|
-
return response;
|
|
590
|
-
}
|
|
591
|
-
async create(sharing) {
|
|
592
|
-
const response = await super.create(sharing);
|
|
593
|
-
return response;
|
|
594
|
-
}
|
|
595
|
-
async patch(assetId, sharing) {
|
|
596
|
-
await super.update([this.filter("asset_id", assetId)], sharing);
|
|
597
|
-
return true;
|
|
598
|
-
}
|
|
599
|
-
async delete(assetId) {
|
|
600
|
-
await super.remove([this.filter("asset_id", assetId)]);
|
|
601
|
-
return true;
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
// src/context.ts
|
|
606
|
-
container.register(
|
|
607
|
-
"SharingRepository",
|
|
608
|
-
SharingRepository
|
|
609
|
-
);
|
|
610
|
-
container.register(
|
|
611
|
-
"SharingDetailsRepository",
|
|
612
|
-
SharingDetailsRepository
|
|
613
|
-
);
|
|
614
|
-
container.register("UserRepository", UserRepository);
|
|
615
|
-
container.register("RoleRepository", GroupRepository);
|
|
616
|
-
container.register(
|
|
617
|
-
"dxRepository",
|
|
618
|
-
DashboardRepository
|
|
619
|
-
);
|
|
620
|
-
container.register(
|
|
621
|
-
"dmRepository",
|
|
622
|
-
DownloadManagerRepository
|
|
623
|
-
);
|
|
624
|
-
container.register(
|
|
625
|
-
"OrganizationRepository",
|
|
626
|
-
OrganizationRepository
|
|
627
|
-
);
|
|
628
|
-
container.register(
|
|
629
|
-
"AdminRepository",
|
|
630
|
-
AdminRepository
|
|
631
|
-
);
|
|
632
|
-
var Context = container;
|
|
633
|
-
|
|
634
|
-
// src/common/util.ts
|
|
635
|
-
function isComposer(type) {
|
|
636
|
-
return type === "qrveyLogin" /* composer */ || type === "OPENID_CREATORS" /* openIdComposer */;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// src/quser/entities/user.ts
|
|
640
|
-
var User = class {
|
|
641
|
-
constructor(params) {
|
|
642
|
-
this.userId = params.userid;
|
|
643
|
-
this.email = params.email;
|
|
644
|
-
this.groups = params.groups;
|
|
645
|
-
this.organization = params.organization;
|
|
646
|
-
}
|
|
647
|
-
get getUserId() {
|
|
648
|
-
return this.userId;
|
|
649
|
-
}
|
|
650
|
-
get getEmail() {
|
|
651
|
-
return this.email;
|
|
652
|
-
}
|
|
653
|
-
get getGroups() {
|
|
654
|
-
return this.groups;
|
|
655
|
-
}
|
|
656
|
-
get getOrganization() {
|
|
657
|
-
return this.organization;
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
// src/quser/services/fromTokenToUser.ts
|
|
662
|
-
var FromTokenToUser = class {
|
|
663
|
-
constructor(userRepository) {
|
|
664
|
-
this.userRepository = userRepository;
|
|
665
|
-
}
|
|
666
|
-
async execute({
|
|
667
|
-
body
|
|
668
|
-
}) {
|
|
669
|
-
var _a;
|
|
670
|
-
const current = await this.userRepository.getOne(
|
|
671
|
-
body.clientId || body.userId
|
|
672
|
-
);
|
|
673
|
-
if (current) {
|
|
674
|
-
const user = new User(current);
|
|
675
|
-
return {
|
|
676
|
-
userId: user.getUserId,
|
|
677
|
-
roles: user.getGroups,
|
|
678
|
-
orgId: (_a = body.orgId) != null ? _a : ORGANIZATION_QRVEY
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
const inComposer = isComposer(body.loginType || "");
|
|
682
|
-
if (!inComposer) {
|
|
683
|
-
return {
|
|
684
|
-
userId: body.clientId || "",
|
|
685
|
-
roles: body.roles || [],
|
|
686
|
-
orgId: body.orgId || ""
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
return {
|
|
690
|
-
userId: "",
|
|
691
|
-
roles: [],
|
|
692
|
-
orgId: ""
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
FromTokenToUser = __decorateClass([
|
|
697
|
-
injectable(),
|
|
698
|
-
__decorateParam(0, inject("UserRepository"))
|
|
699
|
-
], FromTokenToUser);
|
|
700
|
-
var HasAdminRole = class {
|
|
701
|
-
constructor(userRepository) {
|
|
702
|
-
this.userRepository = userRepository;
|
|
703
|
-
}
|
|
704
|
-
async execute({
|
|
705
|
-
apiKey,
|
|
706
|
-
clientId,
|
|
707
|
-
orgId,
|
|
708
|
-
userId,
|
|
709
|
-
loginType
|
|
710
|
-
} = {}) {
|
|
711
|
-
if (!userId) return false;
|
|
712
|
-
const existingUser = await this.userRepository.getOne(userId);
|
|
713
|
-
const isMasterKey = apiKey && (orgId === void 0 || orgId === ORGANIZATION_QRVEY);
|
|
714
|
-
if (isMasterKey && existingUser && (!clientId || clientId === userId))
|
|
715
|
-
return true;
|
|
716
|
-
const user = await this.userRepository.getList({
|
|
717
|
-
data: { identifier: clientId != null ? clientId : userId, role: "administrator" }
|
|
718
|
-
});
|
|
719
|
-
const isAdmin = user.items.length > 0;
|
|
720
|
-
if (isMasterKey && isAdmin) return true;
|
|
721
|
-
const inComposer = isComposer(loginType || "");
|
|
722
|
-
const isExternal = !clientId && !inComposer || orgId && orgId !== ORGANIZATION_QRVEY;
|
|
723
|
-
if (isExternal) return false;
|
|
724
|
-
if (isAdmin) return true;
|
|
725
|
-
return false;
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
HasAdminRole = __decorateClass([
|
|
729
|
-
injectable(),
|
|
730
|
-
__decorateParam(0, inject("UserRepository"))
|
|
731
|
-
], HasAdminRole);
|
|
732
|
-
var CheckAppPermissions = class {
|
|
733
|
-
constructor(adminRepository) {
|
|
734
|
-
this.adminRepository = adminRepository;
|
|
735
|
-
}
|
|
736
|
-
//TODO Need Test
|
|
737
|
-
async execute({
|
|
738
|
-
appId,
|
|
739
|
-
userId
|
|
740
|
-
}) {
|
|
741
|
-
if (!userId) return { privacy: "private" /* PRIVATE */ };
|
|
742
|
-
const appInfo = await this.adminRepository.getApplicationInfo({
|
|
743
|
-
appId,
|
|
744
|
-
userId
|
|
745
|
-
});
|
|
746
|
-
const platform = await this.adminRepository.getPlatformConfiguration();
|
|
747
|
-
if (appInfo.status !== 200)
|
|
748
|
-
return { privacy: "private" /* PRIVATE */ };
|
|
749
|
-
const hasPublicAccess = platform == null ? void 0 : platform.legacyMode;
|
|
750
|
-
const privacy = hasPublicAccess ? "public" /* PUBLIC */ : "private" /* PRIVATE */;
|
|
751
|
-
return { privacy };
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
CheckAppPermissions = __decorateClass([
|
|
755
|
-
injectable(),
|
|
756
|
-
__decorateParam(0, inject("AdminRepository"))
|
|
757
|
-
], CheckAppPermissions);
|
|
758
|
-
var CheckOrgPermissions = class {
|
|
759
|
-
constructor(organizationRepository) {
|
|
760
|
-
this.organizationRepository = organizationRepository;
|
|
761
|
-
}
|
|
762
|
-
//TODO Need Tes
|
|
763
|
-
async execute({
|
|
764
|
-
orgId
|
|
765
|
-
}) {
|
|
766
|
-
const hasPublicAccess = await this.organizationRepository.getOne(orgId);
|
|
767
|
-
const privacy = (hasPublicAccess == null ? void 0 : hasPublicAccess.effective_content_privacy) ? "private" /* PRIVATE */ : "public" /* PUBLIC */;
|
|
768
|
-
return { privacy };
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
CheckOrgPermissions = __decorateClass([
|
|
772
|
-
injectable(),
|
|
773
|
-
__decorateParam(0, inject("OrganizationRepository"))
|
|
774
|
-
], CheckOrgPermissions);
|
|
775
|
-
var SharingDetail = class _SharingDetail {
|
|
776
|
-
constructor(params) {
|
|
777
|
-
this.sharingDetailsId = params.sharingDetailsId;
|
|
778
|
-
this.assetId = params.assetId;
|
|
779
|
-
this.accessLevel = params.accessLevel;
|
|
780
|
-
this.accessLevelAsText = this.convertAccessLevelToText(
|
|
781
|
-
params.accessLevel
|
|
782
|
-
);
|
|
783
|
-
this.orgId = params.orgId;
|
|
784
|
-
this.sharedWith = params.sharedWith;
|
|
785
|
-
this.sharedType = params.sharedType;
|
|
786
|
-
this.sharedEmail = params.sharedEmail;
|
|
787
|
-
this.sharedOrigin = params.sharedOrigin;
|
|
788
|
-
this.createdAt = params.createdAt;
|
|
789
|
-
this.updatedAt = params.updatedAt;
|
|
790
|
-
this.deletedAt = params.deletedAt;
|
|
791
|
-
}
|
|
792
|
-
static create(params) {
|
|
793
|
-
var _a;
|
|
794
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
795
|
-
const obj = __spreadProps(__spreadValues({}, params), {
|
|
796
|
-
sharingDetailsId: (_a = params.sharedId) != null ? _a : getId(),
|
|
797
|
-
createdAt: now,
|
|
798
|
-
updatedAt: now
|
|
799
|
-
});
|
|
800
|
-
return new _SharingDetail(obj);
|
|
801
|
-
}
|
|
802
|
-
static parse(params) {
|
|
803
|
-
return new _SharingDetail({
|
|
804
|
-
sharingDetailsId: params.sharing_details_id,
|
|
805
|
-
assetId: params.asset_id,
|
|
806
|
-
accessLevel: params.access_level,
|
|
807
|
-
orgId: params.org_id,
|
|
808
|
-
sharedWith: params.shared_with,
|
|
809
|
-
sharedType: params.shared_type,
|
|
810
|
-
sharedEmail: params.shared_email,
|
|
811
|
-
sharedOrigin: params.share_origin,
|
|
812
|
-
createdAt: params.created_at,
|
|
813
|
-
updatedAt: params.updated_at,
|
|
814
|
-
deletedAt: params.deleted_at
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
update(params) {
|
|
818
|
-
if (params.accessLevel || params.accessLevel === 0)
|
|
819
|
-
this.accessLevel = params.accessLevel;
|
|
820
|
-
if (params.sharedEmail) this.sharedEmail = params.sharedEmail;
|
|
821
|
-
this.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
822
|
-
}
|
|
823
|
-
toTable() {
|
|
824
|
-
return {
|
|
825
|
-
sharing_details_id: this.sharingDetailsId,
|
|
826
|
-
asset_id: this.assetId,
|
|
827
|
-
access_level: this.accessLevel,
|
|
828
|
-
org_id: this.orgId,
|
|
829
|
-
shared_with: this.sharedWith,
|
|
830
|
-
shared_type: this.sharedType,
|
|
831
|
-
shared_email: this.sharedEmail,
|
|
832
|
-
share_origin: this.sharedOrigin,
|
|
833
|
-
created_at: this.createdAt,
|
|
834
|
-
updated_at: this.updatedAt,
|
|
835
|
-
deleted_at: this.deletedAt
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
toPlain() {
|
|
839
|
-
return {
|
|
840
|
-
sharingDetailsId: this.sharingDetailsId,
|
|
841
|
-
assetId: this.assetId,
|
|
842
|
-
accessLevel: this.accessLevel,
|
|
843
|
-
orgId: this.orgId,
|
|
844
|
-
sharedWith: this.sharedWith,
|
|
845
|
-
sharedType: this.sharedType,
|
|
846
|
-
sharedEmail: this.sharedEmail,
|
|
847
|
-
sharedOrigin: this.sharedOrigin,
|
|
848
|
-
createdAt: this.createdAt,
|
|
849
|
-
updatedAt: this.updatedAt,
|
|
850
|
-
deletedAt: this.deletedAt
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
toJSON() {
|
|
854
|
-
return {
|
|
855
|
-
sharedId: this.sharingDetailsId,
|
|
856
|
-
assetId: this.assetId,
|
|
857
|
-
accessLevel: this.accessLevel,
|
|
858
|
-
accessLevelAsText: this.accessLevelAsText,
|
|
859
|
-
orgId: this.orgId,
|
|
860
|
-
sharedWith: this.sharedWith,
|
|
861
|
-
sharedType: this.sharedType,
|
|
862
|
-
sharedEmail: this.sharedEmail,
|
|
863
|
-
sharedOrigin: this.sharedOrigin,
|
|
864
|
-
createdAt: this.createdAt,
|
|
865
|
-
updatedAt: this.updatedAt
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
get getSharingDetailsId() {
|
|
869
|
-
return this.sharingDetailsId;
|
|
870
|
-
}
|
|
871
|
-
get getAccessLevel() {
|
|
872
|
-
return this.accessLevel;
|
|
873
|
-
}
|
|
874
|
-
get getAccessLevelAsText() {
|
|
875
|
-
return this.accessLevelAsText;
|
|
876
|
-
}
|
|
877
|
-
convertAccessLevelToText(level) {
|
|
878
|
-
var _a;
|
|
879
|
-
return (_a = ACCESS_LEVEL[level]) != null ? _a : "UNKNOWN";
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
|
|
883
|
-
// src/sharing/services/checkUserAccessLevel.ts
|
|
884
|
-
var CheckUserAccessLevel = class {
|
|
885
|
-
constructor(detailsRepository) {
|
|
886
|
-
this.detailsRepository = detailsRepository;
|
|
887
|
-
}
|
|
888
|
-
async execute({
|
|
889
|
-
userId,
|
|
890
|
-
assetId,
|
|
891
|
-
clientId,
|
|
892
|
-
loginType,
|
|
893
|
-
roles,
|
|
894
|
-
orgId
|
|
895
|
-
}) {
|
|
896
|
-
const user = await fromTokenToUser({
|
|
897
|
-
body: { userId, clientId, roles, orgId, loginType }
|
|
898
|
-
});
|
|
899
|
-
const details = await this.detailsRepository.getList({
|
|
900
|
-
data: { assetId, user },
|
|
901
|
-
sorting: [{ column: "access_level", direction: "DESC" }]
|
|
902
|
-
});
|
|
903
|
-
if (details.items.length === 0)
|
|
904
|
-
return { level: 0 /* NONE */, levelAsText: "NONE" };
|
|
905
|
-
const priority = {
|
|
906
|
-
["USER" /* USER */]: 3,
|
|
907
|
-
["ROLE" /* ROLE */]: 2,
|
|
908
|
-
["ORGANIZATION" /* ORGANIZATION */]: 1
|
|
909
|
-
};
|
|
910
|
-
const priorityDetail = details.items.reduce((best, current) => {
|
|
911
|
-
const bestPriority = priority[best.shared_type];
|
|
912
|
-
const currentPriority = priority[current.shared_type];
|
|
913
|
-
const isBetter = currentPriority > bestPriority || currentPriority === bestPriority && current.access_level > best.access_level;
|
|
914
|
-
if (isBetter) return current;
|
|
915
|
-
return best;
|
|
916
|
-
});
|
|
917
|
-
const currentDetail = SharingDetail.parse(priorityDetail);
|
|
918
|
-
return {
|
|
919
|
-
level: currentDetail.getAccessLevel,
|
|
920
|
-
levelAsText: currentDetail.getAccessLevelAsText
|
|
921
|
-
};
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
CheckUserAccessLevel = __decorateClass([
|
|
925
|
-
injectable(),
|
|
926
|
-
__decorateParam(0, inject("SharingDetailsRepository"))
|
|
927
|
-
], CheckUserAccessLevel);
|
|
928
|
-
var DeleteSharing = class {
|
|
929
|
-
constructor(sharingRepository) {
|
|
930
|
-
this.sharingRepository = sharingRepository;
|
|
931
|
-
}
|
|
932
|
-
async execute({ body }) {
|
|
933
|
-
const { assetId } = body;
|
|
934
|
-
const sharing = await this.sharingRepository.getOne(assetId);
|
|
935
|
-
if (!sharing) return null;
|
|
936
|
-
const detailSharing = await this.sharingRepository.delete(assetId);
|
|
937
|
-
return detailSharing;
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
DeleteSharing = __decorateClass([
|
|
941
|
-
injectable(),
|
|
942
|
-
__decorateParam(0, inject("SharingRepository"))
|
|
943
|
-
], DeleteSharing);
|
|
944
|
-
var GetOrgTree = class {
|
|
945
|
-
constructor(organizationRepository) {
|
|
946
|
-
this.organizationRepository = organizationRepository;
|
|
947
|
-
}
|
|
948
|
-
async execute(orgId, contentSharingStatus) {
|
|
949
|
-
return this.organizationRepository.getOrgTree(
|
|
950
|
-
orgId,
|
|
951
|
-
contentSharingStatus
|
|
952
|
-
);
|
|
953
|
-
}
|
|
954
|
-
};
|
|
955
|
-
GetOrgTree = __decorateClass([
|
|
956
|
-
injectable(),
|
|
957
|
-
__decorateParam(0, inject("OrganizationRepository"))
|
|
958
|
-
], GetOrgTree);
|
|
959
|
-
var ListSharing = class {
|
|
960
|
-
constructor(sharingRepository, detailsRepository) {
|
|
961
|
-
this.sharingRepository = sharingRepository;
|
|
962
|
-
this.detailsRepository = detailsRepository;
|
|
963
|
-
}
|
|
964
|
-
async execute({
|
|
965
|
-
body
|
|
966
|
-
}) {
|
|
967
|
-
var _a;
|
|
968
|
-
const {
|
|
969
|
-
data: { assetId },
|
|
970
|
-
pagination
|
|
971
|
-
} = body;
|
|
972
|
-
const sharing = await this.sharingRepository.getOne(assetId);
|
|
973
|
-
if (!sharing) return null;
|
|
974
|
-
const sorting = body.sorting && ((_a = body.sorting) == null ? void 0 : _a.length) > 0 ? body.sorting : [{ column: "created_at", direction: "ASC" }];
|
|
975
|
-
const detailSharing = await this.detailsRepository.getList({
|
|
976
|
-
data: { assetId },
|
|
977
|
-
pagination,
|
|
978
|
-
sorting
|
|
979
|
-
});
|
|
980
|
-
const items = detailSharing.items.map(
|
|
981
|
-
(item) => SharingDetail.parse(item).toJSON()
|
|
982
|
-
);
|
|
983
|
-
return __spreadProps(__spreadValues({}, detailSharing), {
|
|
984
|
-
items
|
|
985
|
-
});
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
ListSharing = __decorateClass([
|
|
989
|
-
injectable(),
|
|
990
|
-
__decorateParam(0, inject("SharingRepository")),
|
|
991
|
-
__decorateParam(1, inject("SharingDetailsRepository"))
|
|
992
|
-
], ListSharing);
|
|
993
|
-
|
|
994
|
-
// src/sharing/entities/sharing.ts
|
|
995
|
-
var Sharing = class _Sharing {
|
|
996
|
-
constructor(params) {
|
|
997
|
-
this.assetId = params.assetId;
|
|
998
|
-
this.assetType = params.assetType;
|
|
999
|
-
this.createdAt = params.createdAt;
|
|
1000
|
-
this.updatedAt = params.updatedAt;
|
|
1001
|
-
this.deletedAt = params.deletedAt;
|
|
1002
|
-
}
|
|
1003
|
-
static create(params) {
|
|
1004
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1005
|
-
const obj = __spreadProps(__spreadValues({}, params), {
|
|
1006
|
-
createdAt: now,
|
|
1007
|
-
updatedAt: now
|
|
1008
|
-
});
|
|
1009
|
-
return new _Sharing(obj);
|
|
1010
|
-
}
|
|
1011
|
-
static parse(params) {
|
|
1012
|
-
return new _Sharing({
|
|
1013
|
-
assetId: params.asset_id,
|
|
1014
|
-
assetType: params.asset_type,
|
|
1015
|
-
createdAt: params.created_at,
|
|
1016
|
-
updatedAt: params.updated_at,
|
|
1017
|
-
deletedAt: params.deleted_at
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
update() {
|
|
1021
|
-
this.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1022
|
-
}
|
|
1023
|
-
toTable() {
|
|
1024
|
-
return {
|
|
1025
|
-
asset_id: this.assetId,
|
|
1026
|
-
asset_type: this.assetType,
|
|
1027
|
-
created_at: this.createdAt,
|
|
1028
|
-
updated_at: this.updatedAt,
|
|
1029
|
-
deleted_at: this.deletedAt
|
|
1030
|
-
};
|
|
1031
|
-
}
|
|
1032
|
-
toPlain() {
|
|
1033
|
-
return {
|
|
1034
|
-
assetId: this.assetId,
|
|
1035
|
-
assetType: this.assetType,
|
|
1036
|
-
createdAt: this.createdAt,
|
|
1037
|
-
updatedAt: this.updatedAt,
|
|
1038
|
-
deletedAt: this.deletedAt
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
toJSON() {
|
|
1042
|
-
return {
|
|
1043
|
-
assetId: this.assetId,
|
|
1044
|
-
assetType: this.assetType,
|
|
1045
|
-
createdAt: this.createdAt,
|
|
1046
|
-
updatedAt: this.updatedAt
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
get getAssetId() {
|
|
1050
|
-
return this.assetId;
|
|
1051
|
-
}
|
|
1052
|
-
get getAssetType() {
|
|
1053
|
-
return this.assetType;
|
|
1054
|
-
}
|
|
1055
|
-
};
|
|
1056
|
-
|
|
1057
|
-
// src/sharing/services/upsert.ts
|
|
1058
|
-
var UpsertSharing = class {
|
|
1059
|
-
constructor(sharingRepository, detailsRepository, dxRepository, dmRepository, userRepository, roleRepository) {
|
|
1060
|
-
this.sharingRepository = sharingRepository;
|
|
1061
|
-
this.detailsRepository = detailsRepository;
|
|
1062
|
-
this.dxRepository = dxRepository;
|
|
1063
|
-
this.dmRepository = dmRepository;
|
|
1064
|
-
this.userRepository = userRepository;
|
|
1065
|
-
this.roleRepository = roleRepository;
|
|
1066
|
-
}
|
|
1067
|
-
async execute({
|
|
1068
|
-
body
|
|
1069
|
-
}) {
|
|
1070
|
-
const assetId = body.assetId;
|
|
1071
|
-
const isValidAsset = await this.validateIfAssetExists(
|
|
1072
|
-
assetId,
|
|
1073
|
-
body.assetType
|
|
1074
|
-
);
|
|
1075
|
-
if (!isValidAsset)
|
|
1076
|
-
throw new Error(`Asset with ID ${assetId} not found`);
|
|
1077
|
-
const sharing = await this.sharingRepository.getOne(assetId);
|
|
1078
|
-
let currentSharing;
|
|
1079
|
-
if (sharing) {
|
|
1080
|
-
currentSharing = Sharing.parse(sharing);
|
|
1081
|
-
} else {
|
|
1082
|
-
const createSharing = {
|
|
1083
|
-
assetId,
|
|
1084
|
-
assetType: body.assetType
|
|
1085
|
-
};
|
|
1086
|
-
currentSharing = Sharing.create(createSharing);
|
|
1087
|
-
await this.sharingRepository.create(currentSharing.toTable());
|
|
1088
|
-
}
|
|
1089
|
-
let updatedList = [];
|
|
1090
|
-
if (body.add) updatedList = await this.addDetails(assetId, body.add);
|
|
1091
|
-
if (body.remove) await this.removeDetails(body.remove);
|
|
1092
|
-
currentSharing.update();
|
|
1093
|
-
await this.sharingRepository.patch(
|
|
1094
|
-
currentSharing.getAssetId,
|
|
1095
|
-
currentSharing.toTable()
|
|
1096
|
-
);
|
|
1097
|
-
return updatedList.map((detail) => detail.toJSON());
|
|
1098
|
-
}
|
|
1099
|
-
async validateIfAssetExists(assetId, assetType) {
|
|
1100
|
-
switch (assetType) {
|
|
1101
|
-
case "DX" /* DX */: {
|
|
1102
|
-
const result = await this.dxRepository.get(assetId);
|
|
1103
|
-
if (result) return true;
|
|
1104
|
-
return false;
|
|
1105
|
-
}
|
|
1106
|
-
case "DM" /* DM */: {
|
|
1107
|
-
return true;
|
|
1108
|
-
}
|
|
1109
|
-
default:
|
|
1110
|
-
return false;
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
async addDetails(assetId, list) {
|
|
1114
|
-
const sharingList = [];
|
|
1115
|
-
for (const detail of list) {
|
|
1116
|
-
const currentDetail = await this.addSpecificDetail(assetId, detail);
|
|
1117
|
-
if (currentDetail) sharingList.push(currentDetail);
|
|
1118
|
-
}
|
|
1119
|
-
return sharingList;
|
|
1120
|
-
}
|
|
1121
|
-
async addSpecificDetail(assetId, detail) {
|
|
1122
|
-
var _a;
|
|
1123
|
-
let currentDetail;
|
|
1124
|
-
const isValid = await this.validateIfSharedWithExist(detail);
|
|
1125
|
-
if (!isValid) return null;
|
|
1126
|
-
let sharingDetail = await this.detailsRepository.getBySharedWith(
|
|
1127
|
-
assetId,
|
|
1128
|
-
detail.sharedWith
|
|
1129
|
-
);
|
|
1130
|
-
if (!sharingDetail && detail.sharedId) {
|
|
1131
|
-
sharingDetail = await this.detailsRepository.getOne(
|
|
1132
|
-
detail.sharedId
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
if (sharingDetail) {
|
|
1136
|
-
currentDetail = SharingDetail.parse(sharingDetail);
|
|
1137
|
-
currentDetail.update(detail);
|
|
1138
|
-
await this.detailsRepository.patch(
|
|
1139
|
-
currentDetail.getSharingDetailsId,
|
|
1140
|
-
currentDetail.toTable()
|
|
1141
|
-
);
|
|
1142
|
-
} else {
|
|
1143
|
-
const createDetails = __spreadValues({
|
|
1144
|
-
assetId,
|
|
1145
|
-
orgId: (_a = detail.orgId) != null ? _a : ORGANIZATION_QRVEY
|
|
1146
|
-
}, detail);
|
|
1147
|
-
currentDetail = SharingDetail.create(createDetails);
|
|
1148
|
-
await this.detailsRepository.create(currentDetail.toTable());
|
|
1149
|
-
}
|
|
1150
|
-
return currentDetail;
|
|
1151
|
-
}
|
|
1152
|
-
async validateIfSharedWithExist(detail) {
|
|
1153
|
-
if (detail.sharedOrigin === "EXTERNAL" /* EXTERNAL */ || detail.sharedOrigin === "UNKNOWN" /* UNKNOWN */)
|
|
1154
|
-
return true;
|
|
1155
|
-
const isQrveyOrg = detail.sharedType === "ORGANIZATION" /* ORGANIZATION */ && detail.sharedWith === ORGANIZATION_QRVEY;
|
|
1156
|
-
if (isQrveyOrg) return true;
|
|
1157
|
-
if (detail.sharedType === "USER" /* USER */) {
|
|
1158
|
-
const user = await this.userRepository.getOne(detail.sharedWith);
|
|
1159
|
-
if (user) return true;
|
|
1160
|
-
}
|
|
1161
|
-
if (detail.sharedType === "ROLE" /* ROLE */) {
|
|
1162
|
-
const role = await this.roleRepository.getOne(detail.sharedWith);
|
|
1163
|
-
if (role) return true;
|
|
1164
|
-
}
|
|
1165
|
-
return false;
|
|
1166
|
-
}
|
|
1167
|
-
async removeDetails(list) {
|
|
1168
|
-
for (const detail of list) {
|
|
1169
|
-
await this.detailsRepository.delete(detail.sharedId);
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
UpsertSharing = __decorateClass([
|
|
1174
|
-
injectable(),
|
|
1175
|
-
__decorateParam(0, inject("SharingRepository")),
|
|
1176
|
-
__decorateParam(1, inject("SharingDetailsRepository")),
|
|
1177
|
-
__decorateParam(2, inject("dxRepository")),
|
|
1178
|
-
__decorateParam(3, inject("dmRepository")),
|
|
1179
|
-
__decorateParam(4, inject("UserRepository")),
|
|
1180
|
-
__decorateParam(5, inject("RoleRepository"))
|
|
1181
|
-
], UpsertSharing);
|
|
1182
|
-
|
|
1183
|
-
// src/index.ts
|
|
1184
|
-
var api = {
|
|
1185
|
-
upsert: (...args) => Context.resolve(UpsertSharing).execute(...args),
|
|
1186
|
-
list: (...args) => Context.resolve(ListSharing).execute(...args),
|
|
1187
|
-
delete: (...args) => Context.resolve(DeleteSharing).execute(...args)
|
|
1188
|
-
};
|
|
1189
|
-
var checkUserAccessLevel = (...args) => Context.resolve(CheckUserAccessLevel).execute(...args);
|
|
1190
|
-
var checkAppPermissions = (...args) => Context.resolve(CheckAppPermissions).execute(...args);
|
|
1191
|
-
var checkOrgPermissions = (...args) => Context.resolve(CheckOrgPermissions).execute(...args);
|
|
1192
|
-
var getOrgTree = (...args) => Context.resolve(GetOrgTree).execute(...args);
|
|
1193
|
-
var fromTokenToUser = (...args) => Context.resolve(FromTokenToUser).execute(...args);
|
|
1194
|
-
var hasAdminRole = (...args) => Context.resolve(HasAdminRole).execute(...args);
|
|
1195
|
-
|
|
1196
|
-
export { ACCESS_LEVEL, APP_SHARING_STATUS, ASSET_TYPE, ORGANIZATION_ANONYMOUS, ORGANIZATION_QRVEY, SHARED_ORIGIN, SHARE_TYPE, api, checkAppPermissions, checkOrgPermissions, checkUserAccessLevel, fromTokenToUser, getOrgTree, hasAdminRole };
|
|
1197
|
-
//# sourceMappingURL=index.mjs.map
|
|
1198
|
-
//# sourceMappingURL=index.mjs.map
|