strapi-plugin-comments 2.1.7 → 2.2.0-beta.0

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 (170) hide show
  1. package/README.md +11 -2
  2. package/admin/src/components/Avatar/index.d.ts +3 -2
  3. package/admin/src/components/Avatar/index.js +2 -2
  4. package/admin/src/components/CommentReviewModal/index.d.ts +11 -0
  5. package/admin/src/components/CommentReviewModal/index.js +19 -0
  6. package/admin/src/components/ConfirmationDialog/index.d.ts +12 -10
  7. package/admin/src/components/ConfirmationDialog/index.js +3 -3
  8. package/admin/src/components/DiscussionStatus/index.d.ts +2 -1
  9. package/admin/src/components/DiscussionThread/index.d.ts +11 -5
  10. package/admin/src/components/DiscussionThread/index.js +3 -3
  11. package/admin/src/components/DiscussionThreadItem/index.d.ts +2 -7
  12. package/admin/src/components/DiscussionThreadItem/index.js +3 -12
  13. package/admin/src/components/DiscussionThreadItemActions/index.d.ts +10 -6
  14. package/admin/src/components/DiscussionThreadItemActions/index.js +75 -53
  15. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +9 -6
  16. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +6 -9
  17. package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +14 -7
  18. package/admin/src/components/DiscussionThreadItemFooter/index.js +3 -3
  19. package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +14 -18
  20. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +71 -52
  21. package/admin/src/components/FormSwitch/index.d.ts +2 -1
  22. package/admin/src/components/Hint/index.d.ts +14 -0
  23. package/admin/src/components/Hint/index.js +22 -0
  24. package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +2 -1
  25. package/admin/src/components/ModeratorResponse/index.d.ts +8 -0
  26. package/admin/src/components/ModeratorResponse/index.js +108 -0
  27. package/admin/src/components/ModeratorResponse/styles.d.ts +2 -0
  28. package/admin/src/components/ModeratorResponse/styles.js +12 -0
  29. package/admin/src/components/ModeratorResponseModal/ModeratorResponseModal.d.ts +11 -0
  30. package/admin/src/components/ModeratorResponseModal/ModeratorResponseModal.js +98 -0
  31. package/admin/src/components/Nav/index.d.ts +2 -1
  32. package/admin/src/components/Nav/index.js +6 -9
  33. package/admin/src/components/PluginIcon/index.d.ts +2 -1
  34. package/admin/src/components/PluginIcon/index.js +2 -6
  35. package/admin/src/components/PreviewWysiwyg/Wrapper.d.ts +3 -0
  36. package/admin/src/components/PreviewWysiwyg/Wrapper.js +162 -0
  37. package/admin/src/components/PreviewWysiwyg/index.d.ts +7 -0
  38. package/admin/src/components/PreviewWysiwyg/index.js +39 -0
  39. package/admin/src/components/PreviewWysiwyg/utils/mdRenderer.d.ts +3 -0
  40. package/admin/src/components/PreviewWysiwyg/utils/mdRenderer.js +88 -0
  41. package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.d.ts +3 -0
  42. package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.js +18 -0
  43. package/admin/src/components/ReportsActions/components/BlockMenu/index.d.ts +16 -0
  44. package/admin/src/components/ReportsActions/components/BlockMenu/index.js +51 -0
  45. package/admin/src/components/ReportsActions/index.d.ts +12 -0
  46. package/admin/src/components/ReportsActions/index.js +31 -0
  47. package/admin/src/components/ReportsReviewModal/index.d.ts +14 -8
  48. package/admin/src/components/ReportsReviewTable/index.d.ts +13 -24
  49. package/admin/src/components/ReportsReviewTable/index.js +11 -24
  50. package/admin/src/components/StatusBadge/index.d.ts +2 -1
  51. package/admin/src/components/TableFilters/index.d.ts +12 -2
  52. package/admin/src/components/TableFilters/index.js +2 -2
  53. package/admin/src/components/TablePagination/index.d.ts +9 -2
  54. package/admin/src/components/Wysiwyg/Editor.d.ts +17 -0
  55. package/admin/src/components/Wysiwyg/Editor.js +84 -0
  56. package/admin/src/components/Wysiwyg/EditorLayout.d.ts +12 -0
  57. package/admin/src/components/Wysiwyg/EditorLayout.js +99 -0
  58. package/admin/src/components/Wysiwyg/EditorStylesContainer.d.ts +2 -0
  59. package/admin/src/components/Wysiwyg/EditorStylesContainer.js +348 -0
  60. package/admin/src/components/Wysiwyg/WysiwygFooter.d.ts +7 -0
  61. package/admin/src/components/Wysiwyg/WysiwygFooter.js +25 -0
  62. package/admin/src/components/Wysiwyg/WysiwygNav.d.ts +13 -0
  63. package/admin/src/components/Wysiwyg/WysiwygNav.js +118 -0
  64. package/admin/src/components/Wysiwyg/WysiwygStyles.d.ts +8 -0
  65. package/admin/src/components/Wysiwyg/WysiwygStyles.js +59 -0
  66. package/admin/src/components/Wysiwyg/index.d.ts +28 -0
  67. package/admin/src/components/Wysiwyg/index.js +136 -0
  68. package/admin/src/components/Wysiwyg/tests/index.test.d.ts +2 -0
  69. package/admin/src/components/Wysiwyg/tests/index.test.js +1633 -0
  70. package/admin/src/components/Wysiwyg/utils/continueList.d.ts +3 -0
  71. package/admin/src/components/Wysiwyg/utils/continueList.js +83 -0
  72. package/admin/src/components/Wysiwyg/utils/utils.d.ts +15 -0
  73. package/admin/src/components/Wysiwyg/utils/utils.js +249 -0
  74. package/admin/src/components/icons/comments.d.ts +2 -1
  75. package/admin/src/components/icons/index.d.ts +2 -5
  76. package/admin/src/components/icons/index.js +24 -12
  77. package/admin/src/components/icons/lock.d.ts +2 -1
  78. package/admin/src/components/icons/review.d.ts +2 -1
  79. package/admin/src/components/icons/strapiIcons.d.ts +24 -0
  80. package/admin/src/components/icons/strapiIcons.js +35 -0
  81. package/admin/src/components/icons/unlock.d.ts +2 -1
  82. package/admin/src/custom-fields/comments/components/icon.d.ts +3 -0
  83. package/admin/src/custom-fields/comments/components/icon.js +14 -0
  84. package/admin/src/custom-fields/comments/components/index.d.ts +3 -0
  85. package/admin/src/custom-fields/comments/components/index.js +19 -0
  86. package/admin/src/custom-fields/comments/components/input/index.d.ts +3 -0
  87. package/admin/src/custom-fields/comments/components/input/index.js +5 -0
  88. package/admin/src/custom-fields/comments/components/input/input.d.ts +4 -0
  89. package/admin/src/custom-fields/comments/components/input/input.js +102 -0
  90. package/admin/src/custom-fields/comments/components/input/types.d.ts +10 -0
  91. package/admin/src/custom-fields/comments/components/input/types.js +3 -0
  92. package/admin/src/custom-fields/comments/components/input/utils.d.ts +35 -0
  93. package/admin/src/custom-fields/comments/components/input/utils.js +146 -0
  94. package/admin/src/custom-fields/comments/index.d.ts +3 -0
  95. package/admin/src/custom-fields/comments/index.js +53 -0
  96. package/admin/src/custom-fields/index.d.ts +3 -0
  97. package/admin/src/custom-fields/index.js +13 -0
  98. package/admin/src/hooks/useConfig.d.ts +4 -4
  99. package/admin/src/hooks/useConfig.js +3 -6
  100. package/admin/src/hooks/useReportsActionsHandlers.d.ts +19 -0
  101. package/admin/src/hooks/useReportsActionsHandlers.js +70 -0
  102. package/admin/src/index.d.ts +2 -1
  103. package/admin/src/index.js +4 -2
  104. package/admin/src/pages/App/index.js +8 -7
  105. package/admin/src/pages/App/reducer/index.d.ts +1 -1
  106. package/admin/src/pages/ComingSoonPage/index.d.ts +2 -1
  107. package/admin/src/pages/ComingSoonPage/index.js +2 -2
  108. package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +8 -6
  109. package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +5 -3
  110. package/admin/src/pages/Details/index.js +10 -7
  111. package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +11 -5
  112. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +7 -81
  113. package/admin/src/pages/Discover/index.js +14 -13
  114. package/admin/src/pages/NoAccessPage/index.d.ts +4 -0
  115. package/admin/src/pages/NoAccessPage/index.js +31 -0
  116. package/admin/src/pages/Reports/components/ReportsTableRow/index.d.ts +16 -0
  117. package/admin/src/pages/Reports/components/ReportsTableRow/index.js +91 -0
  118. package/admin/src/pages/Reports/components/ReportsTableRow/styles.d.ts +2 -0
  119. package/admin/src/pages/Reports/components/ReportsTableRow/styles.js +14 -0
  120. package/admin/src/pages/Reports/index.d.ts +4 -0
  121. package/admin/src/pages/Reports/index.js +196 -0
  122. package/admin/src/pages/Reports/utils/api.d.ts +2 -0
  123. package/admin/src/pages/Reports/utils/api.js +16 -0
  124. package/admin/src/pages/Reports/utils/filtersSchema.d.ts +11 -0
  125. package/admin/src/pages/Reports/utils/filtersSchema.js +11 -0
  126. package/admin/src/pages/Settings/index.d.ts +2 -1
  127. package/admin/src/pages/Settings/index.js +6 -7
  128. package/admin/src/pages/utils/api.d.ts +17 -10
  129. package/admin/src/pages/utils/api.js +25 -2
  130. package/admin/src/reducers.d.ts +1 -1
  131. package/admin/src/translations/en.json +49 -1
  132. package/admin/src/utils/axiosInstance.d.ts +1 -1
  133. package/admin/src/utils/constants.d.ts +9 -5
  134. package/admin/src/utils/constants.js +5 -3
  135. package/admin/src/utils/errors.d.ts +5 -0
  136. package/admin/src/utils/errors.js +10 -0
  137. package/admin/src/utils/functions.d.ts +2 -0
  138. package/admin/src/utils/functions.js +11 -0
  139. package/admin/src/utils/getMessage.d.ts +1 -1
  140. package/admin/src/utils/getMessage.js +1 -1
  141. package/admin/src/utils/getRelatedGroups.d.ts +6 -2
  142. package/admin/src/utils/handleAPIError.d.ts +1 -1
  143. package/admin/src/utils/index.d.ts +16 -11
  144. package/admin/src/utils/index.js +12 -1
  145. package/admin/src/utils/renderInitials.js +6 -5
  146. package/admin/src/utils/resolveCommentStatus.d.ts +8 -2
  147. package/admin/src/utils/resolveReportStatus.d.ts +4 -0
  148. package/admin/src/utils/resolveReportStatus.js +23 -0
  149. package/admin/src/utils/resolveReportStatusColor.d.ts +4 -0
  150. package/admin/src/utils/resolveReportStatusColor.js +17 -0
  151. package/package.json +7 -4
  152. package/server/controllers/admin.js +67 -2
  153. package/server/index.d.ts +1 -1
  154. package/server/register/custom-fields/comments.d.ts +6 -0
  155. package/server/register/custom-fields/comments.js +9 -0
  156. package/server/register/custom-fields/index.d.ts +3 -0
  157. package/server/register/custom-fields/index.js +14 -0
  158. package/server/register/index.d.ts +4 -0
  159. package/server/register/index.js +8 -0
  160. package/server/routes/admin.js +56 -0
  161. package/server/services/admin.d.ts +1 -1
  162. package/server/services/admin.js +196 -10
  163. package/server/services/client.js +1 -1
  164. package/server/utils/error.js +1 -1
  165. package/strapi-server.d.ts +1 -1
  166. package/tsconfig.tsbuildinfo +1 -1
  167. package/types/utils.d.ts +5 -0
  168. package/types/utils.js +10 -0
  169. package/server/register.d.ts +0 -3
  170. package/server/register.js +0 -4
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  const functions_1 = require("./../utils/functions");
6
6
  const lodash_1 = require("lodash");
