@webiny/api-apw 0.0.0-unstable.1e66d121db → 0.0.0-unstable.2696f9d9e8

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 (267) hide show
  1. package/ApwChangeRequestNotification.d.ts +27 -0
  2. package/ApwChangeRequestNotification.js +28 -0
  3. package/ApwChangeRequestNotification.js.map +1 -0
  4. package/ApwCommentNotification.d.ts +27 -0
  5. package/ApwCommentNotification.js +28 -0
  6. package/ApwCommentNotification.js.map +1 -0
  7. package/ApwContentReviewNotification.d.ts +26 -0
  8. package/ApwContentReviewNotification.js +28 -0
  9. package/ApwContentReviewNotification.js.map +1 -0
  10. package/ApwContentUrlPlugin.d.ts +19 -0
  11. package/ApwContentUrlPlugin.js +28 -0
  12. package/ApwContentUrlPlugin.js.map +1 -0
  13. package/ContentApwSettingsPlugin.js +5 -9
  14. package/ContentApwSettingsPlugin.js.map +1 -1
  15. package/README.md +3 -3
  16. package/crud/createChangeRequestMethods.js +7 -12
  17. package/crud/createChangeRequestMethods.js.map +1 -1
  18. package/crud/createCommentMethods.js +7 -13
  19. package/crud/createCommentMethods.js.map +1 -1
  20. package/crud/createContentReviewMethods.js +83 -111
  21. package/crud/createContentReviewMethods.js.map +1 -1
  22. package/crud/createReviewerMethods.js +7 -13
  23. package/crud/createReviewerMethods.js.map +1 -1
  24. package/crud/createWorkflowMethods.js +7 -18
  25. package/crud/createWorkflowMethods.js.map +1 -1
  26. package/crud/index.js +5 -29
  27. package/crud/index.js.map +1 -1
  28. package/crud/utils.js +6 -33
  29. package/crud/utils.js.map +1 -1
  30. package/index.d.ts +2 -3
  31. package/index.js +6 -16
  32. package/index.js.map +1 -1
  33. package/package.json +40 -47
  34. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +4 -19
  35. package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
  36. package/plugins/cms/apwEntryPlugins.js +8 -13
  37. package/plugins/cms/apwEntryPlugins.js.map +1 -1
  38. package/plugins/cms/index.js +7 -10
  39. package/plugins/cms/index.js.map +1 -1
  40. package/plugins/cms/linkContentReviewToEntry.js +4 -20
  41. package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
  42. package/plugins/cms/linkWorkflowToEntry.js +17 -45
  43. package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
  44. package/plugins/cms/notifications/changeRequestNotification.d.ts +1 -0
  45. package/plugins/cms/notifications/changeRequestNotification.js +33 -0
  46. package/plugins/cms/notifications/changeRequestNotification.js.map +1 -0
  47. package/plugins/cms/notifications/commentNotification.d.ts +1 -0
  48. package/plugins/cms/notifications/commentNotification.js +33 -0
  49. package/plugins/cms/notifications/commentNotification.js.map +1 -0
  50. package/plugins/cms/notifications/contentReviewNotification.d.ts +1 -0
  51. package/plugins/cms/notifications/contentReviewNotification.js +33 -0
  52. package/plugins/cms/notifications/contentReviewNotification.js.map +1 -0
  53. package/plugins/cms/notifications/contentUrl.d.ts +8 -0
  54. package/plugins/cms/notifications/contentUrl.js +55 -0
  55. package/plugins/cms/notifications/contentUrl.js.map +1 -0
  56. package/plugins/cms/triggerContentReview.js +5 -18
  57. package/plugins/cms/triggerContentReview.js.map +1 -1
  58. package/plugins/cms/updateContentReviewStatus.js +14 -30
  59. package/plugins/cms/updateContentReviewStatus.js.map +1 -1
  60. package/plugins/cms/utils.d.ts +3 -2
  61. package/plugins/cms/utils.js +23 -60
  62. package/plugins/cms/utils.js.map +1 -1
  63. package/plugins/context.d.ts +0 -1
  64. package/plugins/context.js +2 -45
  65. package/plugins/context.js.map +1 -1
  66. package/plugins/graphql/changeRequest.gql.js +16 -19
  67. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  68. package/plugins/graphql/comment.gql.js +41 -42
  69. package/plugins/graphql/comment.gql.js.map +1 -1
  70. package/plugins/graphql/contentReview.gql.js +25 -34
  71. package/plugins/graphql/contentReview.gql.js.map +1 -1
  72. package/plugins/graphql/reviewer.gql.js +17 -19
  73. package/plugins/graphql/reviewer.gql.js.map +1 -1
  74. package/plugins/graphql/utils.d.ts +2 -0
  75. package/plugins/graphql/utils.js +12 -0
  76. package/plugins/graphql/utils.js.map +1 -0
  77. package/plugins/graphql/workflow.gql.js +15 -19
  78. package/plugins/graphql/workflow.gql.js.map +1 -1
  79. package/plugins/graphql.js +5 -18
  80. package/plugins/graphql.js.map +1 -1
  81. package/plugins/hooks/createReviewerFromIdentity.js +28 -15
  82. package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
  83. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +3 -9
  84. package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
  85. package/plugins/hooks/deleteCommentsAfterChangeRequest.js +3 -8
  86. package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
  87. package/plugins/hooks/index.js +4 -13
  88. package/plugins/hooks/index.js.map +1 -1
  89. package/plugins/hooks/initializeContentReviewSteps.js +15 -20
  90. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  91. package/plugins/hooks/initializeNotifications.d.ts +2 -0
  92. package/plugins/hooks/initializeNotifications.js +17 -0
  93. package/plugins/hooks/initializeNotifications.js.map +1 -0
  94. package/plugins/hooks/listContentReviews.d.ts +1 -1
  95. package/plugins/hooks/listContentReviews.js +11 -33
  96. package/plugins/hooks/listContentReviews.js.map +1 -1
  97. package/plugins/hooks/notifications/appUrl.d.ts +2 -0
  98. package/plugins/hooks/notifications/appUrl.js +20 -0
  99. package/plugins/hooks/notifications/appUrl.js.map +1 -0
  100. package/plugins/hooks/notifications/changeRequestAfterCreate.d.ts +2 -0
  101. package/plugins/hooks/notifications/changeRequestAfterCreate.js +113 -0
  102. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -0
  103. package/plugins/hooks/notifications/changeRequestUrl.d.ts +8 -0
  104. package/plugins/hooks/notifications/changeRequestUrl.js +29 -0
  105. package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -0
  106. package/plugins/hooks/notifications/commentAfterCreate.d.ts +2 -0
  107. package/plugins/hooks/notifications/commentAfterCreate.js +124 -0
  108. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -0
  109. package/plugins/hooks/notifications/commentUrl.d.ts +8 -0
  110. package/plugins/hooks/notifications/commentUrl.js +29 -0
  111. package/plugins/hooks/notifications/commentUrl.js.map +1 -0
  112. package/plugins/hooks/notifications/contentReviewAfterCreate.d.ts +2 -0
  113. package/plugins/hooks/notifications/contentReviewAfterCreate.js +96 -0
  114. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -0
  115. package/plugins/hooks/notifications/contentReviewUrl.d.ts +7 -0
  116. package/plugins/hooks/notifications/contentReviewUrl.js +28 -0
  117. package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -0
  118. package/plugins/hooks/notifications/contentUrl.d.ts +7 -0
  119. package/plugins/hooks/notifications/contentUrl.js +26 -0
  120. package/plugins/hooks/notifications/contentUrl.js.map +1 -0
  121. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.d.ts +11 -0
  122. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +23 -0
  123. package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -0
  124. package/plugins/hooks/notifications/lastCommentNotificationPlugin.d.ts +11 -0
  125. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +23 -0
  126. package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -0
  127. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.d.ts +11 -0
  128. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +23 -0
  129. package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -0
  130. package/plugins/hooks/notifications/reviewers.d.ts +15 -0
  131. package/plugins/hooks/notifications/reviewers.js +47 -0
  132. package/plugins/hooks/notifications/reviewers.js.map +1 -0
  133. package/plugins/hooks/notifications/sendChangeRequestNotification.d.ts +2 -0
  134. package/plugins/hooks/notifications/sendChangeRequestNotification.js +43 -0
  135. package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -0
  136. package/plugins/hooks/notifications/sendCommentNotification.d.ts +2 -0
  137. package/plugins/hooks/notifications/sendCommentNotification.js +43 -0
  138. package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -0
  139. package/plugins/hooks/notifications/sendContentReviewNotification.d.ts +2 -0
  140. package/plugins/hooks/notifications/sendContentReviewNotification.js +43 -0
  141. package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -0
  142. package/plugins/hooks/updatePendingChangeRequests.js +7 -13
  143. package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
  144. package/plugins/hooks/updateTotalComments.js +21 -23
  145. package/plugins/hooks/updateTotalComments.js.map +1 -1
  146. package/plugins/hooks/validateChangeRequest.js +27 -16
  147. package/plugins/hooks/validateChangeRequest.js.map +1 -1
  148. package/plugins/hooks/validateComment.js +13 -12
  149. package/plugins/hooks/validateComment.js.map +1 -1
  150. package/plugins/hooks/validateContentReview.js +2 -6
  151. package/plugins/hooks/validateContentReview.js.map +1 -1
  152. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +4 -19
  153. package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
  154. package/plugins/pageBuilder/apwContentPagePlugins.js +2 -4
  155. package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
  156. package/plugins/pageBuilder/extendPbPageSettingsSchema.js +3 -6
  157. package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
  158. package/plugins/pageBuilder/index.js +7 -8
  159. package/plugins/pageBuilder/index.js.map +1 -1
  160. package/plugins/pageBuilder/linkContentReviewToPage.js +15 -27
  161. package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
  162. package/plugins/pageBuilder/linkWorkflowToPage.js +3 -31
  163. package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
  164. package/plugins/pageBuilder/notifications/changeRequestNotification.d.ts +1 -0
  165. package/plugins/pageBuilder/notifications/changeRequestNotification.js +33 -0
  166. package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -0
  167. package/plugins/pageBuilder/notifications/commentNotification.d.ts +1 -0
  168. package/plugins/pageBuilder/notifications/commentNotification.js +33 -0
  169. package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -0
  170. package/plugins/pageBuilder/notifications/contentReviewNotification.d.ts +1 -0
  171. package/plugins/pageBuilder/notifications/contentReviewNotification.js +33 -0
  172. package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -0
  173. package/plugins/pageBuilder/notifications/contentUrl.d.ts +1 -0
  174. package/plugins/pageBuilder/notifications/contentUrl.js +49 -0
  175. package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -0
  176. package/plugins/pageBuilder/triggerContentReview.js +2 -11
  177. package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
  178. package/plugins/pageBuilder/updateContentReviewStatus.js +10 -17
  179. package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
  180. package/plugins/pageBuilder/utils.d.ts +2 -2
  181. package/plugins/pageBuilder/utils.js +3 -35
  182. package/plugins/pageBuilder/utils.js.map +1 -1
  183. package/plugins/utils.d.ts +1 -2
  184. package/plugins/utils.js +6 -52
  185. package/plugins/utils.js.map +1 -1
  186. package/scheduler/createScheduleActionMethods.js +45 -50
  187. package/scheduler/createScheduleActionMethods.js.map +1 -1
  188. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  189. package/scheduler/handlers/executeAction/index.js +47 -40
  190. package/scheduler/handlers/executeAction/index.js.map +1 -1
  191. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
  192. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +19 -9
  193. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  194. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
  195. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +11 -28
  196. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  197. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
  198. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +10 -92
  199. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  200. package/scheduler/handlers/executeAction/security.js +2 -11
  201. package/scheduler/handlers/executeAction/security.js.map +1 -1
  202. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  203. package/scheduler/handlers/scheduleAction/index.js +24 -37
  204. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  205. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +20 -36
  206. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  207. package/scheduler/handlers/utils.d.ts +2 -4
  208. package/scheduler/handlers/utils.js +8 -47
  209. package/scheduler/handlers/utils.js.map +1 -1
  210. package/scheduler/index.js +2 -3
  211. package/scheduler/index.js.map +1 -1
  212. package/scheduler/types.d.ts +12 -28
  213. package/scheduler/types.js +13 -22
  214. package/scheduler/types.js.map +1 -1
  215. package/storageOperations/changeRequestStorageOperations.js +59 -45
  216. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  217. package/storageOperations/commentStorageOperations.js +35 -50
  218. package/storageOperations/commentStorageOperations.js.map +1 -1
  219. package/storageOperations/contentReviewStorageOperations.d.ts +1 -1
  220. package/storageOperations/contentReviewStorageOperations.js +34 -43
  221. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  222. package/storageOperations/index.d.ts +1 -7
  223. package/storageOperations/index.js +10 -29
  224. package/storageOperations/index.js.map +1 -1
  225. package/storageOperations/models/changeRequest.model.d.ts +1 -2
  226. package/storageOperations/models/changeRequest.model.js +6 -15
  227. package/storageOperations/models/changeRequest.model.js.map +1 -1
  228. package/storageOperations/models/comment.model.d.ts +1 -2
  229. package/storageOperations/models/comment.model.js +6 -14
  230. package/storageOperations/models/comment.model.js.map +1 -1
  231. package/storageOperations/models/contentReview.model.d.ts +1 -2
  232. package/storageOperations/models/contentReview.model.js +13 -37
  233. package/storageOperations/models/contentReview.model.js.map +1 -1
  234. package/storageOperations/models/index.js +6 -50
  235. package/storageOperations/models/index.js.map +1 -1
  236. package/storageOperations/models/reviewer.model.d.ts +1 -2
  237. package/storageOperations/models/reviewer.model.js +22 -14
  238. package/storageOperations/models/reviewer.model.js.map +1 -1
  239. package/storageOperations/models/utils.js +2 -4
  240. package/storageOperations/models/utils.js.map +1 -1
  241. package/storageOperations/models/workflow.model.d.ts +1 -2
  242. package/storageOperations/models/workflow.model.js +19 -42
  243. package/storageOperations/models/workflow.model.js.map +1 -1
  244. package/storageOperations/reviewerStorageOperations.d.ts +1 -1
  245. package/storageOperations/reviewerStorageOperations.js +34 -40
  246. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  247. package/storageOperations/types.js +3 -1
  248. package/storageOperations/workflowStorageOperations.js +40 -47
  249. package/storageOperations/workflowStorageOperations.js.map +1 -1
  250. package/types.d.ts +39 -25
  251. package/types.js +126 -42
  252. package/types.js.map +1 -1
  253. package/utils/contentApwSettingsPlugin.js +2 -6
  254. package/utils/contentApwSettingsPlugin.js.map +1 -1
  255. package/utils/errors.js +2 -17
  256. package/utils/errors.js.map +1 -1
  257. package/utils/fieldResolver.js +8 -18
  258. package/utils/fieldResolver.js.map +1 -1
  259. package/utils/pickEntryFieldValues.d.ts +3 -0
  260. package/utils/pickEntryFieldValues.js +31 -0
  261. package/utils/pickEntryFieldValues.js.map +1 -0
  262. package/utils/resolve.d.ts +1 -1
  263. package/utils/resolve.js +2 -3
  264. package/utils/resolve.js.map +1 -1
  265. package/storageOperations/models/contentModelPluginFactory.d.ts +0 -15
  266. package/storageOperations/models/contentModelPluginFactory.js +0 -28
  267. package/storageOperations/models/contentModelPluginFactory.js.map +0 -1
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.initializeContentReviewSteps = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
8
  var _set = _interopRequireDefault(require("lodash/set"));
