@strapi/review-workflows 0.0.0-experimental.edc24aaa3bb5a90fa5fd4fee208167dd4e2e38d4 → 0.0.0-experimental.f0d3b2d782e972f1dcb8acf0dce31d4090d1e420

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 (59) hide show
  1. package/dist/_chunks/{Layout-D3DDQmMI.js → Layout-8i0EXRRs.js} +7 -8
  2. package/dist/_chunks/Layout-8i0EXRRs.js.map +1 -0
  3. package/dist/_chunks/{Layout-Da8jupiA.mjs → Layout-C9m07iTY.mjs} +7 -8
  4. package/dist/_chunks/Layout-C9m07iTY.mjs.map +1 -0
  5. package/dist/_chunks/{_id-CnRDP3Xx.js → id-CmtaTf1x.js} +13 -40
  6. package/dist/_chunks/id-CmtaTf1x.js.map +1 -0
  7. package/dist/_chunks/{_id-xSrgPSJs.mjs → id-DV0Ndeav.mjs} +13 -40
  8. package/dist/_chunks/id-DV0Ndeav.mjs.map +1 -0
  9. package/dist/_chunks/{index-4kp4AkBB.js → index-B8WmHbCU.js} +9 -29
  10. package/dist/_chunks/index-B8WmHbCU.js.map +1 -0
  11. package/dist/_chunks/{index-DhPxWpsW.js → index-BCUO98DV.js} +78 -67
  12. package/dist/_chunks/index-BCUO98DV.js.map +1 -0
  13. package/dist/_chunks/{index-jfO5GxtW.mjs → index-CA5Axcoc.mjs} +11 -31
  14. package/dist/_chunks/index-CA5Axcoc.mjs.map +1 -0
  15. package/dist/_chunks/{index-DDsJlZQw.mjs → index-CqYVkW3E.mjs} +79 -68
  16. package/dist/_chunks/index-CqYVkW3E.mjs.map +1 -0
  17. package/dist/_chunks/{router-DSXpeew4.js → router-BOXlNnrU.js} +3 -3
  18. package/dist/_chunks/router-BOXlNnrU.js.map +1 -0
  19. package/dist/_chunks/{router-DOEULOpS.mjs → router-Jdt6SbIA.mjs} +3 -3
  20. package/dist/_chunks/router-Jdt6SbIA.mjs.map +1 -0
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/admin/src/services/admin.d.ts +1 -1
  24. package/dist/admin/src/services/api.d.ts +1 -1
  25. package/dist/admin/src/services/content-manager.d.ts +4 -4
  26. package/dist/admin/src/services/settings.d.ts +1733 -7
  27. package/dist/server/index.js +49 -68
  28. package/dist/server/index.js.map +1 -1
  29. package/dist/server/index.mjs +49 -68
  30. package/dist/server/index.mjs.map +1 -1
  31. package/dist/server/src/controllers/assignees.d.ts.map +1 -1
  32. package/dist/server/src/controllers/index.d.ts +0 -1
  33. package/dist/server/src/controllers/index.d.ts.map +1 -1
  34. package/dist/server/src/controllers/stages.d.ts.map +1 -1
  35. package/dist/server/src/controllers/workflows.d.ts +0 -7
  36. package/dist/server/src/controllers/workflows.d.ts.map +1 -1
  37. package/dist/server/src/index.d.ts +1 -2
  38. package/dist/server/src/index.d.ts.map +1 -1
  39. package/dist/server/src/routes/review-workflows.d.ts.map +1 -1
  40. package/dist/server/src/services/document-service-middleware.d.ts.map +1 -1
  41. package/dist/server/src/services/index.d.ts +1 -1
  42. package/dist/server/src/services/metrics/weekly-metrics.d.ts.map +1 -1
  43. package/dist/server/src/services/stages.d.ts +2 -7
  44. package/dist/server/src/services/stages.d.ts.map +1 -1
  45. package/dist/shared/contracts/review-workflows.d.ts +1 -14
  46. package/dist/shared/contracts/review-workflows.d.ts.map +1 -1
  47. package/package.json +10 -10
  48. package/dist/_chunks/Layout-D3DDQmMI.js.map +0 -1
  49. package/dist/_chunks/Layout-Da8jupiA.mjs.map +0 -1
  50. package/dist/_chunks/_id-CnRDP3Xx.js.map +0 -1
  51. package/dist/_chunks/_id-xSrgPSJs.mjs.map +0 -1
  52. package/dist/_chunks/index-4kp4AkBB.js.map +0 -1
  53. package/dist/_chunks/index-DDsJlZQw.mjs.map +0 -1
  54. package/dist/_chunks/index-DhPxWpsW.js.map +0 -1
  55. package/dist/_chunks/index-jfO5GxtW.mjs.map +0 -1
  56. package/dist/_chunks/router-DOEULOpS.mjs.map +0 -1
  57. package/dist/_chunks/router-DSXpeew4.js.map +0 -1
  58. package/strapi-server.js +0 -3
  59. /package/dist/admin/src/routes/settings/{:id.d.ts → id.d.ts} +0 -0
