@griddo/ax 12.13.1 → 12.15.0-astro-rc.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/config/webpack.config.js +1 -1
- package/package.json +4 -4
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.caption.test.tsx +59 -0
- package/src/__tests__/containers/PageEditor/accessGrants.test.ts +104 -0
- package/src/__tests__/containers/PageEditor/savePageForbidden.test.ts +66 -0
- package/src/__tests__/forms/validators.test.ts +37 -0
- package/src/__tests__/gainup-trace.test.ts +1 -1
- package/src/__tests__/hooks/permissionsForPageKeys.contract.test.ts +50 -0
- package/src/__tests__/hooks/permissionsPageId.test.ts +17 -0
- package/src/__tests__/hooks/users.test.tsx +167 -8
- package/src/components/Fields/Wysiwyg/index.tsx +33 -0
- package/src/containers/PageEditor/actions.tsx +70 -49
- package/src/containers/PageEditor/constants.tsx +4 -0
- package/src/forms/errors.tsx +2 -2
- package/src/forms/validators.tsx +14 -12
- package/src/hooks/index.tsx +12 -6
- package/src/hooks/users.tsx +84 -9
- package/src/modules/ActivityLog/DownloadModal/index.tsx +4 -2
- package/src/modules/ActivityLog/index.tsx +6 -5
- package/src/modules/GlobalEditor/index.tsx +2 -1
- package/src/modules/PageEditor/index.tsx +2 -1
package/config/webpack.config.js
CHANGED
|
@@ -83,7 +83,7 @@ const hasJsxRuntime = (() => {
|
|
|
83
83
|
|
|
84
84
|
// This is the production and development configuration.
|
|
85
85
|
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
|
|
86
|
-
module.exports =
|
|
86
|
+
module.exports = (webpackEnv) => {
|
|
87
87
|
const isEnvDevelopment = webpackEnv === "development";
|
|
88
88
|
const isEnvProduction = webpackEnv === "production";
|
|
89
89
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.15.0-astro-rc.0",
|
|
5
5
|
"homepage": "https://griddo.io",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
129
|
"@biomejs/biome": "2.5.15",
|
|
130
|
-
"@griddo/core": "12.
|
|
130
|
+
"@griddo/core": "12.15.0-astro-rc.0",
|
|
131
131
|
"@types/redux-mock-store": "1.5.0",
|
|
132
132
|
"@vitest/coverage-v8": "4.1.11",
|
|
133
133
|
"axios-mock-adapter": "1.22.0",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"vitest-styled-components": "1.0.0"
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"@griddo/core": "12.
|
|
141
|
+
"@griddo/core": "12.15.0-astro-rc.0"
|
|
142
142
|
},
|
|
143
143
|
"babel": {
|
|
144
144
|
"presets": [
|
|
@@ -171,5 +171,5 @@
|
|
|
171
171
|
"publishConfig": {
|
|
172
172
|
"access": "public"
|
|
173
173
|
},
|
|
174
|
-
"gitHead": "
|
|
174
|
+
"gitHead": "cc977c8324bdf596f10eb851ae07fd7b67081d7c"
|
|
175
175
|
}
|
|
@@ -159,6 +159,65 @@ describe("Wysiwyg image caption", () => {
|
|
|
159
159
|
expect(editor.el.querySelectorAll(".fr-img-space-wrap")).toHaveLength(2);
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
+
describe("with the size popup", () => {
|
|
163
|
+
const widthInput = (editor: any) => editor.popups.get("image.size").find('input[name="width"]');
|
|
164
|
+
|
|
165
|
+
const captionedAt40 = async () => {
|
|
166
|
+
const editor = await mountEditor('<p><img src="http://x/a.png" alt="" class="fr-dib" style="width: 40%;"></p>');
|
|
167
|
+
const img = editor.el.querySelector("img");
|
|
168
|
+
toggleCaption(editor);
|
|
169
|
+
editor.image.edit(editor.$(img));
|
|
170
|
+
editor.image.showSizePopup();
|
|
171
|
+
return { editor, img };
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
it("should show a captioned image's width", async () => {
|
|
175
|
+
const { editor } = await captionedAt40();
|
|
176
|
+
|
|
177
|
+
expect(widthInput(editor).val()).toBe("40%");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("should size a captioned image through its caption only", async () => {
|
|
181
|
+
const { editor, img } = await captionedAt40();
|
|
182
|
+
|
|
183
|
+
widthInput(editor).val("30%");
|
|
184
|
+
editor.commands.exec("imageSetSize");
|
|
185
|
+
|
|
186
|
+
expect(caption(editor)?.style.width).toBe("30%");
|
|
187
|
+
expect(img.style.width).toBe("");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("should keep a captioned image's height on the image", async () => {
|
|
191
|
+
const { editor, img } = await captionedAt40();
|
|
192
|
+
|
|
193
|
+
editor.popups.get("image.size").find('input[name="height"]').val("200px");
|
|
194
|
+
editor.commands.exec("imageSetSize");
|
|
195
|
+
|
|
196
|
+
expect(img.style.height).toBe("200px");
|
|
197
|
+
expect(caption(editor)?.style.height).toBe("");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("should keep the size set in the popup when it is opened again and when the caption goes", async () => {
|
|
201
|
+
const { editor, img } = await captionedAt40();
|
|
202
|
+
const heightInput = () => editor.popups.get("image.size").find('input[name="height"]');
|
|
203
|
+
|
|
204
|
+
widthInput(editor).val("30%");
|
|
205
|
+
heightInput().val("200px");
|
|
206
|
+
editor.commands.exec("imageSetSize");
|
|
207
|
+
editor.image.edit(editor.$(img));
|
|
208
|
+
editor.image.showSizePopup();
|
|
209
|
+
|
|
210
|
+
expect(widthInput(editor).val()).toBe("30%");
|
|
211
|
+
expect(heightInput().val()).toBe("200px");
|
|
212
|
+
|
|
213
|
+
toggleCaption(editor, img);
|
|
214
|
+
|
|
215
|
+
expect(caption(editor)).toBeNull();
|
|
216
|
+
expect(img.style.width).toBe("30%");
|
|
217
|
+
expect(img.style.height).toBe("200px");
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
162
221
|
describe("when resizing a captioned image", () => {
|
|
163
222
|
// jsdom has no layout: the column is 600px, and the caption, with the
|
|
164
223
|
// paragraph and image inside it, takes the share its style asks for
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { pages } from "@ax/api";
|
|
2
|
+
import { pageEditorActions } from "@ax/containers/PageEditor";
|
|
3
|
+
import type { PageAccessGrantsSummary } from "@ax/types";
|
|
4
|
+
|
|
5
|
+
const SITE = 7;
|
|
6
|
+
const PAGE = 100;
|
|
7
|
+
const DRAFT = 213;
|
|
8
|
+
|
|
9
|
+
const GRANTS: PageAccessGrantsSummary = { users: [42], roles: [] };
|
|
10
|
+
const GRANTS_IN_EDITOR: PageAccessGrantsSummary = { users: [7], roles: [] };
|
|
11
|
+
|
|
12
|
+
const editorContent = (id: number, draftFromPage: number | null) => ({
|
|
13
|
+
id,
|
|
14
|
+
draftFromPage,
|
|
15
|
+
accessGrants: GRANTS_IN_EDITOR,
|
|
16
|
+
header: null,
|
|
17
|
+
footer: null,
|
|
18
|
+
templateConfig: {},
|
|
19
|
+
template: { templateType: "BasicTemplate" },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("[UC-AX-restrict-page-access] Los accesos son de la página, no de la versión en edición", () => {
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const applyGrants = async (editing: { id: number; draftFromPage: number | null }) => {
|
|
28
|
+
const setPageAccessGrants = vi
|
|
29
|
+
.spyOn(pages, "setPageAccessGrants")
|
|
30
|
+
.mockResolvedValue({ status: 200, data: {} } as any);
|
|
31
|
+
const dispatch = vi.fn();
|
|
32
|
+
const getState = (() => ({
|
|
33
|
+
pageEditor: { editorContent: editorContent(editing.id, editing.draftFromPage) },
|
|
34
|
+
})) as any;
|
|
35
|
+
|
|
36
|
+
await pageEditorActions.updatePageAccessGrants({
|
|
37
|
+
siteID: SITE,
|
|
38
|
+
pageID: editing.id,
|
|
39
|
+
accessGrants: GRANTS,
|
|
40
|
+
})(dispatch, getState);
|
|
41
|
+
|
|
42
|
+
return setPageAccessGrants;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
it("AC8 · aplicar accesos editando un borrador los persiste sobre su página", async () => {
|
|
46
|
+
const fromDraft = await applyGrants({ id: DRAFT, draftFromPage: PAGE });
|
|
47
|
+
|
|
48
|
+
expect(fromDraft).toHaveBeenCalledWith({ siteID: SITE, pageID: PAGE, accessGrants: GRANTS });
|
|
49
|
+
|
|
50
|
+
// Y una página sin borrador de por medio se sigue direccionando a sí misma.
|
|
51
|
+
const fromPage = await applyGrants({ id: PAGE, draftFromPage: null });
|
|
52
|
+
|
|
53
|
+
expect(fromPage).toHaveBeenCalledWith({ siteID: SITE, pageID: PAGE, accessGrants: GRANTS });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("AC9 · el guardado normal de la versión en edición no reescribe los accesos", async () => {
|
|
57
|
+
const updatePage = vi
|
|
58
|
+
.spyOn(pages, "updatePage")
|
|
59
|
+
.mockResolvedValue({ status: 400, data: { message: "cortado a propósito" } } as any);
|
|
60
|
+
const dispatch = vi.fn();
|
|
61
|
+
const getState = (() => ({
|
|
62
|
+
pageEditor: {
|
|
63
|
+
selectedEditorID: 0,
|
|
64
|
+
isNewTranslation: false,
|
|
65
|
+
editorContent: editorContent(DRAFT, PAGE),
|
|
66
|
+
lastTimeout: null,
|
|
67
|
+
},
|
|
68
|
+
sites: { currentSiteInfo: { id: SITE } },
|
|
69
|
+
app: { lang: 1 },
|
|
70
|
+
})) as any;
|
|
71
|
+
|
|
72
|
+
await pageEditorActions.savePage({ setToast: vi.fn() })(dispatch, getState);
|
|
73
|
+
|
|
74
|
+
expect(updatePage).toHaveBeenCalled();
|
|
75
|
+
|
|
76
|
+
const [, body] = updatePage.mock.calls[0];
|
|
77
|
+
|
|
78
|
+
expect(body).not.toHaveProperty("accessGrants");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("una página nueva sí nace con los accesos que se le hayan puesto", async () => {
|
|
82
|
+
const createPage = vi
|
|
83
|
+
.spyOn(pages, "createPage")
|
|
84
|
+
.mockResolvedValue({ status: 400, data: { message: "cortado a propósito" } } as any);
|
|
85
|
+
const dispatch = vi.fn();
|
|
86
|
+
const nuevaPagina = { ...editorContent(0, null), id: undefined };
|
|
87
|
+
const getState = (() => ({
|
|
88
|
+
pageEditor: {
|
|
89
|
+
selectedEditorID: 0,
|
|
90
|
+
isNewTranslation: false,
|
|
91
|
+
editorContent: nuevaPagina,
|
|
92
|
+
lastTimeout: null,
|
|
93
|
+
},
|
|
94
|
+
sites: { currentSiteInfo: { id: SITE } },
|
|
95
|
+
app: { lang: 1 },
|
|
96
|
+
})) as any;
|
|
97
|
+
|
|
98
|
+
await pageEditorActions.savePage({ setToast: vi.fn() })(dispatch, getState);
|
|
99
|
+
|
|
100
|
+
const [body] = createPage.mock.calls[0];
|
|
101
|
+
|
|
102
|
+
expect(body).toHaveProperty("accessGrants", GRANTS_IN_EDITOR);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { pages } from "@ax/api";
|
|
2
|
+
import { pageEditorActions } from "@ax/containers/PageEditor";
|
|
3
|
+
import { PAGE_EDIT_FORBIDDEN_MESSAGE } from "@ax/containers/PageEditor/constants";
|
|
4
|
+
|
|
5
|
+
// A save rejected by the page whitelist (403 since sc-119240) shows a permission message, not the
|
|
6
|
+
// raw API error text.
|
|
7
|
+
const getState = (() => ({
|
|
8
|
+
pageEditor: {
|
|
9
|
+
selectedEditorID: 0,
|
|
10
|
+
isNewTranslation: false,
|
|
11
|
+
editorContent: {
|
|
12
|
+
id: 100,
|
|
13
|
+
draftFromPage: null,
|
|
14
|
+
header: null,
|
|
15
|
+
footer: null,
|
|
16
|
+
templateConfig: {},
|
|
17
|
+
template: { templateType: "BasicTemplate" },
|
|
18
|
+
},
|
|
19
|
+
lastTimeout: null,
|
|
20
|
+
},
|
|
21
|
+
sites: { currentSiteInfo: { id: 7 } },
|
|
22
|
+
app: { lang: 1 },
|
|
23
|
+
})) as any;
|
|
24
|
+
|
|
25
|
+
describe("[UC-AX-save-validate-page] savePage rejected by permissions", () => {
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
vi.restoreAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("AC7 · a 403 shows the permission message", async () => {
|
|
31
|
+
vi.spyOn(pages, "updatePage").mockResolvedValue({
|
|
32
|
+
status: 403,
|
|
33
|
+
data: { code: 403, message: "[ForbiddenError] Cannot update page #100" },
|
|
34
|
+
} as any);
|
|
35
|
+
const setToast = vi.fn();
|
|
36
|
+
|
|
37
|
+
const saved = await pageEditorActions.savePage({ setToast })(vi.fn(), getState);
|
|
38
|
+
|
|
39
|
+
expect(saved).toBe(false);
|
|
40
|
+
expect(setToast).toHaveBeenCalledWith(PAGE_EDIT_FORBIDDEN_MESSAGE);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("AC7 · a 403 from a role permission check (no [ForbiddenError]) keeps the API message", async () => {
|
|
44
|
+
vi.spyOn(pages, "updatePage").mockResolvedValue({
|
|
45
|
+
status: 403,
|
|
46
|
+
data: { code: 403, message: "You don't have enough permissions to edit this type of page." },
|
|
47
|
+
} as any);
|
|
48
|
+
const setToast = vi.fn();
|
|
49
|
+
|
|
50
|
+
await pageEditorActions.savePage({ setToast })(vi.fn(), getState);
|
|
51
|
+
|
|
52
|
+
expect(setToast).toHaveBeenCalledWith("You don't have enough permissions to edit this type of page.");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("AC7 · any other error keeps the API message", async () => {
|
|
56
|
+
vi.spyOn(pages, "updatePage").mockResolvedValue({
|
|
57
|
+
status: 400,
|
|
58
|
+
data: { code: 400, message: "Slug already exists" },
|
|
59
|
+
} as any);
|
|
60
|
+
const setToast = vi.fn();
|
|
61
|
+
|
|
62
|
+
await pageEditorActions.savePage({ setToast })(vi.fn(), getState);
|
|
63
|
+
|
|
64
|
+
expect(setToast).toHaveBeenCalledWith("Slug already exists");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getValidity } from "@ax/forms";
|
|
2
|
+
|
|
3
|
+
describe("getValidity", () => {
|
|
4
|
+
describe("minValue", () => {
|
|
5
|
+
it("should accept the minimum itself", () => {
|
|
6
|
+
expect(getValidity({ minValue: 5 }, "5")).toEqual({ isValid: true, errorText: "" });
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should ask for at least the minimum when the value is below it", () => {
|
|
10
|
+
expect(getValidity({ minValue: 5 }, "3")).toEqual({
|
|
11
|
+
isValid: false,
|
|
12
|
+
errorText: "Please, enter a value of at least 5",
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should show a minimum of 0 in the message", () => {
|
|
17
|
+
expect(getValidity({ minValue: 0 }, "-1").errorText).toBe("Please, enter a value of at least 0");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("maxValue", () => {
|
|
22
|
+
it("should accept the maximum itself", () => {
|
|
23
|
+
expect(getValidity({ maxValue: 10 }, "10")).toEqual({ isValid: true, errorText: "" });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should ask for at most the maximum when the value is above it", () => {
|
|
27
|
+
expect(getValidity({ maxValue: 10 }, "12")).toEqual({
|
|
28
|
+
isValid: false,
|
|
29
|
+
errorText: "Please, enter a value of at most 10",
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should show a maximum of 0 in the message", () => {
|
|
34
|
+
expect(getValidity({ maxValue: 0 }, "1").errorText).toBe("Please, enter a value of at most 0");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -17,7 +17,7 @@ const TRACE = join(homedir(), ".claude", "gainup", "scripts", "gainup-trace.mjs"
|
|
|
17
17
|
|
|
18
18
|
// GAINUP se instala como plugin de Claude Code, y su ruta de instalación es versionada
|
|
19
19
|
// (…/plugins/cache/<marketplace>/gainup/<versión>/): el alias de arriba lo mantiene el hook
|
|
20
|
-
// SessionStart del plugin, porque este arnés corre desde `
|
|
20
|
+
// SessionStart del plugin, porque este arnés corre desde `pnpm` y no tiene ${CLAUDE_PLUGIN_ROOT}.
|
|
21
21
|
//
|
|
22
22
|
// «Sin instalar» es un estado legítimo y el guardián se salta. «Instalado pero sin resolver»
|
|
23
23
|
// no lo es: sería un verde por no haber validado nada — el verde falso contra el que está
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { NON_PROTECTED_PERMISSION_KEYS, PROTECTED_PERMISSION_KEYS } from "@ax/hooks";
|
|
2
|
+
|
|
3
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { join, relative } from "node:path";
|
|
5
|
+
|
|
6
|
+
// Contract between `usePermissionsForPage` and its callers (sc-119240): the page whitelist blocks the
|
|
7
|
+
// keys listed in PROTECTED_PERMISSION_KEYS by NAME. A caller that adds a key nobody classified would
|
|
8
|
+
// silently escape the whitelist (or be blocked by mistake), so every key must be classified, and every
|
|
9
|
+
// protected key must still be used by someone (a stale list is a mirror of the API that drifted).
|
|
10
|
+
const SRC = join(__dirname, "..", "..");
|
|
11
|
+
// The keys object is the first `{` after the call: site and page id arguments contain no braces.
|
|
12
|
+
const HOOK_CALL = /usePermissionsForPage\([^{]*?\{([\s\S]*?)\}/g;
|
|
13
|
+
const KEY = /^\s*(\w+)\s*:/gm;
|
|
14
|
+
|
|
15
|
+
const sourceFiles = (dir: string): string[] =>
|
|
16
|
+
readdirSync(dir).flatMap((name) => {
|
|
17
|
+
const path = join(dir, name);
|
|
18
|
+
|
|
19
|
+
if (name === "__tests__" || name === "node_modules") return [];
|
|
20
|
+
|
|
21
|
+
return statSync(path).isDirectory() ? sourceFiles(path) : /\.tsx?$/.test(name) ? [path] : [];
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const keysByCaller = sourceFiles(SRC).flatMap((file) =>
|
|
25
|
+
[...readFileSync(file, "utf8").matchAll(HOOK_CALL)].map((call) => ({
|
|
26
|
+
caller: relative(SRC, file),
|
|
27
|
+
keys: [...(call[1] ?? "").matchAll(KEY)].map((match) => match[1] as string),
|
|
28
|
+
})),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
describe("[UC-AX-restrict-page-access] usePermissionsForPage permission keys contract", () => {
|
|
32
|
+
it("finds the hook callers", () => {
|
|
33
|
+
expect(keysByCaller.length).toBeGreaterThanOrEqual(6);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("AC14 · every key used by a caller is classified as protected or not protected", () => {
|
|
37
|
+
const classified = new Set([...PROTECTED_PERMISSION_KEYS, ...NON_PROTECTED_PERMISSION_KEYS]);
|
|
38
|
+
const unclassified = keysByCaller.flatMap(({ caller, keys }) =>
|
|
39
|
+
keys.filter((key) => !classified.has(key)).map((key) => `${caller}: ${key}`),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(unclassified).toEqual([]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("AC14 · every protected key is still used by some caller", () => {
|
|
46
|
+
const used = new Set(keysByCaller.flatMap(({ keys }) => keys));
|
|
47
|
+
|
|
48
|
+
expect(PROTECTED_PERMISSION_KEYS.filter((key: string) => !used.has(key))).toEqual([]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { permissionsPageId } from "@ax/hooks";
|
|
2
|
+
|
|
3
|
+
// Page permissions (profile page list, whitelist) belong to the page, not to the version being edited:
|
|
4
|
+
// a draft is checked as its original page (sc-119240, rescue of 11dbbcd2bf).
|
|
5
|
+
describe("[UC-AX-restrict-page-access] permissionsPageId", () => {
|
|
6
|
+
it("AC15 · a draft is checked as its original page", () => {
|
|
7
|
+
expect(permissionsPageId({ draftFromPage: 100 }, 213)).toBe(100);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it.each([
|
|
11
|
+
["not a draft", { draftFromPage: null }],
|
|
12
|
+
["content without draftFromPage", {}],
|
|
13
|
+
["no content loaded yet", undefined],
|
|
14
|
+
])("AC15 · %s is checked as itself", (_label, editorContent) => {
|
|
15
|
+
expect(permissionsPageId(editorContent, 213)).toBe(213);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -163,7 +163,7 @@ describe("usePermissionsForPage hook", () => {
|
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
describe("5. Access grants", () => {
|
|
166
|
+
describe("[UC-AX-restrict-page-access] 5. Access grants", () => {
|
|
167
167
|
it("should allow access when no accessGrants are defined", () => {
|
|
168
168
|
setupMockState({ users: { currentUser: mockUser, roles: [mockRole] } });
|
|
169
169
|
|
|
@@ -172,7 +172,7 @@ describe("usePermissionsForPage hook", () => {
|
|
|
172
172
|
expect(result.current.edit).toBe(true);
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
it("should allow access when accessGrants is empty", () => {
|
|
175
|
+
it("AC12 · should allow access when accessGrants is empty", () => {
|
|
176
176
|
const emptyAccessGrants: PageAccessGrantsSummary = { users: [], roles: [] };
|
|
177
177
|
setupMockState({ users: { currentUser: mockUser, roles: [mockRole] } });
|
|
178
178
|
|
|
@@ -212,7 +212,7 @@ describe("usePermissionsForPage hook", () => {
|
|
|
212
212
|
expect(result.current.edit).toBe(false);
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
-
it("should
|
|
215
|
+
it("AC10 · should deny editing when the page is in pagePermissions but the whitelist excludes the user (sc-119240)", () => {
|
|
216
216
|
const userWithPagePerms = {
|
|
217
217
|
...mockUser,
|
|
218
218
|
pagePermissions: [{ siteId: 1, pageIds: [1] }],
|
|
@@ -220,18 +220,18 @@ describe("usePermissionsForPage hook", () => {
|
|
|
220
220
|
const accessGrants: PageAccessGrantsSummary = { users: [2, 3], roles: [2, 3] };
|
|
221
221
|
setupMockState({ users: { currentUser: userWithPagePerms, roles: [mockRole] } });
|
|
222
222
|
|
|
223
|
-
const { result } = renderHook(() => usePermissionsForPage(1, 1, {
|
|
223
|
+
const { result } = renderHook(() => usePermissionsForPage(1, 1, { editContentPages: "edit_page" }, accessGrants));
|
|
224
224
|
|
|
225
|
-
expect(result.current.
|
|
225
|
+
expect(result.current.editContentPages).toBe(false);
|
|
226
226
|
});
|
|
227
227
|
|
|
228
|
-
it("should
|
|
228
|
+
it("AC10 · should deny editing when user has no pagePermissions and is not in the whitelist (sc-119240)", () => {
|
|
229
229
|
const accessGrants: PageAccessGrantsSummary = { users: [2, 3], roles: [2, 3] };
|
|
230
230
|
setupMockState({ users: { currentUser: mockUser, roles: [mockRole] } });
|
|
231
231
|
|
|
232
|
-
const { result } = renderHook(() => usePermissionsForPage(1, 1, {
|
|
232
|
+
const { result } = renderHook(() => usePermissionsForPage(1, 1, { editContentPages: "edit_page" }, accessGrants));
|
|
233
233
|
|
|
234
|
-
expect(result.current.
|
|
234
|
+
expect(result.current.editContentPages).toBe(false);
|
|
235
235
|
});
|
|
236
236
|
|
|
237
237
|
it("should allow access when user is restricted by pagePermissions but in accessGrants for the page", () => {
|
|
@@ -423,4 +423,163 @@ describe("usePermissionsForPage hook", () => {
|
|
|
423
423
|
expect(result.current.edit).toBe(false);
|
|
424
424
|
});
|
|
425
425
|
});
|
|
426
|
+
|
|
427
|
+
describe("[UC-AX-restrict-page-access] 9. Page whitelist prevails on protected keys (sc-119240)", () => {
|
|
428
|
+
const EDIT = "content.editContentPages";
|
|
429
|
+
const PUBLISH = "content.publishUnpublishPages";
|
|
430
|
+
const DELETE = "content.deletePages";
|
|
431
|
+
const CREATE = "content.createPages";
|
|
432
|
+
const EXEMPTION = "general.setPermissionPerPage";
|
|
433
|
+
const GLOBAL_EXEMPTION = "global.globalData.setPermissionPerPage";
|
|
434
|
+
const GLOBAL_EDIT = "global.globalData.editAllGlobalData";
|
|
435
|
+
|
|
436
|
+
const role = (id: number, sitePermissions: string[], globalPermissions: string[] = []) => ({
|
|
437
|
+
id,
|
|
438
|
+
name: `role ${id}`,
|
|
439
|
+
permissions: {
|
|
440
|
+
sitePermissions: sitePermissions.map((key) => ({ key })),
|
|
441
|
+
globalPermissions: globalPermissions.map((key) => ({ key })),
|
|
442
|
+
},
|
|
443
|
+
});
|
|
444
|
+
const EDITOR = role(10, [EDIT, PUBLISH, DELETE, CREATE], [GLOBAL_EDIT]);
|
|
445
|
+
const REVIEWER = role(11, [EDIT]);
|
|
446
|
+
const ADMIN = role(12, [EDIT, PUBLISH, DELETE, CREATE, EXEMPTION], [GLOBAL_EDIT, GLOBAL_EXEMPTION]);
|
|
447
|
+
const ROLES = [EDITOR, REVIEWER, ADMIN];
|
|
448
|
+
const PAGE_KEYS = { editContentPages: EDIT, publishPages: PUBLISH, deletePages: DELETE, createPages: CREATE };
|
|
449
|
+
const ONLY_USER_7: PageAccessGrantsSummary = { users: [7], roles: [] };
|
|
450
|
+
|
|
451
|
+
const user = (id: number, roles: { siteId: number | "all" | "global"; roles: number[] }[], extra = {}) => ({
|
|
452
|
+
id,
|
|
453
|
+
email: `u${id}@test.com`,
|
|
454
|
+
isSuperAdmin: false,
|
|
455
|
+
roles,
|
|
456
|
+
pagePermissions: undefined,
|
|
457
|
+
...extra,
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
const permissionsOn = (
|
|
461
|
+
currentUser: unknown,
|
|
462
|
+
accessGrants: PageAccessGrantsSummary | undefined,
|
|
463
|
+
siteId: number | "global" = 1,
|
|
464
|
+
keys: Record<string, string> = PAGE_KEYS,
|
|
465
|
+
) => {
|
|
466
|
+
setupMockState({ users: { currentUser, roles: ROLES } });
|
|
467
|
+
|
|
468
|
+
return renderHook(() => usePermissionsForPage(siteId, 1, keys, accessGrants)).result.current;
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
it("AC10 · a site editor out of the whitelist cannot edit, publish nor delete, but can still create", () => {
|
|
472
|
+
const result = permissionsOn(user(9, [{ siteId: 1, roles: [10] }]), ONLY_USER_7);
|
|
473
|
+
|
|
474
|
+
expect(result).toEqual({ editContentPages: false, publishPages: false, deletePages: false, createPages: true });
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
it("AC11 · the user of the whitelist edits", () => {
|
|
478
|
+
expect(permissionsOn(user(7, [{ siteId: 1, roles: [10] }]), ONLY_USER_7).editContentPages).toBe(true);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("AC11 · whitelist ids sent as text still match", () => {
|
|
482
|
+
const asText = { users: ["7"], roles: [] } as unknown as PageAccessGrantsSummary;
|
|
483
|
+
|
|
484
|
+
expect(permissionsOn(user(7, [{ siteId: 1, roles: [10] }]), asText).editContentPages).toBe(true);
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it("AC11 · a role of the whitelist in the page's site edits", () => {
|
|
488
|
+
const result = permissionsOn(user(9, [{ siteId: 1, roles: [10, 11] }]), { users: [], roles: [11] });
|
|
489
|
+
|
|
490
|
+
expect(result.editContentPages).toBe(true);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('AC11 · a role of the whitelist given in "all" counts', () => {
|
|
494
|
+
const result = permissionsOn(
|
|
495
|
+
user(9, [
|
|
496
|
+
{ siteId: 1, roles: [10] },
|
|
497
|
+
{ siteId: "all", roles: [11] },
|
|
498
|
+
]),
|
|
499
|
+
{ users: [], roles: [11] },
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
expect(result.editContentPages).toBe(true);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("AC11 · a role of the whitelist in another site does not count", () => {
|
|
506
|
+
const result = permissionsOn(
|
|
507
|
+
user(9, [
|
|
508
|
+
{ siteId: 1, roles: [10] },
|
|
509
|
+
{ siteId: 2, roles: [11] },
|
|
510
|
+
]),
|
|
511
|
+
{ users: [], roles: [11] },
|
|
512
|
+
);
|
|
513
|
+
|
|
514
|
+
expect(result.editContentPages).toBe(false);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it("AC12 · an empty whitelist restricts nobody", () => {
|
|
518
|
+
const result = permissionsOn(user(9, [{ siteId: 1, roles: [10] }]), { users: [], roles: [] });
|
|
519
|
+
|
|
520
|
+
expect(result.editContentPages).toBe(true);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it('AC11 · roles of the site and of "all" are joined for the permissions too', () => {
|
|
524
|
+
const result = permissionsOn(
|
|
525
|
+
user(9, [
|
|
526
|
+
{ siteId: 1, roles: [11] },
|
|
527
|
+
{ siteId: "all", roles: [10] },
|
|
528
|
+
]),
|
|
529
|
+
undefined,
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
expect(result.deletePages).toBe(true);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
describe("exemption by setPermissionPerPage (Administrator)", () => {
|
|
536
|
+
it("AC13 · an exempt user in the page's site edits a page whose whitelist excludes them", () => {
|
|
537
|
+
expect(permissionsOn(user(9, [{ siteId: 1, roles: [12] }]), ONLY_USER_7).editContentPages).toBe(true);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it('AC13 · the exemption given in "all" counts on a site page', () => {
|
|
541
|
+
expect(permissionsOn(user(9, [{ siteId: "all", roles: [12] }]), ONLY_USER_7).editContentPages).toBe(true);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("AC13 · the exemption only counts in its own site", () => {
|
|
545
|
+
const result = permissionsOn(
|
|
546
|
+
user(9, [
|
|
547
|
+
{ siteId: 1, roles: [10] },
|
|
548
|
+
{ siteId: 2, roles: [12] },
|
|
549
|
+
]),
|
|
550
|
+
ONLY_USER_7,
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
expect(result.editContentPages).toBe(false);
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("AC13 · an exempt user with other pages in their profile is still limited to them", () => {
|
|
557
|
+
const result = permissionsOn(
|
|
558
|
+
user(9, [{ siteId: 1, roles: [12] }], { pagePermissions: [{ siteId: 1, pageIds: [2] }] }),
|
|
559
|
+
ONLY_USER_7,
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
expect(result.editContentPages).toBe(false);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("AC13 · on a global page only the global-scope exemption counts", () => {
|
|
566
|
+
const keys = { editContentPages: GLOBAL_EDIT };
|
|
567
|
+
|
|
568
|
+
expect(permissionsOn(user(9, [{ siteId: "global", roles: [12] }]), ONLY_USER_7, "global", keys)).toEqual({
|
|
569
|
+
editContentPages: true,
|
|
570
|
+
});
|
|
571
|
+
expect(
|
|
572
|
+
permissionsOn(
|
|
573
|
+
user(9, [
|
|
574
|
+
{ siteId: "global", roles: [10] },
|
|
575
|
+
{ siteId: "all", roles: [12] },
|
|
576
|
+
]),
|
|
577
|
+
ONLY_USER_7,
|
|
578
|
+
"global",
|
|
579
|
+
keys,
|
|
580
|
+
),
|
|
581
|
+
).toEqual({ editContentPages: false });
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
});
|
|
426
585
|
});
|
|
@@ -52,6 +52,7 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
52
52
|
} | null>(null);
|
|
53
53
|
const replaceImgRef = useRef<any>(null);
|
|
54
54
|
const captionWidthRef = useRef<any>(null);
|
|
55
|
+
const uncaptionedHeightRef = useRef<{ img: HTMLElement; height: string } | null>(null);
|
|
55
56
|
const liftedCaptionRef = useRef<{ paragraph: HTMLElement; nodes: ChildNode[] } | null>(null);
|
|
56
57
|
const lastValueRef = useRef(value);
|
|
57
58
|
|
|
@@ -231,6 +232,14 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
231
232
|
},
|
|
232
233
|
true,
|
|
233
234
|
);
|
|
235
|
+
|
|
236
|
+
// A captioned image keeps its width on the caption, but Froala's size
|
|
237
|
+
// popup only reads the image's own: show the caption's instead of auto.
|
|
238
|
+
this.popups.onRefresh("image.size", () => {
|
|
239
|
+
const caption = this.image.get()?.get(0)?.closest(".fr-img-caption");
|
|
240
|
+
if (!caption?.style.width) return;
|
|
241
|
+
this.popups.get("image.size").find('input[name="width"]').val(caption.style.width).trigger("change");
|
|
242
|
+
});
|
|
234
243
|
}
|
|
235
244
|
|
|
236
245
|
editorEl.addEventListener("griddo:openLinkPopover", (e: Event) => {
|
|
@@ -348,6 +357,12 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
348
357
|
if (seeded) $sized.attr("width", width);
|
|
349
358
|
captionWidthRef.current = { img, width, $seeded: seeded ? $sized : null };
|
|
350
359
|
}
|
|
360
|
+
// Removing the caption hands the image the caption's style in place of
|
|
361
|
+
// its own, and the height lives on the image: keep it.
|
|
362
|
+
if (cmd === "imageCaption" && this.opts.imageResizeWithPercent && this.image.hasCaption()) {
|
|
363
|
+
const img = this.image.get()?.get(0);
|
|
364
|
+
if (img?.style.height) uncaptionedHeightRef.current = { img, height: img.style.height };
|
|
365
|
+
}
|
|
351
366
|
},
|
|
352
367
|
"commands.after": function (this: any, cmd: string) {
|
|
353
368
|
if (cmd === "fullscreen" && !this.fullscreen.isActive()) {
|
|
@@ -362,6 +377,24 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
362
377
|
if (!img.getAttribute("style")) img.removeAttribute("style");
|
|
363
378
|
captionWidthRef.current = null;
|
|
364
379
|
}
|
|
380
|
+
if (cmd === "imageCaption" && uncaptionedHeightRef.current) {
|
|
381
|
+
const { img, height } = uncaptionedHeightRef.current;
|
|
382
|
+
img.style.height = height;
|
|
383
|
+
uncaptionedHeightRef.current = null;
|
|
384
|
+
}
|
|
385
|
+
// The size popup sets the width and height on the caption and on the
|
|
386
|
+
// image inside it, so the size is applied twice: in percent the widths
|
|
387
|
+
// multiply, and a fixed height on the caption leaves no room for its
|
|
388
|
+
// text. Keep the width on the caption and the height on the image.
|
|
389
|
+
if (cmd === "imageSetSize" && this.opts.imageResizeWithPercent && this.image.hasCaption()) {
|
|
390
|
+
const img = this.image.get()?.get(0);
|
|
391
|
+
const caption = img?.closest(".fr-img-caption");
|
|
392
|
+
img?.style.removeProperty("width");
|
|
393
|
+
caption?.style.removeProperty("height");
|
|
394
|
+
for (const el of [img, caption]) {
|
|
395
|
+
if (el && !el.getAttribute("style")) el.removeAttribute("style");
|
|
396
|
+
}
|
|
397
|
+
}
|
|
365
398
|
},
|
|
366
399
|
"image.resizeEnd": () => {
|
|
367
400
|
const lifted = liftedCaptionRef.current;
|
|
@@ -57,6 +57,7 @@ import type {
|
|
|
57
57
|
import type { Dispatch } from "redux";
|
|
58
58
|
|
|
59
59
|
import {
|
|
60
|
+
PAGE_EDIT_FORBIDDEN_MESSAGE,
|
|
60
61
|
RESET_PAGE_EDITOR_STORE,
|
|
61
62
|
SET_BREADCRUMB,
|
|
62
63
|
SET_COPY_MODULE,
|
|
@@ -465,6 +466,13 @@ function savePage(data?: {
|
|
|
465
466
|
delete values.language;
|
|
466
467
|
}
|
|
467
468
|
|
|
469
|
+
// Los accesos son de la página, no de la versión que se guarda: el panel de
|
|
470
|
+
// restricciones tiene su propio endpoint y un borrador los hereda de su
|
|
471
|
+
// original, así que solo una página nueva o una traducción nacen con ellos.
|
|
472
|
+
if (!isNewPage && !isNewTranslation) {
|
|
473
|
+
delete values.accessGrants;
|
|
474
|
+
}
|
|
475
|
+
|
|
468
476
|
if (createDraft) {
|
|
469
477
|
values.draftFromPage = values.id;
|
|
470
478
|
delete values.id;
|
|
@@ -519,10 +527,16 @@ function savePage(data?: {
|
|
|
519
527
|
dispatch(setIsSaving(false));
|
|
520
528
|
return true;
|
|
521
529
|
} else {
|
|
530
|
+
// A 403 from the page policy ([ForbiddenError], the page whitelist) gets the permission message;
|
|
531
|
+
// any other 403 (legacy role permission checks also answer 403) keeps the API text.
|
|
532
|
+
const isWhitelistRejection =
|
|
533
|
+
saveResponse.status === 403 && String(saveResponse.data?.message ?? "").includes("[ForbiddenError]");
|
|
534
|
+
const errorMessage = isWhitelistRejection ? PAGE_EDIT_FORBIDDEN_MESSAGE : saveResponse.data.message;
|
|
535
|
+
|
|
522
536
|
if (typeof setToast === "function") {
|
|
523
|
-
setToast(
|
|
537
|
+
setToast(errorMessage);
|
|
524
538
|
} else {
|
|
525
|
-
appActions.handleError(saveResponse)(dispatch);
|
|
539
|
+
appActions.handleError(saveResponse, false, errorMessage)(dispatch);
|
|
526
540
|
}
|
|
527
541
|
dispatch(setIsSaving(false));
|
|
528
542
|
return false;
|
|
@@ -1659,6 +1673,11 @@ function schedulePublication(
|
|
|
1659
1673
|
};
|
|
1660
1674
|
}
|
|
1661
1675
|
|
|
1676
|
+
/**
|
|
1677
|
+
* Persiste los accesos por página. Los accesos son una propiedad de la página, no de
|
|
1678
|
+
* la versión que se esté editando: desde un borrador se aplican sobre su página
|
|
1679
|
+
* original. Sin `pageID` (página aún sin crear) solo actualiza el estado local.
|
|
1680
|
+
*/
|
|
1662
1681
|
function updatePageAccessGrants(data: {
|
|
1663
1682
|
siteID: number | "global";
|
|
1664
1683
|
pageID: number | null;
|
|
@@ -1672,6 +1691,12 @@ function updatePageAccessGrants(data: {
|
|
|
1672
1691
|
return true;
|
|
1673
1692
|
}
|
|
1674
1693
|
|
|
1694
|
+
const {
|
|
1695
|
+
pageEditor: { editorContent },
|
|
1696
|
+
} = getState();
|
|
1697
|
+
|
|
1698
|
+
const ownerPageID: number = (editorContent as IPage).draftFromPage ?? data.pageID;
|
|
1699
|
+
|
|
1675
1700
|
const responseActions = {
|
|
1676
1701
|
handleSuccess: () => {
|
|
1677
1702
|
dispatch(setPageAccessGrants(data.accessGrants));
|
|
@@ -1679,11 +1704,7 @@ function updatePageAccessGrants(data: {
|
|
|
1679
1704
|
handleError: (response: any) => appActions.handleError(response)(dispatch),
|
|
1680
1705
|
};
|
|
1681
1706
|
|
|
1682
|
-
const callback = async () => {
|
|
1683
|
-
if (data.pageID) {
|
|
1684
|
-
return await pages.setPageAccessGrants({ ...data, pageID: data.pageID });
|
|
1685
|
-
}
|
|
1686
|
-
};
|
|
1707
|
+
const callback = async () => await pages.setPageAccessGrants({ ...data, pageID: ownerPageID });
|
|
1687
1708
|
|
|
1688
1709
|
return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
|
|
1689
1710
|
} catch (e) {
|
|
@@ -1694,59 +1715,59 @@ function updatePageAccessGrants(data: {
|
|
|
1694
1715
|
}
|
|
1695
1716
|
|
|
1696
1717
|
export {
|
|
1697
|
-
setEditorContent,
|
|
1698
|
-
setTemplate,
|
|
1699
|
-
setBreadcrumb,
|
|
1700
|
-
setSchema,
|
|
1701
|
-
setSelectedPageContent,
|
|
1702
|
-
setSelectedEditorID,
|
|
1703
|
-
setTab,
|
|
1704
|
-
setCurrentPageID,
|
|
1705
|
-
setCurrentPageStatus,
|
|
1706
|
-
setCurrentPageName,
|
|
1707
|
-
setCurrentPageLanguages,
|
|
1708
|
-
setIsNewTranslation,
|
|
1709
|
-
createNewTranslation,
|
|
1710
|
-
getPageBreadcrumb,
|
|
1711
|
-
getPage,
|
|
1712
|
-
savePage,
|
|
1713
|
-
deletePage,
|
|
1714
|
-
updatePageStatus,
|
|
1715
|
-
getPageLanguages,
|
|
1716
|
-
addTemplate,
|
|
1717
1718
|
addComponent,
|
|
1719
|
+
addComponentInArray,
|
|
1718
1720
|
addModule,
|
|
1721
|
+
addTemplate,
|
|
1722
|
+
copyModule,
|
|
1723
|
+
createNewTranslation,
|
|
1724
|
+
deleteBulk,
|
|
1725
|
+
deleteError,
|
|
1719
1726
|
deleteModule,
|
|
1720
|
-
|
|
1727
|
+
deletePage,
|
|
1728
|
+
discardDraft,
|
|
1721
1729
|
duplicateModule,
|
|
1722
|
-
replaceElementsInCollection,
|
|
1723
|
-
overwriteHeaderConfig,
|
|
1724
|
-
generatePageContent,
|
|
1725
|
-
updateEditorContent,
|
|
1726
|
-
setSelectedContent,
|
|
1727
|
-
setSelectedTab,
|
|
1728
|
-
resetPageEditor,
|
|
1729
|
-
moveElement,
|
|
1730
|
-
deleteBulk,
|
|
1731
1730
|
duplicatePage,
|
|
1732
|
-
|
|
1733
|
-
deleteError,
|
|
1734
|
-
restorePage,
|
|
1731
|
+
generatePageContent,
|
|
1735
1732
|
getGlobalFromLocalPage,
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1733
|
+
getPage,
|
|
1734
|
+
getPageBreadcrumb,
|
|
1735
|
+
getPageLanguages,
|
|
1736
|
+
getPageRetranslation,
|
|
1737
|
+
getPageSummary,
|
|
1738
|
+
getPageTranslation,
|
|
1739
1739
|
getTemplatePage,
|
|
1740
|
-
|
|
1740
|
+
moveElement,
|
|
1741
|
+
overwriteHeaderConfig,
|
|
1741
1742
|
pasteModule,
|
|
1742
1743
|
removeNavigationFromPage,
|
|
1744
|
+
replaceElementsInCollection,
|
|
1745
|
+
replaceModule,
|
|
1746
|
+
replaceModuleInArray,
|
|
1747
|
+
resetPageEditor,
|
|
1748
|
+
restorePage,
|
|
1743
1749
|
restorePageNavigation,
|
|
1744
|
-
|
|
1745
|
-
getPageTranslation,
|
|
1746
|
-
getPageRetranslation,
|
|
1750
|
+
savePage,
|
|
1747
1751
|
schedulePublication,
|
|
1752
|
+
sendPagePing,
|
|
1753
|
+
setBreadcrumb,
|
|
1754
|
+
setCurrentPageID,
|
|
1755
|
+
setCurrentPageLanguages,
|
|
1756
|
+
setCurrentPageName,
|
|
1757
|
+
setCurrentPageStatus,
|
|
1758
|
+
setEditorContent,
|
|
1759
|
+
setIsNewTranslation,
|
|
1760
|
+
setSchema,
|
|
1748
1761
|
setScrollEditorID,
|
|
1749
|
-
|
|
1750
|
-
|
|
1762
|
+
setSelectedContent,
|
|
1763
|
+
setSelectedEditorID,
|
|
1764
|
+
setSelectedPageContent,
|
|
1765
|
+
setSelectedTab,
|
|
1766
|
+
setSitePageID,
|
|
1767
|
+
setTab,
|
|
1768
|
+
setTemplate,
|
|
1769
|
+
updateEditorContent,
|
|
1751
1770
|
updatePageAccessGrants,
|
|
1771
|
+
updatePageStatus,
|
|
1772
|
+
validatePage,
|
|
1752
1773
|
};
|
|
@@ -27,3 +27,7 @@ export const SET_PAGE_ACCESS_GRANTS = `${NAME}/SET_PAGE_ACCESS_GRANTS`;
|
|
|
27
27
|
|
|
28
28
|
export const INITIAL_TEMPLATE = "BasicTemplate";
|
|
29
29
|
export const MULTIMEDIA_COMPONENTS = ["LinkableImage", "Video"];
|
|
30
|
+
|
|
31
|
+
/** Shown when the API rejects a save with 403: the page is restricted to other users (sc-119240). */
|
|
32
|
+
export const PAGE_EDIT_FORBIDDEN_MESSAGE =
|
|
33
|
+
"You don't have permission to edit this page. Only the users allowed in its access settings can edit it.";
|
package/src/forms/errors.tsx
CHANGED
|
@@ -6,8 +6,8 @@ const ERRORS: Record<string, string> = {
|
|
|
6
6
|
ERR005: "Remember using this structure: http://website.com",
|
|
7
7
|
ERR006: "Remember using a valid URL format",
|
|
8
8
|
ERR007: "Mmm, that doesn't look like a phone to me.",
|
|
9
|
-
ERR008: "Please, enter a value
|
|
10
|
-
ERR009: "Please, enter a value
|
|
9
|
+
ERR008: "Please, enter a value of at least {value}",
|
|
10
|
+
ERR009: "Please, enter a value of at most {value}",
|
|
11
11
|
ERR010: "Please, enter a future date.",
|
|
12
12
|
ERR011: "Please, enter a past date.",
|
|
13
13
|
ERR012: "Please, enter at least {value} elements to look great.",
|
package/src/forms/validators.tsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
+
import { findByEditorID } from "@ax/forms";
|
|
1
2
|
import {
|
|
2
3
|
getDeactivatedModules,
|
|
3
4
|
getDefaultSchema,
|
|
5
|
+
getFormTemplate,
|
|
6
|
+
getRange,
|
|
4
7
|
getSchema,
|
|
5
8
|
getTemplate,
|
|
6
9
|
hasProps,
|
|
10
|
+
isComponentEmpty,
|
|
7
11
|
isEmptyContainer,
|
|
12
|
+
isEmptyObj,
|
|
8
13
|
isModuleDisabled,
|
|
9
|
-
getRange,
|
|
10
14
|
isValidDate,
|
|
11
15
|
isValidDateRange,
|
|
12
16
|
stringToDate,
|
|
13
|
-
isEmptyObj,
|
|
14
17
|
stripHtml,
|
|
15
|
-
getFormTemplate,
|
|
16
|
-
isComponentEmpty,
|
|
17
18
|
} from "@ax/helpers";
|
|
18
|
-
|
|
19
|
-
import { findByEditorID } from "@ax/forms";
|
|
20
19
|
import type { IErrorItem, ISchemaField, ITemplate } from "@ax/types";
|
|
20
|
+
|
|
21
21
|
import { ERRORS } from "./errors";
|
|
22
22
|
|
|
23
23
|
const VALIDATORS = {
|
|
@@ -123,7 +123,7 @@ const VALIDATORS = {
|
|
|
123
123
|
|
|
124
124
|
const getErrorMessage = (key: string, val: number | string | null): string => {
|
|
125
125
|
const error: string = ERRORS[key];
|
|
126
|
-
if (val) {
|
|
126
|
+
if (val || val === 0) {
|
|
127
127
|
return error.replace("{value}", val.toString());
|
|
128
128
|
}
|
|
129
129
|
return error;
|
|
@@ -307,7 +307,9 @@ const getValidationErrors = (
|
|
|
307
307
|
if (field.type === "ConditionalField") {
|
|
308
308
|
innerFields = field.fields.filter((f) => f.condition === undefined || f.condition === current[field.key]);
|
|
309
309
|
const hiddenFields = field.fields.filter((f) => f.condition !== current[field.key]);
|
|
310
|
-
hiddenFields.forEach((field) =>
|
|
310
|
+
hiddenFields.forEach((field) => {
|
|
311
|
+
delete current[field.key];
|
|
312
|
+
});
|
|
311
313
|
}
|
|
312
314
|
|
|
313
315
|
const innerErrors = getValidationErrors(innerFields, current, name, tab, template, isFormInPage);
|
|
@@ -512,11 +514,11 @@ interface IError {
|
|
|
512
514
|
}
|
|
513
515
|
|
|
514
516
|
export {
|
|
515
|
-
|
|
516
|
-
isTemplateActivated,
|
|
517
|
-
findPackagesActivationErrors,
|
|
517
|
+
checkH1content,
|
|
518
518
|
findFieldsErrors,
|
|
519
519
|
findMandatoryStructuredDataErrors,
|
|
520
|
-
|
|
520
|
+
findPackagesActivationErrors,
|
|
521
|
+
getValidity,
|
|
522
|
+
isTemplateActivated,
|
|
521
523
|
parseValidationErrors,
|
|
522
524
|
};
|
package/src/hooks/index.tsx
CHANGED
|
@@ -33,6 +33,9 @@ import {
|
|
|
33
33
|
useUndoRedoShortcuts,
|
|
34
34
|
} from "./shortcuts";
|
|
35
35
|
import {
|
|
36
|
+
NON_PROTECTED_PERMISSION_KEYS,
|
|
37
|
+
PROTECTED_PERMISSION_KEYS,
|
|
38
|
+
permissionsPageId,
|
|
36
39
|
useGlobalPermission,
|
|
37
40
|
usePermission,
|
|
38
41
|
usePermissions,
|
|
@@ -42,14 +45,22 @@ import {
|
|
|
42
45
|
import { useFirefoxScrollLock, useWindowSize } from "./window";
|
|
43
46
|
|
|
44
47
|
export {
|
|
48
|
+
type IBulkSelectedItems,
|
|
49
|
+
type KeyCombo,
|
|
50
|
+
type ModifierKey,
|
|
51
|
+
NON_PROTECTED_PERMISSION_KEYS,
|
|
52
|
+
PROTECTED_PERMISSION_KEYS,
|
|
45
53
|
parseShortcut,
|
|
54
|
+
permissionsPageId,
|
|
55
|
+
type ShortcutConfig,
|
|
46
56
|
shortcut,
|
|
47
57
|
shortcutEngine,
|
|
58
|
+
type UseShortcutsOptions,
|
|
48
59
|
useAdaptiveText,
|
|
49
60
|
useBroadcastChannel,
|
|
50
61
|
useBroadcastClipboard,
|
|
51
|
-
useBroadcastLogout,
|
|
52
62
|
useBroadcastContentUpdate,
|
|
63
|
+
useBroadcastLogout,
|
|
53
64
|
useBulkSelection,
|
|
54
65
|
useCategoryColors,
|
|
55
66
|
useContextMenu,
|
|
@@ -85,9 +96,4 @@ export {
|
|
|
85
96
|
useUndoRedoShortcuts,
|
|
86
97
|
useURLSearchParam,
|
|
87
98
|
useWindowSize,
|
|
88
|
-
type IBulkSelectedItems,
|
|
89
|
-
type KeyCombo,
|
|
90
|
-
type ModifierKey,
|
|
91
|
-
type ShortcutConfig,
|
|
92
|
-
type UseShortcutsOptions,
|
|
93
99
|
};
|
package/src/hooks/users.tsx
CHANGED
|
@@ -146,6 +146,43 @@ const usePermissionsForSite = <T extends Record<string, string | string[]>>(
|
|
|
146
146
|
}, [siteId, permissions, currentUser, roles, isSuperAdmin]);
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Permission keys (as callers of {@link usePermissionsForPage} name them) that a page whitelist
|
|
151
|
+
* blocks for users not in it. Mirror of the API's `PROTECTED_ACTIONS` (update / delete / publish
|
|
152
|
+
* in `PagePolicy`): edit, publish and delete.
|
|
153
|
+
*/
|
|
154
|
+
export const PROTECTED_PERMISSION_KEYS: readonly string[] = [
|
|
155
|
+
"editContentPages",
|
|
156
|
+
"editPages",
|
|
157
|
+
"publishPages",
|
|
158
|
+
"publishUnpublishPages",
|
|
159
|
+
"deletePages",
|
|
160
|
+
"deletePublishedPages",
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
/** Permission keys a page whitelist does NOT block (creating, duplicating, managing restrictions…). */
|
|
164
|
+
export const NON_PROTECTED_PERMISSION_KEYS: readonly string[] = [
|
|
165
|
+
"createPages",
|
|
166
|
+
"duplicatePages",
|
|
167
|
+
"copyPageInOtherSite",
|
|
168
|
+
"setPagePermissions",
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Page id to check page permissions against: a draft is checked as its original page, because the
|
|
173
|
+
* profile page list and the page whitelist belong to the page, not to the version being edited.
|
|
174
|
+
*/
|
|
175
|
+
export const permissionsPageId = (
|
|
176
|
+
editorContent: { draftFromPage?: number | null } | null | undefined,
|
|
177
|
+
pageID: number,
|
|
178
|
+
): number => editorContent?.draftFromPage ?? pageID;
|
|
179
|
+
|
|
180
|
+
/** Permission that exempts from a page whitelist, by scope. Same rule as the API's `Subject.isExemptFromPageWhitelist`. */
|
|
181
|
+
const WHITELIST_EXEMPTION_PERMISSION = {
|
|
182
|
+
site: "general.setPermissionPerPage",
|
|
183
|
+
global: "global.globalData.setPermissionPerPage",
|
|
184
|
+
} as const;
|
|
185
|
+
|
|
149
186
|
const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
150
187
|
siteId: number | string,
|
|
151
188
|
pageId: number,
|
|
@@ -174,9 +211,19 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
174
211
|
return createPermissionResult(true);
|
|
175
212
|
}
|
|
176
213
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
214
|
+
// Roles of the page's site plus the "all" ones (same union as the API's `rolesFor`).
|
|
215
|
+
const userRoles = [
|
|
216
|
+
...new Set(
|
|
217
|
+
currentUser.roles
|
|
218
|
+
.filter((roleSite) => roleSite.siteId === siteId || roleSite.siteId === "all")
|
|
219
|
+
.flatMap((roleSite) => roleSite.roles),
|
|
220
|
+
),
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
// Ids may come as text from the API: compare as numbers.
|
|
224
|
+
const isInWhitelist = (grants: PageAccessGrantsSummary) =>
|
|
225
|
+
(grants.users ?? []).map(Number).includes(Number(currentUser.id)) ||
|
|
226
|
+
userRoles.some((roleId) => (grants.roles ?? []).map(Number).includes(roleId));
|
|
180
227
|
|
|
181
228
|
// Check if pageId is part of a translation group in pageLanguages
|
|
182
229
|
// If yes, user can access it if they have access to ANY translation
|
|
@@ -251,9 +298,7 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
251
298
|
const pageHasAccessGrants = accessGrants?.users?.length || accessGrants?.roles?.length;
|
|
252
299
|
|
|
253
300
|
if (pageHasAccessGrants) {
|
|
254
|
-
const hasAccessGrantsAccess =
|
|
255
|
-
accessGrants.users?.includes(currentUser.id || -1) ||
|
|
256
|
-
userRoles?.some((roleId) => accessGrants.roles?.includes(roleId));
|
|
301
|
+
const hasAccessGrantsAccess = isInWhitelist(accessGrants);
|
|
257
302
|
|
|
258
303
|
if (!hasAccessGrantsAccess) {
|
|
259
304
|
return createPermissionResult(false);
|
|
@@ -269,6 +314,31 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
269
314
|
}
|
|
270
315
|
|
|
271
316
|
const roleMap = new Map(roles?.map((r) => [r.id, r]) || []);
|
|
317
|
+
|
|
318
|
+
// A page whitelist prevails on edit / publish / delete, whatever the profile page list says:
|
|
319
|
+
// only its users or roles, or exempt users (SuperAdmin returned above, or setPermissionPerPage
|
|
320
|
+
// in the page's scope; on a global page only a global-scope role counts, "all" does not), pass.
|
|
321
|
+
const isExempt = (() => {
|
|
322
|
+
if (siteId === "global") {
|
|
323
|
+
const globalScopeRoles = currentUser.roles
|
|
324
|
+
.filter((roleSite) => roleSite.siteId === "global")
|
|
325
|
+
.flatMap((roleSite) => roleSite.roles);
|
|
326
|
+
|
|
327
|
+
return globalScopeRoles.some((roleID) =>
|
|
328
|
+
roleMap
|
|
329
|
+
.get(roleID)
|
|
330
|
+
?.permissions.globalPermissions.some((perm) => perm.key === WHITELIST_EXEMPTION_PERMISSION.global),
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return userRoles.some((roleID) =>
|
|
335
|
+
roleMap
|
|
336
|
+
.get(roleID)
|
|
337
|
+
?.permissions.sitePermissions.some((perm) => perm.key === WHITELIST_EXEMPTION_PERMISSION.site),
|
|
338
|
+
);
|
|
339
|
+
})();
|
|
340
|
+
const pageHasWhitelist = !!(accessGrants?.users?.length || accessGrants?.roles?.length);
|
|
341
|
+
const blockedByWhitelist = !!accessGrants && pageHasWhitelist && !isExempt && !isInWhitelist(accessGrants);
|
|
272
342
|
const sitePermissionsSet = new Set<string>();
|
|
273
343
|
|
|
274
344
|
userRoles.forEach((roleID: number) => {
|
|
@@ -283,6 +353,11 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
283
353
|
|
|
284
354
|
const result: Record<string, boolean> = {};
|
|
285
355
|
for (const key of Object.keys(permissions)) {
|
|
356
|
+
if (blockedByWhitelist && PROTECTED_PERMISSION_KEYS.includes(key)) {
|
|
357
|
+
result[key] = false;
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
|
|
286
361
|
const permission = permissions[key as keyof T];
|
|
287
362
|
const arrayPermission = Array.isArray(permission) ? permission : [permission];
|
|
288
363
|
result[key] = arrayPermission.some((perm: string) => sitePermissionsSet.has(perm));
|
|
@@ -292,10 +367,10 @@ const usePermissionsForPage = <T extends Record<string, string | string[]>>(
|
|
|
292
367
|
};
|
|
293
368
|
|
|
294
369
|
export {
|
|
295
|
-
|
|
370
|
+
useGlobalPermission,
|
|
296
371
|
usePermission,
|
|
297
372
|
usePermissions,
|
|
298
|
-
useGlobalPermission,
|
|
299
|
-
usePermissionsForSite,
|
|
300
373
|
usePermissionsForPage,
|
|
374
|
+
usePermissionsForSite,
|
|
375
|
+
useUserState,
|
|
301
376
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
|
|
3
|
-
import type { ExportFormat } from "@griddo/api-types";
|
|
4
|
-
import type { IModal } from "@ax/types";
|
|
5
3
|
import { FieldsBehavior, Modal } from "@ax/components";
|
|
4
|
+
import type { IModal } from "@ax/types";
|
|
5
|
+
|
|
6
|
+
import type { ExportFormat } from "@griddo/api-types";
|
|
7
|
+
|
|
6
8
|
import type { IDownloadFormState } from "..";
|
|
7
9
|
|
|
8
10
|
import * as S from "./style";
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { connect } from "react-redux";
|
|
3
|
-
import { format, subDays } from "date-fns";
|
|
4
3
|
|
|
5
|
-
import type { ExportFormat, LogActivityExportRequest, LogActivityPaginationRequest } from "@griddo/api-types";
|
|
6
|
-
import type { ILogItemsByDay, ILogItemsByUser, IQueryValue, IRootState, IStructuredData } from "@ax/types";
|
|
7
4
|
import { EmptyState, ErrorToast, FilterTagsBar, MainWrapper, SearchTagsBar, Select, TableList } from "@ax/components";
|
|
8
5
|
import { activityLogActions } from "@ax/containers/ActivityLog";
|
|
9
6
|
import { structuredDataActions } from "@ax/containers/StructuredData";
|
|
10
7
|
import { useModal } from "@ax/hooks";
|
|
8
|
+
import type { ILogItemsByDay, ILogItemsByUser, IQueryValue, IRootState, IStructuredData } from "@ax/types";
|
|
11
9
|
|
|
10
|
+
import type { ExportFormat, LogActivityExportRequest, LogActivityPaginationRequest } from "@griddo/api-types";
|
|
11
|
+
import { format, subDays } from "date-fns";
|
|
12
|
+
|
|
13
|
+
import DownloadModal from "./DownloadModal";
|
|
12
14
|
import { useFilterQuery } from "./hooks";
|
|
13
|
-
import TableHeader from "./TableHeader";
|
|
14
15
|
import ItemLog from "./ItemLog";
|
|
15
16
|
import ItemLogUser from "./ItemLogUser";
|
|
16
|
-
import
|
|
17
|
+
import TableHeader from "./TableHeader";
|
|
17
18
|
|
|
18
19
|
import * as S from "./style";
|
|
19
20
|
|
|
@@ -27,6 +27,7 @@ import { usersActions } from "@ax/containers/Users";
|
|
|
27
27
|
import { RouteLeavingGuard } from "@ax/guards";
|
|
28
28
|
import { dateToString, getDefaultTheme } from "@ax/helpers";
|
|
29
29
|
import {
|
|
30
|
+
permissionsPageId,
|
|
30
31
|
useBroadcastClipboard,
|
|
31
32
|
useBroadcastContentUpdate,
|
|
32
33
|
useEditingHeartbeat,
|
|
@@ -92,7 +93,7 @@ const GlobalEditor = (props: IProps) => {
|
|
|
92
93
|
|
|
93
94
|
const isAllowedTo = usePermissionsForPage(
|
|
94
95
|
"global",
|
|
95
|
-
pageID,
|
|
96
|
+
permissionsPageId(editorContent, pageID),
|
|
96
97
|
{
|
|
97
98
|
publishPages: "global.globalData.publishUnpublishAllGlobalData",
|
|
98
99
|
createPages: "global.globalData.createAllGlobalData",
|
|
@@ -25,6 +25,7 @@ import { dataPacksActions } from "@ax/containers/Settings/DataPacks";
|
|
|
25
25
|
import { RouteLeavingGuard } from "@ax/guards";
|
|
26
26
|
import { dateToString, getDeactivatedModules, isModuleDisabled } from "@ax/helpers";
|
|
27
27
|
import {
|
|
28
|
+
permissionsPageId,
|
|
28
29
|
useBroadcastClipboard,
|
|
29
30
|
useBroadcastContentUpdate,
|
|
30
31
|
useEditingHeartbeat,
|
|
@@ -95,7 +96,7 @@ const PageEditor = (props: IProps) => {
|
|
|
95
96
|
|
|
96
97
|
const isAllowedTo = usePermissionsForPage(
|
|
97
98
|
currentSiteInfo.id,
|
|
98
|
-
pageID,
|
|
99
|
+
permissionsPageId(editorContent, pageID),
|
|
99
100
|
{
|
|
100
101
|
publishPages: "content.publishUnpublishPages",
|
|
101
102
|
createPages: "content.createPages",
|