@strapi/review-workflows 5.50.0 → 5.50.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.
Files changed (71) hide show
  1. package/dist/admin/routes/content-manager/model/components/AssigneeFilter.js +1 -1
  2. package/dist/admin/routes/content-manager/model/components/AssigneeFilter.js.map +1 -1
  3. package/dist/admin/routes/content-manager/model/components/AssigneeFilter.mjs +1 -1
  4. package/dist/admin/routes/content-manager/model/components/AssigneeFilter.mjs.map +1 -1
  5. package/dist/admin/routes/content-manager/model/components/StageFilter.js.map +1 -1
  6. package/dist/admin/routes/content-manager/model/components/StageFilter.mjs.map +1 -1
  7. package/dist/admin/routes/settings/components/Stages.js +4 -3
  8. package/dist/admin/routes/settings/components/Stages.js.map +1 -1
  9. package/dist/admin/routes/settings/components/Stages.mjs +4 -3
  10. package/dist/admin/routes/settings/components/Stages.mjs.map +1 -1
  11. package/dist/admin/routes/settings/components/WorkflowAttributes.js +2 -2
  12. package/dist/admin/routes/settings/components/WorkflowAttributes.js.map +1 -1
  13. package/dist/admin/routes/settings/components/WorkflowAttributes.mjs +2 -2
  14. package/dist/admin/routes/settings/components/WorkflowAttributes.mjs.map +1 -1
  15. package/dist/admin/src/routes/settings/components/Stages.d.ts +1 -1
  16. package/dist/admin/src/services/admin.d.ts +1 -1
  17. package/dist/admin/src/services/api.d.ts +1 -1
  18. package/dist/admin/src/services/content-manager.d.ts +4 -4
  19. package/dist/admin/src/services/settings.d.ts +3 -3
  20. package/dist/admin/src/utils/api.d.ts +2 -2
  21. package/dist/admin/translations/pl.json.js +34 -1
  22. package/dist/admin/translations/pl.json.js.map +1 -1
  23. package/dist/admin/translations/pl.json.mjs +34 -1
  24. package/dist/admin/translations/pl.json.mjs.map +1 -1
  25. package/dist/admin/utils/api.js.map +1 -1
  26. package/dist/admin/utils/api.mjs.map +1 -1
  27. package/dist/server/bootstrap.js +4 -4
  28. package/dist/server/bootstrap.js.map +1 -1
  29. package/dist/server/bootstrap.mjs +4 -4
  30. package/dist/server/bootstrap.mjs.map +1 -1
  31. package/dist/server/constants/workflows.js +1 -1
  32. package/dist/server/constants/workflows.js.map +1 -1
  33. package/dist/server/constants/workflows.mjs +1 -1
  34. package/dist/server/constants/workflows.mjs.map +1 -1
  35. package/dist/server/controllers/stages.js.map +1 -1
  36. package/dist/server/controllers/stages.mjs.map +1 -1
  37. package/dist/server/controllers/workflows.js.map +1 -1
  38. package/dist/server/controllers/workflows.mjs.map +1 -1
  39. package/dist/server/destroy.js +1 -1
  40. package/dist/server/destroy.js.map +1 -1
  41. package/dist/server/destroy.mjs +1 -1
  42. package/dist/server/destroy.mjs.map +1 -1
  43. package/dist/server/register.js +0 -2
  44. package/dist/server/register.js.map +1 -1
  45. package/dist/server/register.mjs +0 -2
  46. package/dist/server/register.mjs.map +1 -1
  47. package/dist/server/services/assignees.js.map +1 -1
  48. package/dist/server/services/assignees.mjs.map +1 -1
  49. package/dist/server/services/document-service-middleware.js +3 -3
  50. package/dist/server/services/document-service-middleware.js.map +1 -1
  51. package/dist/server/services/document-service-middleware.mjs +3 -3
  52. package/dist/server/services/document-service-middleware.mjs.map +1 -1
  53. package/dist/server/services/stages.js.map +1 -1
  54. package/dist/server/services/stages.mjs.map +1 -1
  55. package/dist/server/src/bootstrap.d.ts +4 -1
  56. package/dist/server/src/bootstrap.d.ts.map +1 -1
  57. package/dist/server/src/constants/workflows.d.ts +1 -1
  58. package/dist/server/src/destroy.d.ts +1 -4
  59. package/dist/server/src/destroy.d.ts.map +1 -1
  60. package/dist/server/src/index.d.ts +2 -2
  61. package/dist/server/src/register.d.ts.map +1 -1
  62. package/dist/server/src/services/assignees.d.ts +2 -2
  63. package/dist/server/src/services/assignees.d.ts.map +1 -1
  64. package/dist/server/src/services/stages.d.ts.map +1 -1
  65. package/package.json +11 -5
  66. package/dist/server/migrations/shorten-stage-attribute.js +0 -49
  67. package/dist/server/migrations/shorten-stage-attribute.js.map +0 -1
  68. package/dist/server/migrations/shorten-stage-attribute.mjs +0 -43
  69. package/dist/server/migrations/shorten-stage-attribute.mjs.map +0 -1
  70. package/dist/server/src/migrations/shorten-stage-attribute.d.ts +0 -6
  71. package/dist/server/src/migrations/shorten-stage-attribute.d.ts.map +0 -1
@@ -1,7 +1,40 @@
1
1
  'use strict';
2
2
 
3
3
  var pl = {
4
- "stage.label": "Etap przeglądu"
4
+ "assignee.clear": "Wyczyść przypisanie",
5
+ "assignee.error": "Wystąpił błąd podczas pobierania użytkowników",
6
+ "assignee.label": "Przypisany",
7
+ "assignee.notification.saved": "Przypisanie zaktualizowane",
8
+ "assignee.placeholder": "Wybierz…",
9
+ "containers.list.table-headers.reviewWorkflows.assignee": "przypisany",
10
+ "containers.list.table-headers.reviewWorkflows.assignee.label": "Przypisany",
11
+ "containers.list.table-headers.reviewWorkflows.stage": "etap przeglądu",
12
+ "settings.not-available": "Przepływy pracy przeglądów są dostępne tylko jako część edycji Enterprise. Uaktualnij, aby tworzyć i zarządzać przepływami pracy.",
13
+ "settings.page.delete.confirm.body": "Wszystkie wpisy przypisane do usuniętych etapów zostaną przeniesione do poprzedniego etapu. Czy na pewno chcesz zapisać?",
14
+ "settings.page.isLoading": "Przepływ pracy jest ładowany",
15
+ "settings.page.purchase.description": "Zarządzaj procesem przeglądu treści",
16
+ "settings.page.purchase.perks1": "Konfigurowalne etapy przeglądu",
17
+ "settings.page.purchase.perks2": "Zarządzaj uprawnieniami użytkowników",
18
+ "settings.page.purchase.perks3": "Wsparcie dla webhooków",
19
+ "settings.page.subtitle": "{count, plural, one {# etap} other {# etapów}}",
20
+ "settings.page.title": "Przepływy pracy przeglądów",
21
+ "settings.review-workflows.workflow.stageRequiredToPublish.any": "Dowolny etap",
22
+ "settings.review-workflows.workflow.stageRequiredToPublish.hint": "Zapobiega publikowaniu wpisów, jeśli nie znajdują się na wymaganym etapie.",
23
+ "settings.review-workflows.workflow.stageRequiredToPublish.label": "Wymagany etap do publikacji",
24
+ "settings.stage.name.label": "Nazwa etapu",
25
+ "stage.color": "Kolor",
26
+ "stage.label": "Etap przeglądu",
27
+ "stage.notification.error": "Wystąpił błąd podczas aktualizacji etapu przeglądu",
28
+ "stage.notification.saved": "Etap przeglądu zaktualizowany",
29
+ "stages.limit.body": "Spróbuj usunąć niektóre etapy lub skontaktuj się ze sprzedażą, aby włączyć więcej etapów.",
30
+ "stages.limit.title": "Osiągnąłeś limit etapów dla tego przepływu pracy w swoim planie",
31
+ "stages.no-transition": "Nie masz uprawnień do aktualizacji tego etapu.",
32
+ "stages.save-first": "Zapisz ten wpis, aby przypisać etap przepływu pracy.",
33
+ "stages.single-stage": "Ten przepływ pracy ma tylko jeden etap. Dodaj więcej etapów, aby móc przechodzić między nimi.",
34
+ "widget.assigned.no-data": "Brak wpisów",
35
+ "widget.assigned.title": "Przypisane do mnie",
36
+ "workflows.limit.body": "Usuń przepływ pracy lub skontaktuj się ze sprzedażą, aby włączyć więcej przepływów pracy.",
37
+ "workflows.limit.title": "Osiągnąłeś limit przepływów pracy w swoim planie"
5
38
  };
6
39
 
7
40
  module.exports = pl;
