@qrvey/assets-sharing 0.3.4 → 0.3.5-1236
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/constants.js +11 -1
- package/dist/cjs/common/constants.js.map +1 -1
- package/dist/cjs/common/util.js +5 -0
- package/dist/cjs/common/util.js.map +1 -1
- package/dist/cjs/context.js +6 -0
- package/dist/cjs/context.js.map +1 -1
- package/dist/cjs/index.js +23 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/quser/implementations/group.model.js +3 -0
- package/dist/cjs/quser/implementations/group.model.js.map +1 -1
- package/dist/cjs/quser/implementations/group.repository.js +22 -1
- package/dist/cjs/quser/implementations/group.repository.js.map +1 -1
- package/dist/cjs/quser/implementations/permission.repository.js +27 -0
- package/dist/cjs/quser/implementations/permission.repository.js.map +1 -0
- package/dist/cjs/quser/interfaces/permissionsRepository.interface.js +3 -0
- package/dist/cjs/quser/interfaces/permissionsRepository.interface.js.map +1 -0
- package/dist/cjs/quser/services/fromTokenToUser.js +5 -1
- package/dist/cjs/quser/services/fromTokenToUser.js.map +1 -1
- package/dist/cjs/quser/services/hasAdminRole.js +31 -12
- package/dist/cjs/quser/services/hasAdminRole.js.map +1 -1
- package/dist/cjs/quser/services/hasSharingPermission.js +47 -0
- package/dist/cjs/quser/services/hasSharingPermission.js.map +1 -0
- package/dist/cjs/sharing/entities/details.js +13 -2
- package/dist/cjs/sharing/entities/details.js.map +1 -1
- package/dist/cjs/sharing/entities/types/orgTreeResult.js +10 -0
- package/dist/cjs/sharing/entities/types/orgTreeResult.js.map +1 -0
- package/dist/cjs/sharing/entities/types/organization.type.js +3 -0
- package/dist/cjs/sharing/entities/types/organization.type.js.map +1 -0
- package/dist/cjs/sharing/implementations/admin.repository.js +30 -0
- package/dist/cjs/sharing/implementations/admin.repository.js.map +1 -0
- package/dist/cjs/sharing/implementations/details.repository.js +13 -4
- package/dist/cjs/sharing/implementations/details.repository.js.map +1 -1
- package/dist/cjs/sharing/implementations/organization.model.js +31 -0
- package/dist/cjs/sharing/implementations/organization.model.js.map +1 -0
- package/dist/cjs/sharing/implementations/organization.repository.js +73 -0
- package/dist/cjs/sharing/implementations/organization.repository.js.map +1 -0
- package/dist/cjs/sharing/implementations/sharing.model.js +4 -2
- package/dist/cjs/sharing/implementations/sharing.model.js.map +1 -1
- package/dist/cjs/sharing/interfaces/adminRepository.interface.js +3 -0
- package/dist/cjs/sharing/interfaces/adminRepository.interface.js.map +1 -0
- package/dist/cjs/sharing/interfaces/organizationRepository.interface.js +3 -0
- package/dist/cjs/sharing/interfaces/organizationRepository.interface.js.map +1 -0
- package/dist/cjs/sharing/services/checkAppAccess.js +47 -0
- package/dist/cjs/sharing/services/checkAppAccess.js.map +1 -0
- package/dist/cjs/sharing/services/checkOrgPermissions.js +36 -0
- package/dist/cjs/sharing/services/checkOrgPermissions.js.map +1 -0
- package/dist/cjs/sharing/services/checkUserAccessLevel.js +30 -7
- package/dist/cjs/sharing/services/checkUserAccessLevel.js.map +1 -1
- package/dist/cjs/sharing/services/delete.js +5 -1
- package/dist/cjs/sharing/services/delete.js.map +1 -1
- package/dist/cjs/sharing/services/getOrgTree.js +31 -0
- package/dist/cjs/sharing/services/getOrgTree.js.map +1 -0
- package/dist/cjs/sharing/services/list.js +5 -1
- package/dist/cjs/sharing/services/list.js.map +1 -1
- package/dist/cjs/sharing/services/upsert.js +11 -2
- package/dist/cjs/sharing/services/upsert.js.map +1 -1
- package/dist/cjs/sharing/services/upsertDefaultSharing.js +71 -0
- package/dist/cjs/sharing/services/upsertDefaultSharing.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/index.mjs +1089 -312
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +348 -54
- package/package.json +60 -51
- package/.eslintrc +0 -88
- package/__test__/hasAdminRole.test.ts +0 -299
- package/jest.config.ts +0 -15
- package/src/common/common.type.ts +0 -33
- package/src/common/constants.ts +0 -47
- package/src/common/persistence/base.ts +0 -13
- package/src/common/persistence/poolClient.ts +0 -7
- package/src/common/util.ts +0 -8
- package/src/context.ts +0 -35
- package/src/index.ts +0 -38
- package/src/quser/entities/types/user.type.ts +0 -14
- package/src/quser/entities/user.ts +0 -31
- package/src/quser/implementations/group.model.ts +0 -18
- package/src/quser/implementations/group.repository.ts +0 -20
- package/src/quser/implementations/user.model.ts +0 -23
- package/src/quser/implementations/user.repository.ts +0 -35
- package/src/quser/interfaces/rolesRepository.interface.ts +0 -3
- package/src/quser/interfaces/userRepository.interface.ts +0 -10
- package/src/quser/services/fromTokenToUser.ts +0 -49
- package/src/quser/services/hasAdminRole.ts +0 -52
- package/src/sharing/entities/details.ts +0 -144
- package/src/sharing/entities/sharing.ts +0 -84
- package/src/sharing/entities/types/details.type.ts +0 -58
- package/src/sharing/entities/types/sharing.type.ts +0 -24
- package/src/sharing/implementations/details.model.ts +0 -93
- package/src/sharing/implementations/details.repository.ts +0 -154
- package/src/sharing/implementations/dm.model.ts +0 -21
- package/src/sharing/implementations/dm.repository.ts +0 -23
- package/src/sharing/implementations/dx.model.ts +0 -30
- package/src/sharing/implementations/dx.repository.ts +0 -22
- package/src/sharing/implementations/sharing.model.ts +0 -33
- package/src/sharing/implementations/sharing.repository.ts +0 -36
- package/src/sharing/interfaces/dashboardRepository.interface.ts +0 -3
- package/src/sharing/interfaces/detailsRepository.interface.ts +0 -60
- package/src/sharing/interfaces/downloadManagerRepository.interface.ts +0 -3
- package/src/sharing/interfaces/sharingRepository.interface.ts +0 -32
- package/src/sharing/services/checkUserAccessLevel.ts +0 -63
- package/src/sharing/services/delete.ts +0 -24
- package/src/sharing/services/list.ts +0 -53
- package/src/sharing/services/upsert.ts +0 -197
- package/tsconfig.cjs.json +0 -7
- package/tsconfig.json +0 -19
- package/tsup.config.cjs.ts +0 -11
- package/tsup.config.esm.ts +0 -12
- package/tsup.config.types.ts +0 -9
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { inject, injectable } from 'tsyringe';
|
|
2
|
-
|
|
3
|
-
import { ParamsFromTokenToUser } from '../../common/common.type';
|
|
4
|
-
import { ORGANIZATION_QRVEY } from '../../common/constants';
|
|
5
|
-
import { isComposer } from '../../common/util';
|
|
6
|
-
import { UserToken } from '../entities/types/user.type';
|
|
7
|
-
import { User } from '../entities/user';
|
|
8
|
-
import { UserRepositoryInterface } from '../interfaces/userRepository.interface';
|
|
9
|
-
|
|
10
|
-
@injectable()
|
|
11
|
-
export class FromTokenToUser {
|
|
12
|
-
constructor(
|
|
13
|
-
@inject('UserRepository')
|
|
14
|
-
private readonly userRepository: UserRepositoryInterface,
|
|
15
|
-
) {}
|
|
16
|
-
|
|
17
|
-
public async execute({
|
|
18
|
-
body,
|
|
19
|
-
}: {
|
|
20
|
-
body: UserToken;
|
|
21
|
-
}): Promise<ParamsFromTokenToUser> {
|
|
22
|
-
const current = await this.userRepository.getOne(
|
|
23
|
-
body.clientId || body.userId,
|
|
24
|
-
);
|
|
25
|
-
if (current) {
|
|
26
|
-
const user = new User(current);
|
|
27
|
-
return {
|
|
28
|
-
userId: user.getUserId,
|
|
29
|
-
roles: user.getGroups,
|
|
30
|
-
orgId: body.orgId ?? ORGANIZATION_QRVEY,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const inComposer = isComposer(body.loginType || '');
|
|
35
|
-
if (!inComposer) {
|
|
36
|
-
return {
|
|
37
|
-
userId: body.clientId || '',
|
|
38
|
-
roles: body.roles || [],
|
|
39
|
-
orgId: body.orgId || '',
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
userId: '',
|
|
45
|
-
roles: [],
|
|
46
|
-
orgId: '',
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { inject, injectable } from 'tsyringe';
|
|
2
|
-
|
|
3
|
-
import { ORGANIZATION_QRVEY } from '../../common/constants';
|
|
4
|
-
import { isComposer } from '../../common/util';
|
|
5
|
-
import { UserRepositoryInterface } from '../interfaces/userRepository.interface';
|
|
6
|
-
|
|
7
|
-
@injectable()
|
|
8
|
-
export class HasAdminRole {
|
|
9
|
-
constructor(
|
|
10
|
-
@inject('UserRepository')
|
|
11
|
-
private readonly userRepository: UserRepositoryInterface,
|
|
12
|
-
) {}
|
|
13
|
-
|
|
14
|
-
public async execute({
|
|
15
|
-
apiKey,
|
|
16
|
-
clientId,
|
|
17
|
-
orgId,
|
|
18
|
-
userId,
|
|
19
|
-
loginType,
|
|
20
|
-
}: {
|
|
21
|
-
apiKey?: string;
|
|
22
|
-
clientId?: string;
|
|
23
|
-
orgId?: string;
|
|
24
|
-
userId?: string;
|
|
25
|
-
loginType?: string;
|
|
26
|
-
} = {}): Promise<boolean> {
|
|
27
|
-
if (!userId) return false;
|
|
28
|
-
|
|
29
|
-
const existingUser = await this.userRepository.getOne(userId);
|
|
30
|
-
const isMasterKey =
|
|
31
|
-
apiKey && (orgId === undefined || orgId === ORGANIZATION_QRVEY);
|
|
32
|
-
if (isMasterKey && existingUser && (!clientId || clientId === userId))
|
|
33
|
-
return true;
|
|
34
|
-
|
|
35
|
-
const user = await this.userRepository.getList({
|
|
36
|
-
data: { identifier: clientId ?? userId, role: 'administrator' },
|
|
37
|
-
});
|
|
38
|
-
const isAdmin = user.items.length > 0;
|
|
39
|
-
|
|
40
|
-
if (isMasterKey && isAdmin) return true;
|
|
41
|
-
|
|
42
|
-
const inComposer = isComposer(loginType || '');
|
|
43
|
-
const isExternal =
|
|
44
|
-
(!clientId && !inComposer) ||
|
|
45
|
-
(orgId && orgId !== ORGANIZATION_QRVEY);
|
|
46
|
-
if (isExternal) return false;
|
|
47
|
-
|
|
48
|
-
if (isAdmin) return true;
|
|
49
|
-
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { getId } from '@qrvey/id-generator';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
BaseSharingDetails,
|
|
5
|
-
CreateSharingDetails,
|
|
6
|
-
ResponseSharingDetails,
|
|
7
|
-
SharingDetailsTable,
|
|
8
|
-
UpdateSharingDetails,
|
|
9
|
-
} from './types/details.type';
|
|
10
|
-
import {
|
|
11
|
-
ACCESS_LEVEL,
|
|
12
|
-
SHARED_ORIGIN,
|
|
13
|
-
SHARE_TYPE,
|
|
14
|
-
} from '../../common/constants';
|
|
15
|
-
|
|
16
|
-
export class SharingDetail {
|
|
17
|
-
private sharingDetailsId: string;
|
|
18
|
-
private assetId: string;
|
|
19
|
-
private accessLevel: ACCESS_LEVEL;
|
|
20
|
-
private accessLevelAsText: string;
|
|
21
|
-
private orgId: string;
|
|
22
|
-
private sharedWith: string;
|
|
23
|
-
private sharedType: SHARE_TYPE;
|
|
24
|
-
private sharedOrigin: SHARED_ORIGIN;
|
|
25
|
-
private sharedEmail?: string;
|
|
26
|
-
private createdAt: string;
|
|
27
|
-
private updatedAt: string;
|
|
28
|
-
private deletedAt?: string;
|
|
29
|
-
|
|
30
|
-
constructor(params: BaseSharingDetails) {
|
|
31
|
-
this.sharingDetailsId = params.sharingDetailsId;
|
|
32
|
-
this.assetId = params.assetId;
|
|
33
|
-
this.accessLevel = params.accessLevel;
|
|
34
|
-
this.accessLevelAsText = this.convertAccessLevelToText(
|
|
35
|
-
params.accessLevel,
|
|
36
|
-
);
|
|
37
|
-
this.orgId = params.orgId;
|
|
38
|
-
this.sharedWith = params.sharedWith;
|
|
39
|
-
this.sharedType = params.sharedType;
|
|
40
|
-
this.sharedEmail = params.sharedEmail;
|
|
41
|
-
this.sharedOrigin = params.sharedOrigin;
|
|
42
|
-
this.createdAt = params.createdAt;
|
|
43
|
-
this.updatedAt = params.updatedAt;
|
|
44
|
-
this.deletedAt = params.deletedAt;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static create(params: CreateSharingDetails): SharingDetail {
|
|
48
|
-
const now = new Date().toISOString();
|
|
49
|
-
const obj: BaseSharingDetails = {
|
|
50
|
-
...params,
|
|
51
|
-
sharingDetailsId: params.sharedId ?? getId(),
|
|
52
|
-
createdAt: now,
|
|
53
|
-
updatedAt: now,
|
|
54
|
-
};
|
|
55
|
-
return new SharingDetail(obj);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static parse(params: SharingDetailsTable): SharingDetail {
|
|
59
|
-
return new SharingDetail({
|
|
60
|
-
sharingDetailsId: params.sharing_details_id,
|
|
61
|
-
assetId: params.asset_id,
|
|
62
|
-
accessLevel: params.access_level as ACCESS_LEVEL,
|
|
63
|
-
orgId: params.org_id,
|
|
64
|
-
sharedWith: params.shared_with,
|
|
65
|
-
sharedType: params.shared_type as SHARE_TYPE,
|
|
66
|
-
sharedEmail: params.shared_email,
|
|
67
|
-
sharedOrigin: params.share_origin as SHARED_ORIGIN,
|
|
68
|
-
createdAt: params.created_at,
|
|
69
|
-
updatedAt: params.updated_at,
|
|
70
|
-
deletedAt: params.deleted_at,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
update(params: UpdateSharingDetails) {
|
|
75
|
-
if (params.accessLevel || params.accessLevel === 0)
|
|
76
|
-
this.accessLevel = params.accessLevel;
|
|
77
|
-
if (params.sharedEmail) this.sharedEmail = params.sharedEmail;
|
|
78
|
-
this.updatedAt = new Date().toISOString();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
toTable(): SharingDetailsTable {
|
|
82
|
-
return {
|
|
83
|
-
sharing_details_id: this.sharingDetailsId,
|
|
84
|
-
asset_id: this.assetId,
|
|
85
|
-
access_level: this.accessLevel,
|
|
86
|
-
org_id: this.orgId,
|
|
87
|
-
shared_with: this.sharedWith,
|
|
88
|
-
shared_type: this.sharedType,
|
|
89
|
-
shared_email: this.sharedEmail,
|
|
90
|
-
share_origin: this.sharedOrigin,
|
|
91
|
-
created_at: this.createdAt,
|
|
92
|
-
updated_at: this.updatedAt,
|
|
93
|
-
deleted_at: this.deletedAt,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
toPlain(): BaseSharingDetails {
|
|
98
|
-
return {
|
|
99
|
-
sharingDetailsId: this.sharingDetailsId,
|
|
100
|
-
assetId: this.assetId,
|
|
101
|
-
accessLevel: this.accessLevel,
|
|
102
|
-
orgId: this.orgId,
|
|
103
|
-
sharedWith: this.sharedWith,
|
|
104
|
-
sharedType: this.sharedType,
|
|
105
|
-
sharedEmail: this.sharedEmail,
|
|
106
|
-
sharedOrigin: this.sharedOrigin,
|
|
107
|
-
createdAt: this.createdAt,
|
|
108
|
-
updatedAt: this.updatedAt,
|
|
109
|
-
deletedAt: this.deletedAt,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
toJSON(): ResponseSharingDetails {
|
|
114
|
-
return {
|
|
115
|
-
sharedId: this.sharingDetailsId,
|
|
116
|
-
assetId: this.assetId,
|
|
117
|
-
accessLevel: this.accessLevel,
|
|
118
|
-
accessLevelAsText: this.accessLevelAsText,
|
|
119
|
-
orgId: this.orgId,
|
|
120
|
-
sharedWith: this.sharedWith,
|
|
121
|
-
sharedType: this.sharedType,
|
|
122
|
-
sharedEmail: this.sharedEmail,
|
|
123
|
-
sharedOrigin: this.sharedOrigin,
|
|
124
|
-
createdAt: this.createdAt,
|
|
125
|
-
updatedAt: this.updatedAt,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public get getSharingDetailsId(): string {
|
|
130
|
-
return this.sharingDetailsId;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public get getAccessLevel(): ACCESS_LEVEL {
|
|
134
|
-
return this.accessLevel;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public get getAccessLevelAsText(): string {
|
|
138
|
-
return this.accessLevelAsText;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
private convertAccessLevelToText(level: number): string {
|
|
142
|
-
return ACCESS_LEVEL[level] ?? 'UNKNOWN';
|
|
143
|
-
}
|
|
144
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseSharing,
|
|
3
|
-
CreateSharing,
|
|
4
|
-
ResponseSharing,
|
|
5
|
-
SharingTable,
|
|
6
|
-
} from './types/sharing.type';
|
|
7
|
-
import { ASSET_TYPE } from '../../common/constants';
|
|
8
|
-
|
|
9
|
-
export class Sharing {
|
|
10
|
-
private assetId: string;
|
|
11
|
-
private assetType: ASSET_TYPE;
|
|
12
|
-
private createdAt: string;
|
|
13
|
-
private updatedAt: string;
|
|
14
|
-
private deletedAt?: string;
|
|
15
|
-
|
|
16
|
-
constructor(params: BaseSharing) {
|
|
17
|
-
this.assetId = params.assetId;
|
|
18
|
-
this.assetType = params.assetType;
|
|
19
|
-
this.createdAt = params.createdAt;
|
|
20
|
-
this.updatedAt = params.updatedAt;
|
|
21
|
-
this.deletedAt = params.deletedAt;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static create(params: CreateSharing): Sharing {
|
|
25
|
-
const now = new Date().toISOString();
|
|
26
|
-
const obj: BaseSharing = {
|
|
27
|
-
...params,
|
|
28
|
-
createdAt: now,
|
|
29
|
-
updatedAt: now,
|
|
30
|
-
};
|
|
31
|
-
return new Sharing(obj);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static parse(params: SharingTable): Sharing {
|
|
35
|
-
return new Sharing({
|
|
36
|
-
assetId: params.asset_id,
|
|
37
|
-
assetType: params.asset_type as ASSET_TYPE,
|
|
38
|
-
createdAt: params.created_at,
|
|
39
|
-
updatedAt: params.updated_at,
|
|
40
|
-
deletedAt: params.deleted_at,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
update() {
|
|
45
|
-
this.updatedAt = new Date().toISOString();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
toTable(): SharingTable {
|
|
49
|
-
return {
|
|
50
|
-
asset_id: this.assetId,
|
|
51
|
-
asset_type: this.assetType,
|
|
52
|
-
created_at: this.createdAt,
|
|
53
|
-
updated_at: this.updatedAt,
|
|
54
|
-
deleted_at: this.deletedAt,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
toPlain(): BaseSharing {
|
|
59
|
-
return {
|
|
60
|
-
assetId: this.assetId,
|
|
61
|
-
assetType: this.assetType,
|
|
62
|
-
createdAt: this.createdAt,
|
|
63
|
-
updatedAt: this.updatedAt,
|
|
64
|
-
deletedAt: this.deletedAt,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
toJSON(): ResponseSharing {
|
|
69
|
-
return {
|
|
70
|
-
assetId: this.assetId,
|
|
71
|
-
assetType: this.assetType,
|
|
72
|
-
createdAt: this.createdAt,
|
|
73
|
-
updatedAt: this.updatedAt,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public get getAssetId(): string {
|
|
78
|
-
return this.assetId;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public get getAssetType(): string {
|
|
82
|
-
return this.assetType;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ListInput, ListOutput } from '../../../common/common.type';
|
|
2
|
-
import {
|
|
3
|
-
ACCESS_LEVEL,
|
|
4
|
-
SHARED_ORIGIN,
|
|
5
|
-
SHARE_TYPE,
|
|
6
|
-
} from '../../../common/constants';
|
|
7
|
-
|
|
8
|
-
export interface BaseSharingDetails {
|
|
9
|
-
sharingDetailsId: string;
|
|
10
|
-
assetId: string;
|
|
11
|
-
accessLevel: ACCESS_LEVEL;
|
|
12
|
-
orgId: string;
|
|
13
|
-
sharedWith: string;
|
|
14
|
-
sharedType: SHARE_TYPE;
|
|
15
|
-
sharedOrigin: SHARED_ORIGIN;
|
|
16
|
-
sharedEmail?: string;
|
|
17
|
-
createdAt: string;
|
|
18
|
-
updatedAt: string;
|
|
19
|
-
deletedAt?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type CreateSharingDetails = Omit<
|
|
23
|
-
BaseSharingDetails,
|
|
24
|
-
'sharingDetailsId' | 'createdAt' | 'updatedAt' | 'deletedAt'
|
|
25
|
-
> & {
|
|
26
|
-
sharedId?: string; // `sharingDetailsId` is converted to `sharedId` for the API.
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type UpdateSharingDetails = Pick<
|
|
30
|
-
BaseSharingDetails,
|
|
31
|
-
'accessLevel' | 'sharedEmail'
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
export type ResponseSharingDetails = Omit<
|
|
35
|
-
BaseSharingDetails,
|
|
36
|
-
'sharingDetailsId' | 'deletedAt'
|
|
37
|
-
> & {
|
|
38
|
-
sharedId: string; // `sharingDetailsId` is converted to `sharedId` to better legibility in the API.
|
|
39
|
-
accessLevelAsText: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export interface SharingDetailsTable {
|
|
43
|
-
sharing_details_id: string;
|
|
44
|
-
asset_id: string;
|
|
45
|
-
access_level: number;
|
|
46
|
-
org_id: string;
|
|
47
|
-
shared_with: string;
|
|
48
|
-
shared_type: string;
|
|
49
|
-
shared_email?: string;
|
|
50
|
-
share_origin: string;
|
|
51
|
-
created_at: string;
|
|
52
|
-
updated_at: string;
|
|
53
|
-
deleted_at?: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type GetSharingList = ListInput<{ assetId: string }>;
|
|
57
|
-
|
|
58
|
-
export type ListSharingDetails = ListOutput<ResponseSharingDetails>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ASSET_TYPE } from '../../../common/constants';
|
|
2
|
-
|
|
3
|
-
export interface BaseSharing {
|
|
4
|
-
assetId: string;
|
|
5
|
-
assetType: ASSET_TYPE;
|
|
6
|
-
createdAt: string;
|
|
7
|
-
updatedAt: string;
|
|
8
|
-
deletedAt?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type CreateSharing = Omit<
|
|
12
|
-
BaseSharing,
|
|
13
|
-
'createdAt' | 'updatedAt' | 'deletedAt'
|
|
14
|
-
>;
|
|
15
|
-
|
|
16
|
-
export type ResponseSharing = Omit<BaseSharing, 'deletedAt'>;
|
|
17
|
-
|
|
18
|
-
export interface SharingTable {
|
|
19
|
-
asset_id: string;
|
|
20
|
-
asset_type: ASSET_TYPE | string;
|
|
21
|
-
created_at: string;
|
|
22
|
-
updated_at: string;
|
|
23
|
-
deleted_at?: string;
|
|
24
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { CrudSchema } from '@qrvey/data-persistence';
|
|
2
|
-
|
|
3
|
-
import { DATABASE_INFO } from '../../common/constants';
|
|
4
|
-
|
|
5
|
-
export class SharingDetailsModel extends CrudSchema {
|
|
6
|
-
static table = {
|
|
7
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}_sharing_details`,
|
|
8
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_sharing_details`,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
static columns = {
|
|
12
|
-
sharing_details_id: { type: 'string', primary: true },
|
|
13
|
-
asset_id: { type: 'string' },
|
|
14
|
-
access_level: { type: 'numeric' },
|
|
15
|
-
org_id: { type: 'string' },
|
|
16
|
-
shared_with: { type: 'string' },
|
|
17
|
-
shared_type: { type: 'string' },
|
|
18
|
-
shared_email: { type: 'string' },
|
|
19
|
-
share_origin: { type: 'string' },
|
|
20
|
-
created_at: { type: 'date' },
|
|
21
|
-
updated_at: { type: 'date' },
|
|
22
|
-
deleted_at: { type: 'date' },
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
static indexes = {
|
|
26
|
-
sharingDetailsOrgId: {
|
|
27
|
-
name: 'sharing_details_org_id_index',
|
|
28
|
-
columns: [
|
|
29
|
-
'org_id',
|
|
30
|
-
'asset_id',
|
|
31
|
-
'sharing_details_id',
|
|
32
|
-
'shared_with',
|
|
33
|
-
'shared_type',
|
|
34
|
-
'shared_email',
|
|
35
|
-
'share_origin',
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
sharingDetailsSharedWithAccessLevel: {
|
|
39
|
-
name: 'sharing_details_shared_with_access_level_index',
|
|
40
|
-
columns: [
|
|
41
|
-
'shared_with',
|
|
42
|
-
'access_level',
|
|
43
|
-
'asset_id',
|
|
44
|
-
'sharing_details_id',
|
|
45
|
-
'org_id',
|
|
46
|
-
'shared_type',
|
|
47
|
-
'shared_email',
|
|
48
|
-
'share_origin',
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
sharingDetailsAccessLevelSharedWithOrgId: {
|
|
52
|
-
name: 'sharing_details_access_level_shared_with_org_id_index',
|
|
53
|
-
columns: [
|
|
54
|
-
'access_level',
|
|
55
|
-
'shared_with',
|
|
56
|
-
'org_id',
|
|
57
|
-
'asset_id',
|
|
58
|
-
'sharing_details_id',
|
|
59
|
-
'shared_type',
|
|
60
|
-
'shared_email',
|
|
61
|
-
'share_origin',
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
sharingDetailsAccessLevelOrgId: {
|
|
65
|
-
name: 'sharing_details_access_level_org_id_index',
|
|
66
|
-
columns: [
|
|
67
|
-
'access_level',
|
|
68
|
-
'org_id',
|
|
69
|
-
'asset_id',
|
|
70
|
-
'sharing_details_id',
|
|
71
|
-
'shared_with',
|
|
72
|
-
'shared_type',
|
|
73
|
-
'shared_email',
|
|
74
|
-
'share_origin',
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
sharingDetailsAssetId: {
|
|
78
|
-
name: 'sharing_details_asset_id_index',
|
|
79
|
-
columns: [
|
|
80
|
-
'asset_id',
|
|
81
|
-
'sharing_details_id',
|
|
82
|
-
'org_id',
|
|
83
|
-
'shared_with',
|
|
84
|
-
'shared_type',
|
|
85
|
-
'shared_email',
|
|
86
|
-
'share_origin',
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
static schema = DATABASE_INFO.DATA_PERSISTENCE_SCHEMA;
|
|
92
|
-
static usePool = true;
|
|
93
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { IFilter } from '@qrvey/data-persistence';
|
|
2
|
-
|
|
3
|
-
import { SharingDetailsModel } from './details.model';
|
|
4
|
-
import {
|
|
5
|
-
ListInput,
|
|
6
|
-
ListOutput,
|
|
7
|
-
Pagination,
|
|
8
|
-
ParamsFromTokenToUser,
|
|
9
|
-
} from '../../common/common.type';
|
|
10
|
-
import { LIMIT_PER_PAGE, ORGANIZATION_QRVEY } from '../../common/constants';
|
|
11
|
-
import { BaseRepository } from '../../common/persistence/base';
|
|
12
|
-
import { SharingDetailsTable } from '../entities/types/details.type';
|
|
13
|
-
import { SharingDetailsRepositoryInterface } from '../interfaces/detailsRepository.interface';
|
|
14
|
-
|
|
15
|
-
export class SharingDetailsRepository
|
|
16
|
-
extends BaseRepository
|
|
17
|
-
implements SharingDetailsRepositoryInterface
|
|
18
|
-
{
|
|
19
|
-
constructor() {
|
|
20
|
-
super(SharingDetailsModel);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getOne(sharingDetailId: string): Promise<SharingDetailsTable | null> {
|
|
24
|
-
const params = {
|
|
25
|
-
filters: [this.filter('sharing_details_id', sharingDetailId)],
|
|
26
|
-
};
|
|
27
|
-
const response = await super.findItem(params);
|
|
28
|
-
return response as SharingDetailsTable;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async getBySharedWith(
|
|
32
|
-
assetId: string,
|
|
33
|
-
sharedWith: string,
|
|
34
|
-
): Promise<SharingDetailsTable | null> {
|
|
35
|
-
const filterList = [
|
|
36
|
-
this.filter('asset_id', assetId),
|
|
37
|
-
this.filter('shared_with', sharedWith),
|
|
38
|
-
];
|
|
39
|
-
const params = {
|
|
40
|
-
filters: filterList,
|
|
41
|
-
};
|
|
42
|
-
const response = await super.findItem(params);
|
|
43
|
-
return response as SharingDetailsTable;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getList(
|
|
47
|
-
options: ListInput<{ assetId: string; user?: ParamsFromTokenToUser }>,
|
|
48
|
-
): Promise<ListOutput<SharingDetailsTable>> {
|
|
49
|
-
const assetIndex = SharingDetailsModel.indexes.sharingDetailsAssetId;
|
|
50
|
-
const pagination = this.getPagination(options.pagination);
|
|
51
|
-
const params: {
|
|
52
|
-
pagination: any;
|
|
53
|
-
index: any;
|
|
54
|
-
filters?: any;
|
|
55
|
-
sorting?: any;
|
|
56
|
-
} = {
|
|
57
|
-
pagination,
|
|
58
|
-
index: {
|
|
59
|
-
indexName: assetIndex.name,
|
|
60
|
-
columns: assetIndex.columns,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const filterList = [this.filter('asset_id', options.data.assetId)];
|
|
65
|
-
if (options.filters) {
|
|
66
|
-
options.filters.forEach((filter) => {
|
|
67
|
-
filterList.push(this.filter(filter.column, filter.value));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
params.filters = filterList;
|
|
71
|
-
|
|
72
|
-
if (options.data.user) {
|
|
73
|
-
const currentFilter = this.getUserFilter(
|
|
74
|
-
options.data.user,
|
|
75
|
-
filterList,
|
|
76
|
-
);
|
|
77
|
-
params.filters = currentFilter;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (options.sorting) params.sorting = options.sorting;
|
|
81
|
-
|
|
82
|
-
const response = await super.find(params);
|
|
83
|
-
return response as ListOutput<SharingDetailsTable>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async create(details: SharingDetailsTable): Promise<SharingDetailsTable> {
|
|
87
|
-
const response = (await super.create(details)) as SharingDetailsTable;
|
|
88
|
-
return response;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async patch(
|
|
92
|
-
sharingDetailId: string,
|
|
93
|
-
details: SharingDetailsTable,
|
|
94
|
-
): Promise<boolean> {
|
|
95
|
-
await super.update(
|
|
96
|
-
[this.filter('sharing_details_id', sharingDetailId)],
|
|
97
|
-
details,
|
|
98
|
-
);
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async delete(sharingDetailId: string): Promise<boolean> {
|
|
103
|
-
await super.remove([
|
|
104
|
-
this.filter('sharing_details_id', sharingDetailId),
|
|
105
|
-
]);
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private getPagination(options?: Pagination): Pagination {
|
|
110
|
-
return {
|
|
111
|
-
limit: options?.limit ?? LIMIT_PER_PAGE,
|
|
112
|
-
from: options?.from ?? undefined,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private getUserFilter(
|
|
117
|
-
user: ParamsFromTokenToUser,
|
|
118
|
-
currentFilters?: IFilter[],
|
|
119
|
-
) {
|
|
120
|
-
const { userId, roles } = user;
|
|
121
|
-
const orgId = user.orgId === '' ? ORGANIZATION_QRVEY : user.orgId; //Review if this is right
|
|
122
|
-
const sharing = {
|
|
123
|
-
OR: [
|
|
124
|
-
{
|
|
125
|
-
AND: [
|
|
126
|
-
this.buildFilter('shared_with', userId),
|
|
127
|
-
this.buildFilter('shared_type', 'USER'),
|
|
128
|
-
this.buildFilter('org_id', orgId),
|
|
129
|
-
],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
AND: [
|
|
133
|
-
this.buildFilter('shared_with', orgId),
|
|
134
|
-
this.buildFilter('shared_type', 'ORGANIZATION'),
|
|
135
|
-
this.buildFilter('org_id', orgId),
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
};
|
|
140
|
-
if (roles && roles?.length > 0) {
|
|
141
|
-
sharing.OR.push({
|
|
142
|
-
AND: [
|
|
143
|
-
this.buildFilter('shared_with', roles, 'IN'),
|
|
144
|
-
this.buildFilter('shared_type', 'ROLE'),
|
|
145
|
-
this.buildFilter('org_id', orgId),
|
|
146
|
-
],
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
const filter = [];
|
|
150
|
-
if (currentFilters) filter.push(...currentFilters);
|
|
151
|
-
filter.push(sharing);
|
|
152
|
-
return { AND: filter };
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CrudSchema } from '@qrvey/data-persistence';
|
|
2
|
-
|
|
3
|
-
import { DATABASE_INFO } from '../../common/constants';
|
|
4
|
-
|
|
5
|
-
export class DownloadManagerSchema extends CrudSchema {
|
|
6
|
-
static table = {
|
|
7
|
-
name: `${DATABASE_INFO.SERVER_PREFIX}DownloadManager`,
|
|
8
|
-
alias: `${DATABASE_INFO.TABLE_PREFIX}_download_manager`,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
static columns = {
|
|
12
|
-
downloadManagerId: {
|
|
13
|
-
primary: true,
|
|
14
|
-
type: 'String',
|
|
15
|
-
columnId: true,
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
static schema = 'exports';
|
|
20
|
-
static usePool = true;
|
|
21
|
-
}
|