@webiny/api-website-builder-scheduler 6.5.2-beta.0 → 6.5.2-beta.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/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.d.ts +3 -1
- package/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.js +13 -10
- package/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.js.map +1 -1
- package/features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.d.ts +3 -1
- package/features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.js +12 -9
- package/features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.js.map +1 -1
- package/features/NamespaceHandler/PageNamespaceHandler.d.ts +3 -1
- package/features/NamespaceHandler/PageNamespaceHandler.js +8 -3
- package/features/NamespaceHandler/PageNamespaceHandler.js.map +1 -1
- package/features/NamespaceHandler/RedirectNamespaceHandler.d.ts +3 -1
- package/features/NamespaceHandler/RedirectNamespaceHandler.js +7 -3
- package/features/NamespaceHandler/RedirectNamespaceHandler.js.map +1 -1
- package/package.json +16 -16
package/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PageAfterDeleteEventHandler } from "@webiny/api-website-builder/exports/api/website-builder/page.js";
|
|
2
2
|
import { CancelScheduledActionUseCase, ListScheduledActionsUseCase } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
3
|
import { Logger } from "@webiny/api-core/exports/api/logger.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Cancels scheduled actions when a page is deleted.
|
|
6
7
|
*
|
|
@@ -11,7 +12,8 @@ declare class CancelScheduledActionOnPageDeleteHandlerImpl implements PageAfterD
|
|
|
11
12
|
private listScheduledActions;
|
|
12
13
|
private cancelScheduledAction;
|
|
13
14
|
private logger;
|
|
14
|
-
|
|
15
|
+
private identityContext;
|
|
16
|
+
constructor(listScheduledActions: ListScheduledActionsUseCase.Interface, cancelScheduledAction: CancelScheduledActionUseCase.Interface, logger: Logger.Interface, identityContext: IdentityContext.Interface);
|
|
15
17
|
handle(event: PageAfterDeleteEventHandler.Event): Promise<void>;
|
|
16
18
|
}
|
|
17
19
|
export declare const CancelScheduledActionOnPageDeleteEventHandler: typeof CancelScheduledActionOnPageDeleteHandlerImpl & {
|
package/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.js
CHANGED
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import { PageAfterDeleteEventHandler } from "@webiny/api-website-builder/exports/api/website-builder/page.js";
|
|
2
2
|
import { CancelScheduledActionUseCase, ListScheduledActionsUseCase } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
3
|
import { Logger } from "@webiny/api-core/exports/api/logger.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
5
|
import { createNamespace } from "../../utils/namespace.js";
|
|
5
6
|
import { SCHEDULED_ACTION_TYPE_PAGE } from "../../constants.js";
|
|
6
7
|
class CancelScheduledActionOnPageDeleteHandlerImpl {
|
|
7
|
-
constructor(listScheduledActions, cancelScheduledAction, logger){
|
|
8
|
+
constructor(listScheduledActions, cancelScheduledAction, logger, identityContext){
|
|
8
9
|
this.listScheduledActions = listScheduledActions;
|
|
9
10
|
this.cancelScheduledAction = cancelScheduledAction;
|
|
10
11
|
this.logger = logger;
|
|
12
|
+
this.identityContext = identityContext;
|
|
11
13
|
}
|
|
12
14
|
async handle(event) {
|
|
13
15
|
const { page } = event.payload;
|
|
14
|
-
const actionsResult = await this.listScheduledActions.execute({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const actionsResult = await this.identityContext.withoutAuthorization(()=>this.listScheduledActions.execute({
|
|
17
|
+
limit: 10000,
|
|
18
|
+
where: {
|
|
19
|
+
namespace: createNamespace(SCHEDULED_ACTION_TYPE_PAGE),
|
|
20
|
+
targetId: page.id
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
21
23
|
if (actionsResult.isFail()) return void this.logger.error(actionsResult.error);
|
|
22
24
|
const actions = actionsResult.value.items;
|
|
23
25
|
for (const action of actions){
|
|
24
|
-
const cancelRes = await this.cancelScheduledAction.execute(action);
|
|
26
|
+
const cancelRes = await this.identityContext.withoutAuthorization(()=>this.cancelScheduledAction.execute(action));
|
|
25
27
|
cancelRes.isFail();
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -31,7 +33,8 @@ const CancelScheduledActionOnPageDeleteEventHandler = PageAfterDeleteEventHandle
|
|
|
31
33
|
dependencies: [
|
|
32
34
|
ListScheduledActionsUseCase,
|
|
33
35
|
CancelScheduledActionUseCase,
|
|
34
|
-
Logger
|
|
36
|
+
Logger,
|
|
37
|
+
IdentityContext
|
|
35
38
|
]
|
|
36
39
|
});
|
|
37
40
|
export { CancelScheduledActionOnPageDeleteEventHandler };
|
package/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.js","sources":["../../../src/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.ts"],"sourcesContent":["import { PageAfterDeleteEventHandler } from \"@webiny/api-website-builder/exports/api/website-builder/page.js\";\nimport {\n CancelScheduledActionUseCase,\n ListScheduledActionsUseCase\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\nimport { SCHEDULED_ACTION_TYPE_PAGE } from \"~/constants.js\";\n\n/**\n * Cancels scheduled actions when a page is deleted.\n *\n * When a user deletes a page revision, any scheduled publish/unpublish\n * actions for that revision should be canceled since the page no longer exists.\n */\nclass CancelScheduledActionOnPageDeleteHandlerImpl\n implements PageAfterDeleteEventHandler.Interface\n{\n constructor(\n private listScheduledActions: ListScheduledActionsUseCase.Interface,\n private cancelScheduledAction: CancelScheduledActionUseCase.Interface,\n private logger: Logger.Interface\n ) {}\n\n async handle(event: PageAfterDeleteEventHandler.Event): Promise<void> {\n const { page } = event.payload;\n\n const actionsResult = await this.listScheduledActions.execute({\n
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.js","sources":["../../../src/features/CancelScheduledActionOnChange/CancelScheduledActionOnPageDeleteEventHandler.ts"],"sourcesContent":["import { PageAfterDeleteEventHandler } from \"@webiny/api-website-builder/exports/api/website-builder/page.js\";\nimport {\n CancelScheduledActionUseCase,\n ListScheduledActionsUseCase\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\nimport { SCHEDULED_ACTION_TYPE_PAGE } from \"~/constants.js\";\n\n/**\n * Cancels scheduled actions when a page is deleted.\n *\n * When a user deletes a page revision, any scheduled publish/unpublish\n * actions for that revision should be canceled since the page no longer exists.\n */\nclass CancelScheduledActionOnPageDeleteHandlerImpl\n implements PageAfterDeleteEventHandler.Interface\n{\n constructor(\n private listScheduledActions: ListScheduledActionsUseCase.Interface,\n private cancelScheduledAction: CancelScheduledActionUseCase.Interface,\n private logger: Logger.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async handle(event: PageAfterDeleteEventHandler.Event): Promise<void> {\n const { page } = event.payload;\n\n /**\n * System cleanup after a delete the user was allowed to do: list and cancel every schedule\n * for the deleted target, without the caller's permission checks (the target no longer exists).\n */\n const actionsResult = await this.identityContext.withoutAuthorization(() => {\n return this.listScheduledActions.execute({\n limit: 10000,\n where: {\n namespace: createNamespace(SCHEDULED_ACTION_TYPE_PAGE),\n targetId: page.id\n }\n });\n });\n\n if (actionsResult.isFail()) {\n this.logger.error(actionsResult.error);\n return;\n }\n\n const actions = actionsResult.value.items;\n\n for (const action of actions) {\n const cancelRes = await this.identityContext.withoutAuthorization(() => {\n return this.cancelScheduledAction.execute(action);\n });\n if (cancelRes.isFail()) {\n // Silently ignore errors - this is non-critical cleanup.\n // The page was deleted successfully, cancelling scheduled actions is best-effort.\n }\n }\n }\n}\n\nexport const CancelScheduledActionOnPageDeleteEventHandler =\n PageAfterDeleteEventHandler.createImplementation({\n implementation: CancelScheduledActionOnPageDeleteHandlerImpl,\n dependencies: [\n ListScheduledActionsUseCase,\n CancelScheduledActionUseCase,\n Logger,\n IdentityContext\n ]\n });\n"],"names":["CancelScheduledActionOnPageDeleteHandlerImpl","listScheduledActions","cancelScheduledAction","logger","identityContext","event","page","actionsResult","createNamespace","SCHEDULED_ACTION_TYPE_PAGE","actions","action","cancelRes","CancelScheduledActionOnPageDeleteEventHandler","PageAfterDeleteEventHandler","ListScheduledActionsUseCase","CancelScheduledActionUseCase","Logger","IdentityContext"],"mappings":";;;;;;AAgBA,MAAMA;IAGF,YACYC,oBAA2D,EAC3DC,qBAA6D,EAC7DC,MAAwB,EACxBC,eAA0C,CACpD;aAJUH,oBAAoB,GAApBA;aACAC,qBAAqB,GAArBA;aACAC,MAAM,GAANA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,EAAEC,IAAI,EAAE,GAAGD,MAAM,OAAO;QAM9B,MAAME,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IAC3D,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;gBACrC,OAAO;gBACP,OAAO;oBACH,WAAWC,gBAAgBC;oBAC3B,UAAUH,KAAK,EAAE;gBACrB;YACJ;QAGJ,IAAIC,cAAc,MAAM,IAAI,YACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAACA,cAAc,KAAK;QAIzC,MAAMG,UAAUH,cAAc,KAAK,CAAC,KAAK;QAEzC,KAAK,MAAMI,UAAUD,QAAS;YAC1B,MAAME,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IACvD,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACD;YAE1CC,UAAU,MAAM;QAIxB;IACJ;AACJ;AAEO,MAAMC,gDACTC,4BAA4B,oBAAoB,CAAC;IAC7C,gBAAgBd;IAChB,cAAc;QACVe;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RedirectAfterDeleteEventHandler } from "@webiny/api-website-builder/exports/api/website-builder/redirect.js";
|
|
2
2
|
import { CancelScheduledActionUseCase, ListScheduledActionsUseCase } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
3
|
import { Logger } from "@webiny/api-core/exports/api/logger.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* Cancels scheduled actions when a redirect is deleted.
|
|
6
7
|
*
|
|
@@ -12,7 +13,8 @@ declare class CancelScheduledActionOnRedirectDeleteHandlerImpl implements Redire
|
|
|
12
13
|
private listScheduledActions;
|
|
13
14
|
private cancelScheduledAction;
|
|
14
15
|
private logger;
|
|
15
|
-
|
|
16
|
+
private identityContext;
|
|
17
|
+
constructor(listScheduledActions: ListScheduledActionsUseCase.Interface, cancelScheduledAction: CancelScheduledActionUseCase.Interface, logger: Logger.Interface, identityContext: IdentityContext.Interface);
|
|
16
18
|
handle(event: RedirectAfterDeleteEventHandler.Event): Promise<void>;
|
|
17
19
|
}
|
|
18
20
|
export declare const CancelScheduledActionOnRedirectDeleteEventHandler: typeof CancelScheduledActionOnRedirectDeleteHandlerImpl & {
|
package/features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.js
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { RedirectAfterDeleteEventHandler } from "@webiny/api-website-builder/exports/api/website-builder/redirect.js";
|
|
2
2
|
import { CancelScheduledActionUseCase, ListScheduledActionsUseCase } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
3
3
|
import { Logger } from "@webiny/api-core/exports/api/logger.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
5
|
import { createNamespace } from "../../utils/namespace.js";
|
|
5
6
|
import { SCHEDULED_ACTION_TYPE_REDIRECT } from "../../constants.js";
|
|
6
7
|
class CancelScheduledActionOnRedirectDeleteHandlerImpl {
|
|
7
|
-
constructor(listScheduledActions, cancelScheduledAction, logger){
|
|
8
|
+
constructor(listScheduledActions, cancelScheduledAction, logger, identityContext){
|
|
8
9
|
this.listScheduledActions = listScheduledActions;
|
|
9
10
|
this.cancelScheduledAction = cancelScheduledAction;
|
|
10
11
|
this.logger = logger;
|
|
12
|
+
this.identityContext = identityContext;
|
|
11
13
|
}
|
|
12
14
|
async handle(event) {
|
|
13
15
|
const { redirect } = event.payload;
|
|
14
|
-
const actionsResult = await this.listScheduledActions.execute({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const actionsResult = await this.identityContext.withoutAuthorization(()=>this.listScheduledActions.execute({
|
|
17
|
+
where: {
|
|
18
|
+
namespace: createNamespace(SCHEDULED_ACTION_TYPE_REDIRECT),
|
|
19
|
+
targetId: redirect.id
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
20
22
|
if (actionsResult.isFail()) return void this.logger.error(actionsResult.error);
|
|
21
23
|
const actions = actionsResult.value.items;
|
|
22
24
|
for (const action of actions){
|
|
23
|
-
const cancelRes = await this.cancelScheduledAction.execute(action);
|
|
25
|
+
const cancelRes = await this.identityContext.withoutAuthorization(()=>this.cancelScheduledAction.execute(action));
|
|
24
26
|
cancelRes.isFail();
|
|
25
27
|
}
|
|
26
28
|
}
|
|
@@ -30,7 +32,8 @@ const CancelScheduledActionOnRedirectDeleteEventHandler = RedirectAfterDeleteEve
|
|
|
30
32
|
dependencies: [
|
|
31
33
|
ListScheduledActionsUseCase,
|
|
32
34
|
CancelScheduledActionUseCase,
|
|
33
|
-
Logger
|
|
35
|
+
Logger,
|
|
36
|
+
IdentityContext
|
|
34
37
|
]
|
|
35
38
|
});
|
|
36
39
|
export { CancelScheduledActionOnRedirectDeleteEventHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.js","sources":["../../../src/features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.ts"],"sourcesContent":["import { RedirectAfterDeleteEventHandler } from \"@webiny/api-website-builder/exports/api/website-builder/redirect.js\";\nimport {\n CancelScheduledActionUseCase,\n ListScheduledActionsUseCase\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\nimport { SCHEDULED_ACTION_TYPE_REDIRECT } from \"~/constants.js\";\n\n/**\n * Cancels scheduled actions when a redirect is deleted.\n *\n * When a user deletes a redirect, any scheduled publish/unpublish\n * actions for that redirect should be canceled since the redirect\n * no longer exists.\n */\nclass CancelScheduledActionOnRedirectDeleteHandlerImpl\n implements RedirectAfterDeleteEventHandler.Interface\n{\n constructor(\n private listScheduledActions: ListScheduledActionsUseCase.Interface,\n private cancelScheduledAction: CancelScheduledActionUseCase.Interface,\n private logger: Logger.Interface\n ) {}\n\n async handle(event: RedirectAfterDeleteEventHandler.Event): Promise<void> {\n const { redirect } = event.payload;\n\n const actionsResult = await this.listScheduledActions.execute({\n
|
|
1
|
+
{"version":3,"file":"features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.js","sources":["../../../src/features/CancelScheduledActionOnChange/CancelScheduledActionOnRedirectDeleteEventHandler.ts"],"sourcesContent":["import { RedirectAfterDeleteEventHandler } from \"@webiny/api-website-builder/exports/api/website-builder/redirect.js\";\nimport {\n CancelScheduledActionUseCase,\n ListScheduledActionsUseCase\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { Logger } from \"@webiny/api-core/exports/api/logger.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { createNamespace } from \"~/utils/namespace.js\";\nimport { SCHEDULED_ACTION_TYPE_REDIRECT } from \"~/constants.js\";\n\n/**\n * Cancels scheduled actions when a redirect is deleted.\n *\n * When a user deletes a redirect, any scheduled publish/unpublish\n * actions for that redirect should be canceled since the redirect\n * no longer exists.\n */\nclass CancelScheduledActionOnRedirectDeleteHandlerImpl\n implements RedirectAfterDeleteEventHandler.Interface\n{\n constructor(\n private listScheduledActions: ListScheduledActionsUseCase.Interface,\n private cancelScheduledAction: CancelScheduledActionUseCase.Interface,\n private logger: Logger.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async handle(event: RedirectAfterDeleteEventHandler.Event): Promise<void> {\n const { redirect } = event.payload;\n\n /**\n * System cleanup after a delete the user was allowed to do: list and cancel every schedule\n * for the deleted target, without the caller's permission checks (the target no longer exists).\n */\n const actionsResult = await this.identityContext.withoutAuthorization(() => {\n return this.listScheduledActions.execute({\n where: {\n namespace: createNamespace(SCHEDULED_ACTION_TYPE_REDIRECT),\n targetId: redirect.id\n }\n });\n });\n\n if (actionsResult.isFail()) {\n this.logger.error(actionsResult.error);\n return;\n }\n\n const actions = actionsResult.value.items;\n\n for (const action of actions) {\n const cancelRes = await this.identityContext.withoutAuthorization(() => {\n return this.cancelScheduledAction.execute(action);\n });\n if (cancelRes.isFail()) {\n // Silently ignore errors - this is non-critical cleanup.\n // The redirect was deleted successfully, cancelling scheduled actions is best-effort.\n }\n }\n }\n}\n\nexport const CancelScheduledActionOnRedirectDeleteEventHandler =\n RedirectAfterDeleteEventHandler.createImplementation({\n implementation: CancelScheduledActionOnRedirectDeleteHandlerImpl,\n dependencies: [\n ListScheduledActionsUseCase,\n CancelScheduledActionUseCase,\n Logger,\n IdentityContext\n ]\n });\n"],"names":["CancelScheduledActionOnRedirectDeleteHandlerImpl","listScheduledActions","cancelScheduledAction","logger","identityContext","event","redirect","actionsResult","createNamespace","SCHEDULED_ACTION_TYPE_REDIRECT","actions","action","cancelRes","CancelScheduledActionOnRedirectDeleteEventHandler","RedirectAfterDeleteEventHandler","ListScheduledActionsUseCase","CancelScheduledActionUseCase","Logger","IdentityContext"],"mappings":";;;;;;AAiBA,MAAMA;IAGF,YACYC,oBAA2D,EAC3DC,qBAA6D,EAC7DC,MAAwB,EACxBC,eAA0C,CACpD;aAJUH,oBAAoB,GAApBA;aACAC,qBAAqB,GAArBA;aACAC,MAAM,GAANA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,OAAOC,KAA4C,EAAiB;QACtE,MAAM,EAAEC,QAAQ,EAAE,GAAGD,MAAM,OAAO;QAMlC,MAAME,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IAC3D,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC;gBACrC,OAAO;oBACH,WAAWC,gBAAgBC;oBAC3B,UAAUH,SAAS,EAAE;gBACzB;YACJ;QAGJ,IAAIC,cAAc,MAAM,IAAI,YACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAACA,cAAc,KAAK;QAIzC,MAAMG,UAAUH,cAAc,KAAK,CAAC,KAAK;QAEzC,KAAK,MAAMI,UAAUD,QAAS;YAC1B,MAAME,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IACvD,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACD;YAE1CC,UAAU,MAAM;QAIxB;IACJ;AACJ;AAEO,MAAMC,oDACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBd;IAChB,cAAc;QACVe;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { NamespaceHandler as NamespaceHandlerAbstraction } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { WbPermissions } from "@webiny/api-website-builder/features/permissions/abstractions.js";
|
|
2
3
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
4
|
import type { IScheduledActionPayload } from "../../types.js";
|
|
4
5
|
import { GetPageByIdUseCase } from "@webiny/api-website-builder/exports/api/website-builder/page.js";
|
|
5
6
|
declare class PageNamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {
|
|
6
7
|
private getPageByIdUseCase;
|
|
7
|
-
|
|
8
|
+
private permissions;
|
|
9
|
+
constructor(getPageByIdUseCase: GetPageByIdUseCase.Interface, permissions: WbPermissions.Interface);
|
|
8
10
|
canHandle(namespace: string): boolean;
|
|
9
11
|
execute(params: NamespaceHandlerAbstraction.Params): NamespaceHandlerAbstraction.Response<IScheduledActionPayload>;
|
|
10
12
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { NamespaceHandler } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
1
|
+
import { NamespaceHandler, ScheduledActionTypePublish, SchedulerNotAuthorizedError } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { WbPermissions } from "@webiny/api-website-builder/features/permissions/abstractions.js";
|
|
2
3
|
import { extractModelIdFromNamespace } from "../../utils/namespace.js";
|
|
3
4
|
import { Result } from "@webiny/feature/exports/api.js";
|
|
4
5
|
import { SCHEDULED_ACTION_TYPE_PAGE } from "../../constants.js";
|
|
5
6
|
import { GetPageByIdUseCase } from "@webiny/api-website-builder/exports/api/website-builder/page.js";
|
|
6
7
|
class PageNamespaceHandlerImpl {
|
|
7
|
-
constructor(getPageByIdUseCase){
|
|
8
|
+
constructor(getPageByIdUseCase, permissions){
|
|
8
9
|
this.getPageByIdUseCase = getPageByIdUseCase;
|
|
10
|
+
this.permissions = permissions;
|
|
9
11
|
}
|
|
10
12
|
canHandle(namespace) {
|
|
11
13
|
const type = extractModelIdFromNamespace(namespace);
|
|
@@ -16,6 +18,8 @@ class PageNamespaceHandlerImpl {
|
|
|
16
18
|
const pageResult = await this.getPageByIdUseCase.execute(params.targetId);
|
|
17
19
|
if (pageResult.isFail()) return Result.fail(pageResult.error);
|
|
18
20
|
const page = pageResult.value;
|
|
21
|
+
const canPublishOrUnpublish = params.actionType === ScheduledActionTypePublish ? await this.permissions.canPublish("page") : await this.permissions.canUnpublish("page");
|
|
22
|
+
if (!canPublishOrUnpublish || !await this.permissions.canAccess("page", page)) return Result.fail(new SchedulerNotAuthorizedError());
|
|
19
23
|
const title = page.properties.title || "Unknown page title";
|
|
20
24
|
return Result.ok({
|
|
21
25
|
namespace: params.namespace,
|
|
@@ -31,7 +35,8 @@ class PageNamespaceHandlerImpl {
|
|
|
31
35
|
const PageNamespaceHandler = NamespaceHandler.createImplementation({
|
|
32
36
|
implementation: PageNamespaceHandlerImpl,
|
|
33
37
|
dependencies: [
|
|
34
|
-
GetPageByIdUseCase
|
|
38
|
+
GetPageByIdUseCase,
|
|
39
|
+
WbPermissions
|
|
35
40
|
]
|
|
36
41
|
});
|
|
37
42
|
export { PageNamespaceHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/NamespaceHandler/PageNamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/PageNamespaceHandler.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/NamespaceHandler/PageNamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/PageNamespaceHandler.ts"],"sourcesContent":["import {\n NamespaceHandler as NamespaceHandlerAbstraction,\n SchedulerNotAuthorizedError,\n ScheduledActionTypePublish\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { WbPermissions } from \"@webiny/api-website-builder/features/permissions/abstractions.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SCHEDULED_ACTION_TYPE_PAGE } from \"~/constants.js\";\nimport type { IScheduledActionPayload } from \"~/types.js\";\nimport { GetPageByIdUseCase } from \"@webiny/api-website-builder/exports/api/website-builder/page.js\";\n\nclass PageNamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {\n public constructor(\n private getPageByIdUseCase: GetPageByIdUseCase.Interface,\n private permissions: WbPermissions.Interface\n ) {}\n\n public canHandle(namespace: string): boolean {\n const type = extractModelIdFromNamespace(namespace);\n return type === SCHEDULED_ACTION_TYPE_PAGE;\n }\n\n public async execute(\n params: NamespaceHandlerAbstraction.Params\n ): NamespaceHandlerAbstraction.Response<IScheduledActionPayload> {\n const type = extractModelIdFromNamespace(params.namespace)!;\n\n const pageResult = await this.getPageByIdUseCase.execute(params.targetId);\n if (pageResult.isFail()) {\n return Result.fail(pageResult.error as any);\n }\n const page = pageResult.value;\n // Same checks as publishing / unpublishing the page directly.\n const canPublishOrUnpublish =\n params.actionType === ScheduledActionTypePublish\n ? await this.permissions.canPublish(\"page\")\n : await this.permissions.canUnpublish(\"page\");\n if (!canPublishOrUnpublish || !(await this.permissions.canAccess(\"page\", page))) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n\n const title = page.properties.title || \"Unknown page title\";\n\n return Result.ok({\n namespace: params.namespace,\n title,\n type,\n actionType: params.actionType,\n targetId: params.targetId,\n scheduleId: params.scheduleId,\n immediately: params.immediately || false\n });\n }\n}\n\nexport const PageNamespaceHandler = NamespaceHandlerAbstraction.createImplementation({\n implementation: PageNamespaceHandlerImpl,\n dependencies: [GetPageByIdUseCase, WbPermissions]\n});\n"],"names":["PageNamespaceHandlerImpl","getPageByIdUseCase","permissions","namespace","type","extractModelIdFromNamespace","SCHEDULED_ACTION_TYPE_PAGE","params","pageResult","Result","page","canPublishOrUnpublish","ScheduledActionTypePublish","SchedulerNotAuthorizedError","title","PageNamespaceHandler","NamespaceHandlerAbstraction","GetPageByIdUseCase","WbPermissions"],"mappings":";;;;;;AAaA,MAAMA;IACF,YACYC,kBAAgD,EAChDC,WAAoC,CAC9C;aAFUD,kBAAkB,GAAlBA;aACAC,WAAW,GAAXA;IACT;IAEI,UAAUC,SAAiB,EAAW;QACzC,MAAMC,OAAOC,4BAA4BF;QACzC,OAAOC,SAASE;IACpB;IAEA,MAAa,QACTC,MAA0C,EACmB;QAC7D,MAAMH,OAAOC,4BAA4BE,OAAO,SAAS;QAEzD,MAAMC,aAAa,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACD,OAAO,QAAQ;QACxE,IAAIC,WAAW,MAAM,IACjB,OAAOC,OAAO,IAAI,CAACD,WAAW,KAAK;QAEvC,MAAME,OAAOF,WAAW,KAAK;QAE7B,MAAMG,wBACFJ,OAAO,UAAU,KAAKK,6BAChB,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,UAClC,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,CAACD,yBAAyB,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQD,OACrE,OAAOD,OAAO,IAAI,CAAC,IAAII;QAG3B,MAAMC,QAAQJ,KAAK,UAAU,CAAC,KAAK,IAAI;QAEvC,OAAOD,OAAO,EAAE,CAAC;YACb,WAAWF,OAAO,SAAS;YAC3BO;YACAV;YACA,YAAYG,OAAO,UAAU;YAC7B,UAAUA,OAAO,QAAQ;YACzB,YAAYA,OAAO,UAAU;YAC7B,aAAaA,OAAO,WAAW,IAAI;QACvC;IACJ;AACJ;AAEO,MAAMQ,uBAAuBC,iBAAAA,oBAAgD,CAAC;IACjF,gBAAgBhB;IAChB,cAAc;QAACiB;QAAoBC;KAAc;AACrD"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { NamespaceHandler as NamespaceHandlerAbstraction } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { WbPermissions } from "@webiny/api-website-builder/features/permissions/abstractions.js";
|
|
2
3
|
import type { GenericRecord } from "@webiny/api/types.js";
|
|
3
4
|
import type { IScheduledActionPayload } from "../../types.js";
|
|
4
5
|
import { GetRedirectByIdUseCase } from "@webiny/api-website-builder/exports/api/website-builder/redirect.js";
|
|
5
6
|
declare class RedirectNamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {
|
|
6
7
|
private getRedirectByIdUseCase;
|
|
7
|
-
|
|
8
|
+
private permissions;
|
|
9
|
+
constructor(getRedirectByIdUseCase: GetRedirectByIdUseCase.Interface, permissions: WbPermissions.Interface);
|
|
8
10
|
canHandle(namespace: string): boolean;
|
|
9
11
|
execute(params: NamespaceHandlerAbstraction.Params): NamespaceHandlerAbstraction.Response<IScheduledActionPayload>;
|
|
10
12
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { NamespaceHandler } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
1
|
+
import { NamespaceHandler, SchedulerNotAuthorizedError } from "@webiny/api-scheduler/exports/api/scheduler.js";
|
|
2
|
+
import { WbPermissions } from "@webiny/api-website-builder/features/permissions/abstractions.js";
|
|
2
3
|
import { extractModelIdFromNamespace } from "../../utils/namespace.js";
|
|
3
4
|
import { Result } from "@webiny/feature/exports/api.js";
|
|
4
5
|
import { SCHEDULED_ACTION_TYPE_REDIRECT } from "../../constants.js";
|
|
5
6
|
import { GetRedirectByIdUseCase } from "@webiny/api-website-builder/exports/api/website-builder/redirect.js";
|
|
6
7
|
class RedirectNamespaceHandlerImpl {
|
|
7
|
-
constructor(getRedirectByIdUseCase){
|
|
8
|
+
constructor(getRedirectByIdUseCase, permissions){
|
|
8
9
|
this.getRedirectByIdUseCase = getRedirectByIdUseCase;
|
|
10
|
+
this.permissions = permissions;
|
|
9
11
|
}
|
|
10
12
|
canHandle(namespace) {
|
|
11
13
|
const type = extractModelIdFromNamespace(namespace);
|
|
@@ -16,6 +18,7 @@ class RedirectNamespaceHandlerImpl {
|
|
|
16
18
|
const redirectResult = await this.getRedirectByIdUseCase.execute(params.targetId);
|
|
17
19
|
if (redirectResult.isFail()) return Result.fail(redirectResult.error);
|
|
18
20
|
const redirect = redirectResult.value;
|
|
21
|
+
if (!await this.permissions.canEdit("redirect", redirect)) return Result.fail(new SchedulerNotAuthorizedError());
|
|
19
22
|
const title = redirect.redirectFrom || "Unknown redirect title";
|
|
20
23
|
return Result.ok({
|
|
21
24
|
namespace: params.namespace,
|
|
@@ -31,7 +34,8 @@ class RedirectNamespaceHandlerImpl {
|
|
|
31
34
|
const RedirectNamespaceHandler = NamespaceHandler.createImplementation({
|
|
32
35
|
implementation: RedirectNamespaceHandlerImpl,
|
|
33
36
|
dependencies: [
|
|
34
|
-
GetRedirectByIdUseCase
|
|
37
|
+
GetRedirectByIdUseCase,
|
|
38
|
+
WbPermissions
|
|
35
39
|
]
|
|
36
40
|
});
|
|
37
41
|
export { RedirectNamespaceHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/NamespaceHandler/RedirectNamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/RedirectNamespaceHandler.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"features/NamespaceHandler/RedirectNamespaceHandler.js","sources":["../../../src/features/NamespaceHandler/RedirectNamespaceHandler.ts"],"sourcesContent":["import {\n NamespaceHandler as NamespaceHandlerAbstraction,\n SchedulerNotAuthorizedError\n} from \"@webiny/api-scheduler/exports/api/scheduler.js\";\nimport { WbPermissions } from \"@webiny/api-website-builder/features/permissions/abstractions.js\";\nimport { extractModelIdFromNamespace } from \"~/utils/namespace.js\";\nimport { Result } from \"@webiny/feature/exports/api.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { SCHEDULED_ACTION_TYPE_REDIRECT } from \"~/constants.js\";\nimport type { IScheduledActionPayload } from \"~/types.js\";\nimport { GetRedirectByIdUseCase } from \"@webiny/api-website-builder/exports/api/website-builder/redirect.js\";\n\nclass RedirectNamespaceHandlerImpl implements NamespaceHandlerAbstraction.Interface<GenericRecord> {\n public constructor(\n private getRedirectByIdUseCase: GetRedirectByIdUseCase.Interface,\n private permissions: WbPermissions.Interface\n ) {}\n\n public canHandle(namespace: string): boolean {\n const type = extractModelIdFromNamespace(namespace);\n\n return type === SCHEDULED_ACTION_TYPE_REDIRECT;\n }\n\n public async execute(\n params: NamespaceHandlerAbstraction.Params\n ): NamespaceHandlerAbstraction.Response<IScheduledActionPayload> {\n const type = extractModelIdFromNamespace(params.namespace)!;\n\n const redirectResult = await this.getRedirectByIdUseCase.execute(params.targetId);\n if (redirectResult.isFail()) {\n return Result.fail(redirectResult.error as any);\n }\n const redirect = redirectResult.value;\n // Redirects have no publish permission; changing one requires edit access.\n if (!(await this.permissions.canEdit(\"redirect\", redirect))) {\n return Result.fail(new SchedulerNotAuthorizedError());\n }\n\n const title = redirect.redirectFrom || \"Unknown redirect title\";\n\n return Result.ok({\n namespace: params.namespace,\n title,\n type,\n actionType: params.actionType,\n targetId: params.targetId,\n scheduleId: params.scheduleId,\n immediately: params.immediately || false\n });\n }\n}\n\nexport const RedirectNamespaceHandler = NamespaceHandlerAbstraction.createImplementation({\n implementation: RedirectNamespaceHandlerImpl,\n dependencies: [GetRedirectByIdUseCase, WbPermissions]\n});\n"],"names":["RedirectNamespaceHandlerImpl","getRedirectByIdUseCase","permissions","namespace","type","extractModelIdFromNamespace","SCHEDULED_ACTION_TYPE_REDIRECT","params","redirectResult","Result","redirect","SchedulerNotAuthorizedError","title","RedirectNamespaceHandler","NamespaceHandlerAbstraction","GetRedirectByIdUseCase","WbPermissions"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACYC,sBAAwD,EACxDC,WAAoC,CAC9C;aAFUD,sBAAsB,GAAtBA;aACAC,WAAW,GAAXA;IACT;IAEI,UAAUC,SAAiB,EAAW;QACzC,MAAMC,OAAOC,4BAA4BF;QAEzC,OAAOC,SAASE;IACpB;IAEA,MAAa,QACTC,MAA0C,EACmB;QAC7D,MAAMH,OAAOC,4BAA4BE,OAAO,SAAS;QAEzD,MAAMC,iBAAiB,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAACD,OAAO,QAAQ;QAChF,IAAIC,eAAe,MAAM,IACrB,OAAOC,OAAO,IAAI,CAACD,eAAe,KAAK;QAE3C,MAAME,WAAWF,eAAe,KAAK;QAErC,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAYE,WAC7C,OAAOD,OAAO,IAAI,CAAC,IAAIE;QAG3B,MAAMC,QAAQF,SAAS,YAAY,IAAI;QAEvC,OAAOD,OAAO,EAAE,CAAC;YACb,WAAWF,OAAO,SAAS;YAC3BK;YACAR;YACA,YAAYG,OAAO,UAAU;YAC7B,UAAUA,OAAO,QAAQ;YACzB,YAAYA,OAAO,UAAU;YAC7B,aAAaA,OAAO,WAAW,IAAI;QACvC;IACJ;AACJ;AAEO,MAAMM,2BAA2BC,iBAAAA,oBAAgD,CAAC;IACrF,gBAAgBd;IAChB,cAAc;QAACe;QAAwBC;KAAc;AACzD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-website-builder-scheduler",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.1",
|
|
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-scheduler": "6.5.2-beta.
|
|
22
|
-
"@webiny/api-website-builder": "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.1",
|
|
21
|
+
"@webiny/api-scheduler": "6.5.2-beta.1",
|
|
22
|
+
"@webiny/api-website-builder": "6.5.2-beta.1",
|
|
23
|
+
"@webiny/feature": "6.5.2-beta.1",
|
|
24
|
+
"@webiny/handler-graphql": "6.5.2-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
28
|
-
"@webiny/api-headless-cms": "6.5.2-beta.
|
|
29
|
-
"@webiny/api-opensearch": "6.5.2-beta.
|
|
30
|
-
"@webiny/background-tasks": "6.5.2-beta.
|
|
31
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
32
|
-
"@webiny/handler": "6.5.2-beta.
|
|
33
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
34
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
35
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
36
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
27
|
+
"@webiny/api-core": "6.5.2-beta.1",
|
|
28
|
+
"@webiny/api-headless-cms": "6.5.2-beta.1",
|
|
29
|
+
"@webiny/api-opensearch": "6.5.2-beta.1",
|
|
30
|
+
"@webiny/background-tasks": "6.5.2-beta.1",
|
|
31
|
+
"@webiny/build-tools": "6.5.2-beta.1",
|
|
32
|
+
"@webiny/handler": "6.5.2-beta.1",
|
|
33
|
+
"@webiny/handler-aws": "6.5.2-beta.1",
|
|
34
|
+
"@webiny/plugins": "6.5.2-beta.1",
|
|
35
|
+
"@webiny/project-utils": "6.5.2-beta.1",
|
|
36
|
+
"@webiny/wcp": "6.5.2-beta.1",
|
|
37
37
|
"typescript": "7.0.2",
|
|
38
38
|
"vitest": "5.0.5"
|
|
39
39
|
},
|