13
-
9
+ var _types = require("../../types");
14
10
  var _utils = require("../utils");
15
-
16
11
  var _handlerGraphql = require("@webiny/handler-graphql");
17
-
18
12
  var _contentApwSettingsPlugin = require("../../utils/contentApwSettingsPlugin");
19
-
20
13
  const initializeContentReviewSteps = ({
21
14
  apw,
22
15
  plugins
@@ -32,35 +25,31 @@ const initializeContentReviewSteps = ({
32
25
  /*
33
26
  * Let's set "title" field value.
34
27
  */
35
-
36
28
  const getContent = apw.getContentGetter(type);
37
29
  const content = await getContent(id, settings);
38
-
39
30
  if (!content) {
40
31
  throw new _handlerGraphql.NotFoundError(`Content "${type}" with id ${id} not found.`);
41
32
  }
42
-
43
33
  const {
44
34
  title
45
35
  } = content;
46
36
  input = (0, _set.default)(input, "title", title);
37
+
47
38
  /**
48
39
  * We need to find a plugin which can get a workflow ID for the given type of content.
49
40
  */
50
-
51
41
  const contentApwSettingsPlugin = (0, _contentApwSettingsPlugin.getContentApwSettingsPlugin)({
52
42
  plugins,
53
43
  type
54
44
  });
55
45
  const workflowId = contentApwSettingsPlugin.getWorkflowId(content);
46
+
56
47
  /**
57
48
  * Let's initialize the "ContentReview" steps.
58
49
  */
59
-
60
50
  if (!workflowId) {
61
51
  throw new _handlerGraphql.NotFoundError(`Unable to initiate a "Content review". No workflow found!`);
62
52
  }
63
-
64
53
  input.workflowId = workflowId;
65
54
  const workflow = await apw.workflow.get(workflowId);
66
55
  const workflowSteps = workflow.steps;
@@ -68,19 +57,25 @@ const initializeContentReviewSteps = ({
68
57
  const updatedSteps = workflow.steps.map((step, index) => {
69
58
  const status = (0, _utils.getContentReviewStepInitialStatus)(workflowSteps, index, previousStepStatus);
70
59
  previousStepStatus = status;
71
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, step), {}, {
60
+ return {
61
+ ...step,
72
62
  status,
73
63
  pendingChangeRequests: 0,
74
64
  totalComments: 0
75
- });
65
+ };
76
66
  });
77
67
  /**
78
- * TODO Figure our what does this actually do?
79
- * There is no steps property on CreateApwContentReviewParams
68
+ * If there are only steps which are not mandatory ones, put review status to ApwContentReviewStatus.READY_TO_BE_PUBLISHED.
80
69
  */
81
-
70
+ const isNonMandatory = updatedSteps.every(step => {
71
+ return step.type === _types.ApwWorkflowStepTypes.NON_MANDATORY;
72
+ });
73
+ if (isNonMandatory) {
74
+ input.reviewStatus = _types.ApwContentReviewStatus.READY_TO_BE_PUBLISHED;
75
+ }
82
76
  input = (0, _set.default)(input, "steps", updatedSteps);
83
77
  });
84
78
  };
79
+ exports.initializeContentReviewSteps = initializeContentReviewSteps;
85
80
 
86
- exports.initializeContentReviewSteps = initializeContentReviewSteps;
81
+ //# sourceMappingURL=initializeContentReviewSteps.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["initializeContentReviewSteps","apw","plugins","contentReview","onContentReviewBeforeCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport { ApwContentReviewStepStatus, ApwContext } from \"~/types\";\nimport { getContentReviewStepInitialStatus } from \"~/plugins/utils\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { getContentApwSettingsPlugin } from \"~/utils/contentApwSettingsPlugin\";\n\nexport const initializeContentReviewSteps = ({ apw, plugins }: ApwContext) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { type, id, settings } = input.content;\n /*\n * Let's set \"title\" field value.\n */\n const getContent = apw.getContentGetter(type);\n const content = await getContent(id, settings);\n if (!content) {\n throw new NotFoundError(`Content \"${type}\" with id ${id} not found.`);\n }\n\n const { title } = content;\n input = lodashSet(input, \"title\", title);\n\n /**\n * We need to find a plugin which can get a workflow ID for the given type of content.\n */\n const contentApwSettingsPlugin = getContentApwSettingsPlugin({\n plugins,\n type\n });\n\n const workflowId = contentApwSettingsPlugin.getWorkflowId(content);\n\n /**\n * Let's initialize the \"ContentReview\" steps.\n */\n if (!workflowId) {\n throw new NotFoundError(`Unable to initiate a \"Content review\". No workflow found!`);\n }\n\n input.workflowId = workflowId;\n\n const workflow = await apw.workflow.get(workflowId);\n const workflowSteps = workflow.steps;\n\n let previousStepStatus: ApwContentReviewStepStatus | undefined = undefined;\n const updatedSteps = workflow.steps.map((step, index) => {\n const status = getContentReviewStepInitialStatus(\n workflowSteps,\n index,\n previousStepStatus\n );\n previousStepStatus = status;\n return {\n ...step,\n status,\n pendingChangeRequests: 0,\n totalComments: 0\n };\n });\n /**\n * TODO Figure our what does this actually do?\n * There is no steps property on CreateApwContentReviewParams\n */\n input = lodashSet(input, \"steps\", updatedSteps);\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAEO,MAAMA,4BAA4B,GAAG,CAAC;EAAEC,GAAF;EAAOC;AAAP,CAAD,KAAkC;EAC1ED,GAAG,CAACE,aAAJ,CAAkBC,2BAAlB,CAA8CC,SAA9C,CAAwD,OAAO;IAAEC;EAAF,CAAP,KAAqB;IACzE,MAAM;MAAEC,IAAF;MAAQC,EAAR;MAAYC;IAAZ,IAAyBH,KAAK,CAACI,OAArC;IACA;AACR;AACA;;IACQ,MAAMC,UAAU,GAAGV,GAAG,CAACW,gBAAJ,CAAqBL,IAArB,CAAnB;IACA,MAAMG,OAAO,GAAG,MAAMC,UAAU,CAACH,EAAD,EAAKC,QAAL,CAAhC;;IACA,IAAI,CAACC,OAAL,EAAc;MACV,MAAM,IAAIG,6BAAJ,CAAmB,YAAWN,IAAK,aAAYC,EAAG,aAAlD,CAAN;IACH;;IAED,MAAM;MAAEM;IAAF,IAAYJ,OAAlB;IACAJ,KAAK,GAAG,IAAAS,YAAA,EAAUT,KAAV,EAAiB,OAAjB,EAA0BQ,KAA1B,CAAR;IAEA;AACR;AACA;;IACQ,MAAME,wBAAwB,GAAG,IAAAC,qDAAA,EAA4B;MACzDf,OADyD;MAEzDK;IAFyD,CAA5B,CAAjC;IAKA,MAAMW,UAAU,GAAGF,wBAAwB,CAACG,aAAzB,CAAuCT,OAAvC,CAAnB;IAEA;AACR;AACA;;IACQ,IAAI,CAACQ,UAAL,EAAiB;MACb,MAAM,IAAIL,6BAAJ,CAAmB,2DAAnB,CAAN;IACH;;IAEDP,KAAK,CAACY,UAAN,GAAmBA,UAAnB;IAEA,MAAME,QAAQ,GAAG,MAAMnB,GAAG,CAACmB,QAAJ,CAAaC,GAAb,CAAiBH,UAAjB,CAAvB;IACA,MAAMI,aAAa,GAAGF,QAAQ,CAACG,KAA/B;IAEA,IAAIC,kBAA0D,GAAGC,SAAjE;IACA,MAAMC,YAAY,GAAGN,QAAQ,CAACG,KAAT,CAAeI,GAAf,CAAmB,CAACC,IAAD,EAAOC,KAAP,KAAiB;MACrD,MAAMC,MAAM,GAAG,IAAAC,wCAAA,EACXT,aADW,EAEXO,KAFW,EAGXL,kBAHW,CAAf;MAKAA,kBAAkB,GAAGM,MAArB;MACA,mEACOF,IADP;QAEIE,MAFJ;QAGIE,qBAAqB,EAAE,CAH3B;QAIIC,aAAa,EAAE;MAJnB;IAMH,CAboB,CAArB;IAcA;AACR;AACA;AACA;;IACQ3B,KAAK,GAAG,IAAAS,YAAA,EAAUT,KAAV,EAAiB,OAAjB,EAA0BoB,YAA1B,CAAR;EACH,CAxDD;AAyDH,CA1DM"}
1
+ {"version":3,"names":["_set","_interopRequireDefault","require","_types","_utils","_handlerGraphql","_contentApwSettingsPlugin","initializeContentReviewSteps","apw","plugins","contentReview","onContentReviewBeforeCreate","subscribe","input","type","id","settings","content","getContent","getContentGetter","NotFoundError","title","lodashSet","contentApwSettingsPlugin","getContentApwSettingsPlugin","workflowId","getWorkflowId","workflow","get","workflowSteps","steps","previousStepStatus","undefined","updatedSteps","map","step","index","status","getContentReviewStepInitialStatus","pendingChangeRequests","totalComments","isNonMandatory","every","ApwWorkflowStepTypes","NON_MANDATORY","reviewStatus","ApwContentReviewStatus","READY_TO_BE_PUBLISHED","exports"],"sources":["initializeContentReviewSteps.ts"],"sourcesContent":["import lodashSet from \"lodash/set\";\nimport {\n ApwContentReviewStatus,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwWorkflowStepTypes\n} from \"~/types\";\nimport { getContentReviewStepInitialStatus } from \"~/plugins/utils\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { getContentApwSettingsPlugin } from \"~/utils/contentApwSettingsPlugin\";\n\nexport const initializeContentReviewSteps = ({ apw, plugins }: ApwContext) => {\n apw.contentReview.onContentReviewBeforeCreate.subscribe(async ({ input }) => {\n const { type, id, settings } = input.content;\n /*\n * Let's set \"title\" field value.\n */\n const getContent = apw.getContentGetter(type);\n const content = await getContent(id, settings);\n if (!content) {\n throw new NotFoundError(`Content \"${type}\" with id ${id} not found.`);\n }\n\n const { title } = content;\n input = lodashSet(input, \"title\", title);\n\n /**\n * We need to find a plugin which can get a workflow ID for the given type of content.\n */\n const contentApwSettingsPlugin = getContentApwSettingsPlugin({\n plugins,\n type\n });\n\n const workflowId = contentApwSettingsPlugin.getWorkflowId(content);\n\n /**\n * Let's initialize the \"ContentReview\" steps.\n */\n if (!workflowId) {\n throw new NotFoundError(`Unable to initiate a \"Content review\". No workflow found!`);\n }\n\n input.workflowId = workflowId;\n\n const workflow = await apw.workflow.get(workflowId);\n const workflowSteps = workflow.steps;\n\n let previousStepStatus: ApwContentReviewStepStatus | undefined = undefined;\n const updatedSteps = workflow.steps.map((step, index) => {\n const status = getContentReviewStepInitialStatus(\n workflowSteps,\n index,\n previousStepStatus\n );\n previousStepStatus = status;\n return {\n ...step,\n status,\n pendingChangeRequests: 0,\n totalComments: 0\n };\n });\n /**\n * If there are only steps which are not mandatory ones, put review status to ApwContentReviewStatus.READY_TO_BE_PUBLISHED.\n */\n const isNonMandatory = updatedSteps.every(step => {\n return step.type === ApwWorkflowStepTypes.NON_MANDATORY;\n });\n if (isNonMandatory) {\n input.reviewStatus = ApwContentReviewStatus.READY_TO_BE_PUBLISHED;\n }\n\n input = lodashSet(input, \"steps\", updatedSteps);\n });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,yBAAA,GAAAJ,OAAA;AAEO,MAAMK,4BAA4B,GAAGA,CAAC;EAAEC,GAAG;EAAEC;AAAoB,CAAC,KAAK;EAC1ED,GAAG,CAACE,aAAa,CAACC,2BAA2B,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACzE,MAAM;MAAEC,IAAI;MAAEC,EAAE;MAAEC;IAAS,CAAC,GAAGH,KAAK,CAACI,OAAO;IAC5C;AACR;AACA;IACQ,MAAMC,UAAU,GAAGV,GAAG,CAACW,gBAAgB,CAACL,IAAI,CAAC;IAC7C,MAAMG,OAAO,GAAG,MAAMC,UAAU,CAACH,EAAE,EAAEC,QAAQ,CAAC;IAC9C,IAAI,CAACC,OAAO,EAAE;MACV,MAAM,IAAIG,6BAAa,CAAE,YAAWN,IAAK,aAAYC,EAAG,aAAY,CAAC;IACzE;IAEA,MAAM;MAAEM;IAAM,CAAC,GAAGJ,OAAO;IACzBJ,KAAK,GAAG,IAAAS,YAAS,EAACT,KAAK,EAAE,OAAO,EAAEQ,KAAK,CAAC;;IAExC;AACR;AACA;IACQ,MAAME,wBAAwB,GAAG,IAAAC,qDAA2B,EAAC;MACzDf,OAAO;MACPK;IACJ,CAAC,CAAC;IAEF,MAAMW,UAAU,GAAGF,wBAAwB,CAACG,aAAa,CAACT,OAAO,CAAC;;IAElE;AACR;AACA;IACQ,IAAI,CAACQ,UAAU,EAAE;MACb,MAAM,IAAIL,6BAAa,CAAE,2DAA0D,CAAC;IACxF;IAEAP,KAAK,CAACY,UAAU,GAAGA,UAAU;IAE7B,MAAME,QAAQ,GAAG,MAAMnB,GAAG,CAACmB,QAAQ,CAACC,GAAG,CAACH,UAAU,CAAC;IACnD,MAAMI,aAAa,GAAGF,QAAQ,CAACG,KAAK;IAEpC,IAAIC,kBAA0D,GAAGC,SAAS;IAC1E,MAAMC,YAAY,GAAGN,QAAQ,CAACG,KAAK,CAACI,GAAG,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAK;MACrD,MAAMC,MAAM,GAAG,IAAAC,wCAAiC,EAC5CT,aAAa,EACbO,KAAK,EACLL,kBACJ,CAAC;MACDA,kBAAkB,GAAGM,MAAM;MAC3B,OAAO;QACH,GAAGF,IAAI;QACPE,MAAM;QACNE,qBAAqB,EAAE,CAAC;QACxBC,aAAa,EAAE;MACnB,CAAC;IACL,CAAC,CAAC;IACF;AACR;AACA;IACQ,MAAMC,cAAc,GAAGR,YAAY,CAACS,KAAK,CAACP,IAAI,IAAI;MAC9C,OAAOA,IAAI,CAACrB,IAAI,KAAK6B,2BAAoB,CAACC,aAAa;IAC3D,CAAC,CAAC;IACF,IAAIH,cAAc,EAAE;MAChB5B,KAAK,CAACgC,YAAY,GAAGC,6BAAsB,CAACC,qBAAqB;IACrE;IAEAlC,KAAK,GAAG,IAAAS,YAAS,EAACT,KAAK,EAAE,OAAO,EAAEoB,YAAY,CAAC;EACnD,CAAC,CAAC;AACN,CAAC;AAACe,OAAA,CAAAzC,4BAAA,GAAAA,4BAAA"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../types";
2
+ export declare const initializeNotifications: (context: ApwContext) => void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initializeNotifications = void 0;
7
+ var _contentReviewAfterCreate = require("./notifications/contentReviewAfterCreate");
8
+ var _commentAfterCreate = require("./notifications/commentAfterCreate");
9
+ var _changeRequestAfterCreate = require("./notifications/changeRequestAfterCreate");
10
+ const initializeNotifications = context => {
11
+ (0, _contentReviewAfterCreate.attachContentReviewAfterCreate)(context);
12
+ (0, _commentAfterCreate.attachCommentAfterCreate)(context);
13
+ (0, _changeRequestAfterCreate.attachChangeRequestAfterCreate)(context);
14
+ };
15
+ exports.initializeNotifications = initializeNotifications;
16
+
17
+ //# sourceMappingURL=initializeNotifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_contentReviewAfterCreate","require","_commentAfterCreate","_changeRequestAfterCreate","initializeNotifications","context","attachContentReviewAfterCreate","attachCommentAfterCreate","attachChangeRequestAfterCreate","exports"],"sources":["initializeNotifications.ts"],"sourcesContent":["import { ApwContext } from \"~/types\";\nimport { attachContentReviewAfterCreate } from \"./notifications/contentReviewAfterCreate\";\nimport { attachCommentAfterCreate } from \"./notifications/commentAfterCreate\";\nimport { attachChangeRequestAfterCreate } from \"./notifications/changeRequestAfterCreate\";\n\nexport const initializeNotifications = (context: ApwContext) => {\n attachContentReviewAfterCreate(context);\n attachCommentAfterCreate(context);\n attachChangeRequestAfterCreate(context);\n};\n"],"mappings":";;;;;;AACA,IAAAA,yBAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,yBAAA,GAAAF,OAAA;AAEO,MAAMG,uBAAuB,GAAIC,OAAmB,IAAK;EAC5D,IAAAC,wDAA8B,EAACD,OAAO,CAAC;EACvC,IAAAE,4CAAwB,EAACF,OAAO,CAAC;EACjC,IAAAG,wDAA8B,EAACH,OAAO,CAAC;AAC3C,CAAC;AAACI,OAAA,CAAAL,uBAAA,GAAAA,uBAAA"}
@@ -6,5 +6,5 @@ interface ListWorkflowsParams {
6
6
  cms: HeadlessCms;
7
7
  security: Security;
8
8
  }
9
- export declare const listContentReviews: ({ apw, cms, security }: ListWorkflowsParams) => void;
9
+ export declare const listContentReviews: ({ apw, security }: ListWorkflowsParams) => void;
10
10
  export {};
@@ -4,66 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.listContentReviews = void 0;
7
-
8
- var _contentReview = require("../../storageOperations/models/contentReview.model");
9
-
10
7
  const listContentReviews = ({
11
8
  apw,
12
- cms,
13
9
  security
14
10
  }) => {
15
11
  /**
16
12
  * We need to hook into listing the content review entries.
17
13
  * When listing content review entries, we need to check which ones current user can actually see.
18
14
  */
19
- cms.onEntryBeforeList.subscribe(async ({
20
- model,
15
+ apw.contentReview.onContentReviewBeforeList.subscribe(async ({
21
16
  where
22
17
  }) => {
18
+ /**
19
+ * If there is workflowId_in attached on where, we will not change it.
20
+ */
21
+ if (where.workflowId_in) {
22
+ return;
23
+ }
23
24
  const identity = security.getIdentity();
24
-
25
- if (!(identity !== null && identity !== void 0 && identity.id) || model.modelId !== _contentReview.CONTENT_REVIEW_MODEL_ID) {
25
+ if (!identity?.id) {
26
26
  return;
27
27
  }
28
28
  /**
29
29
  * Find all available workflows.
30
30
  */
31
-
32
-
33
31
  const [workflows] = await apw.workflow.list();
34
-
35
32
  if (workflows.length === 0) {
36
33
  return;
37
34
  }
38
- /**
39
- * We need to find the reviewer entryId to be able to match it to the reviewer entryId in the workflow steps.
40
- */
41
-
42
-
43
- const [reviewers] = await apw.reviewer.list({
44
- where: {
45
- identityId: identity.id
46
- }
47
- });
48
-
49
- if (reviewers.length === 0) {
50
- return;
51
- }
52
-
53
- const reviewerList = reviewers.map(reviewer => reviewer.entryId);
54
35
  /**
55
36
  * Find all workflows which user has access to.
56
37
  * User access is buried quite deep in the workflow data, so we need to do some traversing.
57
38
  */
58
-
59
39
  const userWorkflows = workflows.filter(workflow => {
60
40
  return workflow.steps.some(step => {
61
41
  return step.reviewers.some(reviewer => {
62
- return reviewerList.includes(reviewer.entryId);
42
+ return identity.id === reviewer.identityId;
63
43
  });
64
44
  });
65
45
  });
66
-
67
46
  if (userWorkflows.length === 0) {
68
47
  return;
69
48
  }
@@ -71,10 +50,9 @@ const listContentReviews = ({
71
50
  * In the end, we need to attach the workflow filter by the entryId.
72
51
  * Just in case we add versioning at some point...
73
52
  */
74
-
75
-
76
53
  where.workflowId_in = userWorkflows.map(workflow => workflow.id);
77
54
  });
78
55
  };
56
+ exports.listContentReviews = listContentReviews;
79
57
 
80
- exports.listContentReviews = listContentReviews;
58
+ //# sourceMappingURL=listContentReviews.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["listContentReviews","apw","cms","security","onEntryBeforeList","subscribe","model","where","identity","getIdentity","id","modelId","CONTENT_REVIEW_MODEL_ID","workflows","workflow","list","length","reviewers","reviewer","identityId","reviewerList","map","entryId","userWorkflows","filter","steps","some","step","includes","workflowId_in"],"sources":["listContentReviews.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow } from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\nimport { Security } from \"@webiny/api-security/types\";\n\ninterface ListWorkflowsParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\nexport const listContentReviews = ({ apw, cms, security }: ListWorkflowsParams) => {\n /**\n * We need to hook into listing the content review entries.\n * When listing content review entries, we need to check which ones current user can actually see.\n */\n cms.onEntryBeforeList.subscribe(async ({ model, where }) => {\n const identity = security.getIdentity();\n if (!identity?.id || model.modelId !== CONTENT_REVIEW_MODEL_ID) {\n return;\n }\n /**\n * Find all available workflows.\n */\n const [workflows] = await apw.workflow.list();\n if (workflows.length === 0) {\n return;\n }\n /**\n * We need to find the reviewer entryId to be able to match it to the reviewer entryId in the workflow steps.\n */\n const [reviewers] = await apw.reviewer.list({\n where: {\n identityId: identity.id\n }\n });\n if (reviewers.length === 0) {\n return;\n }\n const reviewerList = reviewers.map(reviewer => reviewer.entryId);\n /**\n * Find all workflows which user has access to.\n * User access is buried quite deep in the workflow data, so we need to do some traversing.\n */\n const userWorkflows = workflows.filter(workflow => {\n return workflow.steps.some(step => {\n return step.reviewers.some(reviewer => {\n return reviewerList.includes(reviewer.entryId);\n });\n });\n });\n if (userWorkflows.length === 0) {\n return;\n }\n /**\n * In the end, we need to attach the workflow filter by the entryId.\n * Just in case we add versioning at some point...\n */\n where.workflowId_in = userWorkflows.map(workflow => workflow.id);\n });\n};\n"],"mappings":";;;;;;;AAEA;;AAQO,MAAMA,kBAAkB,GAAG,CAAC;EAAEC,GAAF;EAAOC,GAAP;EAAYC;AAAZ,CAAD,KAAiD;EAC/E;AACJ;AACA;AACA;EACID,GAAG,CAACE,iBAAJ,CAAsBC,SAAtB,CAAgC,OAAO;IAAEC,KAAF;IAASC;EAAT,CAAP,KAA4B;IACxD,MAAMC,QAAQ,GAAGL,QAAQ,CAACM,WAAT,EAAjB;;IACA,IAAI,EAACD,QAAD,aAACA,QAAD,eAACA,QAAQ,CAAEE,EAAX,KAAiBJ,KAAK,CAACK,OAAN,KAAkBC,sCAAvC,EAAgE;MAC5D;IACH;IACD;AACR;AACA;;;IACQ,MAAM,CAACC,SAAD,IAAc,MAAMZ,GAAG,CAACa,QAAJ,CAAaC,IAAb,EAA1B;;IACA,IAAIF,SAAS,CAACG,MAAV,KAAqB,CAAzB,EAA4B;MACxB;IACH;IACD;AACR;AACA;;;IACQ,MAAM,CAACC,SAAD,IAAc,MAAMhB,GAAG,CAACiB,QAAJ,CAAaH,IAAb,CAAkB;MACxCR,KAAK,EAAE;QACHY,UAAU,EAAEX,QAAQ,CAACE;MADlB;IADiC,CAAlB,CAA1B;;IAKA,IAAIO,SAAS,CAACD,MAAV,KAAqB,CAAzB,EAA4B;MACxB;IACH;;IACD,MAAMI,YAAY,GAAGH,SAAS,CAACI,GAAV,CAAcH,QAAQ,IAAIA,QAAQ,CAACI,OAAnC,CAArB;IACA;AACR;AACA;AACA;;IACQ,MAAMC,aAAa,GAAGV,SAAS,CAACW,MAAV,CAAiBV,QAAQ,IAAI;MAC/C,OAAOA,QAAQ,CAACW,KAAT,CAAeC,IAAf,CAAoBC,IAAI,IAAI;QAC/B,OAAOA,IAAI,CAACV,SAAL,CAAeS,IAAf,CAAoBR,QAAQ,IAAI;UACnC,OAAOE,YAAY,CAACQ,QAAb,CAAsBV,QAAQ,CAACI,OAA/B,CAAP;QACH,CAFM,CAAP;MAGH,CAJM,CAAP;IAKH,CANqB,CAAtB;;IAOA,IAAIC,aAAa,CAACP,MAAd,KAAyB,CAA7B,EAAgC;MAC5B;IACH;IACD;AACR;AACA;AACA;;;IACQT,KAAK,CAACsB,aAAN,GAAsBN,aAAa,CAACF,GAAd,CAAkBP,QAAQ,IAAIA,QAAQ,CAACJ,EAAvC,CAAtB;EACH,CA3CD;AA4CH,CAjDM"}
1
+ {"version":3,"names":["listContentReviews","apw","security","contentReview","onContentReviewBeforeList","subscribe","where","workflowId_in","identity","getIdentity","id","workflows","workflow","list","length","userWorkflows","filter","steps","some","step","reviewers","reviewer","identityId","map","exports"],"sources":["listContentReviews.ts"],"sourcesContent":["import { AdvancedPublishingWorkflow } from \"~/types\";\nimport { HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { Security } from \"@webiny/api-security/types\";\n\ninterface ListWorkflowsParams {\n apw: AdvancedPublishingWorkflow;\n cms: HeadlessCms;\n security: Security;\n}\nexport const listContentReviews = ({ apw, security }: ListWorkflowsParams) => {\n /**\n * We need to hook into listing the content review entries.\n * When listing content review entries, we need to check which ones current user can actually see.\n */\n apw.contentReview.onContentReviewBeforeList.subscribe(async ({ where }) => {\n /**\n * If there is workflowId_in attached on where, we will not change it.\n */\n if (where.workflowId_in) {\n return;\n }\n const identity = security.getIdentity();\n if (!identity?.id) {\n return;\n }\n /**\n * Find all available workflows.\n */\n const [workflows] = await apw.workflow.list();\n if (workflows.length === 0) {\n return;\n }\n /**\n * Find all workflows which user has access to.\n * User access is buried quite deep in the workflow data, so we need to do some traversing.\n */\n const userWorkflows = workflows.filter(workflow => {\n return workflow.steps.some(step => {\n return step.reviewers.some(reviewer => {\n return identity.id === reviewer.identityId;\n });\n });\n });\n if (userWorkflows.length === 0) {\n return;\n }\n /**\n * In the end, we need to attach the workflow filter by the entryId.\n * Just in case we add versioning at some point...\n */\n where.workflowId_in = userWorkflows.map(workflow => workflow.id);\n });\n};\n"],"mappings":";;;;;;AASO,MAAMA,kBAAkB,GAAGA,CAAC;EAAEC,GAAG;EAAEC;AAA8B,CAAC,KAAK;EAC1E;AACJ;AACA;AACA;EACID,GAAG,CAACE,aAAa,CAACC,yBAAyB,CAACC,SAAS,CAAC,OAAO;IAAEC;EAAM,CAAC,KAAK;IACvE;AACR;AACA;IACQ,IAAIA,KAAK,CAACC,aAAa,EAAE;MACrB;IACJ;IACA,MAAMC,QAAQ,GAAGN,QAAQ,CAACO,WAAW,CAAC,CAAC;IACvC,IAAI,CAACD,QAAQ,EAAEE,EAAE,EAAE;MACf;IACJ;IACA;AACR;AACA;IACQ,MAAM,CAACC,SAAS,CAAC,GAAG,MAAMV,GAAG,CAACW,QAAQ,CAACC,IAAI,CAAC,CAAC;IAC7C,IAAIF,SAAS,CAACG,MAAM,KAAK,CAAC,EAAE;MACxB;IACJ;IACA;AACR;AACA;AACA;IACQ,MAAMC,aAAa,GAAGJ,SAAS,CAACK,MAAM,CAACJ,QAAQ,IAAI;MAC/C,OAAOA,QAAQ,CAACK,KAAK,CAACC,IAAI,CAACC,IAAI,IAAI;QAC/B,OAAOA,IAAI,CAACC,SAAS,CAACF,IAAI,CAACG,QAAQ,IAAI;UACnC,OAAOb,QAAQ,CAACE,EAAE,KAAKW,QAAQ,CAACC,UAAU;QAC9C,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC,CAAC;IACF,IAAIP,aAAa,CAACD,MAAM,KAAK,CAAC,EAAE;MAC5B;IACJ;IACA;AACR;AACA;AACA;IACQR,KAAK,CAACC,aAAa,GAAGQ,aAAa,CAACQ,GAAG,CAACX,QAAQ,IAAIA,QAAQ,CAACF,EAAE,CAAC;EACpE,CAAC,CAAC;AACN,CAAC;AAACc,OAAA,CAAAxB,kBAAA,GAAAA,kBAAA"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const getAppUrl: (context: ApwContext) => Promise<import("@webiny/api-admin-settings/types").AdminSettings | null>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAppUrl = void 0;
7
+ const getAppUrl = async context => {
8
+ const tenant = context.tenancy.getCurrentTenant().id;
9
+ try {
10
+ return await context.settings.getSettings(tenant);
11
+ } catch (ex) {
12
+ if (ex.code !== "NOT_FOUND") {
13
+ throw ex;
14
+ }
15
+ }
16
+ return null;
17
+ };
18
+ exports.getAppUrl = getAppUrl;
19
+
20
+ //# sourceMappingURL=appUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getAppUrl","context","tenant","tenancy","getCurrentTenant","id","settings","getSettings","ex","code","exports"],"sources":["appUrl.ts"],"sourcesContent":["import { ApwContext } from \"~/types\";\n\nexport const getAppUrl = async (context: ApwContext) => {\n const tenant = context.tenancy.getCurrentTenant().id;\n try {\n return await context.settings.getSettings(tenant);\n } catch (ex) {\n if (ex.code !== \"NOT_FOUND\") {\n throw ex;\n }\n }\n return null;\n};\n"],"mappings":";;;;;;AAEO,MAAMA,SAAS,GAAG,MAAOC,OAAmB,IAAK;EACpD,MAAMC,MAAM,GAAGD,OAAO,CAACE,OAAO,CAACC,gBAAgB,CAAC,CAAC,CAACC,EAAE;EACpD,IAAI;IACA,OAAO,MAAMJ,OAAO,CAACK,QAAQ,CAACC,WAAW,CAACL,MAAM,CAAC;EACrD,CAAC,CAAC,OAAOM,EAAE,EAAE;IACT,IAAIA,EAAE,CAACC,IAAI,KAAK,WAAW,EAAE;MACzB,MAAMD,EAAE;IACZ;EACJ;EACA,OAAO,IAAI;AACf,CAAC;AAACE,OAAA,CAAAV,SAAA,GAAAA,SAAA"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachChangeRequestAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.attachChangeRequestAfterCreate = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _utils = require("../../utils");
10
+ var _contentUrl = require("./contentUrl");
11
+ var _sendChangeRequestNotification = require("./sendChangeRequestNotification");
12
+ var _reviewers = require("./reviewers");
13
+ var _changeRequestUrl = require("./changeRequestUrl");
14
+ var _appUrl = require("./appUrl");
15
+ const attachChangeRequestAfterCreate = context => {
16
+ context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({
17
+ changeRequest
18
+ }) => {
19
+ const execute = async () => {
20
+ const {
21
+ id: contentReviewId,
22
+ stepId
23
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
24
+ if (!stepId) {
25
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
26
+ step: changeRequest.step
27
+ });
28
+ }
29
+ const settings = await (0, _appUrl.getAppUrl)(context);
30
+ if (!settings) {
31
+ return;
32
+ }
33
+ /**
34
+ * We will check if we can create a comment url before we go digging further into the database.
35
+ */
36
+ const changeRequestUrl = (0, _changeRequestUrl.createChangeRequestUrl)({
37
+ baseUrl: settings.appUrl,
38
+ changeRequestId: changeRequest.id,
39
+ contentReviewId,
40
+ stepId
41
+ });
42
+ if (!changeRequestUrl) {
43
+ return;
44
+ }
45
+ /**
46
+ * Let's see if content review exists.
47
+ */
48
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
49
+ if (!contentReview) {
50
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
51
+ contentReviewId
52
+ });
53
+ }
54
+ /**
55
+ * We go and check the workflow.
56
+ */
57
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
58
+ if (!workflow) {
59
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
60
+ workflowId: contentReview.workflowId
61
+ });
62
+ }
63
+ const contentUrl = (0, _contentUrl.createContentUrl)({
64
+ plugins: context.plugins,
65
+ baseUrl: settings.appUrl,
66
+ contentReview,
67
+ workflow
68
+ });
69
+ if (!contentUrl) {
70
+ return;
71
+ }
72
+ const reviewers = await (0, _reviewers.fetchReviewers)({
73
+ context,
74
+ workflow,
75
+ exclude: [changeRequest.createdBy.id]
76
+ });
77
+ if (reviewers.length === 0) {
78
+ return;
79
+ }
80
+ try {
81
+ await (0, _sendChangeRequestNotification.sendChangeRequestNotification)({
82
+ context,
83
+ reviewers,
84
+ changeRequest,
85
+ contentReview,
86
+ workflow,
87
+ changeRequestUrl,
88
+ contentUrl
89
+ });
90
+ } catch (ex) {
91
+ throw new _error.default(`Could not send change request notifications.`, "CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT", {
92
+ workflowId: workflow.id,
93
+ changeRequestId: changeRequest.id,
94
+ contentReviewId,
95
+ changeRequestUrl,
96
+ contentUrl,
97
+ error: {
98
+ message: ex.message,
99
+ code: ex.code,
100
+ data: ex.data,
101
+ stack: ex.stack
102
+ }
103
+ });
104
+ }
105
+ };
106
+ await context.security.withoutAuthorization(async () => {
107
+ return execute();
108
+ });
109
+ });
110
+ };
111
+ exports.attachChangeRequestAfterCreate = attachChangeRequestAfterCreate;
112
+
113
+ //# sourceMappingURL=changeRequestAfterCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_utils","_contentUrl","_sendChangeRequestNotification","_reviewers","_changeRequestUrl","_appUrl","attachChangeRequestAfterCreate","context","apw","changeRequest","onChangeRequestAfterCreate","subscribe","execute","id","contentReviewId","stepId","extractContentReviewIdAndStep","step","WebinyError","settings","getAppUrl","changeRequestUrl","createChangeRequestUrl","baseUrl","appUrl","changeRequestId","contentReview","get","workflow","workflowId","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","length","sendChangeRequestNotification","ex","error","message","code","data","stack","security","withoutAuthorization","exports"],"sources":["changeRequestAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { sendChangeRequestNotification } from \"./sendChangeRequestNotification\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { createChangeRequestUrl } from \"./changeRequestUrl\";\nimport { getAppUrl } from \"~/plugins/hooks/notifications/appUrl\";\n\nexport const attachChangeRequestAfterCreate = (context: ApwContext): void => {\n context.apw.changeRequest.onChangeRequestAfterCreate.subscribe(async ({ changeRequest }) => {\n const execute = async () => {\n const { id: contentReviewId, stepId } = extractContentReviewIdAndStep(\n changeRequest.step\n );\n if (!stepId) {\n throw new WebinyError(\"Malformed changeRequest.step value.\", \"MALFORMED_VALUE\", {\n step: changeRequest.step\n });\n }\n\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n /**\n * We will check if we can create a comment url before we go digging further into the database.\n */\n const changeRequestUrl = createChangeRequestUrl({\n baseUrl: settings.appUrl,\n changeRequestId: changeRequest.id,\n contentReviewId,\n stepId\n });\n if (!changeRequestUrl) {\n return;\n }\n /**\n * Let's see if content review exists.\n */\n const contentReview = await context.apw.contentReview.get(contentReviewId);\n if (!contentReview) {\n throw new WebinyError(\n `There is no contentReview with id \"${contentReviewId}\".`,\n \"CONTENT_REVIEW_NOT_FOUND\",\n {\n contentReviewId\n }\n );\n }\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with workflowId \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [changeRequest.createdBy.id]\n });\n if (reviewers.length === 0) {\n return;\n }\n\n try {\n await sendChangeRequestNotification({\n context,\n reviewers,\n changeRequest,\n contentReview,\n workflow,\n changeRequestUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send change request notifications.`,\n \"CHANGE_REQUEST_NOTIFICATIONS_NOT_SENT\",\n {\n workflowId: workflow.id,\n changeRequestId: changeRequest.id,\n contentReviewId,\n changeRequestUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n await context.security.withoutAuthorization(async () => {\n return execute();\n });\n });\n};\n"],"mappings":"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"}
@@ -0,0 +1,8 @@
1
+ interface Params {
2
+ baseUrl?: string;
3
+ changeRequestId: string;
4
+ contentReviewId: string;
5
+ stepId: string;
6
+ }
7
+ export declare const createChangeRequestUrl: (params: Params) => string | null;
8
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createChangeRequestUrl = void 0;
7
+ const createChangeRequestUrl = params => {
8
+ /**
9
+ * All variables must exist for URL to be created.
10
+ * We go through all vars and throw a log if it does not exist.
11
+ */
12
+ for (const key in params) {
13
+ if (!!key) {
14
+ continue;
15
+ }
16
+ console.log(`Missing variable "${key}", which we use to create a comment URL.`);
17
+ return null;
18
+ }
19
+ const {
20
+ baseUrl,
21
+ changeRequestId,
22
+ contentReviewId,
23
+ stepId
24
+ } = params;
25
+ return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;
26
+ };
27
+ exports.createChangeRequestUrl = createChangeRequestUrl;
28
+
29
+ //# sourceMappingURL=changeRequestUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createChangeRequestUrl","params","key","console","log","baseUrl","changeRequestId","contentReviewId","stepId","exports"],"sources":["changeRequestUrl.ts"],"sourcesContent":["interface Params {\n baseUrl?: string;\n changeRequestId: string;\n contentReviewId: string;\n stepId: string;\n}\nexport const createChangeRequestUrl = (params: Params) => {\n /**\n * All variables must exist for URL to be created.\n * We go through all vars and throw a log if it does not exist.\n */\n for (const key in params) {\n if (!!key) {\n continue;\n }\n console.log(`Missing variable \"${key}\", which we use to create a comment URL.`);\n return null;\n }\n const { baseUrl, changeRequestId, contentReviewId, stepId } = params;\n\n return `${baseUrl}/apw/content-reviews/${contentReviewId}/${stepId}/${changeRequestId}`;\n};\n"],"mappings":";;;;;;AAMO,MAAMA,sBAAsB,GAAIC,MAAc,IAAK;EACtD;AACJ;AACA;AACA;EACI,KAAK,MAAMC,GAAG,IAAID,MAAM,EAAE;IACtB,IAAI,CAAC,CAACC,GAAG,EAAE;MACP;IACJ;IACAC,OAAO,CAACC,GAAG,CAAE,qBAAoBF,GAAI,0CAAyC,CAAC;IAC/E,OAAO,IAAI;EACf;EACA,MAAM;IAAEG,OAAO;IAAEC,eAAe;IAAEC,eAAe;IAAEC;EAAO,CAAC,GAAGP,MAAM;EAEpE,OAAQ,GAAEI,OAAQ,wBAAuBE,eAAgB,IAAGC,MAAO,IAAGF,eAAgB,EAAC;AAC3F,CAAC;AAACG,OAAA,CAAAT,sBAAA,GAAAA,sBAAA"}
@@ -0,0 +1,2 @@
1
+ import { ApwContext } from "../../../types";
2
+ export declare const attachCommentAfterCreate: (context: ApwContext) => void;
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.attachCommentAfterCreate = void 0;
8
+ var _error = _interopRequireDefault(require("@webiny/error"));
9
+ var _utils = require("../../utils");
10
+ var _contentUrl = require("./contentUrl");
11
+ var _commentUrl = require("./commentUrl");
12
+ var _reviewers = require("./reviewers");
13
+ var _sendCommentNotification = require("./sendCommentNotification");
14
+ var _appUrl = require("./appUrl");
15
+ const attachCommentAfterCreate = context => {
16
+ context.apw.comment.onCommentAfterCreate.subscribe(async ({
17
+ comment
18
+ }) => {
19
+ const execute = async () => {
20
+ const changeRequest = await context.apw.changeRequest.get(comment.changeRequest);
21
+ if (!changeRequest) {
22
+ throw new _error.default("Missing change request.", "CHANGE_REQUEST_NOT_FOUND", {
23
+ changeRequest: comment.changeRequest,
24
+ comment: comment.id
25
+ });
26
+ }
27
+ const {
28
+ id: contentReviewId,
29
+ stepId
30
+ } = (0, _utils.extractContentReviewIdAndStep)(changeRequest.step);
31
+ if (!stepId) {
32
+ throw new _error.default("Malformed changeRequest.step value.", "MALFORMED_VALUE", {
33
+ step: changeRequest.step
34
+ });
35
+ }
36
+ const settings = await (0, _appUrl.getAppUrl)(context);
37
+ if (!settings) {
38
+ return;
39
+ }
40
+ /**
41
+ * We will check if we can create a comment url before we go digging further into the database.
42
+ */
43
+ const commentUrl = (0, _commentUrl.createCommentUrl)({
44
+ baseUrl: settings.appUrl,
45
+ changeRequestId: changeRequest.id,
46
+ contentReviewId,
47
+ stepId
48
+ });
49
+ if (!commentUrl) {
50
+ console.log("No comment url.");
51
+ return;
52
+ }
53
+ /**
54
+ * Let's see if content review exists.
55
+ */
56
+ const contentReview = await context.apw.contentReview.get(contentReviewId);
57
+ if (!contentReview) {
58
+ throw new _error.default(`There is no contentReview with id "${contentReviewId}".`, "CONTENT_REVIEW_NOT_FOUND", {
59
+ contentReviewId
60
+ });
61
+ }
62
+ /**
63
+ * We go and check the workflow.
64
+ */
65
+ const workflow = await context.apw.workflow.get(contentReview.workflowId);
66
+ if (!workflow) {
67
+ throw new _error.default(`There is no workflow with workflowId "${contentReview.workflowId}".`, "WORKFLOW_NOT_FOUND", {
68
+ workflowId: contentReview.workflowId
69
+ });
70
+ }
71
+ const contentUrl = (0, _contentUrl.createContentUrl)({
72
+ plugins: context.plugins,
73
+ baseUrl: settings.appUrl,
74
+ contentReview,
75
+ workflow
76
+ });
77
+ if (!contentUrl) {
78
+ console.log("No content url.");
79
+ return;
80
+ }
81
+ const reviewers = await (0, _reviewers.fetchReviewers)({
82
+ context,
83
+ workflow,
84
+ exclude: [comment.createdBy.id]
85
+ });
86
+ if (reviewers.length === 0) {
87
+ console.log("No reviewers to send the e-mail notification to.");
88
+ return;
89
+ }
90
+ try {
91
+ await (0, _sendCommentNotification.sendCommentNotification)({
92
+ context,
93
+ reviewers,
94
+ changeRequest,
95
+ contentReview,
96
+ workflow,
97
+ commentUrl,
98
+ contentUrl
99
+ });
100
+ } catch (ex) {
101
+ throw new _error.default(`Could not send comment notifications.`, "COMMENT_NOTIFICATIONS_NOT_SENT", {
102
+ commentId: comment.id,
103
+ workflowId: workflow.id,
104
+ changeRequestId: changeRequest.id,
105
+ contentReviewId,
106
+ commentUrl,
107
+ contentUrl,
108
+ error: {
109
+ message: ex.message,
110
+ code: ex.code,
111
+ data: ex.data,
112
+ stack: ex.stack
113
+ }
114
+ });
115
+ }
116
+ };
117
+ await context.security.withoutAuthorization(async () => {
118
+ return execute();
119
+ });
120
+ });
121
+ };
122
+ exports.attachCommentAfterCreate = attachCommentAfterCreate;
123
+
124
+ //# sourceMappingURL=commentAfterCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_error","_interopRequireDefault","require","_utils","_contentUrl","_commentUrl","_reviewers","_sendCommentNotification","_appUrl","attachCommentAfterCreate","context","apw","comment","onCommentAfterCreate","subscribe","execute","changeRequest","get","WebinyError","id","contentReviewId","stepId","extractContentReviewIdAndStep","step","settings","getAppUrl","commentUrl","createCommentUrl","baseUrl","appUrl","changeRequestId","console","log","contentReview","workflow","workflowId","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","length","sendCommentNotification","ex","commentId","error","message","code","data","stack","security","withoutAuthorization","exports"],"sources":["commentAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { extractContentReviewIdAndStep } from \"~/plugins/utils\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { createCommentUrl } from \"./commentUrl\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { sendCommentNotification } from \"./sendCommentNotification\";\nimport { getAppUrl } from \"~/plugins/hooks/notifications/appUrl\";\n\nexport const attachCommentAfterCreate = (context: ApwContext): void => {\n context.apw.comment.onCommentAfterCreate.subscribe(async ({ comment }) => {\n const execute = async () => {\n const changeRequest = await context.apw.changeRequest.get(comment.changeRequest);\n if (!changeRequest) {\n throw new WebinyError(\"Missing change request.\", \"CHANGE_REQUEST_NOT_FOUND\", {\n changeRequest: comment.changeRequest,\n comment: comment.id\n });\n }\n\n const { id: contentReviewId, stepId } = extractContentReviewIdAndStep(\n changeRequest.step\n );\n if (!stepId) {\n throw new WebinyError(\"Malformed changeRequest.step value.\", \"MALFORMED_VALUE\", {\n step: changeRequest.step\n });\n }\n\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n /**\n * We will check if we can create a comment url before we go digging further into the database.\n */\n const commentUrl = createCommentUrl({\n baseUrl: settings.appUrl,\n changeRequestId: changeRequest.id,\n contentReviewId,\n stepId\n });\n if (!commentUrl) {\n console.log(\"No comment url.\");\n return;\n }\n /**\n * Let's see if content review exists.\n */\n const contentReview = await context.apw.contentReview.get(contentReviewId);\n if (!contentReview) {\n throw new WebinyError(\n `There is no contentReview with id \"${contentReviewId}\".`,\n \"CONTENT_REVIEW_NOT_FOUND\",\n {\n contentReviewId\n }\n );\n }\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with workflowId \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n console.log(\"No content url.\");\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [comment.createdBy.id]\n });\n\n if (reviewers.length === 0) {\n console.log(\"No reviewers to send the e-mail notification to.\");\n return;\n }\n\n try {\n await sendCommentNotification({\n context,\n reviewers,\n changeRequest,\n contentReview,\n workflow,\n commentUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send comment notifications.`,\n \"COMMENT_NOTIFICATIONS_NOT_SENT\",\n {\n commentId: comment.id,\n workflowId: workflow.id,\n changeRequestId: changeRequest.id,\n contentReviewId,\n commentUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n await context.security.withoutAuthorization(async () => {\n return execute();\n });\n });\n};\n"],"mappings":"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"}