@webiny/api-headless-cms-scheduler 6.5.2-beta.1 → 6.5.2-beta.2
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.
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { SchedulerPermissions } from "@webiny/api-scheduler/features/permissions/abstractions.js";
|
|
2
2
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
3
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
4
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
3
6
|
declare class CmsSchedulerPermissionsImpl implements SchedulerPermissions.Interface {
|
|
4
7
|
private identityContext;
|
|
5
|
-
|
|
8
|
+
private getModel;
|
|
9
|
+
private listModels;
|
|
10
|
+
private accessControl;
|
|
11
|
+
constructor(identityContext: IdentityContext.Interface, getModel: GetModelUseCase.Interface, listModels: ListModelsUseCase.Interface, accessControl: AccessControl.Interface);
|
|
6
12
|
canHandle(namespace: string): boolean;
|
|
7
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Security: scheduled actions expose entry titles, so reading them requires reading the
|
|
15
|
+
* entries of every model the namespace (or namespace prefix) covers.
|
|
16
|
+
*/
|
|
17
|
+
canRead(params: SchedulerPermissions.Params): Promise<boolean>;
|
|
8
18
|
onlyOwnRecords(): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Models are loaded without authorization only to evaluate access to them.
|
|
21
|
+
*/
|
|
22
|
+
private getModels;
|
|
9
23
|
}
|
|
10
24
|
export declare const CmsSchedulerPermissions: typeof CmsSchedulerPermissionsImpl & {
|
|
11
25
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-scheduler/features/permissions/abstractions.js").ISchedulerPermissions>;
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { SchedulerPermissions } from "@webiny/api-scheduler/features/permissions/abstractions.js";
|
|
2
2
|
import { IdentityContext } from "@webiny/api-core/exports/api/security.js";
|
|
3
|
-
import {
|
|
3
|
+
import { GetModelUseCase } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
4
|
+
import { ListModelsUseCase } from "@webiny/api-headless-cms/features/contentModel/ListModels/index.js";
|
|
5
|
+
import { AccessControl } from "@webiny/api-headless-cms/features/shared/abstractions.js";
|
|
6
|
+
import { CMS_NAMESPACE, createNamespace, extractModelIdFromNamespace } from "../../utils/namespace.js";
|
|
4
7
|
class CmsSchedulerPermissionsImpl {
|
|
5
|
-
constructor(identityContext){
|
|
8
|
+
constructor(identityContext, getModel, listModels, accessControl){
|
|
6
9
|
this.identityContext = identityContext;
|
|
10
|
+
this.getModel = getModel;
|
|
11
|
+
this.listModels = listModels;
|
|
12
|
+
this.accessControl = accessControl;
|
|
7
13
|
}
|
|
8
14
|
canHandle(namespace) {
|
|
9
15
|
return namespace.startsWith(CMS_NAMESPACE);
|
|
10
16
|
}
|
|
11
|
-
async canRead() {
|
|
17
|
+
async canRead(params) {
|
|
18
|
+
if (!this.identityContext.isAuthorizationEnabled()) return true;
|
|
12
19
|
if (await this.identityContext.hasFullAccess()) return true;
|
|
13
|
-
const
|
|
14
|
-
|
|
20
|
+
const models = await this.getModels(params);
|
|
21
|
+
if (!models.length) return false;
|
|
22
|
+
for (const model of models)if (!await this.accessControl.canAccessEntry({
|
|
23
|
+
model,
|
|
24
|
+
rwd: "r"
|
|
25
|
+
})) return false;
|
|
26
|
+
return true;
|
|
15
27
|
}
|
|
16
28
|
async onlyOwnRecords() {
|
|
17
29
|
if (await this.identityContext.hasFullAccess()) return false;
|
|
@@ -19,11 +31,30 @@ class CmsSchedulerPermissionsImpl {
|
|
|
19
31
|
if (!permissions.length) return false;
|
|
20
32
|
return !permissions.some((p)=>!p.own);
|
|
21
33
|
}
|
|
34
|
+
async getModels(params) {
|
|
35
|
+
const { namespace, startsWith } = params;
|
|
36
|
+
if (!startsWith) {
|
|
37
|
+
const modelId = extractModelIdFromNamespace(namespace);
|
|
38
|
+
if (!modelId) return [];
|
|
39
|
+
const result = await this.identityContext.withoutAuthorization(()=>this.getModel.execute(modelId));
|
|
40
|
+
return result.isOk() ? [
|
|
41
|
+
result.value
|
|
42
|
+
] : [];
|
|
43
|
+
}
|
|
44
|
+
const result = await this.identityContext.withoutAuthorization(()=>this.listModels.execute({
|
|
45
|
+
includePrivate: false
|
|
46
|
+
}));
|
|
47
|
+
if (result.isFail()) return [];
|
|
48
|
+
return result.value.filter((model)=>createNamespace(model).startsWith(namespace));
|
|
49
|
+
}
|
|
22
50
|
}
|
|
23
51
|
const CmsSchedulerPermissions = SchedulerPermissions.createImplementation({
|
|
24
52
|
implementation: CmsSchedulerPermissionsImpl,
|
|
25
53
|
dependencies: [
|
|
26
|
-
IdentityContext
|
|
54
|
+
IdentityContext,
|
|
55
|
+
GetModelUseCase,
|
|
56
|
+
ListModelsUseCase,
|
|
57
|
+
AccessControl
|
|
27
58
|
]
|
|
28
59
|
});
|
|
29
60
|
export { CmsSchedulerPermissions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/permissions/CmsSchedulerPermissions.js","sources":["../../../src/features/permissions/CmsSchedulerPermissions.ts"],"sourcesContent":["import { SchedulerPermissions } from \"@webiny/api-scheduler/features/permissions/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { CMS_NAMESPACE } from \"~/utils/namespace.js\";\n\nclass CmsSchedulerPermissionsImpl implements SchedulerPermissions.Interface {\n constructor(private identityContext: IdentityContext.Interface) {}\n\n canHandle(namespace: string): boolean {\n return namespace.startsWith(CMS_NAMESPACE);\n }\n\n async canRead(): Promise<boolean> {\n if (await this.identityContext.hasFullAccess()) {\n return true;\n }\n const
|
|
1
|
+
{"version":3,"file":"features/permissions/CmsSchedulerPermissions.js","sources":["../../../src/features/permissions/CmsSchedulerPermissions.ts"],"sourcesContent":["import { SchedulerPermissions } from \"@webiny/api-scheduler/features/permissions/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/exports/api/security.js\";\nimport { GetModelUseCase } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { AccessControl } from \"@webiny/api-headless-cms/features/shared/abstractions.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CMS_NAMESPACE, createNamespace, extractModelIdFromNamespace } from \"~/utils/namespace.js\";\n\nclass CmsSchedulerPermissionsImpl implements SchedulerPermissions.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private getModel: GetModelUseCase.Interface,\n private listModels: ListModelsUseCase.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n canHandle(namespace: string): boolean {\n return namespace.startsWith(CMS_NAMESPACE);\n }\n\n /**\n * Security: scheduled actions expose entry titles, so reading them requires reading the\n * entries of every model the namespace (or namespace prefix) covers.\n */\n async canRead(params: SchedulerPermissions.Params): Promise<boolean> {\n if (!this.identityContext.isAuthorizationEnabled()) {\n return true;\n }\n if (await this.identityContext.hasFullAccess()) {\n return true;\n }\n const models = await this.getModels(params);\n if (!models.length) {\n return false;\n }\n for (const model of models) {\n if (!(await this.accessControl.canAccessEntry({ model, rwd: \"r\" }))) {\n return false;\n }\n }\n return true;\n }\n\n async onlyOwnRecords(): Promise<boolean> {\n if (await this.identityContext.hasFullAccess()) {\n return false;\n }\n const permissions = await this.identityContext.getPermissions(\"cms.contentEntry\");\n if (!permissions.length) {\n return false;\n }\n return !permissions.some((p: any) => !p.own);\n }\n\n /**\n * Models are loaded without authorization only to evaluate access to them.\n */\n private async getModels(params: SchedulerPermissions.Params): Promise<CmsModel[]> {\n const { namespace, startsWith } = params;\n if (!startsWith) {\n const modelId = extractModelIdFromNamespace(namespace);\n if (!modelId) {\n return [];\n }\n const result = await this.identityContext.withoutAuthorization(() => {\n return this.getModel.execute(modelId);\n });\n return result.isOk() ? [result.value] : [];\n }\n const result = await this.identityContext.withoutAuthorization(() => {\n // Private models can't be scheduled.\n return this.listModels.execute({ includePrivate: false });\n });\n if (result.isFail()) {\n return [];\n }\n return result.value.filter(model => createNamespace(model).startsWith(namespace));\n }\n}\n\nexport const CmsSchedulerPermissions = SchedulerPermissions.createImplementation({\n implementation: CmsSchedulerPermissionsImpl,\n dependencies: [IdentityContext, GetModelUseCase, ListModelsUseCase, AccessControl]\n});\n"],"names":["CmsSchedulerPermissionsImpl","identityContext","getModel","listModels","accessControl","namespace","CMS_NAMESPACE","params","models","model","permissions","p","startsWith","modelId","extractModelIdFromNamespace","result","createNamespace","CmsSchedulerPermissions","SchedulerPermissions","IdentityContext","GetModelUseCase","ListModelsUseCase","AccessControl"],"mappings":";;;;;;AAQA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,QAAmC,EACnCC,UAAuC,EACvCC,aAAsC,CAChD;aAJUH,eAAe,GAAfA;aACAC,QAAQ,GAARA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,UAAUC,SAAiB,EAAW;QAClC,OAAOA,UAAU,UAAU,CAACC;IAChC;IAMA,MAAM,QAAQC,MAAmC,EAAoB;QACjE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,sBAAsB,IAC5C,OAAO;QAEX,IAAI,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,IACxC,OAAO;QAEX,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAACD;QACpC,IAAI,CAACC,OAAO,MAAM,EACd,OAAO;QAEX,KAAK,MAAMC,SAASD,OAChB,IAAI,CAAE,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEC;YAAO,KAAK;QAAI,IAC5D,OAAO;QAGf,OAAO;IACX;IAEA,MAAM,iBAAmC;QACrC,IAAI,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,IACxC,OAAO;QAEX,MAAMC,cAAc,MAAM,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC;QAC9D,IAAI,CAACA,YAAY,MAAM,EACnB,OAAO;QAEX,OAAO,CAACA,YAAY,IAAI,CAAC,CAACC,IAAW,CAACA,EAAE,GAAG;IAC/C;IAKA,MAAc,UAAUJ,MAAmC,EAAuB;QAC9E,MAAM,EAAEF,SAAS,EAAEO,UAAU,EAAE,GAAGL;QAClC,IAAI,CAACK,YAAY;YACb,MAAMC,UAAUC,4BAA4BT;YAC5C,IAAI,CAACQ,SACD,OAAO,EAAE;YAEb,MAAME,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IACpD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACF;YAEjC,OAAOE,OAAO,IAAI,KAAK;gBAACA,OAAO,KAAK;aAAC,GAAG,EAAE;QAC9C;QACA,MAAMA,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IAEpD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,gBAAgB;YAAM;QAE3D,IAAIA,OAAO,MAAM,IACb,OAAO,EAAE;QAEb,OAAOA,OAAO,KAAK,CAAC,MAAM,CAACN,CAAAA,QAASO,gBAAgBP,OAAO,UAAU,CAACJ;IAC1E;AACJ;AAEO,MAAMY,0BAA0BC,qBAAqB,oBAAoB,CAAC;IAC7E,gBAAgBlB;IAChB,cAAc;QAACmB;QAAiBC;QAAiBC;QAAmBC;KAAc;AACtF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-headless-cms-scheduler",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -17,23 +17,23 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@webiny/api": "6.5.2-beta.
|
|
21
|
-
"@webiny/api-headless-cms": "6.5.2-beta.
|
|
22
|
-
"@webiny/api-scheduler": "6.5.2-beta.
|
|
23
|
-
"@webiny/feature": "6.5.2-beta.
|
|
24
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
20
|
+
"@webiny/api": "6.5.2-beta.2",
|
|
21
|
+
"@webiny/api-headless-cms": "6.5.2-beta.2",
|
|
22
|
+
"@webiny/api-scheduler": "6.5.2-beta.2",
|
|
23
|
+
"@webiny/feature": "6.5.2-beta.2",
|
|
24
|
+
"@webiny/handler-graphql": "6.5.2-beta.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
28
|
-
"@webiny/api-opensearch": "6.5.2-beta.
|
|
29
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
30
|
-
"@webiny/handler": "6.5.2-beta.
|
|
31
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
32
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
33
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
34
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
27
|
+
"@webiny/api-core": "6.5.2-beta.2",
|
|
28
|
+
"@webiny/api-opensearch": "6.5.2-beta.2",
|
|
29
|
+
"@webiny/build-tools": "6.5.2-beta.2",
|
|
30
|
+
"@webiny/handler": "6.5.2-beta.2",
|
|
31
|
+
"@webiny/handler-aws": "6.5.2-beta.2",
|
|
32
|
+
"@webiny/plugins": "6.5.2-beta.2",
|
|
33
|
+
"@webiny/project-utils": "6.5.2-beta.2",
|
|
34
|
+
"@webiny/wcp": "6.5.2-beta.2",
|
|
35
35
|
"typescript": "7.0.2",
|
|
36
|
-
"vitest": "5.0
|
|
36
|
+
"vitest": "5.1.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|