@@ -6838,23 +6838,6 @@ const reviewWorkflows = {
6838
6838
  ]
6839
6839
  }
6840
6840
  },
6841
- {
6842
- method: "GET",
6843
- path: "/workflows/:id",
6844
- handler: "workflows.findById",
6845
- config: {
6846
- middlewares: [enableFeatureMiddleware("review-workflows")],
6847
- policies: [
6848
- "admin::isAuthenticatedAdmin",
6849
- {
6850
- name: "admin::hasPermissions",
6851
- config: {
6852
- actions: ["admin::review-workflows.read"]
6853
- }
6854
- }
6855
- ]
6856
- }
6857
- },
6858
6841
  {
6859
6842
  method: "GET",
6860
6843
  path: "/workflows/:workflow_id/stages",
@@ -6918,7 +6901,7 @@ const reviewWorkflows = {
6918
6901
  {
6919
6902
  name: "admin::hasPermissions",
6920
6903
  config: {
6921
- actions: ["admin::users.read", "admin::review-workflows.read"]
6904
+ actions: ["admin::users.read"]
6922
6905
  }
6923
6906
  }
6924
6907
  ]
@@ -7339,23 +7322,19 @@ const stages$1 = ({ strapi: strapi2 }) => {
7339
7322
  },
7340
7323
  /**
7341
7324
  * Update the stage of an entity
7342
- *
7343
- * @param {object} entityInfo
7344
- * @param {number} entityInfo.id - Entity id
7345
- * @param {string} entityInfo.modelUID - the content-type of the entity
7346
- * @param {number} stageId - The id of the stage to assign to the entity
7347
7325
  */
7348
- async updateEntity(entityInfo, stageId) {
7326
+ async updateEntity(documentId, locale, model, stageId) {
7349
7327
  const stage = await this.findById(stageId);
7350
7328
  await workflowValidator.validateWorkflowCount();
7351
7329
  if (!stage) {
7352
7330
  throw new ApplicationError$2(`Selected stage does not exist`);
7353
7331
  }
7354
- const entity = await strapi2.db.query(entityInfo.modelUID).update({
7355
- where: {
7356
- id: entityInfo.id
7357
- },
7358
- data: { [ENTITY_STAGE_ATTRIBUTE]: stageId },
7332
+ const entity = await strapi2.documents(model).update({
7333
+ documentId,
7334
+ locale,
7335
+ // Stage doesn't have DP or i18n enabled, connecting it through the `id`
7336
+ // will be safer than relying on the `documentId` + `locale` + `status` transformation
7337
+ data: { [ENTITY_STAGE_ATTRIBUTE]: fp.pick(["id"], stage) },
7359
7338
  populate: [ENTITY_STAGE_ATTRIBUTE]
7360
7339
  });
7361
7340
  metrics.sendDidChangeEntryStage();
@@ -7631,13 +7610,13 @@ const reviewWorkflowsMetrics = {
7631
7610
  sendDidSendReviewWorkflowPropertiesOnceAWeek,
7632
7611
  sendDidEditAssignee
7633
7612
  };
7634
- function _typeof(obj) {
7613
+ function _typeof(o) {
7635
7614
  "@babel/helpers - typeof";
7636
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
7637
- return typeof obj2;
7638
- } : function(obj2) {
7639
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
7640
- }, _typeof(obj);
7615
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
7616
+ return typeof o2;
7617
+ } : function(o2) {
7618
+ return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
7619
+ }, _typeof(o);
7641
7620
  }
7642
7621
  function toInteger(dirtyNumber) {
7643
7622
  if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
@@ -7772,7 +7751,12 @@ const reviewWorkflowsWeeklyMetrics = ({ strapi: strapi2 }) => {
7772
7751
  },
7773
7752
  async registerCron() {
7774
7753
  const weeklySchedule = await this.ensureWeeklyStoredCronSchedule();
7775
- strapi2.cron.add({ [weeklySchedule]: this.sendMetrics.bind(this) });
7754
+ strapi2.cron.add({
7755
+ reviewWorkflowsWeekly: {
7756
+ task: this.sendMetrics.bind(this),
7757
+ options: weeklySchedule
7758
+ }
7759
+ });
7776
7760
  }
7777
7761
  };
7778
7762
  };
@@ -7828,6 +7812,7 @@ const handleStageOnUpdate = async (ctx, next) => {
7828
7812
  strapi.eventHub.emit(WORKFLOW_UPDATE_STAGE, {
7829
7813
  model: model.modelName,
7830
7814
  uid: model.uid,
7815
+ // TODO v6: Rename to "entry", which is what is used for regular CRUD updates
7831
7816
  entity: {
7832
7817
  // @ts-expect-error
7833
7818
  id: result?.id,
@@ -8029,30 +8014,6 @@ const workflows = {
8029
8014
  workflowCount
8030
8015
  }
8031
8016
  };
8032
- },
8033
- /**
8034
- * Get one workflow based on its id contained in request parameters
8035
- * Returns count of workflows in meta, used to prevent workflow edition when
8036
- * max workflow count is reached for the current plan
8037
- * @param {import('koa').BaseContext} ctx - koa context
8038
- */
8039
- async findById(ctx) {
8040
- const { id } = ctx.params;
8041
- const { query } = ctx.request;
8042
- const { sanitizeOutput, sanitizedQuery } = getWorkflowsPermissionChecker(
8043
- { strapi },
8044
- ctx.state.userAbility
8045
- );
8046
- const { populate } = await sanitizedQuery.read(query);
8047
- const workflowService = getService("workflows");
8048
- const [workflow2, workflowCount] = await Promise.all([
8049
- workflowService.findById(id, { populate }).then(formatWorkflowToAdmin),
8050
- workflowService.count()
8051
- ]);
8052
- ctx.body = {
8053
- data: await sanitizeOutput(workflow2),
8054
- meta: { workflowCount }
8055
- };
8056
8017
  }
8057
8018
  };
8058
8019
  function sanitizeStage({ strapi: strapi2 }, userAbility) {
@@ -8137,7 +8098,12 @@ const stages = {
8137
8098
  );
8138
8099
  const workflow2 = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);
8139
8100
  workflowService.assertStageBelongsToWorkflow(stageId, workflow2);
8140
- const updatedEntity = await stagesService.updateEntity({ id: entity.id, modelUID }, stageId);
8101
+ const updatedEntity = await stagesService.updateEntity(
8102
+ entity.documentId,
8103
+ entity.locale,
8104
+ modelUID,
8105
+ stageId
8106
+ );
8141
8107
  ctx.body = { data: await sanitizeOutput(updatedEntity) };
8142
8108
  },
8143
8109
  /**
@@ -8157,10 +8123,9 @@ const stages = {
8157
8123
  if (strapi.plugin("content-manager").service("permission-checker").create({ userAbility: ctx.state.userAbility, model: modelUID }).cannot.read()) {
8158
8124
  return ctx.forbidden();
8159
8125
  }
8160
- const locale = await validateLocale(query?.locale);
8126
+ const locale = await validateLocale(query?.locale) ?? void 0;
8161
8127
  const entity = await strapi.documents(modelUID).findOne({
8162
8128
  documentId,
8163
- // @ts-expect-error - locale should be also null in the doc service types
8164
8129
  locale,
8165
8130
  populate: [ENTITY_STAGE_ATTRIBUTE]
8166
8131
  });
@@ -8169,12 +8134,13 @@ const stages = {
8169
8134
  }
8170
8135
  const entityStageId = entity[ENTITY_STAGE_ATTRIBUTE]?.id;
8171
8136
  const canTransition = stagePermissions2.can(STAGE_TRANSITION_UID, entityStageId);
8172
- const [workflowCount, { stages: workflowStages }] = await Promise.all([
8137
+ const [workflowCount, workflowResult] = await Promise.all([
8173
8138
  workflowService.count(),
8174
8139
  workflowService.getAssignedWorkflow(modelUID, {
8175
8140
  populate: "stages"
8176
8141
  })
8177
8142
  ]);
8143
+ const workflowStages = workflowResult ? workflowResult.stages : [];
8178
8144
  const meta = {
8179
8145
  stageCount: workflowStages.length,
8180
8146
  workflowCount
@@ -8210,22 +8176,37 @@ const assignees = {
8210
8176
  async updateEntity(ctx) {
8211
8177
  const assigneeService = getService("assignees");
8212
8178
  const workflowService = getService("workflows");
8179
+ const stagePermissions2 = getService("stage-permissions");
8213
8180
  const { model_uid: model, id: documentId } = ctx.params;
8214
- const { locale } = ctx.request.query || {};
8181
+ const locale = await validateLocale(ctx.request.query?.locale) ?? void 0;
8215
8182
  const { sanitizeOutput } = strapi.plugin("content-manager").service("permission-checker").create({ userAbility: ctx.state.userAbility, model });
8183
+ const entity = await strapi.documents(model).findOne({
8184
+ documentId,
8185
+ locale,
8186
+ populate: [ENTITY_STAGE_ATTRIBUTE]
8187
+ });
8188
+ if (!entity) {
8189
+ ctx.throw(404, "Entity not found");
8190
+ }
8191
+ const canTransitionStage = stagePermissions2.can(
8192
+ STAGE_TRANSITION_UID,
8193
+ entity[ENTITY_STAGE_ATTRIBUTE]?.id
8194
+ );
8195
+ if (!canTransitionStage) {
8196
+ ctx.throw(403, "Stage transition permission is required");
8197
+ }
8216
8198
  const { id: assigneeId } = await validateUpdateAssigneeOnEntity(
8217
8199
  ctx.request?.body?.data,
8218
8200
  "You should pass a valid id to the body of the put request."
8219
8201
  );
8220
- await validateLocale(locale);
8221
8202
  await workflowService.assertContentTypeBelongsToWorkflow(model);
8222
- const entity = await assigneeService.updateEntityAssignee(
8203
+ const updatedEntity = await assigneeService.updateEntityAssignee(
8223
8204
  documentId,
8224
8205
  locale || null,
8225
8206
  model,
8226
8207
  assigneeId
8227
8208
  );
8228
- ctx.body = { data: await sanitizeOutput(entity) };
8209
+ ctx.body = { data: await sanitizeOutput(updatedEntity) };
8229
8210
  }
8230
8211
  };
8231
8212
  const controllers = {