@lightdash/common 2.198.6 → 2.199.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/authorization/getDashboardDeleteAccess.d.ts +4 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.d.ts.map +1 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.js +8 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.js.map +1 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.test.d.ts +2 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.test.d.ts.map +1 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.test.js +127 -0
- package/dist/cjs/authorization/getDashboardDeleteAccess.test.js.map +1 -0
- package/dist/cjs/authorization/roleToScopeMapping.testUtils.d.ts +98 -98
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/space.d.ts +1 -0
- package/dist/cjs/types/space.d.ts.map +1 -1
- package/dist/cjs/types/space.js.map +1 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/authorization/getDashboardDeleteAccess.d.ts +4 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.d.ts.map +1 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.js +4 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.js.map +1 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.test.d.ts +2 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.test.d.ts.map +1 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.test.js +125 -0
- package/dist/esm/authorization/getDashboardDeleteAccess.test.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/space.d.ts +1 -0
- package/dist/esm/types/space.d.ts.map +1 -1
- package/dist/esm/types/space.js.map +1 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/authorization/getDashboardDeleteAccess.d.ts +4 -0
- package/dist/types/authorization/getDashboardDeleteAccess.d.ts.map +1 -0
- package/dist/types/authorization/getDashboardDeleteAccess.js +4 -0
- package/dist/types/authorization/getDashboardDeleteAccess.js.map +1 -0
- package/dist/types/authorization/getDashboardDeleteAccess.test.d.ts +2 -0
- package/dist/types/authorization/getDashboardDeleteAccess.test.d.ts.map +1 -0
- package/dist/types/authorization/getDashboardDeleteAccess.test.js +125 -0
- package/dist/types/authorization/getDashboardDeleteAccess.test.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/types/space.d.ts +1 -0
- package/dist/types/types/space.d.ts.map +1 -1
- package/dist/types/types/space.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type SpaceAccess } from '../types/space';
|
|
2
|
+
/** Keep inherited rights intact; only Full access grants dashboard deletion. */
|
|
3
|
+
export declare const getDashboardDeleteAccess: <T extends Pick<SpaceAccess, 'role' | 'grantedVia'>>(access: readonly T[]) => T[];
|
|
4
|
+
//# sourceMappingURL=getDashboardDeleteAccess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDashboardDeleteAccess.d.ts","sourceRoot":"","sources":["../../../src/authorization/getDashboardDeleteAccess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEnE,gFAAgF;AAChF,eAAO,MAAM,wBAAwB,GACjC,CAAC,SAAS,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,CAAC,UAE1C,SAAS,CAAC,EAAE,KACrB,CAAC,EAIC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDashboardDeleteAccess = void 0;
|
|
4
|
+
const space_1 = require("../types/space");
|
|
5
|
+
/** Keep inherited rights intact; only Full access grants dashboard deletion. */
|
|
6
|
+
const getDashboardDeleteAccess = (access) => access.filter(({ role, grantedVia }) => grantedVia !== 'dashboard' || role === space_1.SpaceMemberRole.ADMIN);
|
|
7
|
+
exports.getDashboardDeleteAccess = getDashboardDeleteAccess;
|
|
8
|
+
//# sourceMappingURL=getDashboardDeleteAccess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDashboardDeleteAccess.js","sourceRoot":"","sources":["../../../src/authorization/getDashboardDeleteAccess.ts"],"names":[],"mappings":";;;AAAA,0CAAmE;AAEnE,gFAAgF;AACzE,MAAM,wBAAwB,GAAG,CAGpC,MAAoB,EACjB,EAAE,CACL,MAAM,CAAC,MAAM,CACT,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CACrB,UAAU,KAAK,WAAW,IAAI,IAAI,KAAK,uBAAe,CAAC,KAAK,CACnE,CAAC;AARO,QAAA,wBAAwB,GAAxB,wBAAwB,CAQ/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDashboardDeleteAccess.test.d.ts","sourceRoot":"","sources":["../../../src/authorization/getDashboardDeleteAccess.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ability_1 = require("@casl/ability");
|
|
4
|
+
const projectMemberRole_1 = require("../types/projectMemberRole");
|
|
5
|
+
const space_1 = require("../types/space");
|
|
6
|
+
const getDashboardDeleteAccess_1 = require("./getDashboardDeleteAccess");
|
|
7
|
+
const projectMemberAbility_1 = require("./projectMemberAbility");
|
|
8
|
+
const scopeAbilityBuilder_1 = require("./scopeAbilityBuilder");
|
|
9
|
+
const context = {
|
|
10
|
+
organizationUuid: 'org',
|
|
11
|
+
projectUuid: 'project',
|
|
12
|
+
userUuid: 'user',
|
|
13
|
+
};
|
|
14
|
+
const editorGrant = {
|
|
15
|
+
userUuid: context.userUuid,
|
|
16
|
+
role: space_1.SpaceMemberRole.EDITOR,
|
|
17
|
+
grantedVia: 'dashboard',
|
|
18
|
+
};
|
|
19
|
+
const buildAbility = (scopes) => {
|
|
20
|
+
const builder = new ability_1.AbilityBuilder(ability_1.Ability);
|
|
21
|
+
if (scopes) {
|
|
22
|
+
(0, scopeAbilityBuilder_1.buildAbilityFromScopes)({
|
|
23
|
+
projectUuid: context.projectUuid,
|
|
24
|
+
userUuid: context.userUuid,
|
|
25
|
+
scopes,
|
|
26
|
+
isEnterprise: true,
|
|
27
|
+
}, builder);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
projectMemberAbility_1.projectMemberAbilities.editor({ ...context, role: projectMemberRole_1.ProjectMemberRole.EDITOR }, builder);
|
|
31
|
+
}
|
|
32
|
+
return builder.build();
|
|
33
|
+
};
|
|
34
|
+
describe.each([
|
|
35
|
+
{ name: 'built-in editor', scopes: undefined },
|
|
36
|
+
{ name: 'custom space manager', scopes: ['manage:Dashboard@space'] },
|
|
37
|
+
])('$name dashboard deletion', ({ scopes }) => {
|
|
38
|
+
const ability = buildAbility(scopes);
|
|
39
|
+
test.each([
|
|
40
|
+
{ name: 'direct editor', access: [editorGrant], allowed: false },
|
|
41
|
+
{
|
|
42
|
+
name: 'direct full access',
|
|
43
|
+
access: [{ ...editorGrant, role: space_1.SpaceMemberRole.ADMIN }],
|
|
44
|
+
allowed: true,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'space editor',
|
|
48
|
+
access: [{ ...editorGrant, grantedVia: undefined }],
|
|
49
|
+
allowed: true,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'direct editor plus space viewer',
|
|
53
|
+
access: [
|
|
54
|
+
editorGrant,
|
|
55
|
+
{
|
|
56
|
+
...editorGrant,
|
|
57
|
+
grantedVia: undefined,
|
|
58
|
+
role: space_1.SpaceMemberRole.VIEWER,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
allowed: false,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'direct viewer plus space editor',
|
|
65
|
+
access: [
|
|
66
|
+
{ ...editorGrant, role: space_1.SpaceMemberRole.VIEWER },
|
|
67
|
+
{ ...editorGrant, grantedVia: undefined },
|
|
68
|
+
],
|
|
69
|
+
allowed: true,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'direct user editor plus group admin',
|
|
73
|
+
access: [
|
|
74
|
+
editorGrant,
|
|
75
|
+
{ ...editorGrant, role: space_1.SpaceMemberRole.ADMIN },
|
|
76
|
+
],
|
|
77
|
+
allowed: true,
|
|
78
|
+
},
|
|
79
|
+
{ name: 'no access (including flag off)', access: [], allowed: false },
|
|
80
|
+
{
|
|
81
|
+
name: 'another user full access',
|
|
82
|
+
access: [
|
|
83
|
+
{
|
|
84
|
+
...editorGrant,
|
|
85
|
+
userUuid: 'other',
|
|
86
|
+
role: space_1.SpaceMemberRole.ADMIN,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
allowed: false,
|
|
90
|
+
},
|
|
91
|
+
])('$name: allowed=$allowed', ({ access, allowed }) => {
|
|
92
|
+
expect(ability.can('delete', (0, ability_1.subject)('Dashboard', {
|
|
93
|
+
...context,
|
|
94
|
+
inheritsFromOrgOrProject: false,
|
|
95
|
+
access: (0, getDashboardDeleteAccess_1.getDashboardDeleteAccess)(access),
|
|
96
|
+
}))).toBe(allowed);
|
|
97
|
+
});
|
|
98
|
+
it('keeps editing authorized by the original grant', () => {
|
|
99
|
+
const access = [editorGrant];
|
|
100
|
+
(0, getDashboardDeleteAccess_1.getDashboardDeleteAccess)(access);
|
|
101
|
+
expect(ability.can('update', (0, ability_1.subject)('Dashboard', { ...context, access }))).toBe(true);
|
|
102
|
+
expect(access).toEqual([editorGrant]);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it('preserves unconditional custom-role deletion rights', () => {
|
|
106
|
+
expect(buildAbility(['manage:Dashboard']).can('delete', (0, ability_1.subject)('Dashboard', {
|
|
107
|
+
...context,
|
|
108
|
+
access: (0, getDashboardDeleteAccess_1.getDashboardDeleteAccess)([editorGrant]),
|
|
109
|
+
}))).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
it('does not supply missing project capabilities to full access', () => {
|
|
112
|
+
expect(buildAbility(['view:Dashboard']).can('delete', (0, ability_1.subject)('Dashboard', {
|
|
113
|
+
...context,
|
|
114
|
+
access: (0, getDashboardDeleteAccess_1.getDashboardDeleteAccess)([
|
|
115
|
+
{ ...editorGrant, role: space_1.SpaceMemberRole.ADMIN },
|
|
116
|
+
]),
|
|
117
|
+
}))).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
it('preserves grants sourced from other content types', () => {
|
|
120
|
+
const access = [
|
|
121
|
+
{ role: space_1.SpaceMemberRole.EDITOR, grantedVia: 'saved_chart' },
|
|
122
|
+
{ role: space_1.SpaceMemberRole.EDITOR, grantedVia: 'sql_chart' },
|
|
123
|
+
{ role: space_1.SpaceMemberRole.EDITOR, grantedVia: 'app' },
|
|
124
|
+
];
|
|
125
|
+
expect((0, getDashboardDeleteAccess_1.getDashboardDeleteAccess)(access)).toEqual(access);
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=getDashboardDeleteAccess.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDashboardDeleteAccess.test.js","sourceRoot":"","sources":["../../../src/authorization/getDashboardDeleteAccess.test.ts"],"names":[],"mappings":";;AAAA,2CAAiE;AACjE,kEAA+D;AAC/D,0CAAmE;AACnE,yEAAsE;AACtE,iEAAgE;AAChE,+DAA+D;AAG/D,MAAM,OAAO,GAAG;IACZ,gB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