@griddo/ax 12.13.1 → 12.14.1
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 +381 -33
- package/src/__tests__/components/Fields/Wysiwyg/Wysiwyg.test.tsx +1 -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/helpers.tsx +188 -0
- package/src/components/Fields/Wysiwyg/index.tsx +97 -28
- package/src/components/Fields/Wysiwyg/style.tsx +5 -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
|
@@ -11,7 +11,17 @@ import FroalaEditor from "froala-editor";
|
|
|
11
11
|
|
|
12
12
|
import { LinkPopover } from "./atoms";
|
|
13
13
|
import { buttons, buttonsFull, inlineToolbar, wysiwygConfig } from "./config";
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
createPopupFunctions,
|
|
16
|
+
dropCaptionParagraph,
|
|
17
|
+
getImagePercentWidth,
|
|
18
|
+
getPopupPosition,
|
|
19
|
+
handleImageWrapKeys,
|
|
20
|
+
isolateImage,
|
|
21
|
+
removeImage,
|
|
22
|
+
setLinkAttributes,
|
|
23
|
+
takeTextOutOfCaption,
|
|
24
|
+
} from "./helpers";
|
|
15
25
|
import "./vendors";
|
|
16
26
|
|
|
17
27
|
import { useModals } from "@ax/hooks";
|
|
@@ -51,7 +61,9 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
51
61
|
isImageLink?: boolean;
|
|
52
62
|
} | null>(null);
|
|
53
63
|
const replaceImgRef = useRef<any>(null);
|
|
64
|
+
const captioningImgRef = useRef<HTMLElement | null>(null);
|
|
54
65
|
const captionWidthRef = useRef<any>(null);
|
|
66
|
+
const uncaptionedHeightRef = useRef<{ img: HTMLElement; height: string } | null>(null);
|
|
55
67
|
const liftedCaptionRef = useRef<{ paragraph: HTMLElement; nodes: ChildNode[] } | null>(null);
|
|
56
68
|
const lastValueRef = useRef(value);
|
|
57
69
|
|
|
@@ -212,12 +224,12 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
212
224
|
if (!editorEl) return;
|
|
213
225
|
|
|
214
226
|
// Froala resizes a percentage image against the nearest block around
|
|
215
|
-
// it, and
|
|
216
|
-
// every step of the drag measures against the width
|
|
217
|
-
// just set, and the image bounces. Lift the caption's
|
|
218
|
-
// that paragraph while dragging, so it measures against
|
|
219
|
-
// and put it back in "image.resizeEnd". Capturing runs it
|
|
220
|
-
// Froala's own mousedown on the handle.
|
|
227
|
+
// it, and in captions saved with a <p> inside (see dropCaptionParagraph)
|
|
228
|
+
// that is the <p>: every step of the drag measures against the width
|
|
229
|
+
// the step before just set, and the image bounces. Lift the caption's
|
|
230
|
+
// content out of that paragraph while dragging, so it measures against
|
|
231
|
+
// the column, and put it back in "image.resizeEnd". Capturing runs it
|
|
232
|
+
// before Froala's own mousedown on the handle.
|
|
221
233
|
if (this.opts.imageResizeWithPercent) {
|
|
222
234
|
this.$box?.get?.(0)?.addEventListener(
|
|
223
235
|
"mousedown",
|
|
@@ -231,8 +243,20 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
231
243
|
},
|
|
232
244
|
true,
|
|
233
245
|
);
|
|
246
|
+
|
|
247
|
+
// Captions saved before the image kept its width too have it on the
|
|
248
|
+
// caption alone, but Froala's size popup only reads the image's own:
|
|
249
|
+
// show the caption's instead of auto.
|
|
250
|
+
this.popups.onRefresh("image.size", () => {
|
|
251
|
+
const caption = this.image.get()?.get(0)?.closest(".fr-img-caption");
|
|
252
|
+
if (!caption?.style.width) return;
|
|
253
|
+
this.popups.get("image.size").find('input[name="width"]').val(caption.style.width).trigger("change");
|
|
254
|
+
});
|
|
234
255
|
}
|
|
235
256
|
|
|
257
|
+
// First, so it runs before Froala's own handling of these keys
|
|
258
|
+
this.events.on("keydown", (e: KeyboardEvent) => handleImageWrapKeys(this, e), true);
|
|
259
|
+
|
|
236
260
|
editorEl.addEventListener("griddo:openLinkPopover", (e: Event) => {
|
|
237
261
|
const detail = (e as CustomEvent).detail;
|
|
238
262
|
setLinkPopoverOpen(true);
|
|
@@ -322,53 +346,98 @@ const Wysiwyg = (props: IWysiwygProps) => {
|
|
|
322
346
|
// checking there is one: on an image inside a paragraph, or never resized,
|
|
323
347
|
// it throws and no caption appears. Hand it the image's own width, and
|
|
324
348
|
// once the caption is in, give that width to the caption, as Froala's
|
|
325
|
-
// resizing expects, and
|
|
326
|
-
//
|
|
349
|
+
// resizing expects, and keep it on the image: out of the editor nothing
|
|
350
|
+
// sizes the caption. In here the image fills its caption (see style.tsx),
|
|
351
|
+
// so the width is not applied twice. An image never resized has no width
|
|
352
|
+
// to keep: it leaves with none, so the site's default size still applies.
|
|
327
353
|
//
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
//
|
|
354
|
+
// In any mode, Froala's caption swallows the paragraph the image is in,
|
|
355
|
+
// and removing it deletes whatever it holds: see isolateImage,
|
|
356
|
+
// dropCaptionParagraph and takeTextOutOfCaption. Removing the image is
|
|
357
|
+
// ours too: see removeImage.
|
|
331
358
|
"commands.before": function (this: any, cmd: string) {
|
|
332
359
|
if (cmd === "fullscreen" && !this.fullscreen.isActive()) {
|
|
333
360
|
this.opts.z_index = this.opts.zIndex;
|
|
334
361
|
}
|
|
362
|
+
if (cmd === "imageRemove" && this.image.get()) {
|
|
363
|
+
removeImage(this);
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
if (cmd === "imageCaption" && this.image.get()) {
|
|
367
|
+
const img = this.image.get().get(0);
|
|
368
|
+
if (this.image.hasCaption()) {
|
|
369
|
+
takeTextOutOfCaption(img);
|
|
370
|
+
} else {
|
|
371
|
+
isolateImage(img);
|
|
372
|
+
captioningImgRef.current = img;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
335
375
|
if (cmd === "imageCaption" && this.opts.imageResizeWithPercent && !this.image.hasCaption()) {
|
|
336
376
|
const $img = this.image.get();
|
|
337
377
|
if (!$img) return;
|
|
338
378
|
const img = $img.get(0);
|
|
339
|
-
const
|
|
340
|
-
if (leftoverWrap) {
|
|
341
|
-
const p = document.createElement("p");
|
|
342
|
-
p.append(...leftoverWrap.childNodes);
|
|
343
|
-
leftoverWrap.replaceWith(p);
|
|
344
|
-
}
|
|
345
|
-
const width = getImagePercentWidth(this, $img);
|
|
379
|
+
const width = img.style.width ? getImagePercentWidth(this, $img) : null;
|
|
346
380
|
const $sized = $img.parent().is("a") || $img.parent().is("p") ? $img.parent() : $img;
|
|
347
381
|
const seeded = !$sized.attr("style") && !$sized.attr("width");
|
|
348
|
-
if (seeded) $sized.attr("width", width);
|
|
382
|
+
if (seeded) $sized.attr("width", width ?? "100%");
|
|
349
383
|
captionWidthRef.current = { img, width, $seeded: seeded ? $sized : null };
|
|
350
384
|
}
|
|
385
|
+
// Removing the caption hands the image the caption's style in place of
|
|
386
|
+
// its own, and the height lives on the image: keep it.
|
|
387
|
+
if (cmd === "imageCaption" && this.opts.imageResizeWithPercent && this.image.hasCaption()) {
|
|
388
|
+
const img = this.image.get()?.get(0);
|
|
389
|
+
if (img?.style.height) uncaptionedHeightRef.current = { img, height: img.style.height };
|
|
390
|
+
}
|
|
351
391
|
},
|
|
352
392
|
"commands.after": function (this: any, cmd: string) {
|
|
353
393
|
if (cmd === "fullscreen" && !this.fullscreen.isActive()) {
|
|
354
394
|
this.$tb.css("z-index", "");
|
|
355
395
|
}
|
|
396
|
+
if (cmd === "imageCaption" && captioningImgRef.current) {
|
|
397
|
+
dropCaptionParagraph(this, captioningImgRef.current);
|
|
398
|
+
captioningImgRef.current = null;
|
|
399
|
+
}
|
|
356
400
|
if (cmd === "imageCaption" && captionWidthRef.current) {
|
|
357
401
|
const { img, width, $seeded } = captionWidthRef.current;
|
|
358
402
|
$seeded?.removeAttr("width");
|
|
359
403
|
const caption = img.closest(".fr-img-caption");
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
404
|
+
for (const el of [caption, img]) {
|
|
405
|
+
if (!el) continue;
|
|
406
|
+
if (width) el.style.width = width;
|
|
407
|
+
else el.style.removeProperty("width");
|
|
408
|
+
if (!el.getAttribute("style")) el.removeAttribute("style");
|
|
409
|
+
}
|
|
363
410
|
captionWidthRef.current = null;
|
|
364
411
|
}
|
|
412
|
+
if (cmd === "imageCaption" && uncaptionedHeightRef.current) {
|
|
413
|
+
const { img, height } = uncaptionedHeightRef.current;
|
|
414
|
+
img.style.height = height;
|
|
415
|
+
uncaptionedHeightRef.current = null;
|
|
416
|
+
}
|
|
417
|
+
// The size popup sets the width and height on the caption and on the
|
|
418
|
+
// image inside it. The width belongs on both, but a fixed height on the
|
|
419
|
+
// caption leaves no room for its text: the height is the image's alone.
|
|
420
|
+
if (cmd === "imageSetSize" && this.opts.imageResizeWithPercent && this.image.hasCaption()) {
|
|
421
|
+
const caption = this.image.get()?.get(0)?.closest(".fr-img-caption");
|
|
422
|
+
caption?.style.removeProperty("height");
|
|
423
|
+
if (caption && !caption.getAttribute("style")) caption.removeAttribute("style");
|
|
424
|
+
}
|
|
365
425
|
},
|
|
366
|
-
|
|
426
|
+
// Froala's resizing sizes a captioned image's caption alone: the image
|
|
427
|
+
// takes the same width, for outside the editor. Froala hands AX the
|
|
428
|
+
// content when it saves an undo step, and it saved the drag's before
|
|
429
|
+
// this: save again, or AX keeps the width the image had before.
|
|
430
|
+
"image.resizeEnd": function (this: any, $img: any) {
|
|
431
|
+
const img = $img?.get?.(0);
|
|
432
|
+
const caption = img?.closest(".fr-img-caption");
|
|
433
|
+
if (caption) img.style.width = caption.style.width;
|
|
367
434
|
const lifted = liftedCaptionRef.current;
|
|
368
|
-
if (
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
435
|
+
if (lifted) {
|
|
436
|
+
lifted.nodes[0].before(lifted.paragraph);
|
|
437
|
+
lifted.paragraph.append(...lifted.nodes);
|
|
438
|
+
liftedCaptionRef.current = null;
|
|
439
|
+
}
|
|
440
|
+
this.undo.saveStep();
|
|
372
441
|
},
|
|
373
442
|
// Froala's shortcut dispatcher calls plugin commands unbound, so its own
|
|
374
443
|
// Ctrl/Cmd+K throws instead of opening anything. Returning false cancels
|
|
@@ -81,6 +81,11 @@ export const EditorWrapper = styled.div<{ error: boolean | undefined; disabled?:
|
|
|
81
81
|
font-size: 17px;
|
|
82
82
|
font-weight: 600;
|
|
83
83
|
}
|
|
84
|
+
/* A captioned image carries its width for outside the editor, where nothing
|
|
85
|
+
sizes the caption. In here the caption has that width, and the image fills it. */
|
|
86
|
+
.fr-img-caption img {
|
|
87
|
+
width: 100% !important;
|
|
88
|
+
}
|
|
84
89
|
.fr-toolbar {
|
|
85
90
|
border-color: ${(p) =>
|
|
86
91
|
p.error === true ? p.theme.color.error : p.disabled ? p.theme.color.interactiveDisabled : p.theme.color.uiLine};
|
|
@@ -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";
|