@@ -1 +1 @@
1
- {"version":3,"file":"pl.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
1
+ {"version":3,"file":"pl.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,38 @@
1
1
  var pl = {
2
- "stage.label": "Etap przeglądu"
2
+ "assignee.clear": "Wyczyść przypisanie",
3
+ "assignee.error": "Wystąpił błąd podczas pobierania użytkowników",
4
+ "assignee.label": "Przypisany",
5
+ "assignee.notification.saved": "Przypisanie zaktualizowane",
6
+ "assignee.placeholder": "Wybierz…",
7
+ "containers.list.table-headers.reviewWorkflows.assignee": "przypisany",
8
+ "containers.list.table-headers.reviewWorkflows.assignee.label": "Przypisany",
9
+ "containers.list.table-headers.reviewWorkflows.stage": "etap przeglądu",
10
+ "settings.not-available": "Przepływy pracy przeglądów są dostępne tylko jako część edycji Enterprise. Uaktualnij, aby tworzyć i zarządzać przepływami pracy.",
11
+ "settings.page.delete.confirm.body": "Wszystkie wpisy przypisane do usuniętych etapów zostaną przeniesione do poprzedniego etapu. Czy na pewno chcesz zapisać?",
12
+ "settings.page.isLoading": "Przepływ pracy jest ładowany",
13
+ "settings.page.purchase.description": "Zarządzaj procesem przeglądu treści",
14
+ "settings.page.purchase.perks1": "Konfigurowalne etapy przeglądu",
15
+ "settings.page.purchase.perks2": "Zarządzaj uprawnieniami użytkowników",
16
+ "settings.page.purchase.perks3": "Wsparcie dla webhooków",
17
+ "settings.page.subtitle": "{count, plural, one {# etap} other {# etapów}}",
18
+ "settings.page.title": "Przepływy pracy przeglądów",
19
+ "settings.review-workflows.workflow.stageRequiredToPublish.any": "Dowolny etap",
20
+ "settings.review-workflows.workflow.stageRequiredToPublish.hint": "Zapobiega publikowaniu wpisów, jeśli nie znajdują się na wymaganym etapie.",
21
+ "settings.review-workflows.workflow.stageRequiredToPublish.label": "Wymagany etap do publikacji",
22
+ "settings.stage.name.label": "Nazwa etapu",
23
+ "stage.color": "Kolor",
24
+ "stage.label": "Etap przeglądu",
25
+ "stage.notification.error": "Wystąpił błąd podczas aktualizacji etapu przeglądu",
26
+ "stage.notification.saved": "Etap przeglądu zaktualizowany",
27
+ "stages.limit.body": "Spróbuj usunąć niektóre etapy lub skontaktuj się ze sprzedażą, aby włączyć więcej etapów.",
28
+ "stages.limit.title": "Osiągnąłeś limit etapów dla tego przepływu pracy w swoim planie",
29
+ "stages.no-transition": "Nie masz uprawnień do aktualizacji tego etapu.",
30
+ "stages.save-first": "Zapisz ten wpis, aby przypisać etap przepływu pracy.",
31
+ "stages.single-stage": "Ten przepływ pracy ma tylko jeden etap. Dodaj więcej etapów, aby móc przechodzić między nimi.",
32
+ "widget.assigned.no-data": "Brak wpisów",
33
+ "widget.assigned.title": "Przypisane do mnie",
34
+ "workflows.limit.body": "Usuń przepływ pracy lub skontaktuj się ze sprzedażą, aby włączyć więcej przepływów pracy.",
35
+ "workflows.limit.title": "Osiągnąłeś limit przepływów pracy w swoim planie"
3
36
  };
4
37
 
5
38
  export { pl as default };
@@ -1 +1 @@
1
- {"version":3,"file":"pl.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"pl.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":["../../../admin/src/utils/api.ts"],"sourcesContent":["import { SerializedError } from '@reduxjs/toolkit';\nimport { type UnknownApiError, type ApiError } from '@strapi/admin/strapi-admin';\n\nexport type BaseQueryError = ApiError | UnknownApiError | SerializedError;\n\nconst isBaseQueryError = (error: BaseQueryError): error is ApiError | UnknownApiError => {\n return error.name !== undefined;\n};\n\ninterface Query {\n plugins?: Record<string, unknown>;\n _q?: string;\n [key: string]: any;\n}\n\n/**\n * This type extracts the plugin options from the query\n * and appends them to the root of the query\n */\ntype TransformedQuery<TQuery extends Query> = Omit<TQuery, 'plugins'> & {\n [key: string]: string;\n};\n\n/**\n * @description\n * Creates a valid query params object for get requests\n * ie. plugins[18n][locale]=en becomes locale=en\n */\nconst buildValidParams = <TQuery extends Query>(query: TQuery): TransformedQuery<TQuery> => {\n if (!query) return query;\n\n // Extract pluginOptions from the query, they shouldn't be part of the URL\n const { plugins: _, ...validQueryParams } = {\n ...query,\n ...Object.values(query?.plugins ?? {}).reduce<Record<string, string>>(\n (acc, current) => Object.assign(acc, current),\n {}\n ),\n };\n\n return validQueryParams;\n};\n\nexport { isBaseQueryError, buildValidParams };\n"],"names":["isBaseQueryError","error","name","undefined","buildValidParams","query","plugins","_","validQueryParams","Object","values","reduce","acc","current","assign"],"mappings":";;AAKA,MAAMA,mBAAmB,CAACC,KAAAA,GAAAA;IACxB,OAAOA,KAAAA,CAAMC,IAAI,KAAKC,SAAAA;AACxB;AAgBA;;;;IAKA,MAAMC,mBAAmB,CAAuBC,KAAAA,GAAAA;IAC9C,IAAI,CAACA,OAAO,OAAOA,KAAAA;;AAGnB,IAAA,MAAM,EAAEC,OAAAA,EAASC,CAAC,EAAE,GAAGC,kBAAkB,GAAG;AAC1C,QAAA,GAAGH,KAAK;AACR,QAAA,GAAGI,OAAOC,MAAM,CAACL,OAAOC,OAAAA,IAAW,IAAIK,MAAM,CAC3C,CAACC,GAAAA,EAAKC,UAAYJ,MAAAA,CAAOK,MAAM,CAACF,GAAAA,EAAKC,OAAAA,CAAAA,EACrC,EAAC;AAEL,KAAA;IAEA,OAAOL,gBAAAA;AACT;;;;;"}
1
+ {"version":3,"file":"api.js","sources":["../../../admin/src/utils/api.ts"],"sourcesContent":["import { SerializedError } from '@reduxjs/toolkit';\nimport { type UnknownApiError, type ApiError } from '@strapi/admin/strapi-admin';\n\nexport type BaseQueryError = ApiError | UnknownApiError | SerializedError;\n\nconst isBaseQueryError = (error: BaseQueryError): error is ApiError | UnknownApiError => {\n return error.name !== undefined;\n};\n\ninterface Query {\n plugins?: Record<string, Record<string, string>>;\n _q?: string;\n [key: string]: unknown;\n}\n\n/**\n * This type extracts the plugin options from the query\n * and appends them to the root of the query\n */\ntype TransformedQuery<TQuery extends Query> = Omit<TQuery, 'plugins'> & {\n [key: string]: string;\n};\n\n/**\n * @description\n * Creates a valid query params object for get requests\n * ie. plugins[18n][locale]=en becomes locale=en\n */\nconst buildValidParams = <TQuery extends Query>(query: TQuery): TransformedQuery<TQuery> => {\n if (!query) return query;\n\n // Extract pluginOptions from the query, they shouldn't be part of the URL\n const { plugins: _, ...validQueryParams } = {\n ...query,\n ...Object.values(query?.plugins ?? {}).reduce<Record<string, string>>(\n (acc, current) => Object.assign(acc, current),\n {}\n ),\n };\n\n return validQueryParams;\n};\n\nexport { isBaseQueryError, buildValidParams };\n"],"names":["isBaseQueryError","error","name","undefined","buildValidParams","query","plugins","_","validQueryParams","Object","values","reduce","acc","current","assign"],"mappings":";;AAKA,MAAMA,mBAAmB,CAACC,KAAAA,GAAAA;IACxB,OAAOA,KAAAA,CAAMC,IAAI,KAAKC,SAAAA;AACxB;AAgBA;;;;IAKA,MAAMC,mBAAmB,CAAuBC,KAAAA,GAAAA;IAC9C,IAAI,CAACA,OAAO,OAAOA,KAAAA;;AAGnB,IAAA,MAAM,EAAEC,OAAAA,EAASC,CAAC,EAAE,GAAGC,kBAAkB,GAAG;AAC1C,QAAA,GAAGH,KAAK;AACR,QAAA,GAAGI,OAAOC,MAAM,CAACL,OAAOC,OAAAA,IAAW,IAAIK,MAAM,CAC3C,CAACC,GAAAA,EAAKC,UAAYJ,MAAAA,CAAOK,MAAM,CAACF,GAAAA,EAAKC,OAAAA,CAAAA,EACrC,EAAC;AAEL,KAAA;IAEA,OAAOL,gBAAAA;AACT;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.mjs","sources":["../../../admin/src/utils/api.ts"],"sourcesContent":["import { SerializedError } from '@reduxjs/toolkit';\nimport { type UnknownApiError, type ApiError } from '@strapi/admin/strapi-admin';\n\nexport type BaseQueryError = ApiError | UnknownApiError | SerializedError;\n\nconst isBaseQueryError = (error: BaseQueryError): error is ApiError | UnknownApiError => {\n return error.name !== undefined;\n};\n\ninterface Query {\n plugins?: Record<string, unknown>;\n _q?: string;\n [key: string]: any;\n}\n\n/**\n * This type extracts the plugin options from the query\n * and appends them to the root of the query\n */\ntype TransformedQuery<TQuery extends Query> = Omit<TQuery, 'plugins'> & {\n [key: string]: string;\n};\n\n/**\n * @description\n * Creates a valid query params object for get requests\n * ie. plugins[18n][locale]=en becomes locale=en\n */\nconst buildValidParams = <TQuery extends Query>(query: TQuery): TransformedQuery<TQuery> => {\n if (!query) return query;\n\n // Extract pluginOptions from the query, they shouldn't be part of the URL\n const { plugins: _, ...validQueryParams } = {\n ...query,\n ...Object.values(query?.plugins ?? {}).reduce<Record<string, string>>(\n (acc, current) => Object.assign(acc, current),\n {}\n ),\n };\n\n return validQueryParams;\n};\n\nexport { isBaseQueryError, buildValidParams };\n"],"names":["isBaseQueryError","error","name","undefined","buildValidParams","query","plugins","_","validQueryParams","Object","values","reduce","acc","current","assign"],"mappings":"AAKA,MAAMA,mBAAmB,CAACC,KAAAA,GAAAA;IACxB,OAAOA,KAAAA,CAAMC,IAAI,KAAKC,SAAAA;AACxB;AAgBA;;;;IAKA,MAAMC,mBAAmB,CAAuBC,KAAAA,GAAAA;IAC9C,IAAI,CAACA,OAAO,OAAOA,KAAAA;;AAGnB,IAAA,MAAM,EAAEC,OAAAA,EAASC,CAAC,EAAE,GAAGC,kBAAkB,GAAG;AAC1C,QAAA,GAAGH,KAAK;AACR,QAAA,GAAGI,OAAOC,MAAM,CAACL,OAAOC,OAAAA,IAAW,IAAIK,MAAM,CAC3C,CAACC,GAAAA,EAAKC,UAAYJ,MAAAA,CAAOK,MAAM,CAACF,GAAAA,EAAKC,OAAAA,CAAAA,EACrC,EAAC;AAEL,KAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
1
+ {"version":3,"file":"api.mjs","sources":["../../../admin/src/utils/api.ts"],"sourcesContent":["import { SerializedError } from '@reduxjs/toolkit';\nimport { type UnknownApiError, type ApiError } from '@strapi/admin/strapi-admin';\n\nexport type BaseQueryError = ApiError | UnknownApiError | SerializedError;\n\nconst isBaseQueryError = (error: BaseQueryError): error is ApiError | UnknownApiError => {\n return error.name !== undefined;\n};\n\ninterface Query {\n plugins?: Record<string, Record<string, string>>;\n _q?: string;\n [key: string]: unknown;\n}\n\n/**\n * This type extracts the plugin options from the query\n * and appends them to the root of the query\n */\ntype TransformedQuery<TQuery extends Query> = Omit<TQuery, 'plugins'> & {\n [key: string]: string;\n};\n\n/**\n * @description\n * Creates a valid query params object for get requests\n * ie. plugins[18n][locale]=en becomes locale=en\n */\nconst buildValidParams = <TQuery extends Query>(query: TQuery): TransformedQuery<TQuery> => {\n if (!query) return query;\n\n // Extract pluginOptions from the query, they shouldn't be part of the URL\n const { plugins: _, ...validQueryParams } = {\n ...query,\n ...Object.values(query?.plugins ?? {}).reduce<Record<string, string>>(\n (acc, current) => Object.assign(acc, current),\n {}\n ),\n };\n\n return validQueryParams;\n};\n\nexport { isBaseQueryError, buildValidParams };\n"],"names":["isBaseQueryError","error","name","undefined","buildValidParams","query","plugins","_","validQueryParams","Object","values","reduce","acc","current","assign"],"mappings":"AAKA,MAAMA,mBAAmB,CAACC,KAAAA,GAAAA;IACxB,OAAOA,KAAAA,CAAMC,IAAI,KAAKC,SAAAA;AACxB;AAgBA;;;;IAKA,MAAMC,mBAAmB,CAAuBC,KAAAA,GAAAA;IAC9C,IAAI,CAACA,OAAO,OAAOA,KAAAA;;AAGnB,IAAA,MAAM,EAAEC,OAAAA,EAASC,CAAC,EAAE,GAAGC,kBAAkB,GAAG;AAC1C,QAAA,GAAGH,KAAK;AACR,QAAA,GAAGI,OAAOC,MAAM,CAACL,OAAOC,OAAAA,IAAW,IAAIK,MAAM,CAC3C,CAACC,GAAAA,EAAKC,UAAYJ,MAAAA,CAAOK,MAAM,CAACF,GAAAA,EAAKC,OAAAA,CAAAA,EACrC,EAAC;AAEL,KAAA;IAEA,OAAOL,gBAAAA;AACT;;;;"}
@@ -34,7 +34,7 @@ var webhookEvents = require('./constants/webhook-events.js');
34
34
  * Webhook store limits the events that can be triggered,
35
35
  * this function extends it with the events review workflows can trigger
36
36
  */ const registerWebhookEvents = async ()=>Object.entries(webhookEvents.default).forEach(([eventKey, event])=>strapi.get('webhookStore').addAllowedEvent(eventKey, event));
37
- var bootstrap = (async (args)=>{
37
+ var bootstrap = (async ({ strapi: strapi1 })=>{
38
38
  // Permissions
39
39
  const { actionProvider } = index.getAdminService('permission');
40
40
  await actionProvider.registerMany(actions.reviewWorkflows);
@@ -45,9 +45,9 @@ var bootstrap = (async (args)=>{
45
45
  await initDefaultWorkflow();
46
46
  // Document service middleware
47
47
  const docsMiddlewares = index.getService('document-service-middlewares');
48
- strapi.documents.use(docsMiddlewares.assignStageOnCreate);
49
- strapi.documents.use(docsMiddlewares.handleStageOnUpdate);
50
- strapi.documents.use(docsMiddlewares.checkStageBeforePublish);
48
+ strapi1.documents.use(docsMiddlewares.assignStageOnCreate);
49
+ strapi1.documents.use(docsMiddlewares.handleStageOnUpdate);
50
+ strapi1.documents.use(docsMiddlewares.checkStageBeforePublish);
51
51
  });
52
52
 
53
53
  module.exports = bootstrap;
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.js","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { getAdminService, getService } from './utils';\nimport actions from './config/actions';\n\nimport defaultStages from './constants/default-stages.json';\nimport defaultWorkflow from './constants/default-workflow.json';\nimport webhookEvents from './constants/webhook-events';\n\n/**\n * Initialize the default workflow if there is no workflow in the database\n */\n\nasync function initDefaultWorkflow() {\n const workflowsService = getService('workflows', { strapi });\n const stagesService = getService('stages', { strapi });\n\n const wfCount = await workflowsService.count();\n const stagesCount = await stagesService.count();\n\n // Check if there is nothing about review-workflow in DB\n // If any, the feature has already been initialized with a workflow and stages\n if (wfCount === 0 && stagesCount === 0) {\n const workflow = {\n ...defaultWorkflow,\n contentTypes: [],\n stages: defaultStages,\n };\n\n await workflowsService.create({ data: workflow });\n }\n}\n\n/**\n * Webhook store limits the events that can be triggered,\n * this function extends it with the events review workflows can trigger\n */\nconst registerWebhookEvents = async () =>\n Object.entries(webhookEvents).forEach(([eventKey, event]) =>\n strapi.get('webhookStore').addAllowedEvent(eventKey, event)\n );\n\nexport default async (args: any) => {\n // Permissions\n const { actionProvider } = getAdminService('permission');\n await actionProvider.registerMany(actions.reviewWorkflows);\n\n // Webhooks and events\n await registerWebhookEvents();\n await getService('workflow-weekly-metrics').registerCron();\n\n // Data initialization\n await initDefaultWorkflow();\n\n // Document service middleware\n const docsMiddlewares = getService('document-service-middlewares');\n strapi.documents.use(docsMiddlewares.assignStageOnCreate);\n strapi.documents.use(docsMiddlewares.handleStageOnUpdate);\n strapi.documents.use(docsMiddlewares.checkStageBeforePublish);\n};\n"],"names":["initDefaultWorkflow","workflowsService","getService","strapi","stagesService","wfCount","count","stagesCount","workflow","defaultWorkflow","contentTypes","stages","defaultStages","create","data","registerWebhookEvents","Object","entries","webhookEvents","forEach","eventKey","event","get","addAllowedEvent","args","actionProvider","getAdminService","registerMany","actions","reviewWorkflows","registerCron","docsMiddlewares","documents","use","assignStageOnCreate","handleStageOnUpdate","checkStageBeforePublish"],"mappings":";;;;;;;;AAOA;;AAEC,IAED,eAAeA,mBAAAA,GAAAA;IACb,MAAMC,gBAAAA,GAAmBC,iBAAW,WAAA,EAAa;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAC1D,MAAMC,aAAAA,GAAgBF,iBAAW,QAAA,EAAU;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAEpD,MAAME,OAAAA,GAAU,MAAMJ,gBAAAA,CAAiBK,KAAK,EAAA;IAC5C,MAAMC,WAAAA,GAAc,MAAMH,aAAAA,CAAcE,KAAK,EAAA;;;IAI7C,IAAID,OAAAA,KAAY,CAAA,IAAKE,WAAAA,KAAgB,CAAA,EAAG;AACtC,QAAA,MAAMC,QAAAA,GAAW;AACf,YAAA,GAAGC,uBAAe;AAClBC,YAAAA,YAAAA,EAAc,EAAE;YAChBC,MAAAA,EAAQC;AACV,SAAA;QAEA,MAAMX,gBAAAA,CAAiBY,MAAM,CAAC;YAAEC,IAAAA,EAAMN;AAAS,SAAA,CAAA;AACjD,IAAA;AACF;AAEA;;;IAIA,MAAMO,wBAAwB,UAC5BC,MAAAA,CAAOC,OAAO,CAACC,qBAAAA,CAAAA,CAAeC,OAAO,CAAC,CAAC,CAACC,QAAAA,EAAUC,KAAAA,CAAM,GACtDlB,MAAAA,CAAOmB,GAAG,CAAC,cAAA,CAAA,CAAgBC,eAAe,CAACH,QAAAA,EAAUC,KAAAA,CAAAA,CAAAA;AAGzD,gBAAe,CAAA,OAAOG,IAAAA,GAAAA;;AAEpB,IAAA,MAAM,EAAEC,cAAc,EAAE,GAAGC,qBAAAA,CAAgB,YAAA,CAAA;AAC3C,IAAA,MAAMD,cAAAA,CAAeE,YAAY,CAACC,OAAAA,CAAQC,eAAe,CAAA;;IAGzD,MAAMd,qBAAAA,EAAAA;IACN,MAAMb,gBAAAA,CAAW,2BAA2B4B,YAAY,EAAA;;IAGxD,MAAM9B,mBAAAA,EAAAA;;AAGN,IAAA,MAAM+B,kBAAkB7B,gBAAAA,CAAW,8BAAA,CAAA;AACnCC,IAAAA,MAAAA,CAAO6B,SAAS,CAACC,GAAG,CAACF,gBAAgBG,mBAAmB,CAAA;AACxD/B,IAAAA,MAAAA,CAAO6B,SAAS,CAACC,GAAG,CAACF,gBAAgBI,mBAAmB,CAAA;AACxDhC,IAAAA,MAAAA,CAAO6B,SAAS,CAACC,GAAG,CAACF,gBAAgBK,uBAAuB,CAAA;AAC9D,CAAA;;;;"}
1
+ {"version":3,"file":"bootstrap.js","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { Core } from '@strapi/types';\nimport { getAdminService, getService } from './utils';\nimport actions from './config/actions';\n\nimport defaultStages from './constants/default-stages.json';\nimport defaultWorkflow from './constants/default-workflow.json';\nimport webhookEvents from './constants/webhook-events';\n\n/**\n * Initialize the default workflow if there is no workflow in the database\n */\n\nasync function initDefaultWorkflow() {\n const workflowsService = getService('workflows', { strapi });\n const stagesService = getService('stages', { strapi });\n\n const wfCount = await workflowsService.count();\n const stagesCount = await stagesService.count();\n\n // Check if there is nothing about review-workflow in DB\n // If any, the feature has already been initialized with a workflow and stages\n if (wfCount === 0 && stagesCount === 0) {\n const workflow = {\n ...defaultWorkflow,\n contentTypes: [],\n stages: defaultStages,\n };\n\n await workflowsService.create({ data: workflow });\n }\n}\n\n/**\n * Webhook store limits the events that can be triggered,\n * this function extends it with the events review workflows can trigger\n */\nconst registerWebhookEvents = async () =>\n Object.entries(webhookEvents).forEach(([eventKey, event]) =>\n strapi.get('webhookStore').addAllowedEvent(eventKey, event)\n );\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {\n // Permissions\n const { actionProvider } = getAdminService('permission');\n await actionProvider.registerMany(actions.reviewWorkflows);\n\n // Webhooks and events\n await registerWebhookEvents();\n await getService('workflow-weekly-metrics').registerCron();\n\n // Data initialization\n await initDefaultWorkflow();\n\n // Document service middleware\n const docsMiddlewares = getService('document-service-middlewares');\n strapi.documents.use(docsMiddlewares.assignStageOnCreate);\n strapi.documents.use(docsMiddlewares.handleStageOnUpdate);\n strapi.documents.use(docsMiddlewares.checkStageBeforePublish);\n};\n"],"names":["initDefaultWorkflow","workflowsService","getService","strapi","stagesService","wfCount","count","stagesCount","workflow","defaultWorkflow","contentTypes","stages","defaultStages","create","data","registerWebhookEvents","Object","entries","webhookEvents","forEach","eventKey","event","get","addAllowedEvent","actionProvider","getAdminService","registerMany","actions","reviewWorkflows","registerCron","docsMiddlewares","documents","use","assignStageOnCreate","handleStageOnUpdate","checkStageBeforePublish"],"mappings":";;;;;;;;AAQA;;AAEC,IAED,eAAeA,mBAAAA,GAAAA;IACb,MAAMC,gBAAAA,GAAmBC,iBAAW,WAAA,EAAa;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAC1D,MAAMC,aAAAA,GAAgBF,iBAAW,QAAA,EAAU;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAEpD,MAAME,OAAAA,GAAU,MAAMJ,gBAAAA,CAAiBK,KAAK,EAAA;IAC5C,MAAMC,WAAAA,GAAc,MAAMH,aAAAA,CAAcE,KAAK,EAAA;;;IAI7C,IAAID,OAAAA,KAAY,CAAA,IAAKE,WAAAA,KAAgB,CAAA,EAAG;AACtC,QAAA,MAAMC,QAAAA,GAAW;AACf,YAAA,GAAGC,uBAAe;AAClBC,YAAAA,YAAAA,EAAc,EAAE;YAChBC,MAAAA,EAAQC;AACV,SAAA;QAEA,MAAMX,gBAAAA,CAAiBY,MAAM,CAAC;YAAEC,IAAAA,EAAMN;AAAS,SAAA,CAAA;AACjD,IAAA;AACF;AAEA;;;IAIA,MAAMO,wBAAwB,UAC5BC,MAAAA,CAAOC,OAAO,CAACC,qBAAAA,CAAAA,CAAeC,OAAO,CAAC,CAAC,CAACC,QAAAA,EAAUC,KAAAA,CAAM,GACtDlB,MAAAA,CAAOmB,GAAG,CAAC,cAAA,CAAA,CAAgBC,eAAe,CAACH,QAAAA,EAAUC,KAAAA,CAAAA,CAAAA;AAGzD,gBAAe,CAAA,OAAO,EAAElB,MAAAA,EAAAA,OAAM,EAA2B,GAAA;;AAEvD,IAAA,MAAM,EAAEqB,cAAc,EAAE,GAAGC,qBAAAA,CAAgB,YAAA,CAAA;AAC3C,IAAA,MAAMD,cAAAA,CAAeE,YAAY,CAACC,OAAAA,CAAQC,eAAe,CAAA;;IAGzD,MAAMb,qBAAAA,EAAAA;IACN,MAAMb,gBAAAA,CAAW,2BAA2B2B,YAAY,EAAA;;IAGxD,MAAM7B,mBAAAA,EAAAA;;AAGN,IAAA,MAAM8B,kBAAkB5B,gBAAAA,CAAW,8BAAA,CAAA;AACnCC,IAAAA,OAAAA,CAAO4B,SAAS,CAACC,GAAG,CAACF,gBAAgBG,mBAAmB,CAAA;AACxD9B,IAAAA,OAAAA,CAAO4B,SAAS,CAACC,GAAG,CAACF,gBAAgBI,mBAAmB,CAAA;AACxD/B,IAAAA,OAAAA,CAAO4B,SAAS,CAACC,GAAG,CAACF,gBAAgBK,uBAAuB,CAAA;AAC9D,CAAA;;;;"}
@@ -32,7 +32,7 @@ import webhookEvents from './constants/webhook-events.mjs';
32
32
  * Webhook store limits the events that can be triggered,
33
33
  * this function extends it with the events review workflows can trigger
34
34
  */ const registerWebhookEvents = async ()=>Object.entries(webhookEvents).forEach(([eventKey, event])=>strapi.get('webhookStore').addAllowedEvent(eventKey, event));
35
- var bootstrap = (async (args)=>{
35
+ var bootstrap = (async ({ strapi: strapi1 })=>{
36
36
  // Permissions
37
37
  const { actionProvider } = getAdminService('permission');
38
38
  await actionProvider.registerMany(actions.reviewWorkflows);
@@ -43,9 +43,9 @@ var bootstrap = (async (args)=>{
43
43
  await initDefaultWorkflow();
44
44
  // Document service middleware
45
45
  const docsMiddlewares = getService('document-service-middlewares');
46
- strapi.documents.use(docsMiddlewares.assignStageOnCreate);
47
- strapi.documents.use(docsMiddlewares.handleStageOnUpdate);
48
- strapi.documents.use(docsMiddlewares.checkStageBeforePublish);
46
+ strapi1.documents.use(docsMiddlewares.assignStageOnCreate);
47
+ strapi1.documents.use(docsMiddlewares.handleStageOnUpdate);
48
+ strapi1.documents.use(docsMiddlewares.checkStageBeforePublish);
49
49
  });
50
50
 
51
51
  export { bootstrap as default };
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.mjs","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { getAdminService, getService } from './utils';\nimport actions from './config/actions';\n\nimport defaultStages from './constants/default-stages.json';\nimport defaultWorkflow from './constants/default-workflow.json';\nimport webhookEvents from './constants/webhook-events';\n\n/**\n * Initialize the default workflow if there is no workflow in the database\n */\n\nasync function initDefaultWorkflow() {\n const workflowsService = getService('workflows', { strapi });\n const stagesService = getService('stages', { strapi });\n\n const wfCount = await workflowsService.count();\n const stagesCount = await stagesService.count();\n\n // Check if there is nothing about review-workflow in DB\n // If any, the feature has already been initialized with a workflow and stages\n if (wfCount === 0 && stagesCount === 0) {\n const workflow = {\n ...defaultWorkflow,\n contentTypes: [],\n stages: defaultStages,\n };\n\n await workflowsService.create({ data: workflow });\n }\n}\n\n/**\n * Webhook store limits the events that can be triggered,\n * this function extends it with the events review workflows can trigger\n */\nconst registerWebhookEvents = async () =>\n Object.entries(webhookEvents).forEach(([eventKey, event]) =>\n strapi.get('webhookStore').addAllowedEvent(eventKey, event)\n );\n\nexport default async (args: any) => {\n // Permissions\n const { actionProvider } = getAdminService('permission');\n await actionProvider.registerMany(actions.reviewWorkflows);\n\n // Webhooks and events\n await registerWebhookEvents();\n await getService('workflow-weekly-metrics').registerCron();\n\n // Data initialization\n await initDefaultWorkflow();\n\n // Document service middleware\n const docsMiddlewares = getService('document-service-middlewares');\n strapi.documents.use(docsMiddlewares.assignStageOnCreate);\n strapi.documents.use(docsMiddlewares.handleStageOnUpdate);\n strapi.documents.use(docsMiddlewares.checkStageBeforePublish);\n};\n"],"names":["initDefaultWorkflow","workflowsService","getService","strapi","stagesService","wfCount","count","stagesCount","workflow","defaultWorkflow","contentTypes","stages","defaultStages","create","data","registerWebhookEvents","Object","entries","webhookEvents","forEach","eventKey","event","get","addAllowedEvent","args","actionProvider","getAdminService","registerMany","actions","reviewWorkflows","registerCron","docsMiddlewares","documents","use","assignStageOnCreate","handleStageOnUpdate","checkStageBeforePublish"],"mappings":";;;;;;AAOA;;AAEC,IAED,eAAeA,mBAAAA,GAAAA;IACb,MAAMC,gBAAAA,GAAmBC,WAAW,WAAA,EAAa;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAC1D,MAAMC,aAAAA,GAAgBF,WAAW,QAAA,EAAU;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAEpD,MAAME,OAAAA,GAAU,MAAMJ,gBAAAA,CAAiBK,KAAK,EAAA;IAC5C,MAAMC,WAAAA,GAAc,MAAMH,aAAAA,CAAcE,KAAK,EAAA;;;IAI7C,IAAID,OAAAA,KAAY,CAAA,IAAKE,WAAAA,KAAgB,CAAA,EAAG;AACtC,QAAA,MAAMC,QAAAA,GAAW;AACf,YAAA,GAAGC,eAAe;AAClBC,YAAAA,YAAAA,EAAc,EAAE;YAChBC,MAAAA,EAAQC;AACV,SAAA;QAEA,MAAMX,gBAAAA,CAAiBY,MAAM,CAAC;YAAEC,IAAAA,EAAMN;AAAS,SAAA,CAAA;AACjD,IAAA;AACF;AAEA;;;IAIA,MAAMO,wBAAwB,UAC5BC,MAAAA,CAAOC,OAAO,CAACC,aAAAA,CAAAA,CAAeC,OAAO,CAAC,CAAC,CAACC,QAAAA,EAAUC,KAAAA,CAAM,GACtDlB,MAAAA,CAAOmB,GAAG,CAAC,cAAA,CAAA,CAAgBC,eAAe,CAACH,QAAAA,EAAUC,KAAAA,CAAAA,CAAAA;AAGzD,gBAAe,CAAA,OAAOG,IAAAA,GAAAA;;AAEpB,IAAA,MAAM,EAAEC,cAAc,EAAE,GAAGC,eAAAA,CAAgB,YAAA,CAAA;AAC3C,IAAA,MAAMD,cAAAA,CAAeE,YAAY,CAACC,OAAAA,CAAQC,eAAe,CAAA;;IAGzD,MAAMd,qBAAAA,EAAAA;IACN,MAAMb,UAAAA,CAAW,2BAA2B4B,YAAY,EAAA;;IAGxD,MAAM9B,mBAAAA,EAAAA;;AAGN,IAAA,MAAM+B,kBAAkB7B,UAAAA,CAAW,8BAAA,CAAA;AACnCC,IAAAA,MAAAA,CAAO6B,SAAS,CAACC,GAAG,CAACF,gBAAgBG,mBAAmB,CAAA;AACxD/B,IAAAA,MAAAA,CAAO6B,SAAS,CAACC,GAAG,CAACF,gBAAgBI,mBAAmB,CAAA;AACxDhC,IAAAA,MAAAA,CAAO6B,SAAS,CAACC,GAAG,CAACF,gBAAgBK,uBAAuB,CAAA;AAC9D,CAAA;;;;"}
1
+ {"version":3,"file":"bootstrap.mjs","sources":["../../server/src/bootstrap.ts"],"sourcesContent":["import { Core } from '@strapi/types';\nimport { getAdminService, getService } from './utils';\nimport actions from './config/actions';\n\nimport defaultStages from './constants/default-stages.json';\nimport defaultWorkflow from './constants/default-workflow.json';\nimport webhookEvents from './constants/webhook-events';\n\n/**\n * Initialize the default workflow if there is no workflow in the database\n */\n\nasync function initDefaultWorkflow() {\n const workflowsService = getService('workflows', { strapi });\n const stagesService = getService('stages', { strapi });\n\n const wfCount = await workflowsService.count();\n const stagesCount = await stagesService.count();\n\n // Check if there is nothing about review-workflow in DB\n // If any, the feature has already been initialized with a workflow and stages\n if (wfCount === 0 && stagesCount === 0) {\n const workflow = {\n ...defaultWorkflow,\n contentTypes: [],\n stages: defaultStages,\n };\n\n await workflowsService.create({ data: workflow });\n }\n}\n\n/**\n * Webhook store limits the events that can be triggered,\n * this function extends it with the events review workflows can trigger\n */\nconst registerWebhookEvents = async () =>\n Object.entries(webhookEvents).forEach(([eventKey, event]) =>\n strapi.get('webhookStore').addAllowedEvent(eventKey, event)\n );\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {\n // Permissions\n const { actionProvider } = getAdminService('permission');\n await actionProvider.registerMany(actions.reviewWorkflows);\n\n // Webhooks and events\n await registerWebhookEvents();\n await getService('workflow-weekly-metrics').registerCron();\n\n // Data initialization\n await initDefaultWorkflow();\n\n // Document service middleware\n const docsMiddlewares = getService('document-service-middlewares');\n strapi.documents.use(docsMiddlewares.assignStageOnCreate);\n strapi.documents.use(docsMiddlewares.handleStageOnUpdate);\n strapi.documents.use(docsMiddlewares.checkStageBeforePublish);\n};\n"],"names":["initDefaultWorkflow","workflowsService","getService","strapi","stagesService","wfCount","count","stagesCount","workflow","defaultWorkflow","contentTypes","stages","defaultStages","create","data","registerWebhookEvents","Object","entries","webhookEvents","forEach","eventKey","event","get","addAllowedEvent","actionProvider","getAdminService","registerMany","actions","reviewWorkflows","registerCron","docsMiddlewares","documents","use","assignStageOnCreate","handleStageOnUpdate","checkStageBeforePublish"],"mappings":";;;;;;AAQA;;AAEC,IAED,eAAeA,mBAAAA,GAAAA;IACb,MAAMC,gBAAAA,GAAmBC,WAAW,WAAA,EAAa;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAC1D,MAAMC,aAAAA,GAAgBF,WAAW,QAAA,EAAU;AAAEC,QAAAA;AAAO,KAAA,CAAA;IAEpD,MAAME,OAAAA,GAAU,MAAMJ,gBAAAA,CAAiBK,KAAK,EAAA;IAC5C,MAAMC,WAAAA,GAAc,MAAMH,aAAAA,CAAcE,KAAK,EAAA;;;IAI7C,IAAID,OAAAA,KAAY,CAAA,IAAKE,WAAAA,KAAgB,CAAA,EAAG;AACtC,QAAA,MAAMC,QAAAA,GAAW;AACf,YAAA,GAAGC,eAAe;AAClBC,YAAAA,YAAAA,EAAc,EAAE;YAChBC,MAAAA,EAAQC;AACV,SAAA;QAEA,MAAMX,gBAAAA,CAAiBY,MAAM,CAAC;YAAEC,IAAAA,EAAMN;AAAS,SAAA,CAAA;AACjD,IAAA;AACF;AAEA;;;IAIA,MAAMO,wBAAwB,UAC5BC,MAAAA,CAAOC,OAAO,CAACC,aAAAA,CAAAA,CAAeC,OAAO,CAAC,CAAC,CAACC,QAAAA,EAAUC,KAAAA,CAAM,GACtDlB,MAAAA,CAAOmB,GAAG,CAAC,cAAA,CAAA,CAAgBC,eAAe,CAACH,QAAAA,EAAUC,KAAAA,CAAAA,CAAAA;AAGzD,gBAAe,CAAA,OAAO,EAAElB,MAAAA,EAAAA,OAAM,EAA2B,GAAA;;AAEvD,IAAA,MAAM,EAAEqB,cAAc,EAAE,GAAGC,eAAAA,CAAgB,YAAA,CAAA;AAC3C,IAAA,MAAMD,cAAAA,CAAeE,YAAY,CAACC,OAAAA,CAAQC,eAAe,CAAA;;IAGzD,MAAMb,qBAAAA,EAAAA;IACN,MAAMb,UAAAA,CAAW,2BAA2B2B,YAAY,EAAA;;IAGxD,MAAM7B,mBAAAA,EAAAA;;AAGN,IAAA,MAAM8B,kBAAkB5B,UAAAA,CAAW,8BAAA,CAAA;AACnCC,IAAAA,OAAAA,CAAO4B,SAAS,CAACC,GAAG,CAACF,gBAAgBG,mBAAmB,CAAA;AACxD9B,IAAAA,OAAAA,CAAO4B,SAAS,CAACC,GAAG,CAACF,gBAAgBI,mBAAmB,CAAA;AACxD/B,IAAAA,OAAAA,CAAO4B,SAAS,CAACC,GAAG,CAACF,gBAAgBK,uBAAuB,CAAA;AAC9D,CAAA;;;;"}
@@ -3,7 +3,7 @@
3
3
  const WORKFLOW_MODEL_UID = 'plugin::review-workflows.workflow';
4
4
  const STAGE_MODEL_UID = 'plugin::review-workflows.workflow-stage';
5
5
  /**
6
- * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package
6
+ * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package
7
7
  *
8
8
  * NOTE!: if you change this string you need to change it here too: strapi/packages/core/review-workflows/admin/src/routes/settings/components/Stages.tsx
9
9
  */ const STAGE_TRANSITION_UID = 'admin::review-workflows.stage.transition';
@@ -1 +1 @@
1
- {"version":3,"file":"workflows.js","sources":["../../../server/src/constants/workflows.ts"],"sourcesContent":["export const WORKFLOW_MODEL_UID = 'plugin::review-workflows.workflow';\nexport const STAGE_MODEL_UID = 'plugin::review-workflows.workflow-stage';\n/**\n * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package\n *\n * NOTE!: if you change this string you need to change it here too: strapi/packages/core/review-workflows/admin/src/routes/settings/components/Stages.tsx\n */\nexport const STAGE_TRANSITION_UID = 'admin::review-workflows.stage.transition';\n\nexport const STAGE_DEFAULT_COLOR = '#4945FF';\nexport const ENTITY_STAGE_ATTRIBUTE = 'strapi_stage';\nexport const ENTITY_ASSIGNEE_ATTRIBUTE = 'strapi_assignee';\n\nexport const MAX_WORKFLOWS = 200;\nexport const MAX_STAGES_PER_WORKFLOW = 200;\n\nexport const ERRORS = {\n WORKFLOW_WITHOUT_STAGES: 'A workflow must have at least one stage.',\n WORKFLOWS_LIMIT:\n 'You’ve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.',\n STAGES_LIMIT:\n 'You’ve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.',\n DUPLICATED_STAGE_NAME: 'Stage names must be unique.',\n};\n\nexport const WORKFLOW_POPULATE = {\n stages: {\n populate: {\n permissions: {\n fields: ['action', 'actionParameters'],\n populate: {\n role: { fields: ['id', 'name'] },\n },\n },\n },\n },\n stageRequiredToPublish: true,\n};\n"],"names":["WORKFLOW_MODEL_UID","STAGE_MODEL_UID","STAGE_TRANSITION_UID","STAGE_DEFAULT_COLOR","ENTITY_STAGE_ATTRIBUTE","ENTITY_ASSIGNEE_ATTRIBUTE","MAX_WORKFLOWS","MAX_STAGES_PER_WORKFLOW","ERRORS","WORKFLOW_WITHOUT_STAGES","WORKFLOWS_LIMIT","STAGES_LIMIT","DUPLICATED_STAGE_NAME","WORKFLOW_POPULATE","stages","populate","permissions","fields","role","stageRequiredToPublish"],"mappings":";;AAAO,MAAMA,qBAAqB;AAC3B,MAAMC,kBAAkB;AAC/B;;;;IAKO,MAAMC,oBAAAA,GAAuB;AAE7B,MAAMC,sBAAsB;AAC5B,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAElC,MAAMC,gBAAgB;AACtB,MAAMC,0BAA0B;MAE1BC,MAAAA,GAAS;IACpBC,uBAAAA,EAAyB,0CAAA;IACzBC,eAAAA,EACE,kHAAA;IACFC,YAAAA,EACE,qIAAA;IACFC,qBAAAA,EAAuB;AACzB;MAEaC,iBAAAA,GAAoB;IAC/BC,MAAAA,EAAQ;QACNC,QAAAA,EAAU;YACRC,WAAAA,EAAa;gBACXC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA;AAAmB,iBAAA;gBACtCF,QAAAA,EAAU;oBACRG,IAAAA,EAAM;wBAAED,MAAAA,EAAQ;AAAC,4BAAA,IAAA;AAAM,4BAAA;AAAO;AAAC;AACjC;AACF;AACF;AACF,KAAA;IACAE,sBAAAA,EAAwB;AAC1B;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"workflows.js","sources":["../../../server/src/constants/workflows.ts"],"sourcesContent":["export const WORKFLOW_MODEL_UID = 'plugin::review-workflows.workflow';\nexport const STAGE_MODEL_UID = 'plugin::review-workflows.workflow-stage';\n/**\n * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package\n *\n * NOTE!: if you change this string you need to change it here too: strapi/packages/core/review-workflows/admin/src/routes/settings/components/Stages.tsx\n */\nexport const STAGE_TRANSITION_UID = 'admin::review-workflows.stage.transition';\n\nexport const STAGE_DEFAULT_COLOR = '#4945FF';\nexport const ENTITY_STAGE_ATTRIBUTE = 'strapi_stage';\nexport const ENTITY_ASSIGNEE_ATTRIBUTE = 'strapi_assignee';\n\nexport const MAX_WORKFLOWS = 200;\nexport const MAX_STAGES_PER_WORKFLOW = 200;\n\nexport const ERRORS = {\n WORKFLOW_WITHOUT_STAGES: 'A workflow must have at least one stage.',\n WORKFLOWS_LIMIT:\n 'You’ve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.',\n STAGES_LIMIT:\n 'You’ve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.',\n DUPLICATED_STAGE_NAME: 'Stage names must be unique.',\n};\n\nexport const WORKFLOW_POPULATE = {\n stages: {\n populate: {\n permissions: {\n fields: ['action', 'actionParameters'],\n populate: {\n role: { fields: ['id', 'name'] },\n },\n },\n },\n },\n stageRequiredToPublish: true,\n};\n"],"names":["WORKFLOW_MODEL_UID","STAGE_MODEL_UID","STAGE_TRANSITION_UID","STAGE_DEFAULT_COLOR","ENTITY_STAGE_ATTRIBUTE","ENTITY_ASSIGNEE_ATTRIBUTE","MAX_WORKFLOWS","MAX_STAGES_PER_WORKFLOW","ERRORS","WORKFLOW_WITHOUT_STAGES","WORKFLOWS_LIMIT","STAGES_LIMIT","DUPLICATED_STAGE_NAME","WORKFLOW_POPULATE","stages","populate","permissions","fields","role","stageRequiredToPublish"],"mappings":";;AAAO,MAAMA,qBAAqB;AAC3B,MAAMC,kBAAkB;AAC/B;;;;IAKO,MAAMC,oBAAAA,GAAuB;AAE7B,MAAMC,sBAAsB;AAC5B,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAElC,MAAMC,gBAAgB;AACtB,MAAMC,0BAA0B;MAE1BC,MAAAA,GAAS;IACpBC,uBAAAA,EAAyB,0CAAA;IACzBC,eAAAA,EACE,kHAAA;IACFC,YAAAA,EACE,qIAAA;IACFC,qBAAAA,EAAuB;AACzB;MAEaC,iBAAAA,GAAoB;IAC/BC,MAAAA,EAAQ;QACNC,QAAAA,EAAU;YACRC,WAAAA,EAAa;gBACXC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA;AAAmB,iBAAA;gBACtCF,QAAAA,EAAU;oBACRG,IAAAA,EAAM;wBAAED,MAAAA,EAAQ;AAAC,4BAAA,IAAA;AAAM,4BAAA;AAAO;AAAC;AACjC;AACF;AACF;AACF,KAAA;IACAE,sBAAAA,EAAwB;AAC1B;;;;;;;;;;;;;"}
@@ -1,7 +1,7 @@
1
1
  const WORKFLOW_MODEL_UID = 'plugin::review-workflows.workflow';
2
2
  const STAGE_MODEL_UID = 'plugin::review-workflows.workflow-stage';
3
3
  /**
4
- * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package
4
+ * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package
5
5
  *
6
6
  * NOTE!: if you change this string you need to change it here too: strapi/packages/core/review-workflows/admin/src/routes/settings/components/Stages.tsx
7
7
  */ const STAGE_TRANSITION_UID = 'admin::review-workflows.stage.transition';
@@ -1 +1 @@
1
- {"version":3,"file":"workflows.mjs","sources":["../../../server/src/constants/workflows.ts"],"sourcesContent":["export const WORKFLOW_MODEL_UID = 'plugin::review-workflows.workflow';\nexport const STAGE_MODEL_UID = 'plugin::review-workflows.workflow-stage';\n/**\n * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package\n *\n * NOTE!: if you change this string you need to change it here too: strapi/packages/core/review-workflows/admin/src/routes/settings/components/Stages.tsx\n */\nexport const STAGE_TRANSITION_UID = 'admin::review-workflows.stage.transition';\n\nexport const STAGE_DEFAULT_COLOR = '#4945FF';\nexport const ENTITY_STAGE_ATTRIBUTE = 'strapi_stage';\nexport const ENTITY_ASSIGNEE_ATTRIBUTE = 'strapi_assignee';\n\nexport const MAX_WORKFLOWS = 200;\nexport const MAX_STAGES_PER_WORKFLOW = 200;\n\nexport const ERRORS = {\n WORKFLOW_WITHOUT_STAGES: 'A workflow must have at least one stage.',\n WORKFLOWS_LIMIT:\n 'You’ve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.',\n STAGES_LIMIT:\n 'You’ve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.',\n DUPLICATED_STAGE_NAME: 'Stage names must be unique.',\n};\n\nexport const WORKFLOW_POPULATE = {\n stages: {\n populate: {\n permissions: {\n fields: ['action', 'actionParameters'],\n populate: {\n role: { fields: ['id', 'name'] },\n },\n },\n },\n },\n stageRequiredToPublish: true,\n};\n"],"names":["WORKFLOW_MODEL_UID","STAGE_MODEL_UID","STAGE_TRANSITION_UID","STAGE_DEFAULT_COLOR","ENTITY_STAGE_ATTRIBUTE","ENTITY_ASSIGNEE_ATTRIBUTE","MAX_WORKFLOWS","MAX_STAGES_PER_WORKFLOW","ERRORS","WORKFLOW_WITHOUT_STAGES","WORKFLOWS_LIMIT","STAGES_LIMIT","DUPLICATED_STAGE_NAME","WORKFLOW_POPULATE","stages","populate","permissions","fields","role","stageRequiredToPublish"],"mappings":"AAAO,MAAMA,qBAAqB;AAC3B,MAAMC,kBAAkB;AAC/B;;;;IAKO,MAAMC,oBAAAA,GAAuB;AAE7B,MAAMC,sBAAsB;AAC5B,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAElC,MAAMC,gBAAgB;AACtB,MAAMC,0BAA0B;MAE1BC,MAAAA,GAAS;IACpBC,uBAAAA,EAAyB,0CAAA;IACzBC,eAAAA,EACE,kHAAA;IACFC,YAAAA,EACE,qIAAA;IACFC,qBAAAA,EAAuB;AACzB;MAEaC,iBAAAA,GAAoB;IAC/BC,MAAAA,EAAQ;QACNC,QAAAA,EAAU;YACRC,WAAAA,EAAa;gBACXC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA;AAAmB,iBAAA;gBACtCF,QAAAA,EAAU;oBACRG,IAAAA,EAAM;wBAAED,MAAAA,EAAQ;AAAC,4BAAA,IAAA;AAAM,4BAAA;AAAO;AAAC;AACjC;AACF;AACF;AACF,KAAA;IACAE,sBAAAA,EAAwB;AAC1B;;;;"}
1
+ {"version":3,"file":"workflows.mjs","sources":["../../../server/src/constants/workflows.ts"],"sourcesContent":["export const WORKFLOW_MODEL_UID = 'plugin::review-workflows.workflow';\nexport const STAGE_MODEL_UID = 'plugin::review-workflows.workflow-stage';\n/**\n * TODO: For V4 compatibility, the old UID was kept, when review workflows was in the admin package\n *\n * NOTE!: if you change this string you need to change it here too: strapi/packages/core/review-workflows/admin/src/routes/settings/components/Stages.tsx\n */\nexport const STAGE_TRANSITION_UID = 'admin::review-workflows.stage.transition';\n\nexport const STAGE_DEFAULT_COLOR = '#4945FF';\nexport const ENTITY_STAGE_ATTRIBUTE = 'strapi_stage';\nexport const ENTITY_ASSIGNEE_ATTRIBUTE = 'strapi_assignee';\n\nexport const MAX_WORKFLOWS = 200;\nexport const MAX_STAGES_PER_WORKFLOW = 200;\n\nexport const ERRORS = {\n WORKFLOW_WITHOUT_STAGES: 'A workflow must have at least one stage.',\n WORKFLOWS_LIMIT:\n 'You’ve reached the limit of workflows in your plan. Delete a workflow or contact Sales to enable more workflows.',\n STAGES_LIMIT:\n 'You’ve reached the limit of stages for this workflow in your plan. Try deleting some stages or contact Sales to enable more stages.',\n DUPLICATED_STAGE_NAME: 'Stage names must be unique.',\n};\n\nexport const WORKFLOW_POPULATE = {\n stages: {\n populate: {\n permissions: {\n fields: ['action', 'actionParameters'],\n populate: {\n role: { fields: ['id', 'name'] },\n },\n },\n },\n },\n stageRequiredToPublish: true,\n};\n"],"names":["WORKFLOW_MODEL_UID","STAGE_MODEL_UID","STAGE_TRANSITION_UID","STAGE_DEFAULT_COLOR","ENTITY_STAGE_ATTRIBUTE","ENTITY_ASSIGNEE_ATTRIBUTE","MAX_WORKFLOWS","MAX_STAGES_PER_WORKFLOW","ERRORS","WORKFLOW_WITHOUT_STAGES","WORKFLOWS_LIMIT","STAGES_LIMIT","DUPLICATED_STAGE_NAME","WORKFLOW_POPULATE","stages","populate","permissions","fields","role","stageRequiredToPublish"],"mappings":"AAAO,MAAMA,qBAAqB;AAC3B,MAAMC,kBAAkB;AAC/B;;;;IAKO,MAAMC,oBAAAA,GAAuB;AAE7B,MAAMC,sBAAsB;AAC5B,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAElC,MAAMC,gBAAgB;AACtB,MAAMC,0BAA0B;MAE1BC,MAAAA,GAAS;IACpBC,uBAAAA,EAAyB,0CAAA;IACzBC,eAAAA,EACE,kHAAA;IACFC,YAAAA,EACE,qIAAA;IACFC,qBAAAA,EAAuB;AACzB;MAEaC,iBAAAA,GAAoB;IAC/BC,MAAAA,EAAQ;QACNC,QAAAA,EAAU;YACRC,WAAAA,EAAa;gBACXC,MAAAA,EAAQ;AAAC,oBAAA,QAAA;AAAU,oBAAA;AAAmB,iBAAA;gBACtCF,QAAAA,EAAU;oBACRG,IAAAA,EAAM;wBAAED,MAAAA,EAAQ;AAAC,4BAAA,IAAA;AAAM,4BAAA;AAAO;AAAC;AACjC;AACF;AACF;AACF,KAAA;IACAE,sBAAAA,EAAwB;AAC1B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"stages.js","sources":["../../../server/src/controllers/stages.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport type { Core } from '@strapi/types';\n\nimport { async, validate } from '@strapi/utils';\nimport { getService } from '../utils';\nimport { validateUpdateStageOnEntity, validateLocale } from '../validation/review-workflows';\nimport {\n STAGE_MODEL_UID,\n ENTITY_STAGE_ATTRIBUTE,\n STAGE_TRANSITION_UID,\n} from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { (Stage) => SanitizedStage }\n */\nfunction sanitizeStage({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n const permissionChecker = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: STAGE_MODEL_UID });\n\n return (entity: unknown) => permissionChecker.sanitizeOutput(entity);\n}\n\nexport default {\n /**\n * List all stages\n */\n async find(ctx: Context) {\n const { workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stages = await stagesService.find({\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await async.map(stages, sanitizer),\n };\n },\n /**\n * Get one stage\n */\n async findById(ctx: Context) {\n const { id, workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stage = await stagesService.findById(id, {\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await sanitizer(stage),\n };\n },\n\n /**\n * Updates an entity's stage.\n * @async\n * @param {Object} ctx - The Koa context object.\n * @param {Object} ctx.params - An object containing the parameters from the request URL.\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity to update.\n * @param {Object} ctx.request.body.data - Optional data object containing the new stage ID for the entity.\n * @param {string} ctx.request.body.data.id - The ID of the new stage for the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n * @throws {ValidationError} If the `data` object in the request body fails to pass validation.\n * @returns {Promise<void>} A promise that resolves when the entity's stage has been updated.\n */\n async updateEntity(ctx: Context) {\n const stagesService = getService('stages');\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { body, query = {} } = ctx.request;\n\n const { sanitizeOutput } = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID });\n\n // Load entity\n const locale = await validateLocale(query?.locale);\n const entity = await strapi.documents(modelUID).findOne({\n documentId,\n // @ts-expect-error - locale should be also null in the doc service types\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n });\n\n if (!entity) {\n ctx.throw(404, 'Entity not found');\n }\n\n // Validate if entity stage can be updated\n const canTransition = stagePermissions.can(\n STAGE_TRANSITION_UID,\n entity[ENTITY_STAGE_ATTRIBUTE]?.id\n );\n\n if (!canTransition) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const { id: stageId } = await validateUpdateStageOnEntity(\n { id: Number(body?.data?.id) },\n 'You should pass an id to the body of the put request.'\n );\n\n const workflow = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);\n workflowService.assertStageBelongsToWorkflow(stageId, workflow);\n\n const canTransitionTo = await stagePermissions.canTransitionToStage(stageId);\n if (!canTransitionTo) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const updatedEntity = await stagesService.updateEntity(entity, modelUID, stageId);\n\n ctx.body = { data: await sanitizeOutput(updatedEntity) };\n },\n\n /**\n * List all the stages that are available for a user to transition an entity to.\n * Stages are filtered by both \"from\" permission on the current stage AND \"to\" permission on each target stage.\n * @async\n * @param {*} ctx\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n */\n async listAvailableStages(ctx: Context) {\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { query = {} } = ctx.request;\n\n if (\n strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID })\n .cannot.read()\n ) {\n return ctx.forbidden();\n }\n\n // Load entity\n const locale = (await validateLocale(query?.locale)) ?? undefined;\n const [entity, workflowCount, workflowResult] = await Promise.all([\n strapi.documents(modelUID).findOne({\n documentId,\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n }),\n workflowService.count(),\n workflowService.getAssignedWorkflow(modelUID, {\n populate: { stages: { populate: { permissions: { populate: ['role'] } } } },\n }),\n ]);\n\n const workflowStages = workflowResult ? workflowResult.stages : [];\n const entityStageId = entity?.[ENTITY_STAGE_ATTRIBUTE]?.id;\n const canTransition = stagePermissions.can(STAGE_TRANSITION_UID, entityStageId);\n\n const meta = {\n stageCount: workflowStages.length,\n workflowCount,\n canTransition,\n };\n\n // The entity may not exist yet for the requested locale (e.g. switching to a\n // locale that has not been saved).\n if (!entity) {\n if (!workflowResult) {\n ctx.throw(404, 'Entity not found');\n }\n\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n if (!canTransition) {\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n const otherStages = workflowStages.filter(\n (stage: { id: number; permissions?: unknown[] }) => stage.id !== entityStageId\n );\n\n const data = otherStages.filter((stage: { id: number; permissions?: unknown[] }) =>\n stagePermissions.canTransitionToStageWithPermissions(stage)\n );\n\n ctx.body = {\n data,\n meta,\n };\n },\n};\n"],"names":["sanitizeStage","strapi","userAbility","permissionChecker","plugin","service","create","model","STAGE_MODEL_UID","entity","sanitizeOutput","find","ctx","workflow_id","workflowId","params","populate","query","stagesService","getService","sanitizer","state","stages","body","data","async","map","findById","id","stage","updateEntity","stagePermissions","workflowService","model_uid","modelUID","documentId","request","locale","validateLocale","documents","findOne","ENTITY_STAGE_ATTRIBUTE","throw","canTransition","can","STAGE_TRANSITION_UID","stageId","validateUpdateStageOnEntity","Number","workflow","assertContentTypeBelongsToWorkflow","assertStageBelongsToWorkflow","canTransitionTo","canTransitionToStage","updatedEntity","listAvailableStages","cannot","read","forbidden","undefined","workflowCount","workflowResult","Promise","all","count","getAssignedWorkflow","permissions","workflowStages","entityStageId","meta","stageCount","length","otherStages","filter","canTransitionToStageWithPermissions"],"mappings":";;;;;;;AAYA;;;;;AAKC,IACD,SAASA,aAAAA,CAAc,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9E,MAAMC,iBAAAA,GAAoBF,QACvBG,MAAM,CAAC,mBACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEJ,QAAAA,WAAAA;QAAaK,KAAAA,EAAOC;AAAgB,KAAA,CAAA;AAEhD,IAAA,OAAO,CAACC,MAAAA,GAAoBN,iBAAAA,CAAkBO,cAAc,CAACD,MAAAA,CAAAA;AAC/D;AAEA,aAAe;AACb;;MAGA,MAAME,MAAKC,GAAY,EAAA;AACrB,QAAA,MAAM,EAAEC,WAAAA,EAAaC,UAAU,EAAE,GAAGF,IAAIG,MAAM;AAC9C,QAAA,MAAM,EAAEC,QAAQ,EAAE,GAAGJ,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,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAAC1B,aAAAA,EAAe;AAClB/B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;QAEA,MAAMG,WAAAA,GAAcL,eAAeM,MAAM,CACvC,CAAC5C,KAAAA,GAAmDA,KAAAA,CAAMD,EAAE,KAAKwC,aAAAA,CAAAA;QAGnE,MAAM5C,IAAAA,GAAOgD,YAAYC,MAAM,CAAC,CAAC5C,KAAAA,GAC/BE,gBAAAA,CAAiB2C,mCAAmC,CAAC7C,KAAAA,CAAAA,CAAAA;AAGvDjB,QAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,YAAAA,IAAAA;AACA6C,YAAAA;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"stages.js","sources":["../../../server/src/controllers/stages.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport type { Core } from '@strapi/types';\n\nimport { async } from '@strapi/utils';\nimport { getService } from '../utils';\nimport { validateUpdateStageOnEntity, validateLocale } from '../validation/review-workflows';\nimport {\n STAGE_MODEL_UID,\n ENTITY_STAGE_ATTRIBUTE,\n STAGE_TRANSITION_UID,\n} from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { (Stage) => SanitizedStage }\n */\nfunction sanitizeStage({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n const permissionChecker = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: STAGE_MODEL_UID });\n\n return (entity: unknown) => permissionChecker.sanitizeOutput(entity);\n}\n\nexport default {\n /**\n * List all stages\n */\n async find(ctx: Context) {\n const { workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stages = await stagesService.find({\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await async.map(stages, sanitizer),\n };\n },\n /**\n * Get one stage\n */\n async findById(ctx: Context) {\n const { id, workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stage = await stagesService.findById(id, {\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await sanitizer(stage),\n };\n },\n\n /**\n * Updates an entity's stage.\n * @async\n * @param {Object} ctx - The Koa context object.\n * @param {Object} ctx.params - An object containing the parameters from the request URL.\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity to update.\n * @param {Object} ctx.request.body.data - Optional data object containing the new stage ID for the entity.\n * @param {string} ctx.request.body.data.id - The ID of the new stage for the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n * @throws {ValidationError} If the `data` object in the request body fails to pass validation.\n * @returns {Promise<void>} A promise that resolves when the entity's stage has been updated.\n */\n async updateEntity(ctx: Context) {\n const stagesService = getService('stages');\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { body, query = {} } = ctx.request;\n\n const { sanitizeOutput } = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID });\n\n // Load entity\n const locale = await validateLocale(query?.locale);\n const entity = await strapi.documents(modelUID).findOne({\n documentId,\n // @ts-expect-error - locale should be also null in the doc service types\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n });\n\n if (!entity) {\n ctx.throw(404, 'Entity not found');\n }\n\n // Validate if entity stage can be updated\n const canTransition = stagePermissions.can(\n STAGE_TRANSITION_UID,\n entity[ENTITY_STAGE_ATTRIBUTE]?.id\n );\n\n if (!canTransition) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const { id: stageId } = await validateUpdateStageOnEntity(\n { id: Number(body?.data?.id) },\n 'You should pass an id to the body of the put request.'\n );\n\n const workflow = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);\n workflowService.assertStageBelongsToWorkflow(stageId, workflow);\n\n const canTransitionTo = await stagePermissions.canTransitionToStage(stageId);\n if (!canTransitionTo) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const updatedEntity = await stagesService.updateEntity(entity, modelUID, stageId);\n\n ctx.body = { data: await sanitizeOutput(updatedEntity) };\n },\n\n /**\n * List all the stages that are available for a user to transition an entity to.\n * Stages are filtered by both \"from\" permission on the current stage AND \"to\" permission on each target stage.\n * @async\n * @param {*} ctx\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n */\n async listAvailableStages(ctx: Context) {\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { query = {} } = ctx.request;\n\n if (\n strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID })\n .cannot.read()\n ) {\n return ctx.forbidden();\n }\n\n // Load entity\n const locale = (await validateLocale(query?.locale)) ?? undefined;\n const [entity, workflowCount, workflowResult] = await Promise.all([\n strapi.documents(modelUID).findOne({\n documentId,\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n }),\n workflowService.count(),\n workflowService.getAssignedWorkflow(modelUID, {\n populate: { stages: { populate: { permissions: { populate: ['role'] } } } },\n }),\n ]);\n\n const workflowStages = workflowResult ? workflowResult.stages : [];\n const entityStageId = entity?.[ENTITY_STAGE_ATTRIBUTE]?.id;\n const canTransition = stagePermissions.can(STAGE_TRANSITION_UID, entityStageId);\n\n const meta = {\n stageCount: workflowStages.length,\n workflowCount,\n canTransition,\n };\n\n // The entity may not exist yet for the requested locale (e.g. switching to a\n // locale that has not been saved).\n if (!entity) {\n if (!workflowResult) {\n ctx.throw(404, 'Entity not found');\n }\n\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n if (!canTransition) {\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n const otherStages = workflowStages.filter(\n (stage: { id: number; permissions?: unknown[] }) => stage.id !== entityStageId\n );\n\n const data = otherStages.filter((stage: { id: number; permissions?: unknown[] }) =>\n stagePermissions.canTransitionToStageWithPermissions(stage)\n );\n\n ctx.body = {\n data,\n meta,\n };\n },\n};\n"],"names":["sanitizeStage","strapi","userAbility","permissionChecker","plugin","service","create","model","STAGE_MODEL_UID","entity","sanitizeOutput","find","ctx","workflow_id","workflowId","params","populate","query","stagesService","getService","sanitizer","state","stages","body","data","async","map","findById","id","stage","updateEntity","stagePermissions","workflowService","model_uid","modelUID","documentId","request","locale","validateLocale","documents","findOne","ENTITY_STAGE_ATTRIBUTE","throw","canTransition","can","STAGE_TRANSITION_UID","stageId","validateUpdateStageOnEntity","Number","workflow","assertContentTypeBelongsToWorkflow","assertStageBelongsToWorkflow","canTransitionTo","canTransitionToStage","updatedEntity","listAvailableStages","cannot","read","forbidden","undefined","workflowCount","workflowResult","Promise","all","count","getAssignedWorkflow","permissions","workflowStages","entityStageId","meta","stageCount","length","otherStages","filter","canTransitionToStageWithPermissions"],"mappings":";;;;;;;AAYA;;;;;AAKC,IACD,SAASA,aAAAA,CAAc,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9E,MAAMC,iBAAAA,GAAoBF,QACvBG,MAAM,CAAC,mBACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEJ,QAAAA,WAAAA;QAAaK,KAAAA,EAAOC;AAAgB,KAAA,CAAA;AAEhD,IAAA,OAAO,CAACC,MAAAA,GAAoBN,iBAAAA,CAAkBO,cAAc,CAACD,MAAAA,CAAAA;AAC/D;AAEA,aAAe;AACb;;MAGA,MAAME,MAAKC,GAAY,EAA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;gBACnBjD,GAAAA,CAAI8B,KAAK,CAAC,GAAA,EAAK,kBAAA,CAAA;AACjB,YAAA;AAEA9B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAAC1B,aAAAA,EAAe;AAClB/B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;QAEA,MAAMG,WAAAA,GAAcL,eAAeM,MAAM,CACvC,CAAC5C,KAAAA,GAAmDA,KAAAA,CAAMD,EAAE,KAAKwC,aAAAA,CAAAA;QAGnE,MAAM5C,IAAAA,GAAOgD,YAAYC,MAAM,CAAC,CAAC5C,KAAAA,GAC/BE,gBAAAA,CAAiB2C,mCAAmC,CAAC7C,KAAAA,CAAAA,CAAAA;AAGvDjB,QAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,YAAAA,IAAAA;AACA6C,YAAAA;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"stages.mjs","sources":["../../../server/src/controllers/stages.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport type { Core } from '@strapi/types';\n\nimport { async, validate } from '@strapi/utils';\nimport { getService } from '../utils';\nimport { validateUpdateStageOnEntity, validateLocale } from '../validation/review-workflows';\nimport {\n STAGE_MODEL_UID,\n ENTITY_STAGE_ATTRIBUTE,\n STAGE_TRANSITION_UID,\n} from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { (Stage) => SanitizedStage }\n */\nfunction sanitizeStage({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n const permissionChecker = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: STAGE_MODEL_UID });\n\n return (entity: unknown) => permissionChecker.sanitizeOutput(entity);\n}\n\nexport default {\n /**\n * List all stages\n */\n async find(ctx: Context) {\n const { workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stages = await stagesService.find({\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await async.map(stages, sanitizer),\n };\n },\n /**\n * Get one stage\n */\n async findById(ctx: Context) {\n const { id, workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stage = await stagesService.findById(id, {\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await sanitizer(stage),\n };\n },\n\n /**\n * Updates an entity's stage.\n * @async\n * @param {Object} ctx - The Koa context object.\n * @param {Object} ctx.params - An object containing the parameters from the request URL.\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity to update.\n * @param {Object} ctx.request.body.data - Optional data object containing the new stage ID for the entity.\n * @param {string} ctx.request.body.data.id - The ID of the new stage for the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n * @throws {ValidationError} If the `data` object in the request body fails to pass validation.\n * @returns {Promise<void>} A promise that resolves when the entity's stage has been updated.\n */\n async updateEntity(ctx: Context) {\n const stagesService = getService('stages');\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { body, query = {} } = ctx.request;\n\n const { sanitizeOutput } = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID });\n\n // Load entity\n const locale = await validateLocale(query?.locale);\n const entity = await strapi.documents(modelUID).findOne({\n documentId,\n // @ts-expect-error - locale should be also null in the doc service types\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n });\n\n if (!entity) {\n ctx.throw(404, 'Entity not found');\n }\n\n // Validate if entity stage can be updated\n const canTransition = stagePermissions.can(\n STAGE_TRANSITION_UID,\n entity[ENTITY_STAGE_ATTRIBUTE]?.id\n );\n\n if (!canTransition) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const { id: stageId } = await validateUpdateStageOnEntity(\n { id: Number(body?.data?.id) },\n 'You should pass an id to the body of the put request.'\n );\n\n const workflow = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);\n workflowService.assertStageBelongsToWorkflow(stageId, workflow);\n\n const canTransitionTo = await stagePermissions.canTransitionToStage(stageId);\n if (!canTransitionTo) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const updatedEntity = await stagesService.updateEntity(entity, modelUID, stageId);\n\n ctx.body = { data: await sanitizeOutput(updatedEntity) };\n },\n\n /**\n * List all the stages that are available for a user to transition an entity to.\n * Stages are filtered by both \"from\" permission on the current stage AND \"to\" permission on each target stage.\n * @async\n * @param {*} ctx\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n */\n async listAvailableStages(ctx: Context) {\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { query = {} } = ctx.request;\n\n if (\n strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID })\n .cannot.read()\n ) {\n return ctx.forbidden();\n }\n\n // Load entity\n const locale = (await validateLocale(query?.locale)) ?? undefined;\n const [entity, workflowCount, workflowResult] = await Promise.all([\n strapi.documents(modelUID).findOne({\n documentId,\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n }),\n workflowService.count(),\n workflowService.getAssignedWorkflow(modelUID, {\n populate: { stages: { populate: { permissions: { populate: ['role'] } } } },\n }),\n ]);\n\n const workflowStages = workflowResult ? workflowResult.stages : [];\n const entityStageId = entity?.[ENTITY_STAGE_ATTRIBUTE]?.id;\n const canTransition = stagePermissions.can(STAGE_TRANSITION_UID, entityStageId);\n\n const meta = {\n stageCount: workflowStages.length,\n workflowCount,\n canTransition,\n };\n\n // The entity may not exist yet for the requested locale (e.g. switching to a\n // locale that has not been saved).\n if (!entity) {\n if (!workflowResult) {\n ctx.throw(404, 'Entity not found');\n }\n\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n if (!canTransition) {\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n const otherStages = workflowStages.filter(\n (stage: { id: number; permissions?: unknown[] }) => stage.id !== entityStageId\n );\n\n const data = otherStages.filter((stage: { id: number; permissions?: unknown[] }) =>\n stagePermissions.canTransitionToStageWithPermissions(stage)\n );\n\n ctx.body = {\n data,\n meta,\n };\n },\n};\n"],"names":["sanitizeStage","strapi","userAbility","permissionChecker","plugin","service","create","model","STAGE_MODEL_UID","entity","sanitizeOutput","find","ctx","workflow_id","workflowId","params","populate","query","stagesService","getService","sanitizer","state","stages","body","data","async","map","findById","id","stage","updateEntity","stagePermissions","workflowService","model_uid","modelUID","documentId","request","locale","validateLocale","documents","findOne","ENTITY_STAGE_ATTRIBUTE","throw","canTransition","can","STAGE_TRANSITION_UID","stageId","validateUpdateStageOnEntity","Number","workflow","assertContentTypeBelongsToWorkflow","assertStageBelongsToWorkflow","canTransitionTo","canTransitionToStage","updatedEntity","listAvailableStages","cannot","read","forbidden","undefined","workflowCount","workflowResult","Promise","all","count","getAssignedWorkflow","permissions","workflowStages","entityStageId","meta","stageCount","length","otherStages","filter","canTransitionToStageWithPermissions"],"mappings":";;;;;AAYA;;;;;AAKC,IACD,SAASA,aAAAA,CAAc,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9E,MAAMC,iBAAAA,GAAoBF,QACvBG,MAAM,CAAC,mBACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEJ,QAAAA,WAAAA;QAAaK,KAAAA,EAAOC;AAAgB,KAAA,CAAA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M;AACjCX,YAAAA,aAAAA;AACAjB,YAAAA;AACF,SAAA;;;AAIA,QAAA,IAAI,CAAClC,MAAAA,EAAQ;AACX,YAAA,IAAI,CAACoD,cAAAA,EAAgB;gBACnBjD,GAAAA,CAAI8B,KAAK,CAAC,GAAA,EAAK,kBAAA,CAAA;AACjB,YAAA;AAEA9B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAAC1B,aAAAA,EAAe;AAClB/B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;QAEA,MAAMG,WAAAA,GAAcL,eAAeM,MAAM,CACvC,CAAC5C,KAAAA,GAAmDA,KAAAA,CAAMD,EAAE,KAAKwC,aAAAA,CAAAA;QAGnE,MAAM5C,IAAAA,GAAOgD,YAAYC,MAAM,CAAC,CAAC5C,KAAAA,GAC/BE,gBAAAA,CAAiB2C,mCAAmC,CAAC7C,KAAAA,CAAAA,CAAAA;AAGvDjB,QAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,YAAAA,IAAAA;AACA6C,YAAAA;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"stages.mjs","sources":["../../../server/src/controllers/stages.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport type { Core } from '@strapi/types';\n\nimport { async } from '@strapi/utils';\nimport { getService } from '../utils';\nimport { validateUpdateStageOnEntity, validateLocale } from '../validation/review-workflows';\nimport {\n STAGE_MODEL_UID,\n ENTITY_STAGE_ATTRIBUTE,\n STAGE_TRANSITION_UID,\n} from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { (Stage) => SanitizedStage }\n */\nfunction sanitizeStage({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n const permissionChecker = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: STAGE_MODEL_UID });\n\n return (entity: unknown) => permissionChecker.sanitizeOutput(entity);\n}\n\nexport default {\n /**\n * List all stages\n */\n async find(ctx: Context) {\n const { workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stages = await stagesService.find({\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await async.map(stages, sanitizer),\n };\n },\n /**\n * Get one stage\n */\n async findById(ctx: Context) {\n const { id, workflow_id: workflowId } = ctx.params;\n const { populate } = ctx.query;\n const stagesService = getService('stages');\n const sanitizer = sanitizeStage({ strapi }, ctx.state.userAbility);\n\n const stage = await stagesService.findById(id, {\n workflowId,\n populate,\n });\n\n ctx.body = {\n data: await sanitizer(stage),\n };\n },\n\n /**\n * Updates an entity's stage.\n * @async\n * @param {Object} ctx - The Koa context object.\n * @param {Object} ctx.params - An object containing the parameters from the request URL.\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity to update.\n * @param {Object} ctx.request.body.data - Optional data object containing the new stage ID for the entity.\n * @param {string} ctx.request.body.data.id - The ID of the new stage for the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n * @throws {ValidationError} If the `data` object in the request body fails to pass validation.\n * @returns {Promise<void>} A promise that resolves when the entity's stage has been updated.\n */\n async updateEntity(ctx: Context) {\n const stagesService = getService('stages');\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { body, query = {} } = ctx.request;\n\n const { sanitizeOutput } = strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID });\n\n // Load entity\n const locale = await validateLocale(query?.locale);\n const entity = await strapi.documents(modelUID).findOne({\n documentId,\n // @ts-expect-error - locale should be also null in the doc service types\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n });\n\n if (!entity) {\n ctx.throw(404, 'Entity not found');\n }\n\n // Validate if entity stage can be updated\n const canTransition = stagePermissions.can(\n STAGE_TRANSITION_UID,\n entity[ENTITY_STAGE_ATTRIBUTE]?.id\n );\n\n if (!canTransition) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const { id: stageId } = await validateUpdateStageOnEntity(\n { id: Number(body?.data?.id) },\n 'You should pass an id to the body of the put request.'\n );\n\n const workflow = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);\n workflowService.assertStageBelongsToWorkflow(stageId, workflow);\n\n const canTransitionTo = await stagePermissions.canTransitionToStage(stageId);\n if (!canTransitionTo) {\n ctx.throw(403, 'Forbidden stage transition');\n }\n\n const updatedEntity = await stagesService.updateEntity(entity, modelUID, stageId);\n\n ctx.body = { data: await sanitizeOutput(updatedEntity) };\n },\n\n /**\n * List all the stages that are available for a user to transition an entity to.\n * Stages are filtered by both \"from\" permission on the current stage AND \"to\" permission on each target stage.\n * @async\n * @param {*} ctx\n * @param {string} ctx.params.model_uid - The model UID of the entity.\n * @param {string} ctx.params.id - The ID of the entity.\n * @throws {ApplicationError} If review workflows is not activated on the specified model UID.\n */\n async listAvailableStages(ctx: Context) {\n const stagePermissions = getService('stage-permissions');\n const workflowService = getService('workflows');\n\n const { model_uid: modelUID, id: documentId } = ctx.params;\n const { query = {} } = ctx.request;\n\n if (\n strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility: ctx.state.userAbility, model: modelUID })\n .cannot.read()\n ) {\n return ctx.forbidden();\n }\n\n // Load entity\n const locale = (await validateLocale(query?.locale)) ?? undefined;\n const [entity, workflowCount, workflowResult] = await Promise.all([\n strapi.documents(modelUID).findOne({\n documentId,\n locale,\n populate: [ENTITY_STAGE_ATTRIBUTE],\n }),\n workflowService.count(),\n workflowService.getAssignedWorkflow(modelUID, {\n populate: { stages: { populate: { permissions: { populate: ['role'] } } } },\n }),\n ]);\n\n const workflowStages = workflowResult ? workflowResult.stages : [];\n const entityStageId = entity?.[ENTITY_STAGE_ATTRIBUTE]?.id;\n const canTransition = stagePermissions.can(STAGE_TRANSITION_UID, entityStageId);\n\n const meta = {\n stageCount: workflowStages.length,\n workflowCount,\n canTransition,\n };\n\n // The entity may not exist yet for the requested locale (e.g. switching to a\n // locale that has not been saved).\n if (!entity) {\n if (!workflowResult) {\n ctx.throw(404, 'Entity not found');\n }\n\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n if (!canTransition) {\n ctx.body = {\n data: [],\n meta,\n };\n\n return;\n }\n\n const otherStages = workflowStages.filter(\n (stage: { id: number; permissions?: unknown[] }) => stage.id !== entityStageId\n );\n\n const data = otherStages.filter((stage: { id: number; permissions?: unknown[] }) =>\n stagePermissions.canTransitionToStageWithPermissions(stage)\n );\n\n ctx.body = {\n data,\n meta,\n };\n },\n};\n"],"names":["sanitizeStage","strapi","userAbility","permissionChecker","plugin","service","create","model","STAGE_MODEL_UID","entity","sanitizeOutput","find","ctx","workflow_id","workflowId","params","populate","query","stagesService","getService","sanitizer","state","stages","body","data","async","map","findById","id","stage","updateEntity","stagePermissions","workflowService","model_uid","modelUID","documentId","request","locale","validateLocale","documents","findOne","ENTITY_STAGE_ATTRIBUTE","throw","canTransition","can","STAGE_TRANSITION_UID","stageId","validateUpdateStageOnEntity","Number","workflow","assertContentTypeBelongsToWorkflow","assertStageBelongsToWorkflow","canTransitionTo","canTransitionToStage","updatedEntity","listAvailableStages","cannot","read","forbidden","undefined","workflowCount","workflowResult","Promise","all","count","getAssignedWorkflow","permissions","workflowStages","entityStageId","meta","stageCount","length","otherStages","filter","canTransitionToStageWithPermissions"],"mappings":";;;;;AAYA;;;;;AAKC,IACD,SAASA,aAAAA,CAAc,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9E,MAAMC,iBAAAA,GAAoBF,QACvBG,MAAM,CAAC,m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,CAACC,oBAAAA,EAAsBuB,aAAAA,CAAAA;AAEjE,QAAA,MAAMC,IAAAA,GAAO;AACXC,YAAAA,UAAAA,EAAYH,eAAeI,MAAM;AACjCX,YAAAA,aAAAA;AACAjB,YAAAA;AACF,SAAA;;;AAIA,QAAA,IAAI,CAAClC,MAAAA,EAAQ;AACX,YAAA,IAAI,CAACoD,cAAAA,EAAgB;gBACnBjD,GAAAA,CAAI8B,KAAK,CAAC,GAAA,EAAK,kBAAA,CAAA;AACjB,YAAA;AAEA9B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAAC1B,aAAAA,EAAe;AAClB/B,YAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,gBAAAA,IAAAA,EAAM,EAAE;AACR6C,gBAAAA;AACF,aAAA;AAEA,YAAA;AACF,QAAA;QAEA,MAAMG,WAAAA,GAAcL,eAAeM,MAAM,CACvC,CAAC5C,KAAAA,GAAmDA,KAAAA,CAAMD,EAAE,KAAKwC,aAAAA,CAAAA;QAGnE,MAAM5C,IAAAA,GAAOgD,YAAYC,MAAM,CAAC,CAAC5C,KAAAA,GAC/BE,gBAAAA,CAAiB2C,mCAAmC,CAAC7C,KAAAA,CAAAA,CAAAA;AAGvDjB,QAAAA,GAAAA,CAAIW,IAAI,GAAG;AACTC,YAAAA,IAAAA;AACA6C,YAAAA;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"workflows.js","sources":["../../../server/src/controllers/workflows.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport { update, map, property } from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\nimport type { StagePermission } from '../../../shared/contracts/review-workflows';\nimport { getService } from '../utils';\nimport { validateWorkflowCreate, validateWorkflowUpdate } from '../validation/review-workflows';\nimport { WORKFLOW_MODEL_UID, WORKFLOW_POPULATE } from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { PermissionChecker }\n */\nfunction getWorkflowsPermissionChecker({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n return strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: WORKFLOW_MODEL_UID });\n}\n\n/**\n * Transforms workflow to an admin UI format.\n * Some attributes (like permissions) are presented in a different format in the admin UI.\n *\n * Permissions stored on each stage are split into two arrays:\n * - `fromPermissions`: entries with `actionParameters.from` (controls who can move\n * content out of the stage)\n * - `toPermissions`: entries with `actionParameters.to` (controls who can move\n * content into the stage)\n *\n * Role objects are also flattened to their numeric id.\n */\n\n/**\n * Shape of a permission row as returned by the DB populate.\n */\ninterface PopulatedPermission {\n action: string;\n subject?: string | null;\n role: number | { id: number };\n actionParameters?: { from?: number; to?: number };\n}\n\ninterface PopulatedStage {\n permissions?: PopulatedPermission[];\n [key: string]: unknown;\n}\n\nfunction formatWorkflowToAdmin(workflow: { stages?: PopulatedStage[]; [key: string]: unknown }) {\n if (!workflow) return;\n if (!workflow.stages) return workflow;\n\n const transformRoleToId = ({\n actionParameters: _,\n role,\n ...rest\n }: PopulatedPermission): StagePermission => ({\n ...rest,\n role: typeof role === 'object' ? role.id : role,\n });\n\n const transformStages = map((stage: PopulatedStage) => {\n const { permissions: allPermissions = [], ...rest } = stage;\n\n const fromPermissions = allPermissions\n .filter((p) => p.actionParameters?.from)\n .map(transformRoleToId);\n\n const toPermissions = allPermissions\n .filter((p) => p.actionParameters?.to)\n .map(transformRoleToId);\n\n return {\n ...rest,\n fromPermissions,\n toPermissions,\n };\n });\n\n return update('stages', transformStages, workflow);\n}\n\nexport default {\n /**\n * Create a new workflow\n */\n async create(ctx: Context) {\n const { body, query } = ctx.request;\n const { sanitizeCreateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.create(query);\n\n const workflowBody = await validateWorkflowCreate(body.data);\n\n const workflowService = getService('workflows');\n const createdWorkflow = await workflowService\n .create({\n data: await sanitizeCreateInput(workflowBody),\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n ctx.created({\n data: await sanitizeOutput(createdWorkflow),\n });\n },\n\n /**\n * Update a workflow\n */\n async update(ctx: Context) {\n const { id } = ctx.params;\n const { body, query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeUpdateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.update(query);\n const workflowBody = await validateWorkflowUpdate(body.data);\n\n // Find if workflow exists\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound();\n }\n\n // Sanitize input data\n const getPermittedFieldToUpdate = sanitizeUpdateInput(workflow);\n const dataToUpdate = await getPermittedFieldToUpdate(workflowBody);\n\n // Update workflow\n const updatedWorkflow = await workflowService\n .update(workflow, {\n data: dataToUpdate,\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n // Send sanitized response\n ctx.body = {\n data: await sanitizeOutput(updatedWorkflow),\n };\n },\n\n /**\n * Delete a workflow\n */\n async delete(ctx: Context) {\n const { id } = ctx.params;\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.delete(query);\n\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound(\"Workflow doesn't exist\");\n }\n\n const deletedWorkflow = await workflowService\n .delete(workflow, { populate })\n .then(formatWorkflowToAdmin);\n\n ctx.body = {\n data: await sanitizeOutput(deletedWorkflow),\n };\n },\n\n /**\n * List all workflows\n */\n async find(ctx: Context) {\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate, filters, sort } = await sanitizedQuery.read(query);\n\n const [workflows, workflowCount] = await Promise.all([\n workflowService.find({ populate, filters, sort }).then(map(formatWorkflowToAdmin)),\n workflowService.count(),\n ]);\n\n ctx.body = {\n data: await async.map(workflows, sanitizeOutput),\n meta: {\n workflowCount,\n },\n };\n },\n};\n"],"names":["getWorkflowsPermissionChecker","strapi","userAbility","plugin","service","create","model","WORKFLOW_MODEL_UID","formatWorkflowToAdmin","workflow","stages","transformRoleToId","actionParameters","_","role","rest","id","transformStages","map","stage","permissions","allPermissions","fromPermissions","filter","p","from","toPermissions","to","update","ctx","body","query","request","sanitizeCreateInput","sanitizeOutput","sanitizedQuery","state","populate","workflowBody","validateWorkflowCreate","data","workflowService","getService","createdWorkflow","then","created","params","sanitizeUpdateInput","validateWorkflowUpdate","findById","WORKFLOW_POPULATE","notFound","getPermittedFieldToUpdate","dataToUpdate","updatedWorkflow","delete","deletedWorkflow","find","filters","sort","read","workflows","workflowCount","Promise","all","count","async","meta"],"mappings":";;;;;;;;AAWA;;;;;AAKC,IACD,SAASA,6BAAAA,CAA8B,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9F,OAAOD,OAAAA,CACJE,MAAM,CAAC,iBAAA,CAAA,CACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEH,QAAAA,WAAAA;QAAaI,KAAAA,EAAOC;AAAmB,KAAA,CAAA;AACrD;AA8BA,SAASC,sBAAsBC,QAA+D,EAAA;AAC5F,IAAA,IAAI,CAACA,QAAAA,EAAU;AACf,IAAA,IAAI,CAACA,QAAAA,CAASC,MAAM,EAAE,OAAOD,QAAAA;IAE7B,MAAME,iBAAAA,GAAoB,CAAC,EACzBC,gBAAAA,EAAkBC,CAAC,EACnBC,IAAI,EACJ,GAAGC,IAAAA,EACiB,IAAuB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AAA,GAAAA,CAAIC,IAAI,GAAG;AACTU,YAAAA,IAAAA,EAAM,MAAMN,cAAAA,CAAesB,eAAAA;AAC7B,SAAA;AACF,IAAA,CAAA;AAEA;;MAGA,MAAMC,MAAK5B,GAAY,EAAA;AACrB,QAAA,MAAM,EAAEE,KAAK,EAAE,GAAGF,IAAIG,OAAO;AAC7B,QAAA,MAAMS,kBAAkBC,gBAAAA,CAAW,WAAA,CAAA;AACnC,QAAA,MAAM,EAAER,cAAc,EAAEC,cAAc,EAAE,GAAGnC,6BAAAA,CACzC;AAAEC,YAAAA;SAAO,EACT4B,GAAAA,CAAIO,KAAK,CAAClC,WAAW,CAAA;QAEvB,MAAM,EAAEmC,QAAQ,EAAEqB,OAAO,EAAEC,IAAI,EAAE,GAAG,MAAMxB,cAAAA,CAAeyB,IAAI,CAAC7B,KAAAA,CAAAA;AAE9D,QAAA,MAAM,CAAC8B,SAAAA,EAAWC,aAAAA,CAAc,GAAG,MAAMC,OAAAA,CAAQC,GAAG,CAAC;AACnDvB,YAAAA,eAAAA,CAAgBgB,IAAI,CAAC;AAAEpB,gBAAAA,QAAAA;AAAUqB,gBAAAA,OAAAA;AAASC,gBAAAA;aAAK,CAAA,CAAGf,IAAI,CAAC1B,MAAAA,CAAIV,qBAAAA,CAAAA,CAAAA;AAC3DiC,YAAAA,eAAAA,CAAgBwB,KAAK;AACtB,SAAA,CAAA;AAEDpC,QAAAA,GAAAA,CAAIC,IAAI,GAAG;AACTU,YAAAA,IAAAA,EAAM,MAAM0B,WAAAA,CAAMhD,GAAG,CAAC2C,SAAAA,EAAW3B,cAAAA,CAAAA;YACjCiC,IAAAA,EAAM;AACJL,gBAAAA;AACF;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"workflows.js","sources":["../../../server/src/controllers/workflows.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport { update, map } from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\nimport type { StagePermission } from '../../../shared/contracts/review-workflows';\nimport { getService } from '../utils';\nimport { validateWorkflowCreate, validateWorkflowUpdate } from '../validation/review-workflows';\nimport { WORKFLOW_MODEL_UID, WORKFLOW_POPULATE } from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { PermissionChecker }\n */\nfunction getWorkflowsPermissionChecker({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n return strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: WORKFLOW_MODEL_UID });\n}\n\n/**\n * Transforms workflow to an admin UI format.\n * Some attributes (like permissions) are presented in a different format in the admin UI.\n *\n * Permissions stored on each stage are split into two arrays:\n * - `fromPermissions`: entries with `actionParameters.from` (controls who can move\n * content out of the stage)\n * - `toPermissions`: entries with `actionParameters.to` (controls who can move\n * content into the stage)\n *\n * Role objects are also flattened to their numeric id.\n */\n\n/**\n * Shape of a permission row as returned by the DB populate.\n */\ninterface PopulatedPermission {\n action: string;\n subject?: string | null;\n role: number | { id: number };\n actionParameters?: { from?: number; to?: number };\n}\n\ninterface PopulatedStage {\n permissions?: PopulatedPermission[];\n [key: string]: unknown;\n}\n\nfunction formatWorkflowToAdmin(workflow: { stages?: PopulatedStage[]; [key: string]: unknown }) {\n if (!workflow) return;\n if (!workflow.stages) return workflow;\n\n const transformRoleToId = ({\n actionParameters: _,\n role,\n ...rest\n }: PopulatedPermission): StagePermission => ({\n ...rest,\n role: typeof role === 'object' ? role.id : role,\n });\n\n const transformStages = map((stage: PopulatedStage) => {\n const { permissions: allPermissions = [], ...rest } = stage;\n\n const fromPermissions = allPermissions\n .filter((p) => p.actionParameters?.from)\n .map(transformRoleToId);\n\n const toPermissions = allPermissions\n .filter((p) => p.actionParameters?.to)\n .map(transformRoleToId);\n\n return {\n ...rest,\n fromPermissions,\n toPermissions,\n };\n });\n\n return update('stages', transformStages, workflow);\n}\n\nexport default {\n /**\n * Create a new workflow\n */\n async create(ctx: Context) {\n const { body, query } = ctx.request;\n const { sanitizeCreateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.create(query);\n\n const workflowBody = await validateWorkflowCreate(body.data);\n\n const workflowService = getService('workflows');\n const createdWorkflow = await workflowService\n .create({\n data: await sanitizeCreateInput(workflowBody),\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n ctx.created({\n data: await sanitizeOutput(createdWorkflow),\n });\n },\n\n /**\n * Update a workflow\n */\n async update(ctx: Context) {\n const { id } = ctx.params;\n const { body, query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeUpdateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.update(query);\n const workflowBody = await validateWorkflowUpdate(body.data);\n\n // Find if workflow exists\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound();\n }\n\n // Sanitize input data\n const getPermittedFieldToUpdate = sanitizeUpdateInput(workflow);\n const dataToUpdate = await getPermittedFieldToUpdate(workflowBody);\n\n // Update workflow\n const updatedWorkflow = await workflowService\n .update(workflow, {\n data: dataToUpdate,\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n // Send sanitized response\n ctx.body = {\n data: await sanitizeOutput(updatedWorkflow),\n };\n },\n\n /**\n * Delete a workflow\n */\n async delete(ctx: Context) {\n const { id } = ctx.params;\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.delete(query);\n\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound(\"Workflow doesn't exist\");\n }\n\n const deletedWorkflow = await workflowService\n .delete(workflow, { populate })\n .then(formatWorkflowToAdmin);\n\n ctx.body = {\n data: await sanitizeOutput(deletedWorkflow),\n };\n },\n\n /**\n * List all workflows\n */\n async find(ctx: Context) {\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate, filters, sort } = await sanitizedQuery.read(query);\n\n const [workflows, workflowCount] = await Promise.all([\n workflowService.find({ populate, filters, sort }).then(map(formatWorkflowToAdmin)),\n workflowService.count(),\n ]);\n\n ctx.body = {\n data: await async.map(workflows, sanitizeOutput),\n meta: {\n workflowCount,\n },\n };\n },\n};\n"],"names":["getWorkflowsPermissionChecker","strapi","userAbility","plugin","service","create","model","WORKFLOW_MODEL_UID","formatWorkflowToAdmin","workflow","stages","transformRoleToId","actionParameters","_","role","rest","id","transformStages","map","stage","permissions","allPermissions","fromPermissions","filter","p","from","toPermissions","to","update","ctx","body","query","request","sanitizeCreateInput","sanitizeOutput","sanitizedQuery","state","populate","workflowBody","validateWorkflowCreate","data","workflowService","getService","createdWorkflow","then","created","params","sanitizeUpdateInput","validateWorkflowUpdate","findById","WORKFLOW_POPULATE","notFound","getPermittedFieldToUpdate","dataToUpdate","updatedWorkflow","delete","deletedWorkflow","find","filters","sort","read","workflows","workflowCount","Promise","all","count","async","meta"],"mappings":";;;;;;;;AAWA;;;;;AAKC,IACD,SAASA,6BAAAA,CAA8B,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9F,OAAOD,OAAAA,CACJE,MAAM,CAAC,iBAAA,CAAA,CACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEH,QAAAA,WAAAA;QAAaI,KAAAA,EAAOC;AAAmB,KAAA,CAAA;AACrD;AA8BA,SAASC,sBAAsBC,QAA+D,EAAA;AAC5F,IAAA,IAAI,CAACA,QAAAA,EAAU;AACf,IAAA,IAAI,CAACA,QAAAA,CAASC,MAAM,EAAE,OAAOD,QAAAA;IAE7B,MAAME,i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llers/workflows.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport { update, map, property } from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\nimport type { StagePermission } from '../../../shared/contracts/review-workflows';\nimport { getService } from '../utils';\nimport { validateWorkflowCreate, validateWorkflowUpdate } from '../validation/review-workflows';\nimport { WORKFLOW_MODEL_UID, WORKFLOW_POPULATE } from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { PermissionChecker }\n */\nfunction getWorkflowsPermissionChecker({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n return strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: WORKFLOW_MODEL_UID });\n}\n\n/**\n * Transforms workflow to an admin UI format.\n * Some attributes (like permissions) are presented in a different format in the admin UI.\n *\n * Permissions stored on each stage are split into two arrays:\n * - `fromPermissions`: entries with `actionParameters.from` (controls who can move\n * content out of the stage)\n * - `toPermissions`: entries with `actionParameters.to` (controls who can move\n * content into the stage)\n *\n * Role objects are also flattened to their numeric id.\n */\n\n/**\n * Shape of a permission row as returned by the DB populate.\n */\ninterface PopulatedPermission {\n action: string;\n subject?: string | null;\n role: number | { id: number };\n actionParameters?: { from?: number; to?: number };\n}\n\ninterface PopulatedStage {\n permissions?: PopulatedPermission[];\n [key: string]: unknown;\n}\n\nfunction formatWorkflowToAdmin(workflow: { stages?: PopulatedStage[]; [key: string]: unknown }) {\n if (!workflow) return;\n if (!workflow.stages) return workflow;\n\n const transformRoleToId = ({\n actionParameters: _,\n role,\n ...rest\n }: PopulatedPermission): StagePermission => ({\n ...rest,\n role: typeof role === 'object' ? role.id : role,\n });\n\n const transformStages = map((stage: PopulatedStage) => {\n const { permissions: allPermissions = [], ...rest } = stage;\n\n const fromPermissions = allPermissions\n .filter((p) => p.actionParameters?.from)\n .map(transformRoleToId);\n\n const toPermissions = allPermissions\n .filter((p) => p.actionParameters?.to)\n .map(transformRoleToId);\n\n return {\n ...rest,\n fromPermissions,\n toPermissions,\n };\n });\n\n return update('stages', transformStages, workflow);\n}\n\nexport default {\n /**\n * Create a new workflow\n */\n async create(ctx: Context) {\n const { body, query } = ctx.request;\n const { sanitizeCreateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.create(query);\n\n const workflowBody = await validateWorkflowCreate(body.data);\n\n const workflowService = getService('workflows');\n const createdWorkflow = await workflowService\n .create({\n data: await sanitizeCreateInput(workflowBody),\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n ctx.created({\n data: await sanitizeOutput(createdWorkflow),\n });\n },\n\n /**\n * Update a workflow\n */\n async update(ctx: Context) {\n const { id } = ctx.params;\n const { body, query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeUpdateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.update(query);\n const workflowBody = await validateWorkflowUpdate(body.data);\n\n // Find if workflow exists\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound();\n }\n\n // Sanitize input data\n const getPermittedFieldToUpdate = sanitizeUpdateInput(workflow);\n const dataToUpdate = await getPermittedFieldToUpdate(workflowBody);\n\n // Update workflow\n const updatedWorkflow = await workflowService\n .update(workflow, {\n data: dataToUpdate,\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n // Send sanitized response\n ctx.body = {\n data: await sanitizeOutput(updatedWorkflow),\n };\n },\n\n /**\n * Delete a workflow\n */\n async delete(ctx: Context) {\n const { id } = ctx.params;\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.delete(query);\n\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound(\"Workflow doesn't exist\");\n }\n\n const deletedWorkflow = await workflowService\n .delete(workflow, { populate })\n .then(formatWorkflowToAdmin);\n\n ctx.body = {\n data: await sanitizeOutput(deletedWorkflow),\n };\n },\n\n /**\n * List all workflows\n */\n async find(ctx: Context) {\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate, filters, sort } = await sanitizedQuery.read(query);\n\n const [workflows, workflowCount] = await Promise.all([\n workflowService.find({ populate, filters, sort }).then(map(formatWorkflowToAdmin)),\n workflowService.count(),\n ]);\n\n ctx.body = {\n data: await async.map(workflows, sanitizeOutput),\n meta: {\n workflowCount,\n },\n };\n },\n};\n"],"names":["getWorkflowsPermissionChecker","strapi","userAbility","plugin","service","create","model","WORKFLOW_MODEL_UID","formatWorkflowToAdmin","workflow","stages","transformRoleToId","actionParameters","_","role","rest","id","transformStages","map","stage","permissions","allPermissions","fromPermissions","filter","p","from","toPermissions","to","update","ctx","body","query","request","sanitizeCreateInput","sanitizeOutput","sanitizedQuery","state","populate","workflowBody","validateWorkflowCreate","data","workflowService","getService","createdWorkflow","then","created","params","sanitizeUpdateInput","validateWorkflowUpdate","findById","WORKFLOW_POPULATE","notFound","getPermittedFieldToUpdate","dataToUpdate","updatedWorkflow","delete","deletedWorkflow","find","filters","sort","read","workflows","workflowCount","Promise","all","count","async","meta"],"mappings":";;;;;;AAWA;;;;;AAKC,IACD,SAASA,6BAAAA,CAA8B,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9F,OAAOD,OAAAA,CACJE,MAAM,CAAC,iBAAA,CAAA,CACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEH,QAAAA,WAAAA;QAAaI,KAAAA,EAAOC;AAAmB,KAAA,CAAA;AACrD;AA8BA,SAASC,sBAAsBC,QAA+D,EAAA;AAC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gBAAAA;AACF;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"workflows.mjs","sources":["../../../server/src/controllers/workflows.ts"],"sourcesContent":["import type { Context } from 'koa';\nimport { update, map } from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\nimport type { StagePermission } from '../../../shared/contracts/review-workflows';\nimport { getService } from '../utils';\nimport { validateWorkflowCreate, validateWorkflowUpdate } from '../validation/review-workflows';\nimport { WORKFLOW_MODEL_UID, WORKFLOW_POPULATE } from '../constants/workflows';\n\n/**\n *\n * @param { Core.Strapi } strapi - Strapi instance\n * @param userAbility\n * @return { PermissionChecker }\n */\nfunction getWorkflowsPermissionChecker({ strapi }: { strapi: Core.Strapi }, userAbility: unknown) {\n return strapi\n .plugin('content-manager')\n .service('permission-checker')\n .create({ userAbility, model: WORKFLOW_MODEL_UID });\n}\n\n/**\n * Transforms workflow to an admin UI format.\n * Some attributes (like permissions) are presented in a different format in the admin UI.\n *\n * Permissions stored on each stage are split into two arrays:\n * - `fromPermissions`: entries with `actionParameters.from` (controls who can move\n * content out of the stage)\n * - `toPermissions`: entries with `actionParameters.to` (controls who can move\n * content into the stage)\n *\n * Role objects are also flattened to their numeric id.\n */\n\n/**\n * Shape of a permission row as returned by the DB populate.\n */\ninterface PopulatedPermission {\n action: string;\n subject?: string | null;\n role: number | { id: number };\n actionParameters?: { from?: number; to?: number };\n}\n\ninterface PopulatedStage {\n permissions?: PopulatedPermission[];\n [key: string]: unknown;\n}\n\nfunction formatWorkflowToAdmin(workflow: { stages?: PopulatedStage[]; [key: string]: unknown }) {\n if (!workflow) return;\n if (!workflow.stages) return workflow;\n\n const transformRoleToId = ({\n actionParameters: _,\n role,\n ...rest\n }: PopulatedPermission): StagePermission => ({\n ...rest,\n role: typeof role === 'object' ? role.id : role,\n });\n\n const transformStages = map((stage: PopulatedStage) => {\n const { permissions: allPermissions = [], ...rest } = stage;\n\n const fromPermissions = allPermissions\n .filter((p) => p.actionParameters?.from)\n .map(transformRoleToId);\n\n const toPermissions = allPermissions\n .filter((p) => p.actionParameters?.to)\n .map(transformRoleToId);\n\n return {\n ...rest,\n fromPermissions,\n toPermissions,\n };\n });\n\n return update('stages', transformStages, workflow);\n}\n\nexport default {\n /**\n * Create a new workflow\n */\n async create(ctx: Context) {\n const { body, query } = ctx.request;\n const { sanitizeCreateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.create(query);\n\n const workflowBody = await validateWorkflowCreate(body.data);\n\n const workflowService = getService('workflows');\n const createdWorkflow = await workflowService\n .create({\n data: await sanitizeCreateInput(workflowBody),\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n ctx.created({\n data: await sanitizeOutput(createdWorkflow),\n });\n },\n\n /**\n * Update a workflow\n */\n async update(ctx: Context) {\n const { id } = ctx.params;\n const { body, query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeUpdateInput, sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.update(query);\n const workflowBody = await validateWorkflowUpdate(body.data);\n\n // Find if workflow exists\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound();\n }\n\n // Sanitize input data\n const getPermittedFieldToUpdate = sanitizeUpdateInput(workflow);\n const dataToUpdate = await getPermittedFieldToUpdate(workflowBody);\n\n // Update workflow\n const updatedWorkflow = await workflowService\n .update(workflow, {\n data: dataToUpdate,\n populate,\n })\n .then(formatWorkflowToAdmin);\n\n // Send sanitized response\n ctx.body = {\n data: await sanitizeOutput(updatedWorkflow),\n };\n },\n\n /**\n * Delete a workflow\n */\n async delete(ctx: Context) {\n const { id } = ctx.params;\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate } = await sanitizedQuery.delete(query);\n\n const workflow = await workflowService.findById(id, { populate: WORKFLOW_POPULATE });\n if (!workflow) {\n return ctx.notFound(\"Workflow doesn't exist\");\n }\n\n const deletedWorkflow = await workflowService\n .delete(workflow, { populate })\n .then(formatWorkflowToAdmin);\n\n ctx.body = {\n data: await sanitizeOutput(deletedWorkflow),\n };\n },\n\n /**\n * List all workflows\n */\n async find(ctx: Context) {\n const { query } = ctx.request;\n const workflowService = getService('workflows');\n const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(\n { strapi },\n ctx.state.userAbility\n );\n const { populate, filters, sort } = await sanitizedQuery.read(query);\n\n const [workflows, workflowCount] = await Promise.all([\n workflowService.find({ populate, filters, sort }).then(map(formatWorkflowToAdmin)),\n workflowService.count(),\n ]);\n\n ctx.body = {\n data: await async.map(workflows, sanitizeOutput),\n meta: {\n workflowCount,\n },\n };\n },\n};\n"],"names":["getWorkflowsPermissionChecker","strapi","userAbility","plugin","service","create","model","WORKFLOW_MODEL_UID","formatWorkflowToAdmin","workflow","stages","transformRoleToId","actionParameters","_","role","rest","id","transformStages","map","stage","permissions","allPermissions","fromPermissions","filter","p","from","toPermissions","to","update","ctx","body","query","request","sanitizeCreateInput","sanitizeOutput","sanitizedQuery","state","populate","workflowBody","validateWorkflowCreate","data","workflowService","getService","createdWorkflow","then","created","params","sanitizeUpdateInput","validateWorkflowUpdate","findById","WORKFLOW_POPULATE","notFound","getPermittedFieldToUpdate","dataToUpdate","updatedWorkflow","delete","deletedWorkflow","find","filters","sort","read","workflows","workflowCount","Promise","all","count","async","meta"],"mappings":";;;;;;AAWA;;;;;AAKC,IACD,SAASA,6BAAAA,CAA8B,EAAEC,QAAAA,OAAM,EAA2B,EAAEC,WAAoB,EAAA;IAC9F,OAAOD,OAAAA,CACJE,MAAM,CAAC,iBAAA,CAAA,CACPC,OAAO,CAAC,oBAAA,CAAA,CACRC,MAAM,CAAC;AAAEH,QAAAA,WA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0B,KAAAA,CAAMhD,GAAG,CAAC2C,SAAAA,EAAW3B,cAAAA,CAAAA;YACjCiC,IAAAA,EAAM;AACJL,gBAAAA;AACF;AACF,SAAA;AACF,IAAA;AACF,CAAA;;;;"}
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var destroy = (async ({ strapi })=>{});
3
+ var destroy = (async ()=>{});
4
4
 
5
5
  module.exports = destroy;
6
6
  //# sourceMappingURL=destroy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.js","sources":["../../server/src/destroy.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {};\n"],"names":["strapi"],"mappings":";;AAEA,cAAe,CAAA,OAAO,EAAEA,MAAM,EAA2B,GAAA,CAAM,CAAA;;;;"}
1
+ {"version":3,"file":"destroy.js","sources":["../../server/src/destroy.ts"],"sourcesContent":["export default async () => {};\n"],"names":[],"mappings":";;AAAA,cAAe,CAAA,UAAA,CAAa,CAAA;;;;"}
@@ -1,4 +1,4 @@
1
- var destroy = (async ({ strapi })=>{});
1
+ var destroy = (async ()=>{});
2
2
 
3
3
  export { destroy as default };
4
4
  //# sourceMappingURL=destroy.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"destroy.mjs","sources":["../../server/src/destroy.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nexport default async ({ strapi }: { strapi: Core.Strapi }) => {};\n"],"names":["strapi"],"mappings":"AAEA,cAAe,CAAA,OAAO,EAAEA,MAAM,EAA2B,GAAA,CAAM,CAAA;;;;"}
1
+ {"version":3,"file":"destroy.mjs","sources":["../../server/src/destroy.ts"],"sourcesContent":["export default async () => {};\n"],"names":[],"mappings":"AAAA,cAAe,CAAA,UAAA,CAAa,CAAA;;;;"}
@@ -2,7 +2,6 @@
2
2
 
3
3
  var fp = require('lodash/fp');
4
4
  var index = require('./utils/index.js');
5
- var shortenStageAttribute = require('./migrations/shorten-stage-attribute.js');
6
5
  var setStagesDefaultColor = require('./migrations/set-stages-default-color.js');
7
6
  var setStagesRoles = require('./migrations/set-stages-roles.js');
8
7
  var setupStageTransferToRoles = require('./migrations/setup-stage-transfer-to-roles.js');
@@ -91,7 +90,6 @@ const setRelation = (attributeName, target, contentType)=>{
91
90
  }
92
91
  var register = (async ({ strapi })=>{
93
92
  // Data Migrations
94
- strapi.hook('strapi::content-types.beforeSync').register(shortenStageAttribute);
95
93
  strapi.hook('strapi::content-types.afterSync').register(persistRWOnDowngrade({
96
94
  strapi
97
95
  }));