strapi-plugin-comments 1.0.2 → 2.0.0-beta.3
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/.circleci/config.yml +2 -2
- package/README.md +70 -109
- package/admin/src/components/ConfirmationDialog/index.js +56 -0
- package/admin/src/components/DiscussionStatus/index.js +33 -0
- package/admin/src/components/DiscussionThread/index.js +59 -0
- package/admin/src/components/DiscussionThreadItem/index.js +87 -0
- package/admin/src/components/DiscussionThreadItem/styles.js +88 -0
- package/admin/src/components/DiscussionThreadItemActions/index.js +178 -0
- package/admin/src/components/DiscussionThreadItemActions/styles.js +22 -0
- package/admin/src/components/DiscussionThreadItemMeta/index.js +31 -0
- package/admin/src/components/DiscussionThreadItemWarnings/index.js +141 -0
- package/admin/src/components/DiscussionThreadItemWarnings/styles.js +7 -0
- package/admin/src/components/EntityDetails/index.js +53 -0
- package/admin/src/{containers → components}/Initializer/index.js +4 -4
- package/admin/src/components/LoadingIndicatorOverlay/index.js +15 -0
- package/admin/src/components/LoadingIndicatorOverlay/styles.js +20 -0
- package/admin/src/components/Nav/index.js +45 -0
- package/admin/src/components/PluginIcon/index.js +12 -0
- package/admin/src/components/ReportsReviewModal/index.js +43 -0
- package/admin/src/components/ReportsReviewTable/index.js +146 -0
- package/admin/src/components/TableFilters/index.js +53 -0
- package/admin/src/components/TablePagination/index.js +35 -0
- package/admin/src/components/icons/comments.js +9 -0
- package/admin/src/components/icons/index.js +6 -0
- package/admin/src/components/icons/lock.js +22 -0
- package/admin/src/components/icons/review.js +18 -0
- package/admin/src/components/icons/unlock.js +20 -0
- package/admin/src/index.js +58 -42
- package/admin/src/pages/App/index.js +71 -0
- package/admin/src/pages/App/reducer/actions.js +8 -0
- package/admin/src/pages/App/reducer/constants.js +4 -0
- package/admin/src/pages/App/reducer/index.js +26 -0
- package/admin/src/pages/App/reducer/init.js +7 -0
- package/admin/src/pages/App/reducer/selectors.js +35 -0
- package/admin/src/pages/App/utils/api.js +12 -0
- package/admin/src/pages/ComingSoonPage/index.js +25 -0
- package/admin/src/pages/Details/index.js +109 -0
- package/admin/src/pages/Details/utils/api.js +41 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +196 -0
- package/admin/src/pages/Discover/index.js +157 -0
- package/admin/src/pages/Discover/utils/api.js +14 -0
- package/admin/src/pages/Discover/utils/filtersSchema.js +9 -0
- package/admin/src/permissions.js +13 -33
- package/admin/src/pluginId.js +2 -4
- package/admin/src/reducers.js +8 -0
- package/admin/src/translations/en.json +73 -33
- package/admin/src/translations/fr.json +1 -0
- package/admin/src/utils/axiosInstance.js +35 -0
- package/admin/src/utils/constants.js +28 -0
- package/admin/src/utils/getApiUrl.js +5 -0
- package/admin/src/utils/getMessage.js +21 -0
- package/admin/src/utils/getRelatedGroups.js +5 -0
- package/admin/src/utils/getUrl.js +5 -0
- package/admin/src/utils/handleAPIError.js +15 -0
- package/admin/src/utils/index.js +6 -0
- package/codecov.yml +2 -1
- package/content-types/comment.js +97 -0
- package/content-types/index.js +11 -0
- package/content-types/report.js +54 -0
- package/package.json +11 -25
- package/server/bootstrap.js +5 -0
- package/server/config/index.js +10 -0
- package/server/controllers/admin.js +134 -0
- package/server/controllers/client.js +117 -0
- package/server/controllers/index.js +9 -0
- package/{controllers → server/controllers}/utils/__tests__/functions.test.js +0 -0
- package/{controllers → server/controllers}/utils/functions.js +1 -1
- package/server/destroy.js +5 -0
- package/server/index.js +22 -0
- package/server/register.js +5 -0
- package/server/routes/admin.js +92 -0
- package/server/routes/client.js +52 -0
- package/server/routes/index.js +15 -0
- package/server/services/admin.js +215 -0
- package/server/services/client.js +227 -0
- package/server/services/common.js +197 -0
- package/server/services/index.js +11 -0
- package/{services → server/services}/utils/__tests__/functions.test.js +7 -9
- package/{services → server/services}/utils/functions.js +19 -8
- package/server/utils/constants.js +16 -0
- package/{services → server}/utils/error.js +0 -0
- package/server/utils/functions.js +19 -0
- package/strapi-admin.js +3 -0
- package/strapi-server.js +9 -0
- package/admin/src/assets/images/icon-cross-blue.svg +0 -1
- package/admin/src/assets/images/icon_remove.svg +0 -19
- package/admin/src/assets/images/logo.svg +0 -5
- package/admin/src/components/AbuseReportsPopUp/ItemPreviewContainer.js +0 -8
- package/admin/src/components/AbuseReportsPopUp/ModalFooter.js +0 -31
- package/admin/src/components/AbuseReportsPopUp/TableContainer.js +0 -63
- package/admin/src/components/AbuseReportsPopUp/index.js +0 -148
- package/admin/src/components/Container/index.js +0 -7
- package/admin/src/components/EmptyView/index.js +0 -25
- package/admin/src/components/Filters/index.js +0 -151
- package/admin/src/components/Filters/index.styled.js +0 -82
- package/admin/src/components/Filters/utils.js +0 -21
- package/admin/src/components/Item/CardItem.js +0 -30
- package/admin/src/components/Item/CardWrapper.js +0 -10
- package/admin/src/components/Item/index.js +0 -92
- package/admin/src/components/ItemDetails/CardItem.js +0 -33
- package/admin/src/components/ItemDetails/CardLevelCounter.js +0 -46
- package/admin/src/components/ItemDetails/CardLevelCounterLink.js +0 -24
- package/admin/src/components/ItemDetails/CardLevelWrapper.js +0 -22
- package/admin/src/components/ItemDetails/CardWrapper.js +0 -52
- package/admin/src/components/ItemDetails/index.js +0 -151
- package/admin/src/components/ItemFooter/CardItemAuthor.js +0 -10
- package/admin/src/components/ItemFooter/CardItemRelation.js +0 -18
- package/admin/src/components/ItemFooter/Wrapper.js +0 -20
- package/admin/src/components/ItemFooter/index.js +0 -87
- package/admin/src/components/ItemHeader/CardHeaderBlocked.js +0 -24
- package/admin/src/components/ItemHeader/CardHeaderIndicator.js +0 -30
- package/admin/src/components/ItemHeader/CardHeaderIndicatorBlue.js +0 -11
- package/admin/src/components/ItemHeader/CardHeaderIndicatorRed.js +0 -11
- package/admin/src/components/ItemHeader/CardHeaderIndicatorsContainer.js +0 -18
- package/admin/src/components/ItemHeader/CardHeaderReports.js +0 -40
- package/admin/src/components/ItemHeader/Wrapper.js +0 -16
- package/admin/src/components/ItemHeader/index.js +0 -80
- package/admin/src/components/ItemModeration/Wrapper.js +0 -19
- package/admin/src/components/ItemModeration/index.js +0 -47
- package/admin/src/components/List/Container.js +0 -20
- package/admin/src/components/List/index.js +0 -21
- package/admin/src/components/Search/index.js +0 -83
- package/admin/src/containers/App/Wrapper.js +0 -14
- package/admin/src/containers/App/index.js +0 -47
- package/admin/src/containers/DataManagerProvider/actions.js +0 -11
- package/admin/src/containers/DataManagerProvider/index.js +0 -280
- package/admin/src/containers/DataManagerProvider/init.js +0 -5
- package/admin/src/containers/DataManagerProvider/reducer.js +0 -59
- package/admin/src/containers/DetailsView/Wrapper.js +0 -18
- package/admin/src/containers/DetailsView/index.js +0 -100
- package/admin/src/containers/ListView/FadedWrapper.js +0 -42
- package/admin/src/containers/ListView/Footer.js +0 -53
- package/admin/src/containers/ListView/Wrapper.js +0 -17
- package/admin/src/containers/ListView/components.js +0 -138
- package/admin/src/containers/ListView/index.js +0 -45
- package/admin/src/containers/Panel/actions.js +0 -5
- package/admin/src/containers/Panel/index.js +0 -191
- package/admin/src/containers/Panel/index.styled.js +0 -6
- package/admin/src/containers/Panel/reducer.js +0 -44
- package/admin/src/contexts/DataManagerContext.js +0 -5
- package/admin/src/hooks/useDataManager.js +0 -6
- package/admin/src/lifecycles.js +0 -3
- package/admin/src/translations/index.js +0 -7
- package/admin/src/utils/getTrad.js +0 -5
- package/admin/src/utils/getTradId.js +0 -5
- package/config/functions/bootstrap.js +0 -48
- package/config/routes.json +0 -116
- package/config/schema.graphql.js +0 -270
- package/controllers/comments.js +0 -211
- package/models/comment.js +0 -8
- package/models/comment.settings.json +0 -98
- package/models/report.js +0 -8
- package/models/report.settings.json +0 -49
- package/services/comments.js +0 -486
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { getPluginService } = require('./../utils/functions');
|
|
4
|
+
const { parseParams, throwError } = require('./utils/functions');
|
|
5
|
+
const _ = require('lodash');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
|
|
9
|
+
getService(name = 'client') {
|
|
10
|
+
return getPluginService(name);
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
async findAllFlat(ctx) {
|
|
14
|
+
const { params = {}, query } = ctx;
|
|
15
|
+
const { relation } = parseParams(params);
|
|
16
|
+
try {
|
|
17
|
+
return this.getService('common')
|
|
18
|
+
.findAllFlat({
|
|
19
|
+
query: {
|
|
20
|
+
...query,
|
|
21
|
+
related: relation,
|
|
22
|
+
},
|
|
23
|
+
populate: {
|
|
24
|
+
threadOf: true,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throwError(ctx, e);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
async findAllInHierarchy(ctx) {
|
|
33
|
+
const { params = {}, query } = ctx;
|
|
34
|
+
const { relation } = parseParams(params);
|
|
35
|
+
try {
|
|
36
|
+
return await this.getService('common')
|
|
37
|
+
.findAllInHierarchy({
|
|
38
|
+
query: {
|
|
39
|
+
...query,
|
|
40
|
+
related: relation,
|
|
41
|
+
},
|
|
42
|
+
populate: {
|
|
43
|
+
threadOf: true,
|
|
44
|
+
},
|
|
45
|
+
dropBlockedThreads: true,
|
|
46
|
+
});
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throwError(ctx, e);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
async post(ctx) {
|
|
53
|
+
const { request, params = {}, state = {} } = ctx;
|
|
54
|
+
const { relation } = parseParams(params);
|
|
55
|
+
const { user } = state;
|
|
56
|
+
const { body = {} } = request;
|
|
57
|
+
try {
|
|
58
|
+
const entity = await this.getService()
|
|
59
|
+
.create(relation, body, user);
|
|
60
|
+
|
|
61
|
+
if (entity) {
|
|
62
|
+
return entity;
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throwError(ctx, e);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
async put(ctx) {
|
|
70
|
+
const { request, state, params = {} } = ctx;
|
|
71
|
+
const { body = {} } = request;
|
|
72
|
+
const { user } = state;
|
|
73
|
+
const { commentId, relation } = parseParams(params);
|
|
74
|
+
try {
|
|
75
|
+
return await this.getService()
|
|
76
|
+
.update(commentId, relation, body, user);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
throwError(ctx, e);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
async reportAbuse(ctx) {
|
|
83
|
+
const { request, state, params = {} } = ctx;
|
|
84
|
+
const { body = {} } = request;
|
|
85
|
+
if (!body.content) {
|
|
86
|
+
return ctx.badRequest(null, 'Content field is required');
|
|
87
|
+
}
|
|
88
|
+
const { user } = state;
|
|
89
|
+
const { relation, commentId } = parseParams(params);
|
|
90
|
+
try {
|
|
91
|
+
return await this.getService()
|
|
92
|
+
.reportAbuse(commentId, relation, body, user);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throwError(ctx, e);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async removeComment(ctx) {
|
|
99
|
+
const { params: { relationId, commentId }, query: { authorId } } = ctx;
|
|
100
|
+
if (authorId) {
|
|
101
|
+
try {
|
|
102
|
+
return await this.getService()
|
|
103
|
+
.markAsRemoved(
|
|
104
|
+
relationId,
|
|
105
|
+
commentId,
|
|
106
|
+
authorId,
|
|
107
|
+
);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
if (!e.isBoom) {
|
|
110
|
+
throwError(ctx, e);
|
|
111
|
+
}
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return ctx.badRequest('Not provided authorId');
|
|
116
|
+
},
|
|
117
|
+
};
|
|
File without changes
|
package/server/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const register = require('./register');
|
|
4
|
+
const bootstrap = require('./bootstrap');
|
|
5
|
+
const destroy = require('./destroy');
|
|
6
|
+
const config = require('./config');
|
|
7
|
+
const controllers = require('./controllers');
|
|
8
|
+
const routes = require('./routes');
|
|
9
|
+
const services = require('./services');
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
register,
|
|
13
|
+
bootstrap,
|
|
14
|
+
destroy,
|
|
15
|
+
config,
|
|
16
|
+
controllers,
|
|
17
|
+
routes,
|
|
18
|
+
services,
|
|
19
|
+
contentTypes: {},
|
|
20
|
+
policies: {},
|
|
21
|
+
middlewares: {},
|
|
22
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = [
|
|
4
|
+
{
|
|
5
|
+
method: 'GET',
|
|
6
|
+
path: '/moderate/config',
|
|
7
|
+
handler: 'admin.config',
|
|
8
|
+
config: {
|
|
9
|
+
policies: [],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
method: 'GET',
|
|
14
|
+
path: '/moderate/config/content-types/:contentTypeName',
|
|
15
|
+
handler: 'admin.contentTypeName',
|
|
16
|
+
config: {
|
|
17
|
+
policies: [],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
method: 'GET',
|
|
22
|
+
path: '/moderate/all',
|
|
23
|
+
handler: 'admin.findAll',
|
|
24
|
+
config: {
|
|
25
|
+
policies: [],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
method: 'GET',
|
|
30
|
+
path: '/moderate/single/:id',
|
|
31
|
+
handler: 'admin.findOne',
|
|
32
|
+
config: {
|
|
33
|
+
policies: [],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
method: 'PATCH',
|
|
38
|
+
path: '/moderate/single/:id/approve',
|
|
39
|
+
handler: 'admin.approveComment',
|
|
40
|
+
config: {
|
|
41
|
+
policies: [],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
method: 'PATCH',
|
|
46
|
+
path: '/moderate/single/:id/reject',
|
|
47
|
+
handler: 'admin.rejectComment',
|
|
48
|
+
config: {
|
|
49
|
+
policies: [],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
method: 'PATCH',
|
|
54
|
+
path: '/moderate/single/:id/block',
|
|
55
|
+
handler: 'admin.blockComment',
|
|
56
|
+
config: {
|
|
57
|
+
policies: [],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
method: 'PATCH',
|
|
62
|
+
path: '/moderate/single/:id/unblock',
|
|
63
|
+
handler: 'admin.unblockComment',
|
|
64
|
+
config: {
|
|
65
|
+
policies: [],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
method: 'PATCH',
|
|
70
|
+
path: '/moderate/single/:id/report/:reportId/resolve',
|
|
71
|
+
handler: 'admin.resolveAbuseReport',
|
|
72
|
+
config: {
|
|
73
|
+
policies: [],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
method: 'PATCH',
|
|
78
|
+
path: '/moderate/thread/:id/block',
|
|
79
|
+
handler: 'admin.blockCommentThread',
|
|
80
|
+
config: {
|
|
81
|
+
policies: [],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
method: 'PATCH',
|
|
86
|
+
path: '/moderate/thread/:id/unblock',
|
|
87
|
+
handler: 'admin.unblockCommentThread',
|
|
88
|
+
config: {
|
|
89
|
+
policies: [],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = [
|
|
4
|
+
{
|
|
5
|
+
method: 'GET',
|
|
6
|
+
path: '/:relation',
|
|
7
|
+
handler: 'client.findAllInHierarchy',
|
|
8
|
+
config: {
|
|
9
|
+
policies: [],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
method: 'POST',
|
|
14
|
+
path: '/:relation',
|
|
15
|
+
handler: 'client.post',
|
|
16
|
+
config: {
|
|
17
|
+
policies: [],
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
method: 'GET',
|
|
22
|
+
path: '/:relation/flat',
|
|
23
|
+
handler: 'client.findAllFlat',
|
|
24
|
+
config: {
|
|
25
|
+
policies: [],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
method: 'PUT',
|
|
30
|
+
path: '/:relation/comment/:commentId',
|
|
31
|
+
handler: 'client.put',
|
|
32
|
+
config: {
|
|
33
|
+
policies: [],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
method: 'POST',
|
|
38
|
+
path: '/:relation/comment/:commentId/report-abuse',
|
|
39
|
+
handler: 'client.reportAbuse',
|
|
40
|
+
config: {
|
|
41
|
+
policies: [],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
method: 'DELETE',
|
|
46
|
+
path: '/:relationId/comment/:commentId',
|
|
47
|
+
handler: 'client.removeComment',
|
|
48
|
+
config: {
|
|
49
|
+
policies: [],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const clientRoutes = require('./client');
|
|
4
|
+
const adminRoutes = require('./admin');
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
'content-api': {
|
|
8
|
+
type: 'content-api',
|
|
9
|
+
routes: clientRoutes,
|
|
10
|
+
},
|
|
11
|
+
admin: {
|
|
12
|
+
type: 'admin',
|
|
13
|
+
routes: adminRoutes,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { getPluginService, parseParams } = require('./../utils/functions');
|
|
4
|
+
const { getAssociationModel } = require('./common');
|
|
5
|
+
const { first, isEmpty, isNil, uniq, get } = require('lodash');
|
|
6
|
+
const PluginError = require('./../utils/error');
|
|
7
|
+
const {
|
|
8
|
+
getModelUid,
|
|
9
|
+
getRelatedGroups,
|
|
10
|
+
filterOurResolvedReports,
|
|
11
|
+
convertContentTypeNameToSlug
|
|
12
|
+
} = require('./utils/functions');
|
|
13
|
+
const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Comments Plugin - Moderation services
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
module.exports = ({ strapi }) => ({
|
|
20
|
+
|
|
21
|
+
getCommonService() {
|
|
22
|
+
return getPluginService('common');
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
// Config
|
|
26
|
+
async config() {
|
|
27
|
+
const entryLabel = this.getCommonService().getConfig('entryLabel');
|
|
28
|
+
return {
|
|
29
|
+
entryLabel,
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
// Find all comments
|
|
34
|
+
async findAll({ related, entity, ...query }) {
|
|
35
|
+
const { _q, orderBy, pageSize = 10, page = 1, filters, ...rest } = parseParams(query);
|
|
36
|
+
|
|
37
|
+
let params = {
|
|
38
|
+
where: !isEmpty(filters) ? {
|
|
39
|
+
...filters,
|
|
40
|
+
} : undefined,
|
|
41
|
+
offset: (page - 1)*pageSize,
|
|
42
|
+
limit: pageSize,
|
|
43
|
+
orderBy: orderBy || [{ createdAt: 'desc' }],
|
|
44
|
+
};
|
|
45
|
+
if (_q) {
|
|
46
|
+
params = {
|
|
47
|
+
...params,
|
|
48
|
+
where: {
|
|
49
|
+
...params.where,
|
|
50
|
+
content: {
|
|
51
|
+
$contains: _q
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const entities = await strapi.db.query(getModelUid('comment'))
|
|
58
|
+
.findMany({
|
|
59
|
+
...params,
|
|
60
|
+
populate: {
|
|
61
|
+
authorUser: true,
|
|
62
|
+
reports: {
|
|
63
|
+
where: {
|
|
64
|
+
resolved: false
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const total = await strapi.db.query(getModelUid('comment'))
|
|
70
|
+
.count({
|
|
71
|
+
where: params.where,
|
|
72
|
+
});
|
|
73
|
+
const relatedEntities = await this.getCommonService().findRelatedEntitiesFor(entities);
|
|
74
|
+
const result = entities
|
|
75
|
+
.map(_ => filterOurResolvedReports(this.getCommonService().sanitizeCommentEntity(_)))
|
|
76
|
+
.map(_ => this.getCommonService().mergeRelatedEntityTo(_, relatedEntities));
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
result,
|
|
80
|
+
pagination: {
|
|
81
|
+
page: page,
|
|
82
|
+
pageSize: pageSize,
|
|
83
|
+
pageCount: Math.floor(total / pageSize) + 1,
|
|
84
|
+
total,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
// Find single comment
|
|
90
|
+
async findOneAndThread(id) {
|
|
91
|
+
const reportsPopulation = {
|
|
92
|
+
reports: {
|
|
93
|
+
where: {
|
|
94
|
+
resolved: false,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const entity = await strapi.db.query(getModelUid('comment')).findOne({
|
|
100
|
+
where: {
|
|
101
|
+
id
|
|
102
|
+
},
|
|
103
|
+
populate: {
|
|
104
|
+
authorUser: true,
|
|
105
|
+
threadOf: {
|
|
106
|
+
populate: {
|
|
107
|
+
...reportsPopulation
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
...reportsPopulation,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (!entity){
|
|
115
|
+
throw new PluginError(404, 'Not found');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const [relatedUid, relatedStringId] = getRelatedGroups(entity.related);
|
|
119
|
+
const relatedId = parseInt(relatedStringId, 10);
|
|
120
|
+
const relatedEntity = await strapi.db.query(relatedUid).findOne({
|
|
121
|
+
where: { id: relatedId }
|
|
122
|
+
}).then(_ => ({
|
|
123
|
+
..._,
|
|
124
|
+
uid: relatedUid,
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
if (!relatedEntity) {
|
|
128
|
+
throw new PluginError(404, 'Relation not found');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const levelThreadId = entity?.threadOf?.id || null;
|
|
132
|
+
const entitiesOnSameLevel = await this.getCommonService()
|
|
133
|
+
.findAllInHierarchy({
|
|
134
|
+
query: {
|
|
135
|
+
threadOf: levelThreadId,
|
|
136
|
+
related: entity.related,
|
|
137
|
+
},
|
|
138
|
+
populate: {
|
|
139
|
+
...reportsPopulation,
|
|
140
|
+
},
|
|
141
|
+
startingFromId: levelThreadId,
|
|
142
|
+
isAdmin: true
|
|
143
|
+
}, false);
|
|
144
|
+
|
|
145
|
+
const selectedEntity = this.getCommonService().sanitizeCommentEntity(entity);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
entity: relatedEntity,
|
|
149
|
+
selected: {
|
|
150
|
+
...selectedEntity,
|
|
151
|
+
threadOf: selectedEntity.threadOf ? selectedEntity.threadOf : null,
|
|
152
|
+
},
|
|
153
|
+
level: entitiesOnSameLevel,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
// Block / Unblock a comment
|
|
158
|
+
async blockComment(id, forceStatus) {
|
|
159
|
+
const existingEntity = await this.getCommonService().findOne({ id });
|
|
160
|
+
const changedEntity = await strapi.db.query(getModelUid('comment')).update({
|
|
161
|
+
where: { id },
|
|
162
|
+
data: { blocked: !isNil(forceStatus) ? forceStatus : !existingEntity.blocked }
|
|
163
|
+
});
|
|
164
|
+
return this.getCommonService().sanitizeCommentEntity(changedEntity);
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
// Block / Unblock a comment thread
|
|
168
|
+
async blockCommentThread(id, forceStatus) {
|
|
169
|
+
const existingEntity = await this.getCommonService().findOne({ id });
|
|
170
|
+
const changedEntity = await strapi.db.query(getModelUid('comment')).update({
|
|
171
|
+
where: { id },
|
|
172
|
+
data: { blockedThread: !isNil(forceStatus) ? forceStatus : !existingEntity.blockedThread }
|
|
173
|
+
});
|
|
174
|
+
await this.blockNestedThreads(id, changedEntity.blockedThread);
|
|
175
|
+
|
|
176
|
+
return this.getCommonService().sanitizeCommentEntity(changedEntity);
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
// Approve comment
|
|
180
|
+
async approveComment(id) {
|
|
181
|
+
const changedEntity = await strapi.db.query(getModelUid('comment'))
|
|
182
|
+
.update({
|
|
183
|
+
where: { id },
|
|
184
|
+
data: { approvalStatus: APPROVAL_STATUS.APPROVED }
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return this.getCommonService().sanitizeCommentEntity(changedEntity);
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
async rejectComment(id) {
|
|
191
|
+
const changedEntity = await strapi.db.query(getModelUid('comment'))
|
|
192
|
+
.update({
|
|
193
|
+
where: { id },
|
|
194
|
+
data: { approvalStatus: APPROVAL_STATUS.REJECTED }
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return this.getCommonService().sanitizeCommentEntity(changedEntity);
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
async blockNestedThreads(id, blockStatus) {
|
|
201
|
+
return await this.getCommonService()
|
|
202
|
+
.modifiedNestedNestedComments(id, 'blockedThread', blockStatus)
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
// Resolve reported abuse for comment
|
|
206
|
+
async resolveAbuseReport(id, commentId) {
|
|
207
|
+
return strapi.db.query(getModelUid('comment-report')).update({
|
|
208
|
+
where: {
|
|
209
|
+
id,
|
|
210
|
+
related: commentId,
|
|
211
|
+
},
|
|
212
|
+
data: { resolved: true }
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
});
|