@strapi/review-workflows 5.0.0-rc.9 → 5.0.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 (42) hide show
  1. package/dist/_chunks/{Layout-D5aa9iUm.mjs → Layout-BJOxxAeM.mjs} +2 -2
  2. package/dist/_chunks/{Layout-D5aa9iUm.mjs.map → Layout-BJOxxAeM.mjs.map} +1 -1
  3. package/dist/_chunks/{Layout-AREWDuuq.js → Layout-DnEAvmeU.js} +2 -2
  4. package/dist/_chunks/{Layout-AREWDuuq.js.map → Layout-DnEAvmeU.js.map} +1 -1
  5. package/dist/_chunks/{_id-DDNHKV_W.mjs → _id-6LK95-rZ.mjs} +6 -6
  6. package/dist/_chunks/_id-6LK95-rZ.mjs.map +1 -0
  7. package/dist/_chunks/{_id-C7pCAzXV.js → _id-DSDzUpwX.js} +6 -6
  8. package/dist/_chunks/_id-DSDzUpwX.js.map +1 -0
  9. package/dist/_chunks/{index-Bv3cQ3c-.js → index-6FZL88pd.js} +8 -28
  10. package/dist/_chunks/index-6FZL88pd.js.map +1 -0
  11. package/dist/_chunks/{index-CIBLMG85.js → index-DZSLya4b.js} +25 -19
  12. package/dist/_chunks/index-DZSLya4b.js.map +1 -0
  13. package/dist/_chunks/{index-CeaoNBIP.mjs → index-Df1alkCk.mjs} +10 -30
  14. package/dist/_chunks/index-Df1alkCk.mjs.map +1 -0
  15. package/dist/_chunks/{index-Cx5QECZI.mjs → index-lJqpw8bs.mjs} +25 -19
  16. package/dist/_chunks/index-lJqpw8bs.mjs.map +1 -0
  17. package/dist/_chunks/{router-gRPIa2_c.js → router-CZqe-02r.js} +3 -3
  18. package/dist/_chunks/{router-gRPIa2_c.js.map → router-CZqe-02r.js.map} +1 -1
  19. package/dist/_chunks/{router-BEoNwQZ1.mjs → router-DeSH-NeW.mjs} +3 -3
  20. package/dist/_chunks/{router-BEoNwQZ1.mjs.map → router-DeSH-NeW.mjs.map} +1 -1
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/server/index.js +41 -21
  24. package/dist/server/index.js.map +1 -1
  25. package/dist/server/index.mjs +41 -21
  26. package/dist/server/index.mjs.map +1 -1
  27. package/dist/server/src/controllers/assignees.d.ts.map +1 -1
  28. package/dist/server/src/controllers/stages.d.ts.map +1 -1
  29. package/dist/server/src/index.d.ts +1 -1
  30. package/dist/server/src/services/document-service-middleware.d.ts.map +1 -1
  31. package/dist/server/src/services/index.d.ts +1 -1
  32. package/dist/server/src/services/metrics/weekly-metrics.d.ts.map +1 -1
  33. package/dist/server/src/services/stages.d.ts +2 -7
  34. package/dist/server/src/services/stages.d.ts.map +1 -1
  35. package/package.json +8 -8
  36. package/dist/_chunks/_id-C7pCAzXV.js.map +0 -1
  37. package/dist/_chunks/_id-DDNHKV_W.mjs.map +0 -1
  38. package/dist/_chunks/index-Bv3cQ3c-.js.map +0 -1
  39. package/dist/_chunks/index-CIBLMG85.js.map +0 -1
  40. package/dist/_chunks/index-CeaoNBIP.mjs.map +0 -1
  41. package/dist/_chunks/index-Cx5QECZI.mjs.map +0 -1
  42. package/strapi-server.js +0 -3
@@ -6900,7 +6900,7 @@ const reviewWorkflows = {
6900
6900
  {
6901
6901
  name: "admin::hasPermissions",
6902
6902
  config: {
6903
- actions: ["admin::users.read", "admin::review-workflows.read"]
6903
+ actions: ["admin::users.read"]
6904
6904
  }
6905
6905
  }
6906
6906
  ]
@@ -7321,23 +7321,17 @@ const stages$1 = ({ strapi: strapi2 }) => {
7321
7321
  },
7322
7322
  /**
7323
7323
  * Update the stage of an entity
7324
- *
7325
- * @param {object} entityInfo
7326
- * @param {number} entityInfo.id - Entity id
7327
- * @param {string} entityInfo.modelUID - the content-type of the entity
7328
- * @param {number} stageId - The id of the stage to assign to the entity
7329
7324
  */
