strapi-plugin-comments 1.0.1 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/.circleci/config.yml +2 -2
  2. package/.nvmrc +1 -1
  3. package/README.md +71 -95
  4. package/admin/src/components/ConfirmationDialog/index.js +56 -0
  5. package/admin/src/components/DiscussionStatus/index.js +33 -0
  6. package/admin/src/components/DiscussionThread/index.js +58 -0
  7. package/admin/src/components/DiscussionThreadItem/index.js +87 -0
  8. package/admin/src/components/DiscussionThreadItem/styles.js +87 -0
  9. package/admin/src/components/DiscussionThreadItemActions/index.js +176 -0
  10. package/admin/src/components/DiscussionThreadItemActions/styles.js +22 -0
  11. package/admin/src/components/DiscussionThreadItemMeta/index.js +31 -0
  12. package/admin/src/components/DiscussionThreadItemWarnings/index.js +137 -0
  13. package/admin/src/components/DiscussionThreadItemWarnings/styles.js +7 -0
  14. package/admin/src/components/EntityDetails/index.js +53 -0
  15. package/admin/src/{containers → components}/Initializer/index.js +4 -4
  16. package/admin/src/components/LoadingIndicatorOverlay/index.js +15 -0
  17. package/admin/src/components/LoadingIndicatorOverlay/styles.js +20 -0
  18. package/admin/src/components/Nav/index.js +45 -0
  19. package/admin/src/components/PluginIcon/index.js +12 -0
  20. package/admin/src/components/ReportsReviewModal/index.js +45 -0
  21. package/admin/src/components/ReportsReviewTable/index.js +142 -0
  22. package/admin/src/components/TableFilters/index.js +53 -0
  23. package/admin/src/components/TablePagination/index.js +35 -0
  24. package/admin/src/components/icons/comments.js +9 -0
  25. package/admin/src/index.js +56 -42
  26. package/admin/src/pages/App/index.js +32 -0
  27. package/admin/src/pages/ComingSoonPage/index.js +25 -0
  28. package/admin/src/pages/Details/index.js +109 -0
  29. package/admin/src/pages/Details/utils/api.js +41 -0
  30. package/admin/src/pages/Discover/index.js +185 -0
  31. package/admin/src/pages/Discover/utils/api.js +23 -0
  32. package/admin/src/pages/Discover/utils/filtersSchema.js +9 -0
  33. package/admin/src/permissions.js +13 -33
  34. package/admin/src/pluginId.js +2 -4
  35. package/admin/src/translations/en.json +72 -33
  36. package/admin/src/translations/fr.json +1 -0
  37. package/admin/src/utils/axiosInstance.js +35 -0
  38. package/admin/src/utils/constants.js +28 -0
  39. package/admin/src/utils/getApiUrl.js +5 -0
  40. package/admin/src/utils/getMessage.js +14 -0
  41. package/admin/src/utils/getRelatedGroups.js +5 -0
  42. package/admin/src/utils/getUrl.js +5 -0
  43. package/admin/src/utils/handleAPIError.js +15 -0
  44. package/admin/src/utils/index.js +6 -0
  45. package/codecov.yml +2 -1
  46. package/content-types/comment.js +97 -0
  47. package/content-types/index.js +11 -0
  48. package/content-types/report.js +54 -0
  49. package/package.json +12 -26
  50. package/server/bootstrap.js +5 -0
  51. package/server/config/index.js +6 -0
  52. package/server/controllers/admin.js +150 -0
  53. package/server/controllers/client.js +109 -0
  54. package/server/controllers/index.js +9 -0
  55. package/{controllers → server/controllers}/utils/__tests__/functions.test.js +0 -0
  56. package/{controllers → server/controllers}/utils/functions.js +1 -1
  57. package/server/destroy.js +5 -0
  58. package/server/index.js +22 -0
  59. package/server/register.js +5 -0
  60. package/server/routes/admin.js +92 -0
  61. package/server/routes/client.js +52 -0
  62. package/server/routes/index.js +15 -0
  63. package/server/services/admin.js +180 -0
  64. package/server/services/client.js +227 -0
  65. package/server/services/common.js +191 -0
  66. package/server/services/index.js +11 -0
  67. package/{services → server/services}/utils/__tests__/functions.test.js +7 -9
  68. package/{services → server/services}/utils/functions.js +19 -8
  69. package/server/utils/constants.js +16 -0
  70. package/{services → server}/utils/error.js +0 -0
  71. package/server/utils/functions.js +19 -0
  72. package/strapi-admin.js +3 -0
  73. package/strapi-server.js +9 -0
  74. package/admin/src/assets/images/icon-cross-blue.svg +0 -1
  75. package/admin/src/assets/images/icon_remove.svg +0 -19
  76. package/admin/src/assets/images/logo.svg +0 -5
  77. package/admin/src/components/AbuseReportsPopUp/ItemPreviewContainer.js +0 -8
  78. package/admin/src/components/AbuseReportsPopUp/ModalFooter.js +0 -31
  79. package/admin/src/components/AbuseReportsPopUp/TableContainer.js +0 -63
  80. package/admin/src/components/AbuseReportsPopUp/index.js +0 -148
  81. package/admin/src/components/Container/index.js +0 -7
  82. package/admin/src/components/EmptyView/index.js +0 -25
  83. package/admin/src/components/Filters/index.js +0 -151
  84. package/admin/src/components/Filters/index.styled.js +0 -82
  85. package/admin/src/components/Filters/utils.js +0 -21
  86. package/admin/src/components/Item/CardItem.js +0 -30
  87. package/admin/src/components/Item/CardWrapper.js +0 -10
  88. package/admin/src/components/Item/index.js +0 -92
  89. package/admin/src/components/ItemDetails/CardItem.js +0 -33
  90. package/admin/src/components/ItemDetails/CardLevelCounter.js +0 -46
  91. package/admin/src/components/ItemDetails/CardLevelCounterLink.js +0 -24
  92. package/admin/src/components/ItemDetails/CardLevelWrapper.js +0 -22
  93. package/admin/src/components/ItemDetails/CardWrapper.js +0 -52
  94. package/admin/src/components/ItemDetails/index.js +0 -151
  95. package/admin/src/components/ItemFooter/CardItemAuthor.js +0 -10
  96. package/admin/src/components/ItemFooter/CardItemRelation.js +0 -18
  97. package/admin/src/components/ItemFooter/Wrapper.js +0 -20
  98. package/admin/src/components/ItemFooter/index.js +0 -87
  99. package/admin/src/components/ItemHeader/CardHeaderBlocked.js +0 -24
  100. package/admin/src/components/ItemHeader/CardHeaderIndicator.js +0 -30
  101. package/admin/src/components/ItemHeader/CardHeaderIndicatorBlue.js +0 -11
  102. package/admin/src/components/ItemHeader/CardHeaderIndicatorRed.js +0 -11
  103. package/admin/src/components/ItemHeader/CardHeaderIndicatorsContainer.js +0 -18
  104. package/admin/src/components/ItemHeader/CardHeaderReports.js +0 -40
  105. package/admin/src/components/ItemHeader/Wrapper.js +0 -16
  106. package/admin/src/components/ItemHeader/index.js +0 -80
  107. package/admin/src/components/ItemModeration/Wrapper.js +0 -19
  108. package/admin/src/components/ItemModeration/index.js +0 -47
  109. package/admin/src/components/List/Container.js +0 -20
  110. package/admin/src/components/List/index.js +0 -21
  111. package/admin/src/components/Search/index.js +0 -83
  112. package/admin/src/containers/App/Wrapper.js +0 -14
  113. package/admin/src/containers/App/index.js +0 -47
  114. package/admin/src/containers/DataManagerProvider/actions.js +0 -11
  115. package/admin/src/containers/DataManagerProvider/index.js +0 -280
  116. package/admin/src/containers/DataManagerProvider/init.js +0 -5
  117. package/admin/src/containers/DataManagerProvider/reducer.js +0 -59
  118. package/admin/src/containers/DetailsView/Wrapper.js +0 -18
  119. package/admin/src/containers/DetailsView/index.js +0 -100
  120. package/admin/src/containers/ListView/FadedWrapper.js +0 -42
  121. package/admin/src/containers/ListView/Footer.js +0 -53
  122. package/admin/src/containers/ListView/Wrapper.js +0 -17
  123. package/admin/src/containers/ListView/components.js +0 -138
  124. package/admin/src/containers/ListView/index.js +0 -45
  125. package/admin/src/containers/Panel/actions.js +0 -5
  126. package/admin/src/containers/Panel/index.js +0 -191
  127. package/admin/src/containers/Panel/index.styled.js +0 -6
  128. package/admin/src/containers/Panel/reducer.js +0 -44
  129. package/admin/src/contexts/DataManagerContext.js +0 -5
  130. package/admin/src/hooks/useDataManager.js +0 -6
  131. package/admin/src/lifecycles.js +0 -3
  132. package/admin/src/translations/index.js +0 -7
  133. package/admin/src/utils/getTrad.js +0 -5
  134. package/admin/src/utils/getTradId.js +0 -5
  135. package/config/functions/bootstrap.js +0 -48
  136. package/config/routes.json +0 -124
  137. package/controllers/comments.js +0 -215
  138. package/models/comment.js +0 -8
  139. package/models/comment.settings.json +0 -90
  140. package/models/report.js +0 -8
  141. package/models/report.settings.json +0 -41
  142. package/services/comments.js +0 -478
