@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
@@ -6901,7 +6901,7 @@ const reviewWorkflows = {
6901
6901
  {
6902
6902
  name: "admin::hasPermissions",
6903
6903
  config: {
6904
- actions: ["admin::users.read", "admin::review-workflows.read"]
6904
+ actions: ["admin::users.read"]
6905
6905
  }
6906
6906
  }
6907
6907
  ]
@@ -7322,23 +7322,17 @@ const stages$1 = ({ strapi: strapi2 }) => {
7322
7322
  },
7323
7323
  /**
7324
7324
  * Update the stage of an entity
7325
- *
7326
- * @param {object} entityInfo
7327
- * @param {number} entityInfo.id - Entity id
7328
- * @param {string} entityInfo.modelUID - the content-type of the entity
7329
- * @param {number} stageId - The id of the stage to assign to the entity
7330
7325
  */
7331
- async updateEntity(entityInfo, stageId) {
7326
+ async updateEntity(documentId, locale, model, stageId) {
7332
7327
  const stage = await this.findById(stageId);
7333
7328
  await workflowValidator.validateWorkflowCount();
7334
7329
  if (!stage) {
7335
7330
  throw new ApplicationError$2(`Selected stage does not exist`);
7336
7331
  }
7337
- const entity = await strapi2.db.query(entityInfo.modelUID).update({
7338
- where: {
7339
- id: entityInfo.id
7340
- },
7341
- data: { [ENTITY_STAGE_ATTRIBUTE]: stageId },
7332
+ const entity = await strapi2.documents(model).update({
7333
+ documentId,
7334
+ locale,
7335
+ data: { [ENTITY_STAGE_ATTRIBUTE]: stage },
7342
7336
  populate: [ENTITY_STAGE_ATTRIBUTE]
7343
7337
  });
7344
7338
  metrics.sendDidChangeEntryStage();
@@ -7755,7 +7749,12 @@ const reviewWorkflowsWeeklyMetrics = ({ strapi: strapi2 }) => {
7755
7749
  },
7756
7750
  async registerCron() {
7757
7751
  const weeklySchedule = await this.ensureWeeklyStoredCronSchedule();
7758
- strapi2.cron.add({ [weeklySchedule]: this.sendMetrics.bind(this) });
7752
+ strapi2.cron.add({
7753
+ reviewWorkflowsWeekly: {
7754
+ task: this.sendMetrics.bind(this),
7755
+ options: weeklySchedule
7756
+ }
7757
+ });
7759
7758
  }
7760
7759
  };
7761
7760
  };
@@ -7811,6 +7810,7 @@ const handleStageOnUpdate = async (ctx, next) => {
7811
7810
  strapi.eventHub.emit(WORKFLOW_UPDATE_STAGE, {
7812
7811
  model: model.modelName,
7813
7812
  uid: model.uid,
7813
+ // TODO v6: Rename to "entry", which is what is used for regular CRUD updates
7814
7814
  entity: {
7815
7815
  // @ts-expect-error
7816
7816
  id: result?.id,
@@ -8096,7 +8096,12 @@ const stages = {
8096
8096
  );
8097
8097
  const workflow2 = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);
8098
8098
  workflowService.assertStageBelongsToWorkflow(stageId, workflow2);
8099
- const updatedEntity = await stagesService.updateEntity({ id: entity.id, modelUID }, stageId);
8099
+ const updatedEntity = await stagesService.updateEntity(
8100
+ entity.documentId,
8101
+ entity.locale,
8102
+ modelUID,
8103
+ stageId
8104
+ );
8100
8105
  ctx.body = { data: await sanitizeOutput(updatedEntity) };
8101
8106
  },
8102
8107
  /**
@@ -8116,10 +8121,9 @@ const stages = {
8116
8121
  if (strapi.plugin("content-manager").service("permission-checker").create({ userAbility: ctx.state.userAbility, model: modelUID }).cannot.read()) {
8117
8122
  return ctx.forbidden();
8118
8123
  }
8119
- const locale = await validateLocale(query?.locale);
8124
+ const locale = await validateLocale(query?.locale) ?? void 0;
8120
8125
  const entity = await strapi.documents(modelUID).findOne({
8121
8126
  documentId,
8122
- // @ts-expect-error - locale should be also null in the doc service types
8123
8127
  locale,
8124
8128
  populate: [ENTITY_STAGE_ATTRIBUTE]
8125
8129
  });
@@ -8128,12 +8132,13 @@ const stages = {
8128
8132
  }
8129
8133
  const entityStageId = entity[ENTITY_STAGE_ATTRIBUTE]?.id;
8130
8134
  const canTransition = stagePermissions2.can(STAGE_TRANSITION_UID, entityStageId);
8131
- const [workflowCount, { stages: workflowStages }] = await Promise.all([
8135
+ const [workflowCount, workflowResult] = await Promise.all([
8132
8136
  workflowService.count(),
8133
8137
  workflowService.getAssignedWorkflow(modelUID, {
8134
8138
  populate: "stages"
8135
8139
  })
8136
8140
  ]);
8141
+ const workflowStages = workflowResult ? workflowResult.stages : [];
8137
8142
  const meta = {
8138
8143
  stageCount: workflowStages.length,
8139
8144
  workflowCount
@@ -8169,22 +8174,37 @@ const assignees = {
8169
8174
  async updateEntity(ctx) {
8170
8175
  const assigneeService = getService("assignees");
8171
8176
  const workflowService = getService("workflows");
8177
+ const stagePermissions2 = getService("stage-permissions");
8172
8178
  const { model_uid: model, id: documentId } = ctx.params;
8173
- const { locale } = ctx.request.query || {};
8179
+ const locale = await validateLocale(ctx.request.query?.locale) ?? void 0;
8174
8180
  const { sanitizeOutput } = strapi.plugin("content-manager").service("permission-checker").create({ userAbility: ctx.state.userAbility, model });
8181
+ const entity = await strapi.documents(model).findOne({
8182
+ documentId,
8183
+ locale,
8184
+ populate: [ENTITY_STAGE_ATTRIBUTE]
8185
+ });
8186
+ if (!entity) {
8187
+ ctx.throw(404, "Entity not found");
8188
+ }
8189
+ const canTransitionStage = stagePermissions2.can(
8190
+ STAGE_TRANSITION_UID,
8191
+ entity[ENTITY_STAGE_ATTRIBUTE]?.id
8192
+ );
8193
+ if (!canTransitionStage) {
8194
+ ctx.throw(403, "Stage transition permission is required");
8195
+ }
8175
8196
  const { id: assigneeId } = await validateUpdateAssigneeOnEntity(
8176
8197
  ctx.request?.body?.data,
8177
8198
  "You should pass a valid id to the body of the put request."
8178
8199
  );
8179
- await validateLocale(locale);
8180
8200
  await workflowService.assertContentTypeBelongsToWorkflow(model);
8181
- const entity = await assigneeService.updateEntityAssignee(
8201
+ const updatedEntity = await assigneeService.updateEntityAssignee(
8182
8202
  documentId,
8183
8203
  locale || null,
8184
8204
  model,
8185
8205
  assigneeId
8186
8206
  );
8187
- ctx.body = { data: await sanitizeOutput(entity) };
8207
+ ctx.body = { data: await sanitizeOutput(updatedEntity) };
8188
8208
  }
8189
8209
  };
8190
8210
  const controllers = {