strapi-plugin-comments 2.2.4 → 2.2.5

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 (30) hide show
  1. package/README.md +3 -1
  2. package/admin/src/components/AdminAvatar/index.js +2 -2
  3. package/admin/src/components/AdminAvatar/styles.js +10 -2
  4. package/admin/src/components/Avatar/index.js +3 -6
  5. package/admin/src/components/DiscussionThreadItem/index.js +29 -2
  6. package/admin/src/components/DiscussionThreadItem/styles.d.ts +1 -0
  7. package/admin/src/components/DiscussionThreadItem/styles.js +14 -1
  8. package/admin/src/components/DiscussionThreadItemActions/index.js +13 -7
  9. package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +2 -1
  10. package/admin/src/components/DiscussionThreadItemFooter/index.js +2 -2
  11. package/admin/src/components/ModeratorResponse/index.js +2 -1
  12. package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.d.ts +1 -1
  13. package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.js +2 -2
  14. package/admin/src/components/Wysiwyg/Editor.js +2 -1
  15. package/admin/src/components/Wysiwyg/WysiwygNav.js +1 -23
  16. package/admin/src/components/Wysiwyg/WysiwygStyles.js +1 -1
  17. package/admin/src/pages/Details/index.js +4 -3
  18. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +31 -2
  19. package/admin/src/pages/Settings/index.js +6 -2
  20. package/admin/src/translations/en.json +3 -1
  21. package/package.json +3 -3
  22. package/server/config/index.js +1 -0
  23. package/server/services/admin.js +12 -10
  24. package/server/services/client.js +6 -3
  25. package/server/services/common.js +11 -8
  26. package/server/services/utils/functions.d.ts +1 -1
  27. package/server/services/utils/functions.js +4 -2
  28. package/server/utils/constants.js +1 -0
  29. package/strapi-server.d.ts +1 -0
  30. package/tsconfig.tsbuildinfo +1 -1
@@ -35,9 +35,11 @@ module.exports = ({ strapi }) => ({
35
35
  const entryLabel = getConfigProp("entryLabel");
36
36
  const approvalFlow = getConfigProp("approvalFlow");
37
37
  const reportReasons = getConfigProp("reportReasons");
38
+ const blockedAuthorProps = getConfigProp("blockedAuthorProps");
38
39
  const result = {
39
40
  entryLabel,
40
41
  approvalFlow,
42
+ blockedAuthorProps,
41
43
  reportReasons,
42
44
  ...additionalConfiguration,
43
45
  };
@@ -119,7 +121,7 @@ module.exports = ({ strapi }) => ({
119
121
  });
120
122
  const relatedEntities = await this.getCommonService().findRelatedEntitiesFor(entities);
121
123
  const result = entities
122
- .map((_) => (0, functions_2.filterOurResolvedReports)(this.getCommonService().sanitizeCommentEntity(_, defaultAuthorUserPopulate?.populate)))
124
+ .map((_) => (0, functions_2.filterOurResolvedReports)(this.getCommonService().sanitizeCommentEntity(_, [], defaultAuthorUserPopulate?.populate)))
123
125
  .map((_) => this.getCommonService().mergeRelatedEntityTo(_, relatedEntities));
124
126
  const pageCount = Math.floor(total / pageSize);
125
127
  return {
@@ -194,8 +196,8 @@ module.exports = ({ strapi }) => ({
194
196
  related: this.getCommonService().sanitizeCommentEntity({
195
197
  ..._.related,
196
198
  gotThread: isCommentWithThread,
197
- }),
198
- }, defaultAuthorUserPopulate?.populate));
199
+ }, []),
200
+ }, [], defaultAuthorUserPopulate?.populate));
199
201
  });
200
202
  const pageCount = Math.floor(total / pageSize);
