strapi-plugin-comments 2.0.8 → 2.1.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.
- package/README.md +171 -127
- package/admin/src/components/ActionButton/styles.d.ts +2 -0
- package/admin/src/components/ActionButton/styles.js +13 -8
- package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
- package/admin/src/components/ConfirmationDialog/index.js +36 -55
- package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
- package/admin/src/components/DiscussionStatus/index.js +22 -31
- package/admin/src/components/DiscussionThread/index.d.ts +16 -0
- package/admin/src/components/DiscussionThread/index.js +39 -56
- package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
- package/admin/src/components/DiscussionThreadItem/index.js +28 -52
- package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
- package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
- package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
- package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
- package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
- package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
- package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
- package/admin/src/components/DiscussionThreadItemFooter/index.js +35 -42
- package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
- package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
- package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
- package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
- package/admin/src/components/FormSwitch/index.d.ts +7 -0
- package/admin/src/components/FormSwitch/index.js +15 -18
- package/admin/src/components/FormSwitch/styles.d.ts +2 -0
- package/admin/src/components/FormSwitch/styles.js +14 -8
- package/admin/src/components/IconButton/styles.d.ts +2 -0
- package/admin/src/components/IconButton/styles.js +16 -9
- package/admin/src/components/Initializer/index.d.ts +5 -0
- package/admin/src/components/Initializer/index.js +12 -24
- package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
- package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
- package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
- package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
- package/admin/src/components/Nav/index.d.ts +7 -0
- package/admin/src/components/Nav/index.js +25 -48
- package/admin/src/components/PluginIcon/index.d.ts +3 -0
- package/admin/src/components/PluginIcon/index.js +10 -12
- package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
- package/admin/src/components/ReportsReviewModal/index.js +31 -46
- package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
- package/admin/src/components/ReportsReviewTable/index.js +120 -140
- package/admin/src/components/StatusBadge/index.d.ts +7 -0
- package/admin/src/components/StatusBadge/index.js +12 -17
- package/admin/src/components/StatusBadge/styles.d.ts +2 -0
- package/admin/src/components/StatusBadge/styles.js +19 -13
- package/admin/src/components/TableFilters/index.d.ts +10 -0
- package/admin/src/components/TableFilters/index.js +52 -49
- package/admin/src/components/TablePagination/index.d.ts +17 -0
- package/admin/src/components/TablePagination/index.js +27 -29
- package/admin/src/components/icons/comments.d.ts +6 -0
- package/admin/src/components/icons/comments.js +11 -8
- package/admin/src/components/icons/index.d.ts +6 -0
- package/admin/src/components/icons/index.js +15 -6
- package/admin/src/components/icons/lock.d.ts +7 -0
- package/admin/src/components/icons/lock.js +11 -21
- package/admin/src/components/icons/review.d.ts +7 -0
- package/admin/src/components/icons/review.js +11 -17
- package/admin/src/components/icons/unlock.d.ts +7 -0
- package/admin/src/components/icons/unlock.js +11 -19
- package/admin/src/hooks/useConfig.d.ts +8 -0
- package/admin/src/hooks/useConfig.js +40 -45
- package/admin/src/index.d.ts +7 -0
- package/admin/src/index.js +98 -92
- package/admin/src/pages/App/index.d.ts +4 -0
- package/admin/src/pages/App/index.js +43 -67
- package/admin/src/pages/App/reducer/actions.d.ts +8 -0
- package/admin/src/pages/App/reducer/actions.js +11 -7
- package/admin/src/pages/App/reducer/constants.d.ts +4 -0
- package/admin/src/pages/App/reducer/constants.js +7 -4
- package/admin/src/pages/App/reducer/index.d.ts +9 -0
- package/admin/src/pages/App/reducer/index.js +24 -22
- package/admin/src/pages/App/reducer/init.d.ts +3 -0
- package/admin/src/pages/App/reducer/init.js +6 -4
- package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
- package/admin/src/pages/App/reducer/selectors.js +17 -34
- package/admin/src/pages/App/utils/api.d.ts +2 -0
- package/admin/src/pages/App/utils/api.js +14 -11
- package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
- package/admin/src/pages/ComingSoonPage/index.js +42 -24
- package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
- package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
- package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
- package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
- package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
- package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
- package/admin/src/pages/Details/index.d.ts +4 -0
- package/admin/src/pages/Details/index.js +94 -133
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
- package/admin/src/pages/Discover/index.d.ts +4 -0
- package/admin/src/pages/Discover/index.js +129 -170
- package/admin/src/pages/Discover/utils/api.d.ts +2 -0
- package/admin/src/pages/Discover/utils/api.js +15 -13
- package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
- package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
- package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
- package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
- package/admin/src/pages/Settings/index.d.ts +3 -0
- package/admin/src/pages/Settings/index.js +225 -391
- package/admin/src/pages/Settings/utils/api.d.ts +7 -0
- package/admin/src/pages/Settings/utils/api.js +60 -55
- package/admin/src/pages/utils/api.d.ts +12 -0
- package/admin/src/pages/utils/api.js +58 -53
- package/admin/src/permissions.d.ts +28 -0
- package/admin/src/permissions.js +31 -17
- package/admin/src/pluginId.d.ts +2 -0
- package/admin/src/pluginId.js +29 -5
- package/admin/src/reducers.d.ts +7 -0
- package/admin/src/reducers.js +10 -6
- package/admin/src/translations/en.json +131 -130
- package/admin/src/translations/fr.json +1 -1
- package/admin/src/translations/pt-BR.json +132 -0
- package/admin/src/utils/axiosInstance.d.ts +3 -0
- package/admin/src/utils/axiosInstance.js +21 -27
- package/admin/src/utils/constants.d.ts +25 -0
- package/admin/src/utils/constants.js +23 -22
- package/admin/src/utils/getApiUrl.d.ts +3 -0
- package/admin/src/utils/getApiUrl.js +6 -5
- package/admin/src/utils/getMessage.d.ts +4 -0
- package/admin/src/utils/getMessage.js +15 -15
- package/admin/src/utils/getRelatedGroups.d.ts +4 -0
- package/admin/src/utils/getRelatedGroups.js +5 -3
- package/admin/src/utils/getUrl.d.ts +3 -0
- package/admin/src/utils/getUrl.js +6 -5
- package/admin/src/utils/handleAPIError.d.ts +4 -0
- package/admin/src/utils/handleAPIError.js +12 -11
- package/admin/src/utils/index.d.ts +12 -0
- package/admin/src/utils/index.js +29 -11
- package/admin/src/utils/parseRegExp.d.ts +6 -0
- package/admin/src/utils/parseRegExp.js +6 -5
- package/admin/src/utils/renderEntryTitle.d.ts +4 -0
- package/admin/src/utils/renderEntryTitle.js +11 -12
- package/admin/src/utils/renderInitials.d.ts +3 -0
- package/admin/src/utils/renderInitials.js +10 -5
- package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
- package/admin/src/utils/resolveCommentStatus.js +17 -21
- package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
- package/admin/src/utils/resolveCommentStatusColor.js +19 -19
- package/content-types/comment.d.ts +91 -0
- package/content-types/comment.js +87 -88
- package/content-types/index.d.ts +143 -0
- package/content-types/index.js +15 -10
- package/content-types/report.d.ts +48 -0
- package/content-types/report.js +44 -49
- package/package.json +24 -19
- package/permissions.d.ts +18 -0
- package/permissions.js +12 -13
- package/server/bootstrap.d.ts +4 -0
- package/server/bootstrap.js +56 -62
- package/server/config/index.d.ts +4 -0
- package/server/config/index.js +17 -15
- package/server/controllers/admin.d.ts +4 -0
- package/server/controllers/admin.js +134 -167
- package/server/controllers/client.d.ts +4 -0
- package/server/controllers/client.js +104 -115
- package/server/controllers/index.d.ts +6 -0
- package/server/controllers/index.js +12 -8
- package/server/controllers/utils/functions.d.ts +7 -0
- package/server/controllers/utils/functions.js +22 -17
- package/server/controllers/utils/parsers.d.ts +15 -0
- package/server/controllers/utils/parsers.js +17 -17
- package/server/destroy.d.ts +3 -0
- package/server/destroy.js +3 -4
- package/server/graphql/index.d.ts +4 -0
- package/server/graphql/index.js +27 -25
- package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
- package/server/graphql/mutations/createAbuseReport.js +22 -24
- package/server/graphql/mutations/createComment.d.ts +14 -0
- package/server/graphql/mutations/createComment.js +22 -24
- package/server/graphql/mutations/index.d.ts +4 -0
- package/server/graphql/mutations/index.js +24 -19
- package/server/graphql/mutations/removeComment.d.ts +11 -0
- package/server/graphql/mutations/removeComment.js +22 -24
- package/server/graphql/mutations/updateComment.d.ts +11 -0
- package/server/graphql/mutations/updateComment.js +22 -24
- package/server/graphql/queries/findAllFlat.d.ts +19 -0
- package/server/graphql/queries/findAllFlat.js +31 -30
- package/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
- package/server/graphql/queries/findAllInHierarchy.js +26 -30
- package/server/graphql/queries/index.d.ts +4 -0
- package/server/graphql/queries/index.js +20 -17
- package/server/graphql/resolvers-config.d.ts +23 -0
- package/server/graphql/resolvers-config.js +11 -11
- package/server/graphql/types/comment-author.d.ts +4 -0
- package/server/graphql/types/comment-author.js +10 -8
- package/server/graphql/types/comment-nested.d.ts +4 -0
- package/server/graphql/types/comment-nested.js +17 -15
- package/server/graphql/types/comment.d.ts +4 -0
- package/server/graphql/types/comment.js +16 -14
- package/server/graphql/types/create-comment-author.d.ts +4 -0
- package/server/graphql/types/create-comment-author.js +10 -8
- package/server/graphql/types/create-comment.d.ts +4 -0
- package/server/graphql/types/create-comment.js +10 -8
- package/server/graphql/types/create-report.d.ts +4 -0
- package/server/graphql/types/create-report.js +10 -8
- package/server/graphql/types/id.d.ts +4 -0
- package/server/graphql/types/id.js +24 -23
- package/server/graphql/types/identify-comment-author.d.ts +4 -0
- package/server/graphql/types/identify-comment-author.js +7 -5
- package/server/graphql/types/index.d.ts +4 -0
- package/server/graphql/types/index.js +36 -17
- package/server/graphql/types/remove-comment.d.ts +4 -0
- package/server/graphql/types/remove-comment.js +9 -7
- package/server/graphql/types/report-reason.d.ts +4 -0
- package/server/graphql/types/report-reason.js +10 -8
- package/server/graphql/types/report.d.ts +4 -0
- package/server/graphql/types/report.js +12 -10
- package/server/graphql/types/response-find-all.d.ts +4 -0
- package/server/graphql/types/response-find-all.js +8 -6
- package/server/graphql/types/response-meta.d.ts +4 -0
- package/server/graphql/types/response-meta.js +7 -5
- package/server/graphql/types/response-pagination.d.ts +4 -0
- package/server/graphql/types/response-pagination.js +12 -10
- package/server/graphql/types/update-comment.d.ts +4 -0
- package/server/graphql/types/update-comment.js +10 -8
- package/server/index.d.ts +26 -0
- package/server/index.js +24 -21
- package/server/register.d.ts +3 -0
- package/server/register.js +3 -4
- package/server/routes/admin.d.ts +4 -0
- package/server/routes/admin.js +103 -109
- package/server/routes/client.d.ts +4 -0
- package/server/routes/client.js +48 -46
- package/server/routes/index.d.ts +11 -0
- package/server/routes/index.js +18 -14
- package/server/services/admin.d.ts +5 -0
- package/server/services/admin.js +126 -158
- package/server/services/client.d.ts +5 -0
- package/server/services/client.js +135 -151
- package/server/services/common.d.ts +5 -0
- package/server/services/common.js +165 -194
- package/server/services/graphql.d.ts +5 -0
- package/server/services/graphql.js +117 -182
- package/server/services/index.d.ts +8 -0
- package/server/services/index.js +15 -12
- package/server/services/utils/functions.d.ts +13 -0
- package/server/services/utils/functions.js +100 -109
- package/server/utils/constants.d.ts +9 -0
- package/server/utils/constants.js +19 -23
- package/server/utils/error.d.ts +19 -0
- package/server/utils/error.js +23 -18
- package/server/utils/functions.d.ts +6 -0
- package/server/utils/functions.js +35 -18
- package/strapi-admin.d.ts +3 -0
- package/strapi-admin.js +8 -3
- package/strapi-server.d.ts +177 -0
- package/strapi-server.js +43 -46
- package/tsconfig.tsbuildinfo +1 -0
- package/types/contentTypes.d.ts +44 -0
- package/types/contentTypes.js +3 -0
- package/.husky/pre-commit +0 -4
- package/LICENSE.md +0 -7
- package/__mocks__/initSetup.js +0 -108
- package/jest.config.js +0 -7
- package/server/controllers/utils/__tests__/functions.test.js +0 -43
- package/server/controllers/utils/__tests__/parsers.test.js +0 -94
- package/server/services/__tests__/common.test.js +0 -399
- package/server/services/utils/__tests__/functions.test.js +0 -53
- package/server/utils/__tests__/functions.test.js +0 -17
|
@@ -1,73 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
getRelatedGroups,
|
|
11
|
-
resolveUserContextError,
|
|
12
|
-
} = require('./utils/functions');
|
|
13
|
-
const { APPROVAL_STATUS, REGEX, CONFIG_PARAMS } = require('./../utils/constants')
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Comments Plugin - Client services
|
|
17
|
-
*/
|
|
18
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const functions_1 = require("./../utils/functions");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const error_1 = __importDefault(require("./../utils/error"));
|
|
8
|
+
const functions_2 = require("./utils/functions");
|
|
9
|
+
const constants_1 = require("./../utils/constants");
|
|
19
10
|
module.exports = ({ strapi }) => ({
|
|
20
|
-
|
|
21
11
|
getCommonService() {
|
|
22
|
-
return getPluginService(
|
|
12
|
+
return (0, functions_1.getPluginService)("common");
|
|
23
13
|
},
|
|
24
|
-
|
|
25
|
-
// Create a comment
|
|
26
14
|
async create(relation, data, user = undefined) {
|
|
27
15
|
const { content, threadOf } = data;
|
|
28
|
-
const singleRelationFulfilled = relation && REGEX.relatedUid.test(relation);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
throw new PluginError(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
16
|
+
const singleRelationFulfilled = relation && constants_1.REGEX.relatedUid.test(relation);
|
|
17
|
+
if (!singleRelationFulfilled) {
|
|
18
|
+
throw new error_1.default(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
32
19
|
}
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
const [uid, relatedId] = await this.getCommonService().parseRelationString(relation);
|
|
21
|
+
const relatedEntity = await strapi.db
|
|
22
|
+
.query(uid)
|
|
23
|
+
.findOne(relatedId);
|
|
37
24
|
if (!relatedEntity) {
|
|
38
|
-
throw new
|
|
25
|
+
throw new error_1.default(400, `Relation for field "related" does not exist. Check your payload please.`);
|
|
39
26
|
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}) : true;
|
|
27
|
+
const approvalFlow = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.APPROVAL_FLOW, []);
|
|
28
|
+
const isApprovalFlowEnabled = approvalFlow.includes(uid) || relatedEntity.requireCommentsApproval;
|
|
29
|
+
const linkToThread = !(0, lodash_1.isNil)(threadOf)
|
|
30
|
+
? await this.getCommonService().findOne({
|
|
31
|
+
id: threadOf,
|
|
32
|
+
related: relation,
|
|
33
|
+
})
|
|
34
|
+
: undefined;
|
|
49
35
|
const validContext = this.getCommonService().isValidUserContext(user);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
throw new PluginError(400, 'Thread does not exist');
|
|
36
|
+
if (linkToThread === null) {
|
|
37
|
+
throw new error_1.default(400, "Thread does not exist");
|
|
53
38
|
}
|
|
54
|
-
|
|
55
39
|
if (!validContext) {
|
|
56
|
-
throw resolveUserContextError(user);
|
|
40
|
+
throw (0, functions_2.resolveUserContextError)(user);
|
|
57
41
|
}
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
if ((await this.getCommonService().checkBadWords(content)) &&
|
|
43
|
+
singleRelationFulfilled) {
|
|
60
44
|
const { author = {}, ...rest } = data;
|
|
61
45
|
let authorData = {};
|
|
62
46
|
if (validContext && user) {
|
|
63
47
|
authorData = {
|
|
64
48
|
authorUser: user?.id,
|
|
65
49
|
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (author.email && !constants_1.REGEX.email.test(author.email)) {
|
|
53
|
+
throw new error_1.default(400, 'Field: "author.email". Author e-mail is not valid value. Check your payload');
|
|
69
54
|
}
|
|
70
|
-
|
|
71
55
|
authorData = {
|
|
72
56
|
authorId: author.id,
|
|
73
57
|
authorName: author.name,
|
|
@@ -75,22 +59,25 @@ module.exports = ({ strapi }) => ({
|
|
|
75
59
|
authorAvatar: author.avatar,
|
|
76
60
|
};
|
|
77
61
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
throw new
|
|
62
|
+
if (!(0, lodash_1.isEmpty)(authorData) &&
|
|
63
|
+
!(authorData.authorId || authorData.authorUser)) {
|
|
64
|
+
throw new error_1.default(400, `Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
|
|
81
65
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw new
|
|
66
|
+
if (isApprovalFlowEnabled &&
|
|
67
|
+
!(0, lodash_1.isNil)(data.approvalStatus) &&
|
|
68
|
+
data.approvalStatus !== constants_1.APPROVAL_STATUS.PENDING) {
|
|
69
|
+
throw new error_1.default(400, "Invalid approval status");
|
|
86
70
|
}
|
|
87
|
-
|
|
88
|
-
|
|
71
|
+
const entity = await strapi.db
|
|
72
|
+
.query((0, functions_2.getModelUid)("comment"))
|
|
73
|
+
.create({
|
|
89
74
|
data: {
|
|
90
75
|
...rest,
|
|
91
76
|
...authorData,
|
|
92
77
|
related: relation,
|
|
93
|
-
approvalStatus: isApprovalFlowEnabled
|
|
78
|
+
approvalStatus: isApprovalFlowEnabled
|
|
79
|
+
? constants_1.APPROVAL_STATUS.PENDING
|
|
80
|
+
: null,
|
|
94
81
|
},
|
|
95
82
|
populate: {
|
|
96
83
|
authorUser: true,
|
|
@@ -98,38 +85,31 @@ module.exports = ({ strapi }) => ({
|
|
|
98
85
|
});
|
|
99
86
|
return this.getCommonService().sanitizeCommentEntity({
|
|
100
87
|
...entity,
|
|
101
|
-
threadOf: !isNil(threadOf) ? linkToThread : null,
|
|
88
|
+
threadOf: !(0, lodash_1.isNil)(threadOf) ? linkToThread : null,
|
|
102
89
|
});
|
|
103
90
|
}
|
|
104
|
-
throw new
|
|
91
|
+
throw new error_1.default(400, "No content received");
|
|
105
92
|
},
|
|
106
|
-
|
|
107
|
-
// Update a comment
|
|
108
93
|
async update(id, relation, data, user = undefined) {
|
|
109
94
|
const { content } = data;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if(!singleRelationFulfilled) {
|
|
114
|
-
throw new PluginError(400, `Request property "relation" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
95
|
+
const singleRelationFulfilled = relation && constants_1.REGEX.relatedUid.test(relation);
|
|
96
|
+
if (!singleRelationFulfilled) {
|
|
97
|
+
throw new error_1.default(400, `Request property "relation" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
115
98
|
}
|
|
116
|
-
|
|
117
99
|
await this.getCommonService().parseRelationString(relation);
|
|
118
|
-
|
|
119
100
|
const existingEntity = await this.getCommonService().findOne({
|
|
120
101
|
id,
|
|
121
102
|
related: relation,
|
|
122
103
|
});
|
|
123
|
-
|
|
124
104
|
const validContext = this.getCommonService().isValidUserContext(user);
|
|
125
|
-
|
|
126
105
|
if (!validContext) {
|
|
127
|
-
throw resolveUserContextError(user);
|
|
106
|
+
throw (0, functions_2.resolveUserContextError)(user);
|
|
128
107
|
}
|
|
129
|
-
|
|
130
|
-
if (isEqualEntity(existingEntity, data, user) && content) {
|
|
108
|
+
if ((0, functions_2.isEqualEntity)(existingEntity, data, user) && content) {
|
|
131
109
|
if (await this.getCommonService().checkBadWords(content)) {
|
|
132
|
-
const entity = await strapi.db
|
|
110
|
+
const entity = await strapi.db
|
|
111
|
+
.query((0, functions_2.getModelUid)("comment"))
|
|
112
|
+
.update({
|
|
133
113
|
where: { id },
|
|
134
114
|
data: { content },
|
|
135
115
|
populate: { threadOf: true, authorUser: true },
|
|
@@ -137,127 +117,131 @@ module.exports = ({ strapi }) => ({
|
|
|
137
117
|
return this.getCommonService().sanitizeCommentEntity(entity);
|
|
138
118
|
}
|
|
139
119
|
}
|
|
140
|
-
throw new
|
|
120
|
+
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.`);
|
|
141
121
|
},
|
|
142
|
-
|
|
143
|
-
// Report abuse in comment
|
|
144
|
-
async reportAbuse(id, relation, payload, user = undefined) {
|
|
122
|
+
async reportAbuse(id, relation, payload, user = undefined) {
|
|
145
123
|
if (!this.getCommonService().isValidUserContext(user)) {
|
|
146
|
-
throw resolveUserContextError(user);
|
|
124
|
+
throw (0, functions_2.resolveUserContextError)(user);
|
|
147
125
|
}
|
|
148
|
-
|
|
149
126
|
await this.getCommonService().parseRelationString(relation);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
id,
|
|
127
|
+
const reportAgainstEntity = await this.getCommonService().findOne({
|
|
128
|
+
id,
|
|
153
129
|
related: relation,
|
|
154
130
|
});
|
|
155
|
-
|
|
156
|
-
const entity = await strapi.db
|
|
131
|
+
if (reportAgainstEntity) {
|
|
132
|
+
const entity = await strapi.db
|
|
133
|
+
.query((0, functions_2.getModelUid)("comment-report"))
|
|
134
|
+
.create({
|
|
157
135
|
data: {
|
|
158
136
|
...payload,
|
|
159
137
|
resolved: false,
|
|
160
138
|
related: id,
|
|
161
|
-
}
|
|
139
|
+
},
|
|
162
140
|
});
|
|
163
|
-
|
|
141
|
+
if (entity) {
|
|
164
142
|
const response = {
|
|
165
143
|
...entity,
|
|
166
144
|
related: reportAgainstEntity,
|
|
167
145
|
};
|
|
168
146
|
try {
|
|
169
|
-
await this.sendAbuseReportEmail(entity.reason, entity.content);
|
|
170
|
-
return response
|
|
171
|
-
} catch (err) {
|
|
147
|
+
await this.sendAbuseReportEmail(entity.reason, entity.content);
|
|
172
148
|
return response;
|
|
173
149
|
}
|
|
174
|
-
|
|
175
|
-
|
|
150
|
+
catch (err) {
|
|
151
|
+
return response;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
throw new error_1.default(500, "Report cannot be created");
|
|
176
156
|
}
|
|
177
157
|
}
|
|
178
|
-
throw new
|
|
158
|
+
throw new error_1.default(403, `You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.`);
|
|
179
159
|
},
|
|
180
|
-
|
|
181
|
-
async markAsRemoved(id, relation, authorId, user = undefined){
|
|
160
|
+
async markAsRemoved(id, relation, authorId, user = undefined) {
|
|
182
161
|
if (!this.getCommonService().isValidUserContext(user)) {
|
|
183
|
-
throw resolveUserContextError(user);
|
|
162
|
+
throw (0, functions_2.resolveUserContextError)(user);
|
|
184
163
|
}
|
|
185
|
-
|
|
186
164
|
const author = user?.id || authorId;
|
|
187
|
-
|
|
188
165
|
if (!author) {
|
|
189
|
-
throw new
|
|
166
|
+
throw new error_1.default(403, `You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`);
|
|
190
167
|
}
|
|
191
|
-
|
|
192
168
|
await this.getCommonService().parseRelationString(relation);
|
|
193
|
-
|
|
194
|
-
let entity;
|
|
195
169
|
try {
|
|
196
|
-
const byAuthor = user?.id
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
170
|
+
const byAuthor = user?.id
|
|
171
|
+
? {
|
|
172
|
+
authorUser: author,
|
|
173
|
+
}
|
|
174
|
+
: {
|
|
175
|
+
authorId: author,
|
|
176
|
+
};
|
|
177
|
+
const entity = await this.getCommonService().findOne({
|
|
202
178
|
id,
|
|
203
179
|
related: relation,
|
|
204
180
|
...byAuthor,
|
|
205
181
|
});
|
|
206
|
-
|
|
207
|
-
|
|
182
|
+
if (entity) {
|
|
183
|
+
const removedEntity = await strapi.db
|
|
184
|
+
.query((0, functions_2.getModelUid)("comment"))
|
|
185
|
+
.update({
|
|
186
|
+
where: {
|
|
187
|
+
id,
|
|
188
|
+
related: relation,
|
|
189
|
+
},
|
|
190
|
+
data: { removed: true },
|
|
191
|
+
populate: { threadOf: true, authorUser: true },
|
|
192
|
+
});
|
|
193
|
+
await this.markAsRemovedNested(id, true);
|
|
194
|
+
return this.getCommonService().sanitizeCommentEntity(removedEntity);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
throw new error_1.default(404, `Entity does not exist or you're not allowed to take an action on it`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
throw new error_1.default(404, `Entity does not exist or you're not allowed to take an action on it`);
|
|
208
202
|
}
|
|
209
|
-
|
|
210
|
-
const removedEntity = await strapi.db.query(getModelUid('comment'))
|
|
211
|
-
.update({
|
|
212
|
-
where: {
|
|
213
|
-
id,
|
|
214
|
-
related: relation
|
|
215
|
-
},
|
|
216
|
-
data: { removed: true },
|
|
217
|
-
populate: { threadOf: true, authorUser: true },
|
|
218
|
-
})
|
|
219
|
-
await this.markAsRemovedNested(id, true);
|
|
220
|
-
|
|
221
|
-
return this.getCommonService().sanitizeCommentEntity(removedEntity);
|
|
222
203
|
},
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
where: {
|
|
204
|
+
async sendAbuseReportEmail(reason, content) {
|
|
205
|
+
const rolesToBeNotified = (await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.MODERATOR_ROLES)) || ["strapi-super-admin"];
|
|
206
|
+
const adminUserModel = strapi.db.query("admin::user");
|
|
207
|
+
const emails = await adminUserModel
|
|
208
|
+
.findMany({
|
|
209
|
+
where: {
|
|
230
210
|
roles: { code: rolesToBeNotified },
|
|
231
211
|
},
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
|
|
212
|
+
})
|
|
213
|
+
.then((items) => items.map((_) => _.email));
|
|
214
|
+
const superAdmin = await strapi.db
|
|
215
|
+
.query("admin::user")
|
|
235
216
|
.findOne({
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (emails.length > 0) {
|
|
217
|
+
where: {
|
|
218
|
+
roles: { code: "strapi-super-admin" },
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
if (emails.length > 0) {
|
|
242
222
|
try {
|
|
243
|
-
await strapi
|
|
223
|
+
await strapi
|
|
224
|
+
.plugin("email")
|
|
225
|
+
.service("email")
|
|
226
|
+
.send({
|
|
244
227
|
to: emails,
|
|
245
228
|
from: superAdmin.email,
|
|
246
|
-
subject:
|
|
229
|
+
subject: "New abuse report on comment",
|
|
247
230
|
text: `
|
|
248
231
|
There was a new abuse report on your app.
|
|
249
232
|
Reason: ${reason}
|
|
250
233
|
Message: ${content}
|
|
251
234
|
`,
|
|
252
235
|
});
|
|
253
|
-
}
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
254
238
|
strapi.log.error(err);
|
|
255
239
|
throw err;
|
|
256
240
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return this.getCommonService().modifiedNestedNestedComments(id, 'removed', status);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
async markAsRemovedNested(id, status) {
|
|
244
|
+
return this.getCommonService().modifiedNestedNestedComments(id, "removed", status);
|
|
262
245
|
},
|
|
263
246
|
});
|
|
247
|
+
//# sourceMappingURL=client.js.map
|