7
7
  const error_1 = __importDefault(require("./../utils/error"));
8
+ const utils_1 = require("./../../types/utils");
8
9
  const functions_2 = require("./utils/functions");
9
10
  const constants_1 = require("./../utils/constants");
10
11
  module.exports = ({ strapi }) => ({
@@ -125,11 +126,87 @@ module.exports = ({ strapi }) => ({
125
126
  },
126
127
  };
127
128
  },
129
+ async findReports(query) {
130
+ const { _q, filters, orderBy, page = 1, pageSize = 10, } = (0, functions_1.parseParams)(query);
131
+ const defaultWhere = {
132
+ resolved: { $notNull: true },
133
+ };
134
+ const defaultAuthorUserPopulate = this.getDefaultAuthorPopulate();
135
+ let params = {
136
+ where: !(0, lodash_1.isEmpty)(filters)
137
+ ? {
138
+ ...defaultWhere,
139
+ ...filters,
140
+ }
141
+ : { ...defaultWhere },
142
+ offset: (page - 1) * pageSize,
143
+ limit: pageSize,
144
+ orderBy: orderBy || [{ resolved: "asc" }, { createdAt: "desc" }],
145
+ };
146
+ if (_q) {
147
+ params = {
148
+ ...params,
149
+ where: {
150
+ ...params.where,
151
+ content: {
152
+ $contains: _q,
153
+ },
154
+ },
155
+ };
156
+ }
157
+ const entities = await strapi.db
158
+ .query((0, functions_2.getModelUid)("comment-report"))
159
+ .findMany({
160
+ ...params,
161
+ populate: ["related"],
162
+ });
163
+ const total = await strapi.db
164
+ .query((0, functions_2.getModelUid)("comment-report"))
165
+ .count({
166
+ where: params.where,
167
+ });
168
+ const reportedCommentsIds = entities.map((report) => report.related.id);
169
+ const commentsInThreads = await strapi.db
170
+ .query((0, functions_2.getModelUid)("comment"))
171
+ .findMany({
172
+ where: {
173
+ threadOf: reportedCommentsIds,
174
+ },
175
+ populate: ["threadOf"],
176
+ limit: Number.MAX_SAFE_INTEGER,
177
+ });
178
+ const commentWithThreadIds = [
179
+ ...new Set(commentsInThreads.map(({ threadOf }) => {
180
+ (0, utils_1.assertComment)(threadOf);
181
+ return threadOf.id;
182
+ })),
183
+ ];
184
+ const result = entities.map((_) => {
185
+ const isCommentWithThread = commentWithThreadIds.includes(_.related.id);
186
+ return (0, functions_2.filterOurResolvedReports)(this.getCommonService().sanitizeCommentEntity({
187
+ ..._,
188
+ related: this.getCommonService().sanitizeCommentEntity({
189
+ ..._.related,
190
+ gotThread: isCommentWithThread,
191
+ }),
192
+ }, defaultAuthorUserPopulate?.populate));
193
+ });
194
+ const pageCount = Math.floor(total / pageSize);
195
+ return {
196
+ result,
197
+ pagination: {
198
+ page: page,
199
+ pageSize: pageSize,
200
+ pageCount: total % pageSize === 0 ? pageCount : pageCount + 1,
201
+ total,
202
+ },
203
+ };
204
+ },
128
205
  async findOneAndThread(id, { removed, ...query }) {
129
206
  const defaultAuthorUserPopulate = this.getDefaultAuthorPopulate();
130
207
  const defaultWhere = !removed
131
208
  ? {
132
- $or: [{ removed: false }, { removed: null }],
209
+ $or: [{ removed: false }, { removed: { $notNull: false } }],
133
210
  }
134
211
  : {};
135
212
  const reportsPopulation = {
@@ -213,6 +290,17 @@ module.exports = ({ strapi }) => ({
213
290
  });
214
291
  return this.getCommonService().sanitizeCommentEntity(changedEntity);
215
292
  },
293
+ async deleteComment(id) {
294
+ const changedEntity = await strapi.db
295
+ .query((0, functions_2.getModelUid)("comment"))
296
+ .update({
297
+ where: { id },
298
+ data: {
299
+ removed: true,
300
+ },
301
+ });
302
+ return this.getCommonService().sanitizeCommentEntity(changedEntity);
303
+ },
216
304
  async blockCommentThread(id, forceStatus) {
217
305
  const existingEntity = await this.getCommonService().findOne({ id });
218
306
  const status = !(0, lodash_1.isNil)(forceStatus)
@@ -262,7 +350,7 @@ module.exports = ({ strapi }) => ({
262
350
  data: { resolved: true },
263
351
  });
264
352
  },
265
- async resolveMultipleAbuseReports(ids, commentId) {
353
+ async resolveCommentMultipleAbuseReports(ids, commentId) {
266
354
  const reportsToResolve = await strapi.db
267
355
  .query((0, functions_2.getModelUid)("comment-report"))
268
356
  .findMany({
@@ -270,7 +358,7 @@ module.exports = ({ strapi }) => ({
270
358
  id: ids,
271
359
  related: commentId,
272
360
  },
273
- populate: ['related']
361
+ populate: ["related"],
274
362
  });
275
363
  if (reportsToResolve.length === ids.length) {
276
364
  return strapi.db
@@ -280,20 +368,118 @@ module.exports = ({ strapi }) => ({
280
368
  data: { resolved: true },
281
369
  });
282
370
  }
283
- throw new error_1.default(400, 'At least one of selected reports got invalid comment entity relation. Try again.');
371
+ throw new error_1.default(400, "At least one of selected reports got invalid comment entity relation. Try again.");
372
+ },
373
+ async resolveAllAbuseReportsForComment(commentId) {
374
+ if (commentId) {
375
+ const blockedCommentReports = strapi.db
376
+ .query((0, functions_2.getModelUid)("comment-report"))
377
+ .findMany({
378
+ where: {
379
+ related: commentId,
380
+ resolved: false,
381
+ },
382
+ populate: ["related"],
383
+ });
384
+ const reportIds = (await blockedCommentReports).map((report) => report.id);
385
+ return strapi.db
386
+ .query((0, functions_2.getModelUid)("comment-report"))
387
+ .updateMany({
388
+ where: {
389
+ id: reportIds,
390
+ },
391
+ data: { resolved: true },
392
+ });
393
+ }
394
+ throw new error_1.default(400, "There is something wrong with comment Id. Try again.");
395
+ },
396
+ async resolveAllAbuseReportsForThread(commentId) {
397
+ if (commentId) {
398
+ const commentsInThread = strapi.db
399
+ .query((0, functions_2.getModelUid)("comment"))
400
+ .findMany({
401
+ where: {
402
+ threadOf: commentId,
403
+ },
404
+ });
405
+ const commentsInThreadIds = (await commentsInThread).map((comment) => comment.id);
406
+ commentsInThreadIds.push(commentId);
407
+ const reportsInThread = strapi.db
408
+ .query((0, functions_2.getModelUid)("comment-report"))
409
+ .findMany({
410
+ where: {
411
+ related: commentsInThreadIds,
412
+ resolved: false,
413
+ },
414
+ populate: ["related"],
415
+ });
416
+ const reportsInThreadIds = (await reportsInThread).map((report) => report.id);
417
+ return strapi.db
418
+ .query((0, functions_2.getModelUid)("comment-report"))
419
+ .updateMany({
420
+ where: {
421
+ id: reportsInThreadIds,
422
+ },
423
+ data: { resolved: true },
424
+ });
425
+ }
426
+ throw new error_1.default(400, "There is something wrong with comment Id. Try again.");
427
+ },
428
+ async resolveMultipleAbuseReports(ids) {
429
+ if (!!ids.length) {
430
+ return strapi.db
431
+ .query((0, functions_2.getModelUid)("comment-report"))
432
+ .updateMany({
433
+ where: { id: { $in: ids } },
434
+ data: { resolved: true },
435
+ });
436
+ }
437
+ throw new error_1.default(400, "At least one of selected reports got invalid comment entity relation. Try again.");
438
+ },
439
+ async postComment(threadId, body, author) {
440
+ const entity = await strapi.db
441
+ .query((0, functions_2.getModelUid)("comment"))
442
+ .findOne({
443
+ where: {
444
+ id: threadId,
445
+ },
446
+ });
447
+ return await strapi.db
448
+ .query((0, functions_2.getModelUid)("comment"))
449
+ .create({
450
+ data: {
451
+ approvalStatus: "APPROVED",
452
+ authorId: author.id,
453
+ authorName: author.username,
454
+ authorEmail: author.email,
455
+ content: body,
456
+ threadOf: threadId,
457
+ related: entity.related
458
+ },
459
+ });
460
+ },
461
+ async updateComment(id, body) {
462
+ const updateComment = await strapi.db
463
+ .query((0, functions_2.getModelUid)("comment"))
464
+ .update({
465
+ where: { id },
466
+ data: {
467
+ content: body
468
+ }
469
+ });
470
+ return this.getCommonService().sanitizeCommentEntity(updateComment);
284
471
  },
285
472
  getDefaultAuthorPopulate() {
286
- const strapiUserTypeUid = 'plugin::users-permissions.user';
287
- const allowedTypes = ['media', 'relation'];
473
+ const strapiUserTypeUid = "plugin::users-permissions.user";
474
+ const allowedTypes = ["media", "relation"];
288
475
  const { attributes } = strapi.contentTypes[strapiUserTypeUid] || {};
289
- const relationTypes = Object.keys(attributes)
290
- ?.filter((key) => allowedTypes.includes(attributes[key]?.type));
291
- if (relationTypes.includes('avatar')) {
476
+ const relationTypes = Object.keys(attributes)?.filter((key) => allowedTypes.includes(attributes[key]?.type));
477
+ if (relationTypes.includes("avatar")) {
292
478
  return {
293
479
  populate: { avatar: true },
294
480
  };
295
481
  }
296
482
  return undefined;
297
- }
483
+ },
298
484
  });
299
485
  //# sourceMappingURL=admin.js.map
@@ -24,7 +24,7 @@ module.exports = ({ strapi }) => ({
24
24
  }
25
25
  const relatedEntity = await strapi.db
26
26
  .query(uid)
27
- .findOne(relatedId);
27
+ .findOne({ where: { id: relatedId } });
28
28
  if (!relatedEntity) {
29
29
  throw new error_1.default(400, `Relation for field "related" does not exist. Check your payload please.`);
30
30
  }
@@ -17,9 +17,9 @@ class PluginError extends Error {
17
17
  toJSON() {
18
18
  if (this.payload) {
19
19
  return {
20
+ ...this.payload,
20
21
  name: this.name,
21
22
  message: this.message,
22
- ...(this.payload || {}),
23
23
  };
24
24
  }
25
25
  return this;
@@ -154,7 +154,7 @@ declare const _default: () => {
154
154
  };
155
155
  validator: (config: CommentsPluginConfig) => void;
156
156
  };
157
- register: () => void;
157
+ register: (context: import("strapi-typed").StrapiContext) => void;
158
158
  bootstrap: ({ strapi }: import("strapi-typed").StrapiContext) => Promise<void>;
159
159
  destroy: () => void;
160
160
  controllers: {