201
203
  return {
@@ -289,7 +291,7 @@ module.exports = ({ strapi }) => ({
289
291
  const selectedEntity = this.getCommonService().sanitizeCommentEntity({
290
292
  ...entity,
291
293
  threadOf: entity.threadOf || null,
292
- }, defaultAuthorUserPopulate?.populate);
294
+ }, [], defaultAuthorUserPopulate?.populate);
293
295
  return {
294
296
  entity: relatedEntity,
295
297
  selected: selectedEntity,
@@ -306,7 +308,7 @@ module.exports = ({ strapi }) => ({
306
308
  blocked: !(0, lodash_1.isNil)(forceStatus) ? forceStatus : !existingEntity.blocked,
307
309
  },
308
310
  });
309
- return this.getCommonService().sanitizeCommentEntity(changedEntity);
311
+ return this.getCommonService().sanitizeCommentEntity(changedEntity, []);
310
312
  },
311
313
  async deleteComment(id) {
312
314
  const changedEntity = await strapi.db
@@ -317,7 +319,7 @@ module.exports = ({ strapi }) => ({
317
319
  removed: true,
318
320
  },
319
321
  });
320
- return this.getCommonService().sanitizeCommentEntity(changedEntity);
322
+ return this.getCommonService().sanitizeCommentEntity(changedEntity, []);
321
323
  },
322
324
  async blockCommentThread(id, forceStatus) {
323
325
  const existingEntity = await this.getCommonService().findOne({ id });
@@ -334,7 +336,7 @@ module.exports = ({ strapi }) => ({
334
336
  },
335
337
  });
336
338
  await this.blockNestedThreads(id, changedEntity.blockedThread);
337
- return this.getCommonService().sanitizeCommentEntity(changedEntity);
339
+ return this.getCommonService().sanitizeCommentEntity(changedEntity, []);
338
340
  },
339
341
  async approveComment(id) {
340
342
  const changedEntity = await strapi.db
@@ -343,7 +345,7 @@ module.exports = ({ strapi }) => ({
343
345
  where: { id },
344
346
  data: { approvalStatus: constants_1.APPROVAL_STATUS.APPROVED },
345
347
  });
346
- return this.getCommonService().sanitizeCommentEntity(changedEntity);
348
+ return this.getCommonService().sanitizeCommentEntity(changedEntity, []);
347
349
  },
348
350
  async rejectComment(id) {
349
351
  const changedEntity = await strapi.db
@@ -352,7 +354,7 @@ module.exports = ({ strapi }) => ({
352
354
  where: { id },
353
355
  data: { approvalStatus: constants_1.APPROVAL_STATUS.REJECTED },
354
356
  });
355
- return this.getCommonService().sanitizeCommentEntity(changedEntity);
357
+ return this.getCommonService().sanitizeCommentEntity(changedEntity, []);
356
358
  },
357
359
  async blockNestedThreads(id, blockStatus) {
358
360
  return await this.getCommonService().modifiedNestedNestedComments(id, "blockedThread", blockStatus);
@@ -486,7 +488,7 @@ module.exports = ({ strapi }) => ({
486
488
  content: body
487
489
  }
488
490
  });
489
- return this.getCommonService().sanitizeCommentEntity(updateComment);
491
+ return this.getCommonService().sanitizeCommentEntity(updateComment, []);
490
492
  },
