strapi-plugin-comments 2.0.0-beta.3 → 2.0.0-beta.7
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 +335 -11
- package/admin/src/components/DiscussionThread/index.js +9 -2
- package/admin/src/components/DiscussionThreadItem/index.js +27 -12
- package/admin/src/components/DiscussionThreadItemActions/index.js +61 -50
- package/admin/src/components/DiscussionThreadItemActions/styles.js +0 -4
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +81 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +6 -0
- package/admin/src/components/DiscussionThreadItemMeta/index.js +16 -5
- package/admin/src/components/DiscussionThreadItemWarnings/index.js +16 -10
- package/admin/src/components/Nav/index.js +5 -1
- package/admin/src/components/ReportsReviewModal/index.js +5 -0
- package/admin/src/components/ReportsReviewTable/index.js +60 -52
- package/admin/src/components/icons/review.js +2 -2
- package/admin/src/index.js +1 -1
- package/admin/src/pages/Details/components/DetailsEntity/index.js +66 -0
- package/admin/src/pages/Details/components/DetailsFilters/index.js +37 -0
- package/admin/src/pages/Details/components/DetailsFilters/styles.js +8 -0
- package/admin/src/pages/Details/index.js +75 -42
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +69 -48
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +8 -0
- package/admin/src/pages/Discover/index.js +72 -56
- package/admin/src/pages/{Details/utils → utils}/api.js +15 -3
- package/admin/src/permissions.js +10 -8
- package/admin/src/translations/en.json +17 -4
- package/admin/src/utils/constants.js +3 -6
- package/admin/src/utils/getMessage.js +1 -1
- package/admin/src/utils/getRelatedGroups.js +1 -3
- package/admin/src/utils/index.js +6 -2
- package/admin/src/utils/renderEntryTitle.js +14 -0
- package/admin/src/utils/renderInitials.js +5 -0
- package/admin/src/utils/resolveCommentStatus.js +30 -0
- package/admin/src/utils/resolveCommentStatusColor.js +22 -0
- package/package.json +8 -3
- package/permissions.js +19 -0
- package/server/bootstrap.js +38 -2
- package/server/config/index.js +9 -3
- package/server/controllers/admin.js +3 -3
- package/server/controllers/client.js +4 -18
- package/server/controllers/utils/parsers.js +17 -0
- package/server/graphql/index.js +26 -0
- package/server/graphql/mutations/createAbuseReport.js +20 -0
- package/server/graphql/mutations/createComment.js +20 -0
- package/server/graphql/mutations/index.js +21 -0
- package/server/graphql/mutations/removeComment.js +20 -0
- package/server/graphql/mutations/updateComment.js +20 -0
- package/server/graphql/queries/findAllFlat.js +29 -0
- package/server/graphql/queries/findAllInHierarchy.js +31 -0
- package/server/graphql/queries/index.js +19 -0
- package/server/graphql/resolvers-config.js +10 -0
- package/server/graphql/types/comment-author-user.js +9 -0
- package/server/graphql/types/comment-author.js +9 -0
- package/server/graphql/types/comment-nested.js +16 -0
- package/server/graphql/types/comment.js +16 -0
- package/server/graphql/types/create-comment-author.js +9 -0
- package/server/graphql/types/create-comment.js +9 -0
- package/server/graphql/types/create-report.js +9 -0
- package/server/graphql/types/id.js +24 -0
- package/server/graphql/types/identify-comment-author.js +6 -0
- package/server/graphql/types/index.js +17 -0
- package/server/graphql/types/remove-comment.js +8 -0
- package/server/graphql/types/report-reason.js +10 -0
- package/server/graphql/types/report.js +11 -0
- package/server/graphql/types/update-comment.js +9 -0
- package/server/register.js +3 -1
- package/server/services/admin.js +42 -15
- package/server/services/client.js +54 -38
- package/server/services/common.js +38 -67
- package/server/services/graphql.js +190 -0
- package/server/services/index.js +2 -0
- package/server/services/utils/functions.js +24 -17
- package/server/utils/constants.js +3 -3
- package/strapi-server.js +33 -0
- package/admin/src/components/EntityDetails/index.js +0 -53
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = ({ }) => ({
|
|
4
|
+
'Query.findAllFlat': { auth: false },
|
|
5
|
+
'Query.findAllInHierarchy': { auth: false },
|
|
6
|
+
'Mutation.createComment': { auth: false },
|
|
7
|
+
'Mutation.updateComment': { auth: false },
|
|
8
|
+
'Mutation.removeComment': { auth: false },
|
|
9
|
+
'Mutation.createAbuseReport': { auth: false },
|
|
10
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = ({ nexus }) => nexus.objectType({
|
|
2
|
+
name: "CommentNested",
|
|
3
|
+
definition(t) {
|
|
4
|
+
t.id("id")
|
|
5
|
+
t.nonNull.string("content")
|
|
6
|
+
t.boolean("blocked")
|
|
7
|
+
t.boolean("blockedThread")
|
|
8
|
+
t.string("approvalStatus")
|
|
9
|
+
t.field("threadOf", { type: 'CommentSingle' })
|
|
10
|
+
t.list.field("children", { type: 'CommentNested' })
|
|
11
|
+
t.field("authorUser", { type: 'CommentAuthorUser' })
|
|
12
|
+
t.field("author", { type: 'CommentAuthor' })
|
|
13
|
+
t.string("createdAt")
|
|
14
|
+
t.string("updatedAt")
|
|
15
|
+
}
|
|
16
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = ({ nexus }) => nexus.objectType({
|
|
2
|
+
name: "CommentSingle",
|
|
3
|
+
definition(t) {
|
|
4
|
+
t.id("id")
|
|
5
|
+
t.nonNull.string("content")
|
|
6
|
+
t.boolean("blocked")
|
|
7
|
+
t.boolean("blockedThread")
|
|
8
|
+
t.boolean("removed")
|
|
9
|
+
t.string("approvalStatus")
|
|
10
|
+
t.field("threadOf", { type: 'CommentSingle' })
|
|
11
|
+
t.field("authorUser", { type: 'CommentAuthorUser' })
|
|
12
|
+
t.field("author", { type: 'CommentAuthor' })
|
|
13
|
+
t.string("createdAt")
|
|
14
|
+
t.string("updatedAt")
|
|
15
|
+
}
|
|
16
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { isNumber, parseInt } = require('lodash');
|
|
2
|
+
const { Kind } = require('graphql');
|
|
3
|
+
|
|
4
|
+
module.exports = ({ nexus }) => nexus.scalarType({
|
|
5
|
+
name: "Id",
|
|
6
|
+
asNexusMethod: 'id',
|
|
7
|
+
description: 'Id as string or int',
|
|
8
|
+
parseValue(value) {
|
|
9
|
+
const parsedValue = parseInt(value);
|
|
10
|
+
if (isNumber(parsedValue)) {
|
|
11
|
+
return parsedValue;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
},
|
|
15
|
+
serialize(value) {
|
|
16
|
+
return value;
|
|
17
|
+
},
|
|
18
|
+
parseLiteral(ast) {
|
|
19
|
+
if ([Kind.INT, Kind.STRING].includes(ast.kind)) {
|
|
20
|
+
return ast.value;
|
|
21
|
+
}
|
|
22
|
+
return null
|
|
23
|
+
},
|
|
24
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const typesFactories = [
|
|
2
|
+
require('./id'),
|
|
3
|
+
require('./comment'),
|
|
4
|
+
require('./comment-nested'),
|
|
5
|
+
require('./comment-author'),
|
|
6
|
+
require('./comment-author-user'),
|
|
7
|
+
require('./create-comment'),
|
|
8
|
+
require('./create-comment-author'),
|
|
9
|
+
require('./update-comment'),
|
|
10
|
+
require('./remove-comment'),
|
|
11
|
+
require('./identify-comment-author'),
|
|
12
|
+
require('./report'),
|
|
13
|
+
require('./report-reason'),
|
|
14
|
+
require('./create-report'),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
module.exports = context => typesFactories.map(factory => factory(context));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { getPluginService } = require("../../utils/functions");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module.exports = ({ nexus }) => nexus.enumType({
|
|
5
|
+
name: "ReportReason",
|
|
6
|
+
description: 'Reason of abuse report',
|
|
7
|
+
members: {
|
|
8
|
+
...getPluginService('common').getConfig('reportReasons', {})
|
|
9
|
+
},
|
|
10
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = ({ nexus }) => nexus.objectType({
|
|
2
|
+
name: "Report",
|
|
3
|
+
definition(t) {
|
|
4
|
+
t.id("id")
|
|
5
|
+
t.nonNull.string("content")
|
|
6
|
+
t.field("reason", { type: 'ReportReason' })
|
|
7
|
+
t.field("related", { type: 'CommentSingle' })
|
|
8
|
+
t.string("createdAt")
|
|
9
|
+
t.string("updatedAt")
|
|
10
|
+
}
|
|
11
|
+
})
|
package/server/register.js
CHANGED
package/server/services/admin.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { getPluginService, parseParams } = require('./../utils/functions');
|
|
4
|
-
const {
|
|
5
|
-
const { first, isEmpty, isNil, uniq, get } = require('lodash');
|
|
4
|
+
const { isEmpty, isNil, isNumber, parseInt } = require('lodash');
|
|
6
5
|
const PluginError = require('./../utils/error');
|
|
7
6
|
const {
|
|
8
7
|
getModelUid,
|
|
9
8
|
getRelatedGroups,
|
|
10
9
|
filterOurResolvedReports,
|
|
11
|
-
convertContentTypeNameToSlug
|
|
12
10
|
} = require('./utils/functions');
|
|
13
11
|
const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
14
12
|
|
|
@@ -25,8 +23,14 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
25
23
|
// Config
|
|
26
24
|
async config() {
|
|
27
25
|
const entryLabel = this.getCommonService().getConfig('entryLabel');
|
|
26
|
+
const approvalFlow = this.getCommonService().getConfig('approvalFlow');
|
|
28
27
|
return {
|
|
29
28
|
entryLabel,
|
|
29
|
+
approvalFlow,
|
|
30
|
+
regex: Object.keys(REGEX).reduce((prev, curr) => ({
|
|
31
|
+
...prev,
|
|
32
|
+
[curr]: REGEX[curr].toString(),
|
|
33
|
+
}), {}),
|
|
30
34
|
};
|
|
31
35
|
},
|
|
32
36
|
|
|
@@ -34,10 +38,18 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
34
38
|
async findAll({ related, entity, ...query }) {
|
|
35
39
|
const { _q, orderBy, pageSize = 10, page = 1, filters, ...rest } = parseParams(query);
|
|
36
40
|
|
|
41
|
+
const defaultWhere = {
|
|
42
|
+
$or: [
|
|
43
|
+
{ removed: false },
|
|
44
|
+
{ removed: null },
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
|
|
37
48
|
let params = {
|
|
38
49
|
where: !isEmpty(filters) ? {
|
|
50
|
+
...defaultWhere,
|
|
39
51
|
...filters,
|
|
40
|
-
} :
|
|
52
|
+
} : { ...defaultWhere },
|
|
41
53
|
offset: (page - 1)*pageSize,
|
|
42
54
|
limit: pageSize,
|
|
43
55
|
orderBy: orderBy || [{ createdAt: 'desc' }],
|
|
@@ -59,6 +71,7 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
59
71
|
...params,
|
|
60
72
|
populate: {
|
|
61
73
|
authorUser: true,
|
|
74
|
+
threadOf: true,
|
|
62
75
|
reports: {
|
|
63
76
|
where: {
|
|
64
77
|
resolved: false
|
|
@@ -75,19 +88,27 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
75
88
|
.map(_ => filterOurResolvedReports(this.getCommonService().sanitizeCommentEntity(_)))
|
|
76
89
|
.map(_ => this.getCommonService().mergeRelatedEntityTo(_, relatedEntities));
|
|
77
90
|
|
|
91
|
+
const pageCount = Math.floor(total / pageSize);
|
|
78
92
|
return {
|
|
79
93
|
result,
|
|
80
94
|
pagination: {
|
|
81
95
|
page: page,
|
|
82
96
|
pageSize: pageSize,
|
|
83
|
-
pageCount:
|
|
97
|
+
pageCount: total % pageSize === 0 ? pageCount : pageCount + 1,
|
|
84
98
|
total,
|
|
85
99
|
},
|
|
86
100
|
};
|
|
87
101
|
},
|
|
88
102
|
|
|
89
103
|
// Find single comment
|
|
90
|
-
async findOneAndThread(id) {
|
|
104
|
+
async findOneAndThread(id, { removed, ...query }) {
|
|
105
|
+
const defaultWhere = !removed ? {
|
|
106
|
+
$or: [
|
|
107
|
+
{ removed: false },
|
|
108
|
+
{ removed: null },
|
|
109
|
+
],
|
|
110
|
+
} : {};
|
|
111
|
+
|
|
91
112
|
const reportsPopulation = {
|
|
92
113
|
reports: {
|
|
93
114
|
where: {
|
|
@@ -98,7 +119,7 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
98
119
|
|
|
99
120
|
const entity = await strapi.db.query(getModelUid('comment')).findOne({
|
|
100
121
|
where: {
|
|
101
|
-
id
|
|
122
|
+
id,
|
|
102
123
|
},
|
|
103
124
|
populate: {
|
|
104
125
|
authorUser: true,
|
|
@@ -116,7 +137,8 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
116
137
|
}
|
|
117
138
|
|
|
118
139
|
const [relatedUid, relatedStringId] = getRelatedGroups(entity.related);
|
|
119
|
-
const
|
|
140
|
+
const parsedRelatedId = parseInt(relatedStringId);
|
|
141
|
+
const relatedId = isNumber(parsedRelatedId) ? parsedRelatedId : relatedStringId;
|
|
120
142
|
const relatedEntity = await strapi.db.query(relatedUid).findOne({
|
|
121
143
|
where: { id: relatedId }
|
|
122
144
|
}).then(_ => ({
|
|
@@ -132,6 +154,8 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
132
154
|
const entitiesOnSameLevel = await this.getCommonService()
|
|
133
155
|
.findAllInHierarchy({
|
|
134
156
|
query: {
|
|
157
|
+
...defaultWhere,
|
|
158
|
+
...query,
|
|
135
159
|
threadOf: levelThreadId,
|
|
136
160
|
related: entity.related,
|
|
137
161
|
},
|
|
@@ -141,15 +165,14 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
141
165
|
startingFromId: levelThreadId,
|
|
142
166
|
isAdmin: true
|
|
143
167
|
}, false);
|
|
144
|
-
|
|
145
|
-
|
|
168
|
+
const selectedEntity = this.getCommonService().sanitizeCommentEntity({
|
|
169
|
+
...entity,
|
|
170
|
+
threadOf: entity.threadOf || null,
|
|
171
|
+
});
|
|
146
172
|
|
|
147
173
|
return {
|
|
148
174
|
entity: relatedEntity,
|
|
149
|
-
selected:
|
|
150
|
-
...selectedEntity,
|
|
151
|
-
threadOf: selectedEntity.threadOf ? selectedEntity.threadOf : null,
|
|
152
|
-
},
|
|
175
|
+
selected: selectedEntity,
|
|
153
176
|
level: entitiesOnSameLevel,
|
|
154
177
|
};
|
|
155
178
|
},
|
|
@@ -167,9 +190,13 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
167
190
|
// Block / Unblock a comment thread
|
|
168
191
|
async blockCommentThread(id, forceStatus) {
|
|
169
192
|
const existingEntity = await this.getCommonService().findOne({ id });
|
|
193
|
+
const status = !isNil(forceStatus) ? forceStatus : !existingEntity.blockedThread;
|
|
170
194
|
const changedEntity = await strapi.db.query(getModelUid('comment')).update({
|
|
171
195
|
where: { id },
|
|
172
|
-
data: {
|
|
196
|
+
data: {
|
|
197
|
+
blocked: status,
|
|
198
|
+
blockedThread: status,
|
|
199
|
+
},
|
|
173
200
|
});
|
|
174
201
|
await this.blockNestedThreads(id, changedEntity.blockedThread);
|
|
175
202
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const config = require('
|
|
3
|
+
const config = require('../config');
|
|
4
4
|
const { getPluginService } = require('./../utils/functions');
|
|
5
|
-
const { isNil, isEmpty } = require('lodash');
|
|
5
|
+
const { isNil, isEmpty, isNumber, parseInt } = require('lodash');
|
|
6
6
|
const PluginError = require('./../utils/error');
|
|
7
7
|
const {
|
|
8
8
|
isEqualEntity,
|
|
@@ -26,28 +26,28 @@ module.exports = ({ strapi }) => ({
|
|
|
26
26
|
|
|
27
27
|
// Create a comment
|
|
28
28
|
async create(relation, data, user = undefined) {
|
|
29
|
-
const { content, threadOf
|
|
30
|
-
const singleRelationFulfilled =
|
|
31
|
-
|
|
32
|
-
if (relation !== related) {
|
|
33
|
-
throw new PluginError(400, `Insonsistent relation uid`);
|
|
34
|
-
}
|
|
35
|
-
|
|
29
|
+
const { content, threadOf } = data;
|
|
30
|
+
const singleRelationFulfilled = relation && REGEX.relatedUid.test(relation);
|
|
31
|
+
|
|
36
32
|
if(!singleRelationFulfilled) {
|
|
37
33
|
throw new PluginError(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
38
34
|
}
|
|
39
35
|
|
|
40
|
-
const [ uid, relatedStringId ] = getRelatedGroups(
|
|
41
|
-
const
|
|
36
|
+
const [ uid, relatedStringId ] = getRelatedGroups(relation);
|
|
37
|
+
const parsedRelatedId = parseInt(relatedStringId);
|
|
38
|
+
const relatedId = isNumber(parsedRelatedId) ? parsedRelatedId : relatedStringId;
|
|
42
39
|
|
|
43
40
|
const relatedEntity = await strapi.db.query(uid).findOne(relatedId);
|
|
44
41
|
if (!relatedEntity) {
|
|
45
42
|
throw new PluginError(400, `Relation for field "related" does not exist. Check your payload please.`);
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
const
|
|
45
|
+
const isApprovalFlowEnabled = this.getCommonService().getConfig('approvalFlow', []).includes(uid) ||
|
|
46
|
+
relatedEntity.requireCommentsApproval;
|
|
47
|
+
|
|
48
|
+
const linkToThread = !isNil(threadOf) ? await this.getCommonService().findOne({
|
|
49
49
|
id: threadOf,
|
|
50
|
-
related,
|
|
50
|
+
related: relation,
|
|
51
51
|
}) : true;
|
|
52
52
|
const validContext = isValidUserContext(user);
|
|
53
53
|
|
|
@@ -87,7 +87,8 @@ module.exports = ({ strapi }) => ({
|
|
|
87
87
|
throw new PluginError(400, 'Object: "author" is invalid. Check your payload');
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
if (
|
|
90
|
+
if (isApprovalFlowEnabled &&
|
|
91
|
+
(!isNil(data.approvalStatus) && (data.approvalStatus !== APPROVAL_STATUS.PENDING))) {
|
|
91
92
|
throw new PluginError(400, 'Invalid approval status');
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -95,23 +96,23 @@ module.exports = ({ strapi }) => ({
|
|
|
95
96
|
data: {
|
|
96
97
|
...rest,
|
|
97
98
|
...authorData,
|
|
98
|
-
related,
|
|
99
|
+
related: relation,
|
|
100
|
+
approvalStatus: isApprovalFlowEnabled ? APPROVAL_STATUS.PENDING : null,
|
|
99
101
|
}
|
|
100
102
|
});
|
|
101
|
-
return this.getCommonService().sanitizeCommentEntity(
|
|
103
|
+
return this.getCommonService().sanitizeCommentEntity({
|
|
104
|
+
...entity,
|
|
105
|
+
threadOf: !isNil(threadOf) ? linkToThread : null,
|
|
106
|
+
});
|
|
102
107
|
}
|
|
103
108
|
throw new PluginError(400, 'No content received');
|
|
104
109
|
},
|
|
105
110
|
|
|
106
111
|
// Update a comment
|
|
107
112
|
async update(id, relation, data, user) {
|
|
108
|
-
const { content
|
|
113
|
+
const { content } = data;
|
|
109
114
|
|
|
110
|
-
const singleRelationFulfilled =
|
|
111
|
-
|
|
112
|
-
if (relation !== related) {
|
|
113
|
-
throw new PluginError(400, `Insonsistent relation uid`);
|
|
114
|
-
}
|
|
115
|
+
const singleRelationFulfilled = relation && REGEX.relatedUid.test(relation)
|
|
115
116
|
|
|
116
117
|
if(!singleRelationFulfilled) {
|
|
117
118
|
throw new PluginError(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
@@ -119,7 +120,7 @@ module.exports = ({ strapi }) => ({
|
|
|
119
120
|
|
|
120
121
|
const existingEntity = await this.getCommonService().findOne({
|
|
121
122
|
id,
|
|
122
|
-
related,
|
|
123
|
+
related: relation,
|
|
123
124
|
});
|
|
124
125
|
const validContext = isValidUserContext(user);
|
|
125
126
|
|
|
@@ -132,6 +133,7 @@ module.exports = ({ strapi }) => ({
|
|
|
132
133
|
const entity = await strapi.db.query(getModelUid('comment')).update({
|
|
133
134
|
where: { id },
|
|
134
135
|
data: { content },
|
|
136
|
+
populate: { threadOf: true },
|
|
135
137
|
});
|
|
136
138
|
return this.getCommonService().sanitizeCommentEntity(entity);
|
|
137
139
|
}
|
|
@@ -144,11 +146,11 @@ module.exports = ({ strapi }) => ({
|
|
|
144
146
|
if (!isValidUserContext(user)) {
|
|
145
147
|
throw resolveUserContextError(user);
|
|
146
148
|
}
|
|
147
|
-
const
|
|
149
|
+
const reportAgainstEntity = await this.getCommonService().findOne({
|
|
148
150
|
id,
|
|
149
151
|
related: relation,
|
|
150
152
|
});
|
|
151
|
-
if (
|
|
153
|
+
if (reportAgainstEntity) {
|
|
152
154
|
const entity = await strapi.db.query(getModelUid('comment-report')).create({
|
|
153
155
|
data: {
|
|
154
156
|
...payload,
|
|
@@ -157,32 +159,46 @@ module.exports = ({ strapi }) => ({
|
|
|
157
159
|
}
|
|
158
160
|
});
|
|
159
161
|
if (entity) {
|
|
162
|
+
const response = {
|
|
163
|
+
...entity,
|
|
164
|
+
related: reportAgainstEntity,
|
|
165
|
+
};
|
|
160
166
|
try {
|
|
161
167
|
await this.sendAbuseReportEmail(entity.reason, entity.content); // Could also add some info about relation
|
|
168
|
+
return response
|
|
162
169
|
} catch (err) {
|
|
163
|
-
return
|
|
170
|
+
return response;
|
|
164
171
|
}
|
|
165
172
|
} else {
|
|
166
173
|
throw new PluginError(500, 'Report cannot be created');
|
|
167
174
|
}
|
|
168
|
-
return entity;
|
|
169
175
|
}
|
|
170
176
|
throw new PluginError(409, 'Action on that entity is not allowed');
|
|
171
177
|
},
|
|
172
178
|
|
|
173
|
-
async markAsRemoved(
|
|
179
|
+
async markAsRemoved(id, relation, authorId){
|
|
174
180
|
const entity = await this.getCommonService().findOne({
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
181
|
+
id,
|
|
182
|
+
related: relation,
|
|
183
|
+
$or: [{ authorUser: authorId }, { authorId }],
|
|
178
184
|
});
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
|
|
186
|
+
if (!entity) {
|
|
187
|
+
throw new PluginError(404, 'Entity not exist');
|
|
181
188
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.
|
|
185
|
-
|
|
189
|
+
|
|
190
|
+
const removedEntity = await strapi.db.query(getModelUid('comment'))
|
|
191
|
+
.update({
|
|
192
|
+
where: {
|
|
193
|
+
id,
|
|
194
|
+
related: relation
|
|
195
|
+
},
|
|
196
|
+
data: { removed: true },
|
|
197
|
+
populate: { threadOf: true },
|
|
198
|
+
})
|
|
199
|
+
await this.markAsRemovedNested(id, true);
|
|
200
|
+
|
|
201
|
+
return this.getCommonService().sanitizeCommentEntity(removedEntity);
|
|
186
202
|
},
|
|
187
203
|
|
|
188
204
|
async sendAbuseReportEmail(reason, content) {
|
|
@@ -221,7 +237,7 @@ module.exports = ({ strapi }) => ({
|
|
|
221
237
|
}
|
|
222
238
|
},
|
|
223
239
|
|
|
224
|
-
markAsRemovedNested(id, status){
|
|
240
|
+
async markAsRemovedNested(id, status){
|
|
225
241
|
return this.getCommonService().modifiedNestedNestedComments(id, 'removed', status);
|
|
226
242
|
},
|
|
227
243
|
});
|