@strapi/review-workflows 0.0.0-experimental.fdacf4285d1cada9d94ab4dcd756c5362cba1b54 → 0.0.0-next.185e16fdc3e6f1895610ab73932bc3f044bb59e9

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 (49) hide show
  1. package/dist/_chunks/{Layout-CefL-rfa.mjs → Layout-BmKilx1K.mjs} +2 -2
  2. package/dist/_chunks/{Layout-CefL-rfa.mjs.map → Layout-BmKilx1K.mjs.map} +1 -1
  3. package/dist/_chunks/{Layout-COeOgRsc.js → Layout-Bv8Nx1fv.js} +2 -2
  4. package/dist/_chunks/{Layout-COeOgRsc.js.map → Layout-Bv8Nx1fv.js.map} +1 -1
  5. package/dist/_chunks/{_id-PmPKIqUm.js → id-CsSxw398.js} +4 -5
  6. package/dist/_chunks/id-CsSxw398.js.map +1 -0
  7. package/dist/_chunks/{_id-Dt2oEiro.mjs → id-DEppSbOE.mjs} +4 -5
  8. package/dist/_chunks/id-DEppSbOE.mjs.map +1 -0
  9. package/dist/_chunks/{index-IZXxuQ4h.mjs → index-B40EWubS.mjs} +2 -5
  10. package/dist/_chunks/{index-IZXxuQ4h.mjs.map → index-B40EWubS.mjs.map} +1 -1
  11. package/dist/_chunks/{index-p25R0AkB.js → index-BxrwA-_0.js} +4 -4
  12. package/dist/_chunks/index-BxrwA-_0.js.map +1 -0
  13. package/dist/_chunks/{index-DiWo3Pu2.js → index-C_J52ViX.js} +2 -5
  14. package/dist/_chunks/{index-DiWo3Pu2.js.map → index-C_J52ViX.js.map} +1 -1
  15. package/dist/_chunks/{index-DJtnx2X1.mjs → index-YTnpzhNo.mjs} +4 -4
  16. package/dist/_chunks/index-YTnpzhNo.mjs.map +1 -0
  17. package/dist/_chunks/{router-C8mPPFJk.js → router-8E0pDcC7.js} +3 -3
  18. package/dist/_chunks/router-8E0pDcC7.js.map +1 -0
  19. package/dist/_chunks/{router-DJCVv74P.mjs → router-BKGmmyPp.mjs} +3 -3
  20. package/dist/_chunks/router-BKGmmyPp.mjs.map +1 -0
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/server/index.js +90 -49
  24. package/dist/server/index.js.map +1 -1
  25. package/dist/server/index.mjs +90 -49
  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 +15 -6
  30. package/dist/server/src/index.d.ts.map +1 -1
  31. package/dist/server/src/register.d.ts.map +1 -1
  32. package/dist/server/src/services/assignees.d.ts +8 -4
  33. package/dist/server/src/services/assignees.d.ts.map +1 -1
  34. package/dist/server/src/services/index.d.ts +15 -6
  35. package/dist/server/src/services/index.d.ts.map +1 -1
  36. package/dist/server/src/services/metrics/index.d.ts +4 -4
  37. package/dist/server/src/services/metrics/index.d.ts.map +1 -1
  38. package/dist/server/src/services/metrics/weekly-metrics.d.ts.map +1 -1
  39. package/dist/server/src/services/stages.d.ts +6 -1
  40. package/dist/server/src/services/stages.d.ts.map +1 -1
  41. package/dist/server/src/services/workflows.d.ts.map +1 -1
  42. package/package.json +11 -11
  43. package/dist/_chunks/_id-Dt2oEiro.mjs.map +0 -1
  44. package/dist/_chunks/_id-PmPKIqUm.js.map +0 -1
  45. package/dist/_chunks/index-DJtnx2X1.mjs.map +0 -1
  46. package/dist/_chunks/index-p25R0AkB.js.map +0 -1
  47. package/dist/_chunks/router-C8mPPFJk.js.map +0 -1
  48. package/dist/_chunks/router-DJCVv74P.mjs.map +0 -1
  49. /package/dist/admin/src/routes/settings/{:id.d.ts → id.d.ts} +0 -0
@@ -6562,8 +6562,40 @@ function extendReviewWorkflowContentTypes({ strapi: strapi2 }) {
6562
6562
  });
6563
6563
  }
6564
6564
  }
