diff --git a/build.gradle b/build.gradle index fc46efa7..fd7ad05c 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ dependencies { compileOnly "com.enonic.xp:portal-api:${xpVersion}" compileOnly "com.enonic.xp:script-api:${xpVersion}" + implementation "com.enonic.xp:lib-context:${xpVersion}" implementation "com.enonic.xp:lib-io:${xpVersion}" implementation "com.enonic.xp:lib-portal:${xpVersion}" implementation "com.enonic.xp:lib-schema:${xpVersion}" diff --git a/deno.lock b/deno.lock index a20ec880..0488f6d1 100644 --- a/deno.lock +++ b/deno.lock @@ -1,24 +1,24 @@ { "version": "4", "specifiers": { - "jsr:@std/assert@*": "1.0.6", - "jsr:@std/internal@^1.0.4": "1.0.4" + "jsr:@std/assert@*": "1.0.10", + "jsr:@std/internal@^1.0.5": "1.0.5" }, "jsr": { - "@std/assert@1.0.6": { - "integrity": "1904c05806a25d94fe791d6d883b685c9e2dcd60e4f9fc30f4fc5cf010c72207", + "@std/assert@1.0.10": { + "integrity": "59b5cbac5bd55459a19045d95cc7c2ff787b4f8527c0dd195078ff6f9481fbb3", "dependencies": [ "jsr:@std/internal" ] }, - "@std/internal@1.0.4": { - "integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422" + "@std/internal@1.0.5": { + "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" } }, "workspace": { "packageJson": { "dependencies": [ - "npm:@babel/cli@^7.25.9", + "npm:@babel/cli@^7.26.4", "npm:@babel/core@^7.26.0", "npm:@babel/plugin-proposal-class-properties@^7.17.12", "npm:@babel/plugin-proposal-object-rest-spread@^7.20.7", @@ -26,6 +26,7 @@ "npm:@babel/register@^7.25.9", "npm:@enonic-types/global@^7.15.0-A2", "npm:@enonic-types/lib-content@^7.15.0-A2", + "npm:@enonic-types/lib-context@^7.15.0-A2", "npm:@enonic-types/lib-io@^7.15.0-A2", "npm:@enonic-types/lib-node@^7.15.0-A2", "npm:@enonic-types/lib-portal@^7.15.0-A2", diff --git a/package-lock.json b/package-lock.json index 55dbb2fd..1f5a4d31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "@babel/register": "^7.25.9", "@enonic-types/global": "^7.15.0-A2", "@enonic-types/lib-content": "^7.15.0-A2", + "@enonic-types/lib-context": "^7.15.0-A2", "@enonic-types/lib-io": "^7.15.0-A2", "@enonic-types/lib-node": "^7.15.0-A2", "@enonic-types/lib-portal": "^7.15.0-A2", @@ -2144,6 +2145,16 @@ "@enonic-types/core": "7.15.0-A2" } }, + "node_modules/@enonic-types/lib-context": { + "version": "7.15.0-A2", + "resolved": "https://registry.npmjs.org/@enonic-types/lib-context/-/lib-context-7.15.0-A2.tgz", + "integrity": "sha512-vJg8CLwZPAE4YHn1e28NChhoOZJV04Pfp1zcfOpNUa/Ttp0//kWQ9YKouIWvm/xd3uNA/A6EzN6jUgc4D6ibLA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@enonic-types/core": "7.15.0-A2" + } + }, "node_modules/@enonic-types/lib-io": { "version": "7.15.0-A2", "resolved": "https://registry.npmjs.org/@enonic-types/lib-io/-/lib-io-7.15.0-A2.tgz", diff --git a/package.json b/package.json index 3529d060..cca57221 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@babel/register": "^7.25.9", "@enonic-types/global": "^7.15.0-A2", "@enonic-types/lib-content": "^7.15.0-A2", + "@enonic-types/lib-context": "^7.15.0-A2", "@enonic-types/lib-io": "^7.15.0-A2", "@enonic-types/lib-node": "^7.15.0-A2", "@enonic-types/lib-portal": "^7.15.0-A2", diff --git a/src/main/resources/lib/enonic/react4xp/DataFetcher.ts b/src/main/resources/lib/enonic/react4xp/DataFetcher.ts index 608c81f4..f2434b3f 100644 --- a/src/main/resources/lib/enonic/react4xp/DataFetcher.ts +++ b/src/main/resources/lib/enonic/react4xp/DataFetcher.ts @@ -34,7 +34,9 @@ import type { RenderableWarning, XpRunMode, } from '@enonic/react-components/dist/nashorn'; - +import type { + ContextParams +} from '@enonic-types/lib-context'; import {getIn} from '@enonic/js-utils/object/getIn'; import {setIn} from '@enonic/js-utils/object/setIn'; @@ -53,6 +55,11 @@ import { processHtml, // pageUrl as getPageUrl, } from '/lib/xp/portal'; + +import { + run as runInContext +} from '/lib/xp/context'; + import { REQUEST_METHOD, REQUEST_MODE, @@ -208,6 +215,10 @@ export type ShortcutContent = Content<{ const RUN_MODE = IS_DEV_MODE ? 'development' : 'production'; +const ADMIN_CONTEXT: ContextParams = { + principals: ['role:system.admin'] +} + export class DataFetcher { private content: PageContent; private contentTypes: Record = {}; @@ -273,10 +284,14 @@ export class DataFetcher { if (!mixin) { const [application] = name.split(':'); - const mixinsList = listSchemas({ - application, - type: 'MIXIN' - }) as MixinSchema[]; + const mixinsList = runInContext( + ADMIN_CONTEXT, + () => + listSchemas({ + application, + type: 'MIXIN' + }) as MixinSchema[] + ); // log.debug('findHtmlAreasInFormItemArray mixinsList', mixinsList); for (let j = 0; j < mixinsList.length; j++) { @@ -441,19 +456,19 @@ export class DataFetcher { const {type} = fragment; // log.info('processFragment fragment:', fragment); - if(type === 'part') { + if (type === 'part') { return this.processPart({ component: fragment, ...passAlong }); } - if(type === 'layout') { + if (type === 'layout') { return this.processLayout({ component: fragment, ...passAlong }); } - if(type === 'text') { + if (type === 'text') { return this.processTextComponent({ component: fragment as TextComponent, }); @@ -493,10 +508,14 @@ export class DataFetcher { }; } - const {form} = getComponentSchema({ - key: descriptor, - type: 'LAYOUT', - }) as GetComponentReturnType; + const {form} = runInContext( + ADMIN_CONTEXT, + () => + getComponentSchema({ + key: descriptor, + type: 'LAYOUT', + }) as GetComponentReturnType + ); const processedLayoutComponent = this.processWithRegions({ component, @@ -640,10 +659,14 @@ export class DataFetcher { }; } - const {form} = getComponentSchema({ - key: descriptor, - type: 'PAGE', - }) as GetComponentReturnType; + const {form} = runInContext( + ADMIN_CONTEXT, + () => + getComponentSchema({ + key: descriptor, + type: 'PAGE', + }) as GetComponentReturnType + ); const processedPageComponent = this.processWithRegions({ component, @@ -700,10 +723,14 @@ export class DataFetcher { }; } - const {form} = getComponentSchema({ - key: descriptor, - type: 'PART', - }) as GetComponentReturnType; + const {form} = runInContext( + ADMIN_CONTEXT, + () => + getComponentSchema({ + key: descriptor, + type: 'PART', + }) as GetComponentReturnType + ); const htmlAreas = this.getHtmlAreas({ ancestor: 'config', diff --git a/types/package.template.json b/types/package.template.json index 930f1c50..70cb42fa 100644 --- a/types/package.template.json +++ b/types/package.template.json @@ -5,6 +5,7 @@ }, "dependencies": { "@enonic-types/core": "%XP_TYPES_VERSION%", + "@enonic-types/lib-context": "%XP_TYPES_VERSION%", "@enonic-types/lib-io": "%XP_TYPES_VERSION%", "@enonic-types/lib-portal": "%XP_TYPES_VERSION%", "@enonic-types/lib-schema": "%XP_TYPES_VERSION%",