7330
- async updateEntity(entityInfo, stageId) {
7325
+ async updateEntity(documentId, locale, model, stageId) {
7331
7326
  const stage = await this.findById(stageId);
7332
7327
  await workflowValidator.validateWorkflowCount();
7333
7328
  if (!stage) {
7334
7329
  throw new ApplicationError$2(`Selected stage does not exist`);
7335
7330
  }
7336
- const entity = await strapi2.db.query(entityInfo.modelUID).update({
7337
- where: {
7338
- id: entityInfo.id
7339
- },
7340
- data: { [ENTITY_STAGE_ATTRIBUTE]: stageId },
7331
+ const entity = await strapi2.documents(model).update({
7332
+ documentId,
7333
+ locale,
7334
+ data: { [ENTITY_STAGE_ATTRIBUTE]: stage },
7341
7335
  populate: [ENTITY_STAGE_ATTRIBUTE]
7342
7336
  });
7343
7337
  metrics.sendDidChangeEntryStage();
@@ -7754,7 +7748,12 @@ const reviewWorkflowsWeeklyMetrics = ({ strapi: strapi2 }) => {
7754
7748
  },
7755
7749
  async registerCron() {
7756
7750
  const weeklySchedule = await this.ensureWeeklyStoredCronSchedule();
7757
- strapi2.cron.add({ [weeklySchedule]: this.sendMetrics.bind(this) });
7751
+ strapi2.cron.add({
7752
+ reviewWorkflowsWeekly: {
7753
+ task: this.sendMetrics.bind(this),
7754
+ options: weeklySchedule
7755
+ }
7756
+ });
7758
7757
  }
7759
7758
  };
7760
7759
  };
@@ -7810,6 +7809,7 @@ const handleStageOnUpdate = async (ctx, next) => {
7810
7809
  strapi.eventHub.emit(WORKFLOW_UPDATE_STAGE, {
7811
7810
  model: model.modelName,
7812
7811
  uid: model.uid,
7812
+ // TODO v6: Rename to "entry", which is what is used for regular CRUD updates
7813
7813
  entity: {
7814
7814
  // @ts-expect-error
7815
7815
  id: result?.id,
@@ -8095,7 +8095,12 @@ const stages = {
8095
8095
  );
8096
8096
  const workflow2 = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);
8097
8097
  workflowService.assertStageBelongsToWorkflow(stageId, workflow2);
8098
- const updatedEntity = await stagesService.updateEntity({ id: entity.id, modelUID }, stageId);
8098
+ const updatedEntity = await stagesService.updateEntity(
8099
+ entity.documentId,
8100
+ entity.locale,
8101
+ modelUID,
8102
+ stageId
8103
+ );
8099
8104
  ctx.body = { data: await sanitizeOutput(updatedEntity) };
8100
8105
  },
8101
8106
  /**
@@ -8115,10 +8120,9 @@ const stages = {
8115
8120
  if (strapi.plugin("content-manager").service("permission-checker").create({ userAbility: ctx.state.userAbility, model: modelUID }).cannot.read()) {
8116
8121
  return ctx.forbidden();
8117
8122
  }
8118
- const locale = await validateLocale(query?.locale);
8123
+ const locale = await validateLocale(query?.locale) ?? void 0;
8119
8124
  const entity = await strapi.documents(modelUID).findOne({
8120
8125
  documentId,
8121
- // @ts-expect-error - locale should be also null in the doc service types
8122
8126
  locale,
8123
8127
  populate: [ENTITY_STAGE_ATTRIBUTE]
8124
8128
  });
@@ -8127,12 +8131,13 @@ const stages = {
8127
8131
  }
8128
8132
  const entityStageId = entity[ENTITY_STAGE_ATTRIBUTE]?.id;
8129
8133
  const canTransition = stagePermissions2.can(STAGE_TRANSITION_UID, entityStageId);
8130
- const [workflowCount, { stages: workflowStages }] = await Promise.all([
8134
+ const [workflowCount, workflowResult] = await Promise.all([
8131
8135
  workflowService.count(),
8132
8136
  workflowService.getAssignedWorkflow(modelUID, {
8133
8137
  populate: "stages"
8134
8138
  })
8135
8139
  ]);
8140
+ const workflowStages = workflowResult ? workflowResult.stages : [];
8136
8141
  const meta = {
8137
8142
  stageCount: workflowStages.length,
8138
8143
  workflowCount
@@ -8168,22 +8173,37 @@ const assignees = {
8168
8173
  async updateEntity(ctx) {
8169
8174
  const assigneeService = getService("assignees");
8170
8175
  const workflowService = getService("workflows");
8176
+ const stagePermissions2 = getService("stage-permissions");
8171
8177
  const { model_uid: model, id: documentId } = ctx.params;
8172
- const { locale } = ctx.request.query || {};
8178
+ const locale = await validateLocale(ctx.request.query?.locale) ?? void 0;
8173
8179
  const { sanitizeOutput } = strapi.plugin("content-manager").service("permission-checker").create({ userAbility: ctx.state.userAbility, model });
8180
+ const entity = await strapi.documents(model).findOne({
8181
+ documentId,
8182
+ locale,
8183
+ populate: [ENTITY_STAGE_ATTRIBUTE]
8184
+ });
8185
+ if (!entity) {
8186
+ ctx.throw(404, "Entity not found");
8187
+ }
8188
+ const canTransitionStage = stagePermissions2.can(
8189
+ STAGE_TRANSITION_UID,
8190
+ entity[ENTITY_STAGE_ATTRIBUTE]?.id
8191
+ );
8192
+ if (!canTransitionStage) {
8193
+ ctx.throw(403, "Stage transition permission is required");
8194
+ }
8174
8195
  const { id: assigneeId } = await validateUpdateAssigneeOnEntity(
8175
8196
  ctx.request?.body?.data,
8176
8197
  "You should pass a valid id to the body of the put request."
8177
8198
  );
8178
- await validateLocale(locale);
8179
8199
  await workflowService.assertContentTypeBelongsToWorkflow(model);
8180
- const entity = await assigneeService.updateEntityAssignee(
8200
+ const updatedEntity = await assigneeService.updateEntityAssignee(
8181
8201
  documentId,
8182
8202
  locale || null,
8183
8203
  model,
8184
8204
  assigneeId
8185
8205
  );
8186
- ctx.body = { data: await sanitizeOutput(entity) };
8206
+ ctx.body = { data: await sanitizeOutput(updatedEntity) };
8187
8207
  }
8188
8208
  };
8189
8209
  const controllers = {