6565
+ function persistRWOnDowngrade({ strapi: strapi2 }) {
6566
+ const { removePersistedTablesWithSuffix, persistTables } = getAdminService("persist-tables");
6567
+ return async ({ contentTypes: contentTypes2 }) => {
6568
+ const getStageTableToPersist = (contentTypeUID) => {
6569
+ const { attributes, tableName } = strapi2.db.metadata.get(contentTypeUID);
6570
+ const joinTableName = attributes[ENTITY_STAGE_ATTRIBUTE].joinTable.name;
6571
+ return {
6572
+ name: joinTableName,
6573
+ dependsOn: [{ name: tableName }]
6574
+ };
6575
+ };
6576
+ const getAssigneeTableToPersist = (contentTypeUID) => {
6577
+ const { attributes, tableName } = strapi2.db.metadata.get(contentTypeUID);
6578
+ const joinTableName = attributes[ENTITY_ASSIGNEE_ATTRIBUTE].joinTable.name;
6579
+ return {
6580
+ name: joinTableName,
6581
+ dependsOn: [{ name: tableName }]
6582
+ };
6583
+ };
6584
+ const enabledRWContentTypes = fp.pipe([
6585
+ getVisibleContentTypesUID,
6586
+ fp.filter((uid) => hasStageAttribute(contentTypes2[uid]))
6587
+ ])(contentTypes2);
6588
+ const stageJoinTablesToPersist = enabledRWContentTypes.map(getStageTableToPersist);
6589
+ await removePersistedTablesWithSuffix("_strapi_stage_lnk");
6590
+ await persistTables(stageJoinTablesToPersist);
6591
+ const assigneeJoinTablesToPersist = enabledRWContentTypes.map(getAssigneeTableToPersist);
6592
+ await removePersistedTablesWithSuffix("_strapi_assignee_lnk");
6593
+ await persistTables(assigneeJoinTablesToPersist);
6594
+ };
6595
+ }
6565
6596
  const register = async ({ strapi: strapi2 }) => {
6566
6597
  strapi2.hook("strapi::content-types.beforeSync").register(migrateStageAttribute);
6598
+ strapi2.hook("strapi::content-types.afterSync").register(persistRWOnDowngrade({ strapi: strapi2 }));
6567
6599
  strapi2.hook("strapi::content-types.afterSync").register(migrateReviewWorkflowStagesColor).register(migrateReviewWorkflowStagesRoles).register(migrateReviewWorkflowName).register(migrateWorkflowsContentTypes).register(migrateDeletedCTInWorkflows);
6568
6600
  reviewWorkflowsMiddlewares.contentTypeMiddleware(strapi2);
6569
6601
  extendReviewWorkflowContentTypes({ strapi: strapi2 });
@@ -7064,8 +7096,12 @@ const workflows$1 = ({ strapi: strapi2 }) => {
7064
7096
  stageId: stages2[0].id
7065
7097
  });
7066
7098
  }
7067
- metrics.sendDidCreateWorkflow();
7068
- return strapi2.db.query(WORKFLOW_MODEL_UID).create(strapi2.get("query-params").transform(WORKFLOW_MODEL_UID, createOpts));
7099
+ const createdWorkflow = await strapi2.db.query(WORKFLOW_MODEL_UID).create(strapi2.get("query-params").transform(WORKFLOW_MODEL_UID, createOpts));
7100
+ metrics.sendDidCreateWorkflow(createdWorkflow.id, !!opts.data.stageRequiredToPublishName);
7101
+ if (opts.data.stageRequiredToPublishName) {
7102
+ await strapi2.plugin("content-releases").service("release-action").validateActionsByContentTypes(opts.data.contentTypes);
7103
+ }
7104
+ return createdWorkflow;
7069
7105
  });
7070
7106
  },
7071
7107
  /**
@@ -7116,12 +7152,17 @@ const workflows$1 = ({ strapi: strapi2 }) => {
7116
7152
  stageId: updatedStageIds ? updatedStageIds[0] : workflow2.stages[0].id
7117
7153
  });
7118
7154
  }
7119
- metrics.sendDidEditWorkflow();
7155
+ metrics.sendDidEditWorkflow(workflow2.id, !!opts.data.stageRequiredToPublishName);
7120
7156
  const query = strapi2.get("query-params").transform(WORKFLOW_MODEL_UID, updateOpts);
7121
- return strapi2.db.query(WORKFLOW_MODEL_UID).update({
7157
+ const updatedWorkflow = await strapi2.db.query(WORKFLOW_MODEL_UID).update({
7122
7158
  ...query,
7123
7159
  where: { id: workflow2.id }
7124
7160
  });
7161
+ await strapi2.plugin("content-releases").service("release-action").validateActionsByContentTypes([
7162
+ ...workflow2.contentTypes,
7163
+ ...opts.data.contentTypes || []
7164
+ ]);
7165
+ return updatedWorkflow;
7125
7166
  });
7126
7167
  },
7127
7168
  /**
@@ -7144,10 +7185,12 @@ const workflows$1 = ({ strapi: strapi2 }) => {
7144
7185
  destContentTypes: []
7145
7186
  });
7146
7187
  const query = strapi2.get("query-params").transform(WORKFLOW_MODEL_UID, opts);
7147
- return strapi2.db.query(WORKFLOW_MODEL_UID).delete({
7188
+ const deletedWorkflow = await strapi2.db.query(WORKFLOW_MODEL_UID).delete({
7148
7189
  ...query,
7149
7190
  where: { id: workflow2.id }
7150
7191
  });
7192
+ await strapi2.plugin("content-releases").service("release-action").validateActionsByContentTypes(workflow2.contentTypes);
7193
+ return deletedWorkflow;
7151
7194
  });
7152
7195
  },
7153
7196
  /**
@@ -7359,8 +7402,9 @@ const stages$1 = ({ strapi: strapi2 }) => {
7359
7402
  /**
7360
7403
  * Update the stage of an entity
7361
7404
  */