@@ -1,478 +0,0 @@
1
- 'use strict';
2
-
3
- const { first, isEmpty, isNil, map, uniq, get } = require('lodash');
4
- const { sanitizeEntity } = require('strapi-utils');
5
- const PluginError = require('./utils/error');
6
- const {
7
- isEqualEntity,
8
- extractMeta,
9
- buildNestedStructure,
10
- checkBadWords,
11
- filterOurResolvedReports,
12
- convertContentTypeNameToSlug,
13
- isValidUserContext,
14
- resolveUserContextError,
15
- } = require('./utils/functions');
16
-
17
- /**
18
- * comments.js service
19
- *
20
- * @description: A set of functions similar to controller's actions to avoid code duplication.
21
- */
22
-
23
- module.exports = {
24
- getAssociationModel(ormModel, related) {
25
- const relatedAssociation = ormModel.associations.find(_ => _.alias === 'related');
26
- if (relatedAssociation) {
27
- return relatedAssociation.related.find(rel => rel.collectionName === related);
28
- }
29
- return null;
30
- },
31
-
32
- getMorphModel() {
33
- const { pluginName, model } = extractMeta(strapi.plugins);
34
- const ormModel = strapi.query(model.modelName, pluginName);
35
- return ormModel.model.morph;
36
- },
37
-
38
- isMongoDB(){
39
- const { pluginName, model } = extractMeta(strapi.plugins);
40
- const orm = strapi.query(model.modelName, pluginName).model.orm;
41
- return orm === 'mongoose';
42
- },
43
-
44
- getMorphData(query) {
45
- return this
46
- .getMorphModel()
47
- .query(function () {
48
- this.where(query);
49
- })
50
- .fetchAll()
51
- .then((entities) => entities.map(entity => entity.toJSON()));
52
- },
53
-
54
- // Find all comments
55
- async findAll({ related, entity, ...query }) {
56
- const { pluginName, model } = extractMeta(strapi.plugins);
57
- const paginationEnabled = !isNil(query._start);
58
- const ormModel = strapi.query(model.modelName, pluginName);
59
- let relatedCommentIds = [];
60
- if (related) {
61
- const associationModel = this.getAssociationModel(ormModel, related);
62
- if (associationModel) {
63
- if (this.isMongoDB()) {
64
- const [fieldName] = Object.entries(associationModel.allAttributes).find(([, value]) => value.plugin === 'comments' && value.collection === 'comment') || [];
65
- if (!fieldName){
66
- throw strapi.errors.badRequest();
67
- }
68
- const query = { [fieldName]: { $exists: true, $not: { $size: 0 } } };
69
- if (entity){
70
- query._id = entity;
71
- }
72
- relatedCommentIds = await associationModel
73
- .find(query)
74
- .then((entry) => entry.map(_ => _.toJSON()[fieldName]))
75
- .then(entry => entry.flatMap(comments => comments.map(comment => comment.id)));
76
- } else {
77
- const morphQuery = entity
78
- ? { related_type: related, related_id: entity }
79
- : { related_type: related };
80
- relatedCommentIds = await this
81
- .getMorphData(morphQuery)
82
- .then(_ => _.map(entity => entity.comments_id));
83
- }
84
- } else {
85
- throw strapi.errors.badRequest();
86
- }
87
- }
88
- // we not find any content to related data
89
- if (related && relatedCommentIds.length === 0) {
90
- return {
91
- items: [],
92
- total: 0,
93
- page: 1,
94
- };
95
- }
96
-
97
- const params = {
98
- ...query,
99
- _sort: paginationEnabled ? query._sort || 'created_at:desc' : 'created_at:desc',
100
- };
101
- if (relatedCommentIds.length) {
102
- params.id = relatedCommentIds;
103
- }
104
- const entities = query && query._q ?
105
- await ormModel.search(params, ['authorUser', 'related', 'reports']) :
106
- await ormModel.find(params, ['authorUser', 'related', 'reports']);
107
- const items = entities.map(_ => filterOurResolvedReports(this.sanitizeCommentEntity(_)));
108
- const total = paginationEnabled ?
109
- query && query._q ?
110
- await ormModel.countSearch(params) :
111
- await ormModel.count(params) :
112
- items.length;
113
- return {
114
- items,
115
- total,
116
- page: paginationEnabled ? query._start / query._limit : undefined,
117
- };
118
- },
119
-
120
- // Find comments in the flat structure
121
- async findAllFlat(relation, query, isAdmin = false) {
122
- const { pluginName, model } = extractMeta(strapi.plugins);
123
- let baseCriteria = {};
124
- if (relation) {
125
- baseCriteria = {
126
- ...baseCriteria,
127
- _or: [{ removed_null: true }, { removed: false }],
128
- relatedSlug: relation,
129
- };
130
- }
131
- let criteria = {
132
- ...baseCriteria,
133
- _or: [{ removed_null: true }, { removed: false }],
134
- threadOf_null: true,
135
- };
136
-
137
- if (isAdmin){
138
- delete baseCriteria._or;
139
- delete criteria._or;
140
- }
141
-
142
- if (query) {
143
- criteria = {
144
- ...criteria,
145
- ...query,
146
- };
147
- }
148
-
149
- const entitiesRoot = query && query._q ?
150
- await strapi.query( model.modelName, pluginName)
151
- .search(criteria, ['authorUser', 'related', 'reports']) :
152
- await strapi.query( model.modelName, pluginName)
153
- .find(criteria, ['authorUser', 'related', 'reports']);
154
- const entitiesNested = await strapi.query( model.modelName, pluginName)
155
- .find({
156
- ...baseCriteria,
157
- threadOf_null: false,
158
- }, ['authorUser', 'related', 'reports']);
159
- return [...entitiesRoot, ...entitiesNested].map(_ => filterOurResolvedReports(this.sanitizeCommentEntity(_)));
160
- },
161
-
162
- // Find comments and create relations tree structure
163
- async findAllInHierarchy ({
164
- relation,
165
- query,
166
- startingFromId = null,
167
- dropBlockedThreads = false,
168
- isAdmin = false,
169
- }) {
170
- const entities = await this.findAllFlat(relation, query, isAdmin);
171
- return buildNestedStructure(entities, startingFromId, 'threadOf', dropBlockedThreads, false, this.isMongoDB());
172
- },
173
-
174
- // Find single comment
175
- async findOne(id, relation) {
176
- const { pluginName, model } = extractMeta(strapi.plugins);
177
- let criteria = { id };
178
- if (relation) {
179
- criteria = {
180
- ...criteria,
181
- relatedSlug: relation,
182
- };
183
- }
184
- const entity = await strapi.query( model.modelName, pluginName)
185
- .findOne(criteria, ['related', 'reports']);
186
- if (!entity){
187
- throw strapi.errors.notFound();
188
- }
189
- return filterOurResolvedReports(this.sanitizeCommentEntity(entity));
190
- },
191
-
192
- checkEntityRelation(parsedRelation) {
193
- const result = parsedRelation.some(ref => {
194
- const model = strapi.query(ref);
195
- return model && model.associations.length &&
196
- model.associations.some(_ => _.plugin === 'comments' && _.collection === 'comment');
197
- });
198
- if (!result) {
199
- throw new PluginError(400, 'Comment not have relation to this type content type.');
200
- }
201
- },
202
-
203
- // Create a comment
204
- async create(data, relation, user = undefined) {
205
- const { content, related } = data;
206
- const parsedRelation = related && related instanceof Array ? related : [related];
207
- this.checkEntityRelation(map(parsedRelation, 'ref'));
208
- const singleRelationFulfilled = related && (parsedRelation.length === 1);
209
- const linkToThread = !isNil(data.threadOf) ? !!await this.findOne(data.threadOf, relation) : true;
210
- const validContext = isValidUserContext(user);
211
-
212
- if (!linkToThread) {
213
- throw new PluginError(400, 'Thread does not exist');
214
- }
215
-
216
- if (!validContext) {
217
- throw resolveUserContextError(user);
218
- }
219
-
220
- if (checkBadWords(content) && singleRelationFulfilled) {
221
- const { pluginName, model } = extractMeta(strapi.plugins);
222
- const relatedEntity = !isEmpty(related) ? first(related) : null;
223
- const { authorId, authorEmail, authorName, authorUser, ...rest } = data;
224
- let authorData = {};
225
- if (validContext && user) {
226
- authorData = {
227
- authorUser: user.id ? user.id : authorUser,
228
- };
229
- } else if (authorUser) {
230
- authorData = {
231
- authorUser,
232
- };
233
- } else {
234
- const emailValidation = new RegExp(/\S+@\S+\.\S+/);
235
- if (authorEmail && !emailValidation.test(authorEmail)) {
236
- throw new PluginError(400, 'Author e-mail is not valid value. Key: \'authorEmail\'');
237
- }
238
-
239
- authorData = {
240
- authorId,
241
- authorName,
242
- authorEmail,
243
- };
244
- }
245
-
246
- const relationEntity = await Promise
247
- .all(parsedRelation.map(rel => strapi.query(rel.ref).findOne({ id: rel.refId })));
248
-
249
-
250
- relationEntity.forEach((rel) => {
251
- if (!rel) {
252
- throw new PluginError(404, 'Related entity not found');
253
- }
254
- });
255
-
256
- const entity = await strapi.query( model.modelName, pluginName).create({
257
- ...rest,
258
- ...authorData,
259
- relatedSlug: relatedEntity ? `${relatedEntity.ref}:${relatedEntity.refId}` : relation,
260
- related: parsedRelation
261
- });
262
- return this.sanitizeCommentEntity(entity);
263
- }
264
- throw new PluginError(400, 'No content received');
265
- },
266
-
267
- // Update a comment
268
- async update(id, relation, data, user) {
269
- const { content } = data;
270
- const { pluginName, model } = extractMeta(strapi.plugins);
271
- const existingEntity = await this.findOne(id, relation);
272
- const validContext = isValidUserContext(user);
273
-
274
- if (!validContext) {
275
- throw resolveUserContextError(user);
276
- }
277
-
278
- if (isEqualEntity(existingEntity, data, user) && content) {
279
- if (checkBadWords(content)) {
280
- const entity = await strapi.query( model.modelName, pluginName).update(
281
- { id },
282
- { content }
283
- );
284
- return this.sanitizeCommentEntity(entity);
285
- }
286
- }
287
- throw new PluginError(409, 'Action on that entity is not allowed');
288
- },
289
-
290
- // Points up for comment
291
- async pointsUp(id, relation, user) {
292
- if (!isValidUserContext(user)) {
293
- throw resolveUserContextError(user);
294
- }
295
-
296
- const { pluginName, model } = extractMeta(strapi.plugins);
297
- const existingEntity = await this.findOne(id, relation);
298
- if (existingEntity) {
299
- const entity = await strapi.query( model.modelName, pluginName).update(
300
- { id },
301
- {
302
- points: (existingEntity.points || 0) + 1,
303
- }
304
- );
305
- return this.sanitizeCommentEntity(entity);
306
- }
307
- throw new PluginError(409, 'Action on that entity is not allowed');
308
- },
309
-
310
- // Report abuse in comment
311
- async reportAbuse(id, relation, payload, user) {
312
- if (!isValidUserContext(user)) {
313
- throw resolveUserContextError(user);
314
- }
315
- const { pluginName, plugin } = extractMeta(strapi.plugins);
316
- const { report: reportModel } = plugin.models;
317
- const existingEntity = await this.findOne(id, relation);
318
- if (existingEntity) {
319
- const entity = await strapi.query(reportModel.modelName, pluginName).create({
320
- ...payload,
321
- resolved: false,
322
- related: id,
323
- });
324
- return entity;
325
- }
326
- throw new PluginError(409, 'Action on that entity is not allowed');
327
- },
328
-
329
- async markAsRemoved(relationId, commentId, authorId){
330
- const { pluginName, model } = extractMeta(strapi.plugins);
331
- const entity = await this.findOne(
332
- commentId,
333
- relationId,
334
- { _or: [{ authorUser: authorId }, { authorId }] },
335
- );
336
- if (!entity){
337
- throw strapi.errors.notFound('Entity not exist');
338
- }
339
- return strapi
340
- .query(model.modelName, pluginName)
341
- .update({ id: commentId, relatedSlug: relationId }, { removed: true })
342
- .then(({ id }) => this.markAsRemovedNested(id, true))
343
- .then(() => ({}));
344
- },
345
-
346
- //
347
- // Moderation
348
- //
349
-
350
- // Find single comment
351
- async findOneAndThread(id) {
352
- const { pluginName, model } = extractMeta(strapi.plugins);
353
- const entity = await strapi.query( model.modelName, pluginName).findOne({ id }, ['threadOf', 'threadOf.reports', 'authorUser', 'related', 'reports']);
354
- if (!entity){
355
- throw new PluginError(404, 'Not found');
356
- }
357
- const relatedEntity = !isEmpty(entity.related) ? first(entity.related) : null;
358
- const relation = relatedEntity ? `${convertContentTypeNameToSlug(relatedEntity.__contentType).toLowerCase()}:${relatedEntity.id}` : null;
359
- const entitiesOnSameLevel = await this.findAllInHierarchy({
360
- relation,
361
- startingFromId: entity.threadOf ? entity.threadOf.id : null,
362
- isAdmin: true
363
- })
364
- const selectedEntity = filterOurResolvedReports(this.sanitizeCommentEntity(entity));
365
- return {
366
- selected: {
367
- ...selectedEntity,
368
- threadOf: selectedEntity.threadOf ? filterOurResolvedReports(selectedEntity.threadOf) : null,
369
- },
370
- level: entitiesOnSameLevel.map(_ => filterOurResolvedReports(_))
371
- };
372
- },
373
-
374
- // Block / Unblock a comment
375
- async blockComment(id) {
376
- const { pluginName, model } = extractMeta(strapi.plugins);
377
- const existingEntity = await this.findOne(id);
378
- const changedEntity = await strapi.query( model.modelName, pluginName).update(
379
- { id },
380
- { blocked: !existingEntity.blocked }
381
- );
382
- return this.sanitizeCommentEntity(changedEntity);
383
- },
384
-
385
- // Block / Unblock a comment thread
386
- async blockCommentThread(id) {
387
- const { pluginName, model } = extractMeta(strapi.plugins);
388
- const existingEntity = await this.findOne(id);
389
- const changedEntity = await strapi.query( model.modelName, pluginName).update(
390
- { id },
391
- { blockedThread: !existingEntity.blockedThread }
392
- );
393
- await this.blockNestedThreads(id, changedEntity.blockedThread)
394
- return this.sanitizeCommentEntity(changedEntity);
395
- },
396
-
397
- markAsRemovedNested(id, status){
398
- return this.modifiedNestedNestedComments(id, 'removed', status);
399
- },
400
-
401
- blockNestedThreads(id, blockStatus){
402
- return this.modifiedNestedNestedComments(id, 'blockedThread', blockStatus)
403
- },
404
-
405
- async modifiedNestedNestedComments(id, fieldName, value) {
406
- const { pluginName, model } = extractMeta(strapi.plugins);
407
- try {
408
- const entitiesToChange = await strapi.query(model.modelName, pluginName).find({ threadOf: id });
409
- const changedEntities = await Promise.all(entitiesToChange.map(item => strapi.query(model.modelName, pluginName).update(
410
- { id: item.id },
411
- { [fieldName]: value }
412
- )));
413
- if (changedEntities.length) {
414
- const nestedTransactions = await Promise.all(
415
- changedEntities.map(item => this.modifiedNestedNestedComments(item.id, fieldName, value))
416
- );
417
- return nestedTransactions.length === changedEntities.length;
418
- }
419
- return true;
420
- } catch (e) {
421
- return false;
422
- }
423
- },
424
-
425
- async contentTypeName(contentTypeName) {
426
- const { pluginName, model } = extractMeta(strapi.plugins);
427
- const ormModel = strapi.query(model.modelName, pluginName);
428
- const associationModel = this.getAssociationModel(ormModel, contentTypeName);
429
- const config = get(strapi.config, ['plugins', 'comments', 'relatedContentTypes', contentTypeName], []);
430
- if (isEmpty(config)) {
431
- return [];
432
- }
433
- if (associationModel) {
434
- let relatedIds = [];
435
- let result = [];
436
- if (this.isMongoDB()) {
437
- const [fieldName] = Object.entries(associationModel.allAttributes).find(([, value]) => value.plugin === 'comments' && value.collection === 'comment') || [];
438
- if (!fieldName){
439
- throw strapi.errors.badRequest();
440
- }
441
- result = await associationModel
442
- .find({ [fieldName]: { $exists: true, $not: { $size: 0 } } })
443
- .then((entities) => entities.map(_ => _.toJSON()));
444
- } else {
445
- relatedIds = await this
446
- .getMorphData({ related_type: contentTypeName })
447
- .then(_ => uniq(_.map(entity => entity.related_id)));
448
- result = await strapi.query(associationModel.uid).find({ id: relatedIds });
449
- }
450
- const entries = Object.entries(config);
451
- return result
452
- .map(_ =>
453
- entries
454
- .reduce((acc, [key, val]) => ({ ...acc, [key]: _[val] }), {}),
455
- );
456
-
457
- }
458
- throw strapi.errors.badRequest();
459
- },
460
-
461
- // Resolve reported abuse for comment
462
- async resolveAbuseReport(id, commentId) {
463
- const { pluginName, plugin } = extractMeta(strapi.plugins);
464
- const { report: reportModel } = plugin.models;
465
- const entity = await strapi.query(reportModel.modelName, pluginName).update({
466
- id,
467
- related: commentId,
468
- }, {
469
- resolved: true,
470
- });
471
- return entity;
472
- },
473
-
474
- sanitizeCommentEntity: (entity) => ({
475
- ...entity,
476
- authorUser: sanitizeEntity(entity.authorUser, { model: strapi.plugins['users-permissions'].models.user }),
477
- }),
478
- };