strapi-plugin-comments 2.2.4 → 2.2.6
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.
- package/README.md +3 -1
- package/admin/src/components/AdminAvatar/index.js +2 -2
- package/admin/src/components/AdminAvatar/styles.js +10 -2
- package/admin/src/components/Avatar/index.js +3 -6
- package/admin/src/components/DiscussionThreadItem/index.js +29 -2
- package/admin/src/components/DiscussionThreadItem/styles.d.ts +1 -0
- package/admin/src/components/DiscussionThreadItem/styles.js +14 -1
- package/admin/src/components/DiscussionThreadItemActions/index.js +13 -7
- package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +2 -1
- package/admin/src/components/DiscussionThreadItemFooter/index.js +2 -2
- package/admin/src/components/ModeratorResponse/index.js +2 -1
- package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.d.ts +1 -1
- package/admin/src/components/PreviewWysiwyg/utils/satinizeHtml.js +2 -2
- package/admin/src/components/Wysiwyg/Editor.js +2 -1
- package/admin/src/components/Wysiwyg/WysiwygNav.js +1 -23
- package/admin/src/components/Wysiwyg/WysiwygStyles.js +1 -1
- package/admin/src/pages/Details/index.js +4 -3
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +31 -2
- package/admin/src/pages/Settings/index.js +8 -3
- package/admin/src/translations/en.json +3 -1
- package/package.json +3 -3
- package/server/config/index.js +1 -0
- package/server/services/admin.js +12 -10
- package/server/services/client.js +6 -3
- package/server/services/common.js +16 -11
- package/server/services/utils/functions.d.ts +1 -1
- package/server/services/utils/functions.js +4 -2
- package/server/utils/constants.js +1 -0
- package/strapi-server.d.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/server/services/admin.js
CHANGED
|
@@ -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
|
-
|
|
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`);
|
|
@@ -32,12 +32,15 @@ module.exports = ({ strapi }) => ({
|
|
|
32
32
|
const result = strapi.config.get(`plugin.comments${queryProp ? "." + queryProp : ""}`);
|
|
33
33
|
return (0, lodash_1.isNil)(result) ? defaultValue : result;
|
|
34
34
|
},
|
|
35
|
-
async findAllFlat({ query = {}, populate = {}, sort, pagination, fields, }, relatedEntity = null) {
|
|
35
|
+
async findAllFlat({ query = {}, populate = {}, sort, pagination, fields, isAdmin = false, }, relatedEntity = null) {
|
|
36
36
|
const defaultSelect = ["id", "related"];
|
|
37
37
|
const populateClause = {
|
|
38
38
|
authorUser: true,
|
|
39
39
|
...((0, lodash_1.isObject)(populate) ? populate : {}),
|
|
40
40
|
};
|
|
41
|
+
const doNotPopulateAuthor = isAdmin
|
|
42
|
+
? []
|
|
43
|
+
: await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
41
44
|
let queryExtension = {};
|
|
42
45
|
if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
|
|
43
46
|
queryExtension = {
|
|
@@ -146,16 +149,17 @@ module.exports = ({ strapi }) => ({
|
|
|
146
149
|
: query.threadOf;
|
|
147
150
|
let authorUserPopulate = {};
|
|
148
151
|
if ((0, lodash_1.isObject)(populateClause?.authorUser)) {
|
|
149
|
-
authorUserPopulate =
|
|
150
|
-
populateClause.authorUser
|
|
151
|
-
|
|
152
|
+
authorUserPopulate =
|
|
153
|
+
"populate" in populateClause.authorUser
|
|
154
|
+
? populateClause.authorUser.populate
|
|
155
|
+
: populateClause.authorUser;
|
|
152
156
|
}
|
|
153
157
|
return this.sanitizeCommentEntity({
|
|
154
158
|
..._,
|
|
155
159
|
threadOf: parsedThreadOf || _.threadOf || null,
|
|
156
160
|
gotThread: (threadedItem?.itemsInTread || 0) > 0,
|
|
157
161
|
threadFirstItemId: threadedItem?.firstThreadItemId,
|
|
158
|
-
}, authorUserPopulate);
|
|
162
|
+
}, doNotPopulateAuthor, authorUserPopulate);
|
|
159
163
|
});
|
|
160
164
|
return {
|
|
161
165
|
data: hasRelatedEntitiesToMap
|
|
@@ -164,8 +168,8 @@ module.exports = ({ strapi }) => ({
|
|
|
164
168
|
...((0, lodash_1.isEmpty)(meta) ? {} : { meta }),
|
|
165
169
|
};
|
|
166
170
|
},
|
|
167
|
-
async findAllInHierarchy({ query, populate = {}, sort, fields, startingFromId = null, dropBlockedThreads = false, }, relatedEntity) {
|
|
168
|
-
const entities = await this.findAllFlat({ query, populate, sort, fields }, relatedEntity);
|
|
171
|
+
async findAllInHierarchy({ query, populate = {}, sort, fields, startingFromId = null, dropBlockedThreads = false, isAdmin = false, }, relatedEntity) {
|
|
172
|
+
const entities = await this.findAllFlat({ query, populate, sort, fields, isAdmin }, relatedEntity);
|
|
169
173
|
return (0, functions_1.buildNestedStructure)(entities?.data, startingFromId, "threadOf", dropBlockedThreads, false);
|
|
170
174
|
},
|
|
171
175
|
async findOne(criteria) {
|
|
@@ -181,7 +185,8 @@ module.exports = ({ strapi }) => ({
|
|
|
181
185
|
if (!entity) {
|
|
182
186
|
throw new error_1.default(404, "Comment does not exist. Check your payload please.");
|
|
183
187
|
}
|
|
184
|
-
|
|
188
|
+
const doNotPopulateAuthor = await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
189
|
+
return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity, doNotPopulateAuthor));
|
|
185
190
|
},
|
|
186
191
|
async findRelatedEntitiesFor(entities = []) {
|
|
187
192
|
const data = entities.reduce((acc, curr) => {
|
|
@@ -235,7 +240,7 @@ module.exports = ({ strapi }) => ({
|
|
|
235
240
|
return false;
|
|
236
241
|
}
|
|
237
242
|
},
|
|
238
|
-
sanitizeCommentEntity(entity, populate) {
|
|
243
|
+
sanitizeCommentEntity(entity, blockedAuthorProps, populate) {
|
|
239
244
|
const fieldsToPopulate = (0, lodash_1.isArray)(populate)
|
|
240
245
|
? populate
|
|
241
246
|
: Object.keys(populate || {});
|
|
@@ -243,9 +248,9 @@ module.exports = ({ strapi }) => ({
|
|
|
243
248
|
...(0, functions_1.buildAuthorModel)({
|
|
244
249
|
...entity,
|
|
245
250
|
threadOf: (0, lodash_1.isObject)(entity.threadOf)
|
|
246
|
-
? (0, functions_1.buildAuthorModel)(entity.threadOf, fieldsToPopulate)
|
|
251
|
+
? (0, functions_1.buildAuthorModel)(entity.threadOf, blockedAuthorProps, fieldsToPopulate)
|
|
247
252
|
: entity.threadOf,
|
|
248
|
-
}, fieldsToPopulate),
|
|
253
|
+
}, blockedAuthorProps, fieldsToPopulate),
|
|
249
254
|
};
|
|
250
255
|
},
|
|
251
256
|
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
|
|
95
|
+
author,
|
|
94
96
|
};
|
|
95
97
|
};
|
|
96
98
|
exports.buildAuthorModel = buildAuthorModel;
|
package/strapi-server.d.ts
CHANGED
|
@@ -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;
|