491
493
  getDefaultAuthorPopulate() {
492
494
  const strapiUserTypeUid = "plugin::users-permissions.user";
@@ -30,6 +30,7 @@ module.exports = ({ strapi }) => ({
30
30
  }
31
31
  const approvalFlow = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.APPROVAL_FLOW, []);
32
32
  const isApprovalFlowEnabled = approvalFlow.includes(uid) || relatedEntity.requireCommentsApproval;
33
+ const doNotPopulateAuthor = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
33
34
  let linkToThread;
34
35
  try {
35
36
  linkToThread = !(0, lodash_1.isNil)(threadOf)
@@ -93,7 +94,7 @@ module.exports = ({ strapi }) => ({
93
94
  const sanitizedEntity = this.getCommonService().sanitizeCommentEntity({
94
95
  ...entity,
95
96
  threadOf: linkToThread,
96
- });
97
+ }, doNotPopulateAuthor);
97
98
  try {
98
99
  await this.sendResponseNotification(sanitizedEntity);
99
100
  }
@@ -121,6 +122,7 @@ module.exports = ({ strapi }) => ({
121
122
  }
122
123
  if ((0, functions_2.isEqualEntity)(existingEntity, data, user) && content) {
123
124
  if (await this.getCommonService().checkBadWords(content)) {
125
+ const blockedAuthorProps = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
124
126
  const entity = await strapi.db
125
127
  .query((0, functions_2.getModelUid)("comment"))
126
128
  .update({
@@ -128,7 +130,7 @@ module.exports = ({ strapi }) => ({
128
130
  data: { content },
129
131
  populate: { threadOf: true, authorUser: true },
130
132
  });
131
- return this.getCommonService().sanitizeCommentEntity(entity);
133
+ return this.getCommonService().sanitizeCommentEntity(entity, blockedAuthorProps);
132
134
  }
133
135
  }
134
136
  throw new error_1.default(403, `You're not allowed to take an action on that entity. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
@@ -213,7 +215,8 @@ module.exports = ({ strapi }) => ({
213
215
  populate: { threadOf: true, authorUser: true },
214
216
  });
215
217
  await this.markAsRemovedNested(id, true);
216
- return this.getCommonService().sanitizeCommentEntity(removedEntity);
218
+ const doNotPopulateAuthor = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
219
+ return this.getCommonService().sanitizeCommentEntity(removedEntity, doNotPopulateAuthor);
217
220
  }
218
221
  else {
219
222
  throw new error_1.default(404, `Entity does not exist or you're not allowed to take an action on it`);
@@ -38,6 +38,7 @@ module.exports = ({ strapi }) => ({
38
38
  authorUser: true,
39
39
  ...((0, lodash_1.isObject)(populate) ? populate : {}),
40
40
  };
41
+ const doNotPopulateAuthor = await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
41
42
  let queryExtension = {};
42
43
  if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
43
44
  queryExtension = {
@@ -146,16 +147,17 @@ module.exports = ({ strapi }) => ({
146
147
  : query.threadOf;
147
148
  let authorUserPopulate = {};
148
149
  if ((0, lodash_1.isObject)(populateClause?.authorUser)) {
149
- authorUserPopulate = 'populate' in populateClause.authorUser ?
150
- populateClause.authorUser.populate :
151
- populateClause.authorUser;
150
+ authorUserPopulate =
151
+ "populate" in populateClause.authorUser
152
+ ? populateClause.authorUser.populate
153
+ : populateClause.authorUser;
152
154
  }
153
155
  return this.sanitizeCommentEntity({
154
156
  ..._,
155
157
  threadOf: parsedThreadOf || _.threadOf || null,
156
158
  gotThread: (threadedItem?.itemsInTread || 0) > 0,
157
159
  threadFirstItemId: threadedItem?.firstThreadItemId,
158
- }, authorUserPopulate);
160
+ }, doNotPopulateAuthor, authorUserPopulate);
159
161
  });
160
162
  return {
161
163
  data: hasRelatedEntitiesToMap
@@ -181,7 +183,8 @@ module.exports = ({ strapi }) => ({
181
183
  if (!entity) {
182
184
  throw new error_1.default(404, "Comment does not exist. Check your payload please.");
183
185
  }
184
- return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity));
186
+ const doNotPopulateAuthor = await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
187
+ return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity, doNotPopulateAuthor));
185
188
  },
186
189
  async findRelatedEntitiesFor(entities = []) {
187
190
  const data = entities.reduce((acc, curr) => {
@@ -235,7 +238,7 @@ module.exports = ({ strapi }) => ({
235
238
  return false;
236
239
  }
237
240
  },
238
- sanitizeCommentEntity(entity, populate) {
241
+ sanitizeCommentEntity(entity, blockedAuthorProps, populate) {
239
242
  const fieldsToPopulate = (0, lodash_1.isArray)(populate)
240
243
  ? populate
241
244
  : Object.keys(populate || {});
@@ -243,9 +246,9 @@ module.exports = ({ strapi }) => ({
243
246
  ...(0, functions_1.buildAuthorModel)({
244
247
  ...entity,
245
248
  threadOf: (0, lodash_1.isObject)(entity.threadOf)
246
- ? (0, functions_1.buildAuthorModel)(entity.threadOf, fieldsToPopulate)
249
+ ? (0, functions_1.buildAuthorModel)(entity.threadOf, blockedAuthorProps, fieldsToPopulate)
247
250
  : entity.threadOf,
248
- }, fieldsToPopulate),
251
+ }, blockedAuthorProps, fieldsToPopulate),
249
252
  };
250
253
  },
251
254
  isValidUserContext(user) {
@@ -7,7 +7,7 @@ export declare const getRelatedGroups: (related: string) => Array<string>;
7
7
  export declare const getModelUid: (name: string) => string;
8
8
  export declare const filterOurResolvedReports: (item: Comment) => Comment;
9
9
  export declare const convertContentTypeNameToSlug: (str: string) => string;
10
- export declare const buildAuthorModel: (item: Comment, fieldsToPopulate?: Array<string>) => Comment;
10
+ export declare const buildAuthorModel: (item: Comment, blockedAuthorProps: Array<string>, fieldsToPopulate?: Array<string>) => Comment;
11
11
  export declare const buildConfigQueryProp: (prop?: undefined | string | Array<string>) => string;
12
12
  export declare const resolveUserContextError: (user: StrapiUser) => PluginError;
13
13
  export declare const getAuthorName: (author: StrapiAdmin) => any;
@@ -64,7 +64,7 @@ const convertContentTypeNameToSlug = (str) => {
64
64
  : plainConversion;
65
65
  };
66
66
  exports.convertContentTypeNameToSlug = convertContentTypeNameToSlug;
67
- const buildAuthorModel = (item, fieldsToPopulate = []) => {
67
+ const buildAuthorModel = (item, blockedAuthorProps, fieldsToPopulate = []) => {
68
68
  const { authorUser, authorId, authorName, authorEmail, authorAvatar, ...rest } = item;
69
69
  let author = {};
70
70
  if (authorUser) {
@@ -88,9 +88,11 @@ const buildAuthorModel = (item, fieldsToPopulate = []) => {
88
88
  avatar: authorAvatar,
89
89
  };
90
90
  }
91
+ author = (0, lodash_1.isEmpty)(author) ? author : Object.fromEntries(Object.entries(author)
92
+ .filter(([name]) => !blockedAuthorProps.includes(name)));
91
93
  return {
92
94
  ...rest,
93
- author: (0, lodash_1.isEmpty)(author) ? undefined : author,
95
+ author,
94
96
  };
95
97
  };
96
98
  exports.buildAuthorModel = buildAuthorModel;
@@ -7,6 +7,7 @@ exports.CONFIG_PARAMS = {
7
7
  ENTRY_LABEL: "entryLabel",
8
8
  MODERATOR_ROLES: "moderatorRoles",
9
9
  BAD_WORDS: "badWords",
10
+ AUTHOR_BLOCKED_PROPS: "blockedAuthorProps",
10
11
  };
11
12
  exports.APPROVAL_STATUS = {
12
13
  PENDING: "PENDING",
@@ -150,6 +150,7 @@ declare const _default: () => {
150
150
  enabledCollections: string[];
151
151
  moderatorRoles: string[];
152
152
  approvalFlow: string[];
153
+ blockedAuthorProps: string[];
153
154
  entryLabel: PluginConfigEntryLabels;
154
155
  reportReasons: PluginConfigReportReasons;
155
156
  badWords?: boolean | undefined;