7362
- async updateEntity(documentId, locale, model, stageId) {
7405
+ async updateEntity(entityToUpdate, model, stageId) {
7363
7406
  const stage = await this.findById(stageId);
7407
+ const { documentId, locale } = entityToUpdate;
7364
7408
  await workflowValidator.validateWorkflowCount();
7365
7409
  if (!stage) {
7366
7410
  throw new ApplicationError$2(`Selected stage does not exist`);
@@ -7368,9 +7412,15 @@ const stages$1 = ({ strapi: strapi2 }) => {
7368
7412
  const entity = await strapi2.documents(model).update({
7369
7413
  documentId,
7370
7414
  locale,
7371
- data: { [ENTITY_STAGE_ATTRIBUTE]: stage },
7415
+ // Stage doesn't have DP or i18n enabled, connecting it through the `id`
7416
+ // will be safer than relying on the `documentId` + `locale` + `status` transformation
7417
+ data: { [ENTITY_STAGE_ATTRIBUTE]: fp.pick(["id"], stage) },
7372
7418
  populate: [ENTITY_STAGE_ATTRIBUTE]
7373
7419
  });
7420
+ const { tableName } = strapi2.db.metadata.get(model);
7421
+ await strapi2.db.connection(tableName).where({ id: entityToUpdate.id }).update({
7422
+ updated_at: new Date(entityToUpdate.updatedAt)
7423
+ });
7374
7424
  metrics.sendDidChangeEntryStage();
7375
7425
  return entity;
7376
7426
  },
@@ -7517,32 +7567,28 @@ const assignees$1 = ({ strapi: strapi2 }) => {
7517
7567
  /**
7518
7568
  * Update the assignee of an entity
7519
7569
  */
7520
- async updateEntityAssignee(documentId, locale, model, assigneeId) {
7521
- if (fp.isNil(assigneeId)) {
7522
- return this.deleteEntityAssignee(documentId, locale, model);
7523
- }
7524
- const userExists = await getAdminService("user", { strapi: strapi2 }).exists({ id: assigneeId });
7525
- if (!userExists) {
7526
- throw new ApplicationError(`Selected user does not exist`);
7570
+ async updateEntityAssignee(entityToUpdate, model, assigneeId) {
7571
+ const { documentId, locale } = entityToUpdate;
7572
+ if (!fp.isNil(assigneeId)) {
7573
+ const userExists = await getAdminService("user", { strapi: strapi2 }).exists({ id: assigneeId });
7574
+ if (!userExists) {
7575
+ throw new ApplicationError(`Selected user does not exist`);
7576
+ }
7527
7577
  }
7528
- metrics.sendDidEditAssignee(await this.findEntityAssigneeId(documentId, model), assigneeId);
7529
- return strapi2.documents(model).update({
7578
+ const oldAssigneeId = await this.findEntityAssigneeId(entityToUpdate.id, model);
7579
+ metrics.sendDidEditAssignee(oldAssigneeId, assigneeId || null);
7580
+ const entity = await strapi2.documents(model).update({
7530
7581
  documentId,
7531
7582
  locale,
7532
- data: { [ENTITY_ASSIGNEE_ATTRIBUTE]: assigneeId },
7583
+ data: { [ENTITY_ASSIGNEE_ATTRIBUTE]: assigneeId || null },
7533
7584
  populate: [ENTITY_ASSIGNEE_ATTRIBUTE],
7534
7585
  fields: []
7535
7586
  });
7536
- },
7537
- async deleteEntityAssignee(documentId, locale, model) {
7538
- metrics.sendDidEditAssignee(await this.findEntityAssigneeId(documentId, model), null);
7539
- return strapi2.documents(model).update({
7540
- documentId,
7541
- locale,
7542
- data: { [ENTITY_ASSIGNEE_ATTRIBUTE]: null },
7543
- populate: [ENTITY_ASSIGNEE_ATTRIBUTE],
7544
- fields: []
7587
+ const { tableName } = strapi2.db.metadata.get(model);
7588
+ await strapi2.db.connection(tableName).where({ id: entityToUpdate.id }).update({
7589
+ updated_at: new Date(entityToUpdate.updatedAt)
7545
7590
  });
7591
+ return entity;
7546
7592
  }
7547
7593
  };
7548
7594
  };
@@ -7615,11 +7661,11 @@ const sendDidDeleteStage = async () => {
7615
7661
  const sendDidChangeEntryStage = async () => {
7616
7662
  strapi.telemetry.send("didChangeEntryStage", {});
7617
7663
  };
7618
- const sendDidCreateWorkflow = async () => {
7619
- strapi.telemetry.send("didCreateWorkflow", {});
7664
+ const sendDidCreateWorkflow = async (workflowId, hasRequiredStageToPublish) => {
7665
+ strapi.telemetry.send("didCreateWorkflow", { workflowId, hasRequiredStageToPublish });
7620
7666
  };
7621
- const sendDidEditWorkflow = async () => {
7622
- strapi.telemetry.send("didEditWorkflow", {});
7667
+ const sendDidEditWorkflow = async (workflowId, hasRequiredStageToPublish) => {
7668
+ strapi.telemetry.send("didEditWorkflow", { workflowId, hasRequiredStageToPublish });
7623
7669
  };
7624
7670
  const sendDidEditAssignee = async (fromId, toId) => {
7625
7671
  strapi.telemetry.send("didEditAssignee", { from: fromId, to: toId });
@@ -7644,13 +7690,13 @@ const reviewWorkflowsMetrics = {
7644
7690
  sendDidSendReviewWorkflowPropertiesOnceAWeek,
7645
7691
  sendDidEditAssignee
7646
7692
  };
7647
- function _typeof(obj) {
7693
+ function _typeof(o) {
7648
7694
  "@babel/helpers - typeof";
7649
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
7650
- return typeof obj2;
7651
- } : function(obj2) {
7652
- return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
7653
- }, _typeof(obj);
7695
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
7696
+ return typeof o2;
7697
+ } : function(o2) {
7698
+ return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
7699
+ }, _typeof(o);
7654
7700
  }
7655
7701
  function toInteger(dirtyNumber) {
7656
7702
  if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
@@ -7785,7 +7831,12 @@ const reviewWorkflowsWeeklyMetrics = ({ strapi: strapi2 }) => {
7785
7831
  },
7786
7832
  async registerCron() {
7787
7833
  const weeklySchedule = await this.ensureWeeklyStoredCronSchedule();
7788
- strapi2.cron.add({ [weeklySchedule]: this.sendMetrics.bind(this) });
7834
+ strapi2.cron.add({
7835
+ reviewWorkflowsWeekly: {
7836
+ task: this.sendMetrics.bind(this),
7837
+ options: weeklySchedule
7838
+ }
7839
+ });
7789
7840
  }
7790
7841
  };
7791
7842
  };
@@ -8147,12 +8198,7 @@ const stages = {
8147
8198
  );
8148
8199
  const workflow2 = await workflowService.assertContentTypeBelongsToWorkflow(modelUID);
8149
8200
  workflowService.assertStageBelongsToWorkflow(stageId, workflow2);
8150
- const updatedEntity = await stagesService.updateEntity(
8151
- entity.documentId,
8152
- entity.locale,
8153
- modelUID,
8154
- stageId
8155
- );
8201
+ const updatedEntity = await stagesService.updateEntity(entity, modelUID, stageId);
8156
8202
  ctx.body = { data: await sanitizeOutput(updatedEntity) };
8157
8203
  },
8158
8204
  /**
@@ -8249,12 +8295,7 @@ const assignees = {
8249
8295
  "You should pass a valid id to the body of the put request."
8250
8296
  );
8251
8297
  await workflowService.assertContentTypeBelongsToWorkflow(model);
8252
- const updatedEntity = await assigneeService.updateEntityAssignee(
8253
- documentId,
8254
- locale || null,
8255
- model,
8256
- assigneeId
8257
- );
8298
+ const updatedEntity = await assigneeService.updateEntityAssignee(entity, model, assigneeId);
8258
8299
  ctx.body = { data: await sanitizeOutput(updatedEntity) };
8259
8300
  }
8260
8301
  };