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.
Files changed (154) hide show
  1. package/.circleci/config.yml +2 -2
  2. package/README.md +70 -109
  3. package/admin/src/components/ConfirmationDialog/index.js +56 -0
  4. package/admin/src/components/DiscussionStatus/index.js +33 -0
  5. package/admin/src/components/DiscussionThread/index.js +59 -0
  6. package/admin/src/components/DiscussionThreadItem/index.js +87 -0
  7. package/admin/src/components/DiscussionThreadItem/styles.js +88 -0
  8. package/admin/src/components/DiscussionThreadItemActions/index.js +178 -0
  9. package/admin/src/components/DiscussionThreadItemActions/styles.js +22 -0
  10. package/admin/src/components/DiscussionThreadItemMeta/index.js +31 -0
  11. package/admin/src/components/DiscussionThreadItemWarnings/index.js +141 -0
  12. package/admin/src/components/DiscussionThreadItemWarnings/styles.js +7 -0
  13. package/admin/src/components/EntityDetails/index.js +53 -0
  14. package/admin/src/{containers → components}/Initializer/index.js +4 -4
  15. package/admin/src/components/LoadingIndicatorOverlay/index.js +15 -0
  16. package/admin/src/components/LoadingIndicatorOverlay/styles.js +20 -0
  17. package/admin/src/components/Nav/index.js +45 -0
  18. package/admin/src/components/PluginIcon/index.js +12 -0
  19. package/admin/src/components/ReportsReviewModal/index.js +43 -0
  20. package/admin/src/components/ReportsReviewTable/index.js +146 -0
  21. package/admin/src/components/TableFilters/index.js +53 -0
  22. package/admin/src/components/TablePagination/index.js +35 -0
  23. package/admin/src/components/icons/comments.js +9 -0
  24. package/admin/src/components/icons/index.js +6 -0
  25. package/admin/src/components/icons/lock.js +22 -0
  26. package/admin/src/components/icons/review.js +18 -0
  27. package/admin/src/components/icons/unlock.js +20 -0
  28. package/admin/src/index.js +58 -42
  29. package/admin/src/pages/App/index.js +71 -0
  30. package/admin/src/pages/App/reducer/actions.js +8 -0
  31. package/admin/src/pages/App/reducer/constants.js +4 -0
  32. package/admin/src/pages/App/reducer/index.js +26 -0
  33. package/admin/src/pages/App/reducer/init.js +7 -0
  34. package/admin/src/pages/App/reducer/selectors.js +35 -0
  35. package/admin/src/pages/App/utils/api.js +12 -0
  36. package/admin/src/pages/ComingSoonPage/index.js +25 -0
  37. package/admin/src/pages/Details/index.js +109 -0
  38. package/admin/src/pages/Details/utils/api.js +41 -0
  39. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +196 -0
  40. package/admin/src/pages/Discover/index.js +157 -0
  41. package/admin/src/pages/Discover/utils/api.js +14 -0
  42. package/admin/src/pages/Discover/utils/filtersSchema.js +9 -0
  43. package/admin/src/permissions.js +13 -33
  44. package/admin/src/pluginId.js +2 -4
  45. package/admin/src/reducers.js +8 -0
  46. package/admin/src/translations/en.json +73 -33
  47. package/admin/src/translations/fr.json +1 -0
  48. package/admin/src/utils/axiosInstance.js +35 -0
  49. package/admin/src/utils/constants.js +28 -0
  50. package/admin/src/utils/getApiUrl.js +5 -0
  51. package/admin/src/utils/getMessage.js +21 -0
  52. package/admin/src/utils/getRelatedGroups.js +5 -0
  53. package/admin/src/utils/getUrl.js +5 -0
  54. package/admin/src/utils/handleAPIError.js +15 -0
  55. package/admin/src/utils/index.js +6 -0
  56. package/codecov.yml +2 -1
  57. package/content-types/comment.js +97 -0
  58. package/content-types/index.js +11 -0
  59. package/content-types/report.js +54 -0
  60. package/package.json +11 -25
  61. package/server/bootstrap.js +5 -0
  62. package/server/config/index.js +10 -0
  63. package/server/controllers/admin.js +134 -0
  64. package/server/controllers/client.js +117 -0
  65. package/server/controllers/index.js +9 -0
  66. package/{controllers → server/controllers}/utils/__tests__/functions.test.js +0 -0
  67. package/{controllers → server/controllers}/utils/functions.js +1 -1
  68. package/server/destroy.js +5 -0
  69. package/server/index.js +22 -0
  70. package/server/register.js +5 -0
  71. package/server/routes/admin.js +92 -0
  72. package/server/routes/client.js +52 -0
  73. package/server/routes/index.js +15 -0
  74. package/server/services/admin.js +215 -0
  75. package/server/services/client.js +227 -0
  76. package/server/services/common.js +197 -0
  77. package/server/services/index.js +11 -0
  78. package/{services → server/services}/utils/__tests__/functions.test.js +7 -9
  79. package/{services → server/services}/utils/functions.js +19 -8
  80. package/server/utils/constants.js +16 -0
  81. package/{services → server}/utils/error.js +0 -0
  82. package/server/utils/functions.js +19 -0
  83. package/strapi-admin.js +3 -0
  84. package/strapi-server.js +9 -0
  85. package/admin/src/assets/images/icon-cross-blue.svg +0 -1
  86. package/admin/src/assets/images/icon_remove.svg +0 -19
  87. package/admin/src/assets/images/logo.svg +0 -5
  88. package/admin/src/components/AbuseReportsPopUp/ItemPreviewContainer.js +0 -8
  89. package/admin/src/components/AbuseReportsPopUp/ModalFooter.js +0 -31
  90. package/admin/src/components/AbuseReportsPopUp/TableContainer.js +0 -63
  91. package/admin/src/components/AbuseReportsPopUp/index.js +0 -148
  92. package/admin/src/components/Container/index.js +0 -7
  93. package/admin/src/components/EmptyView/index.js +0 -25
  94. package/admin/src/components/Filters/index.js +0 -151
  95. package/admin/src/components/Filters/index.styled.js +0 -82
  96. package/admin/src/components/Filters/utils.js +0 -21
  97. package/admin/src/components/Item/CardItem.js +0 -30
  98. package/admin/src/components/Item/CardWrapper.js +0 -10
  99. package/admin/src/components/Item/index.js +0 -92
  100. package/admin/src/components/ItemDetails/CardItem.js +0 -33
  101. package/admin/src/components/ItemDetails/CardLevelCounter.js +0 -46
  102. package/admin/src/components/ItemDetails/CardLevelCounterLink.js +0 -24
  103. package/admin/src/components/ItemDetails/CardLevelWrapper.js +0 -22
  104. package/admin/src/components/ItemDetails/CardWrapper.js +0 -52
  105. package/admin/src/components/ItemDetails/index.js +0 -151
  106. package/admin/src/components/ItemFooter/CardItemAuthor.js +0 -10
  107. package/admin/src/components/ItemFooter/CardItemRelation.js +0 -18
  108. package/admin/src/components/ItemFooter/Wrapper.js +0 -20
  109. package/admin/src/components/ItemFooter/index.js +0 -87
  110. package/admin/src/components/ItemHeader/CardHeaderBlocked.js +0 -24
  111. package/admin/src/components/ItemHeader/CardHeaderIndicator.js +0 -30
  112. package/admin/src/components/ItemHeader/CardHeaderIndicatorBlue.js +0 -11
  113. package/admin/src/components/ItemHeader/CardHeaderIndicatorRed.js +0 -11
  114. package/admin/src/components/ItemHeader/CardHeaderIndicatorsContainer.js +0 -18
  115. package/admin/src/components/ItemHeader/CardHeaderReports.js +0 -40
  116. package/admin/src/components/ItemHeader/Wrapper.js +0 -16
  117. package/admin/src/components/ItemHeader/index.js +0 -80
  118. package/admin/src/components/ItemModeration/Wrapper.js +0 -19
  119. package/admin/src/components/ItemModeration/index.js +0 -47
  120. package/admin/src/components/List/Container.js +0 -20
  121. package/admin/src/components/List/index.js +0 -21
  122. package/admin/src/components/Search/index.js +0 -83
  123. package/admin/src/containers/App/Wrapper.js +0 -14
  124. package/admin/src/containers/App/index.js +0 -47
  125. package/admin/src/containers/DataManagerProvider/actions.js +0 -11
  126. package/admin/src/containers/DataManagerProvider/index.js +0 -280
  127. package/admin/src/containers/DataManagerProvider/init.js +0 -5
  128. package/admin/src/containers/DataManagerProvider/reducer.js +0 -59
  129. package/admin/src/containers/DetailsView/Wrapper.js +0 -18
  130. package/admin/src/containers/DetailsView/index.js +0 -100
  131. package/admin/src/containers/ListView/FadedWrapper.js +0 -42
  132. package/admin/src/containers/ListView/Footer.js +0 -53
  133. package/admin/src/containers/ListView/Wrapper.js +0 -17
  134. package/admin/src/containers/ListView/components.js +0 -138
  135. package/admin/src/containers/ListView/index.js +0 -45
  136. package/admin/src/containers/Panel/actions.js +0 -5
  137. package/admin/src/containers/Panel/index.js +0 -191
  138. package/admin/src/containers/Panel/index.styled.js +0 -6
  139. package/admin/src/containers/Panel/reducer.js +0 -44
  140. package/admin/src/contexts/DataManagerContext.js +0 -5
  141. package/admin/src/hooks/useDataManager.js +0 -6
  142. package/admin/src/lifecycles.js +0 -3
  143. package/admin/src/translations/index.js +0 -7
  144. package/admin/src/utils/getTrad.js +0 -5
  145. package/admin/src/utils/getTradId.js +0 -5
  146. package/config/functions/bootstrap.js +0 -48
  147. package/config/routes.json +0 -116
  148. package/config/schema.graphql.js +0 -270
  149. package/controllers/comments.js +0 -211
  150. package/models/comment.js +0 -8
  151. package/models/comment.settings.json +0 -98
  152. package/models/report.js +0 -8
  153. package/models/report.settings.json +0 -49
  154. package/services/comments.js +0 -486
@@ -1,48 +0,0 @@
1
- module.exports = async () => {
2
- // Check if the plugin users-permissions is installed because the comments needs it
3
- if (Object.keys(strapi.plugins).indexOf('users-permissions') === -1) {
4
- throw new Error(
5
- 'In order to make the comments plugin work the users-permissions plugin is required'
6
- );
7
- }
8
-
9
- // Add permissions
10
- const actions = [
11
- {
12
- section: 'plugins',
13
- displayName: 'Access the Comments',
14
- uid: 'read',
15
- pluginName: 'comments',
16
- },
17
- {
18
- section: 'plugins',
19
- displayName: 'Modefation',
20
- uid: 'moderate',
21
- pluginName: 'comments',
22
- },
23
- {
24
- section: 'plugins',
25
- displayName: 'Single comments',
26
- uid: 'moderate.block.comment',
27
- subCategory: 'moderate',
28
- pluginName: 'comments',
29
- },
30
- {
31
- section: 'plugins',
32
- displayName: 'Comments threads',
33
- uid: 'moderate.block.thread',
34
- subCategory: 'moderate',
35
- pluginName: 'comments',
36
- },
37
- {
38
- section: 'plugins',
39
- displayName: 'Review & resolve reports',
40
- uid: 'moderate.reports',
41
- subCategory: 'moderate',
42
- pluginName: 'comments',
43
- },
44
- ];
45
-
46
- const { actionProvider } = strapi.admin.services.permission;
47
- await actionProvider.registerMany(actions);
48
- };
@@ -1,116 +0,0 @@
1
- {
2
- "routes": [
3
- {
4
- "method": "GET",
5
- "path": "/:relation",
6
- "handler": "comments.findAllInHierarchy",
7
- "config": {
8
- "policies": []
9
- }
10
- },
11
- {
12
- "method": "POST",
13
- "path": "/:relation",
14
- "handler": "comments.post",
15
- "config": {
16
- "policies": []
17
- }
18
- },
19
- {
20
- "method": "GET",
21
- "path": "/:relation/flat",
22
- "handler": "comments.findAllFlat",
23
- "config": {
24
- "policies": []
25
- }
26
- },
27
- {
28
- "method": "PUT",
29
- "path": "/:relation/comment/:commentId",
30
- "handler": "comments.put",
31
- "config": {
32
- "policies": []
33
- }
34
- },
35
- {
36
- "method": "POST",
37
- "path": "/:relation/comment/:commentId/report-abuse",
38
- "handler": "comments.reportAbuse",
39
- "config": {
40
- "policies": []
41
- }
42
- },
43
- {
44
- "method": "PATCH",
45
- "path": "/:relation/comment/:commentId/like",
46
- "handler": "comments.pointsUp",
47
- "config": {
48
- "policies": []
49
- }
50
- },
51
- {
52
- "method": "DELETE",
53
- "path": "/:relationId/:commentId",
54
- "handler": "comments.removeComment",
55
- "config": {
56
- "policies": []
57
- }
58
- },
59
- {
60
- "method": "GET",
61
- "path": "/moderation/all",
62
- "handler": "comments.findAll",
63
- "config": {
64
- "policies": [["admin::hasPermissions", ["plugins::comments.read"]]]
65
- }
66
- },
67
- {
68
- "method": "GET",
69
- "path": "/moderation/single/:id",
70
- "handler": "comments.findOne",
71
- "config": {
72
- "policies": [["admin::hasPermissions", ["plugins::comments.read"]]]
73
- }
74
- },
75
- {
76
- "method": "GET",
77
- "path": "/moderation/config",
78
- "handler": "comments.config",
79
- "config": {
80
- "policies": [["admin::hasPermissions", ["plugins::comments.read"]]]
81
- }
82
- },
83
- {
84
- "method": "GET",
85
- "path": "/moderation/contents-types/:contentTypeName",
86
- "handler": "comments.contentTypeName",
87
- "config": {
88
- "policies": [["admin::hasPermissions", ["plugins::comments.read"]]]
89
- }
90
- },
91
- {
92
- "method": "PUT",
93
- "path": "/moderation/block/:id",
94
- "handler": "comments.blockComment",
95
- "config": {
96
- "policies": [["admin::hasPermissions", ["plugins::comments.moderate.block.comment"]]]
97
- }
98
- },
99
- {
100
- "method": "PUT",
101
- "path": "/moderation/block-thread/:id",
102
- "handler": "comments.blockCommentThread",
103
- "config": {
104
- "policies": [["admin::hasPermissions", ["plugins::comments.moderate.block.thread"]]]
105
- }
106
- },
107
- {
108
- "method": "PATCH",
109
- "path": "/moderation/abuse-reports/:commentId/resolve/:id",
110
- "handler": "comments.resolveAbuseReport",
111
- "config": {
112
- "policies": [["admin::hasPermissions", ["plugins::comments.moderate.reports"]]]
113
- }
114
- }
115
- ]
116
- }
@@ -1,270 +0,0 @@
1
- const BASE_COMMENTS = `
2
- id: ID!
3
- content: String!
4
- blocked: Boolean
5
- blockedThread: Boolean
6
- blockReason: String
7
- points: Int
8
- authorUser: UsersPermissionsUser
9
- authorType: String
10
- authorId: String
11
- authorName: String
12
- authorAvatar: String
13
- removed: Boolean
14
- relatedSlug: String
15
- reports: [CommentReport]
16
- `;
17
- const jsonParse = (json) => {
18
- try {
19
- return JSON.parse(json);
20
- } catch (e) {
21
- return {};
22
- }
23
- };
24
- const configRelatedContentTypes = Object.keys(strapi.config
25
- .get('plugins.comments.relatedContentTypes') || {})
26
- .map(key => `${key}: CommentsRelatedContentType`)
27
- .join('\n');
28
- // reports: [CommentReport]
29
- module.exports = {
30
- // language=GraphQL
31
- definition: `
32
- scalar Relation
33
- enum CommentReportReason {
34
- BAD_LANGAUGE
35
- DISCRIMINATION
36
- OTHER
37
- }
38
- type CommentReport {
39
- id: ID!
40
- content: String
41
- reason: CommentReportReason!
42
- resolved: Boolean!
43
- related: Comment
44
- }
45
-
46
- type Comment {
47
- ${BASE_COMMENTS}
48
- }
49
-
50
- type CommentsInHierarchy {
51
- ${BASE_COMMENTS}
52
- children: [Comment]
53
- }
54
-
55
- type CommentsPagination {
56
- items: [Comment]!
57
- total: Int!
58
- page: Float
59
- }
60
-
61
- type CommentsWithThread {
62
- ${BASE_COMMENTS}
63
- threadOf: Comment
64
- }
65
-
66
- type CommentsFindOne {
67
- selected: CommentsWithThread
68
- level: [Comment]!
69
- }
70
-
71
- type CommentsContentTypes {
72
- key: String!
73
- value: String!
74
- }
75
-
76
- type CommentsRelatedContentType {
77
- contentManager: Boolean
78
- isSingle: Boolean
79
- url: String
80
- }
81
-
82
- type CommentsRelatedContentTypes {
83
- ${configRelatedContentTypes}
84
- }
85
-
86
- type CommentsConfig {
87
- contentsTypes: [CommentsContentTypes]!
88
- relatedContentTypes: CommentsRelatedContentTypes
89
- }
90
-
91
- type CommentsContentType {
92
- key: String!
93
- value: String
94
- }
95
-
96
- type CommentRemove {
97
- id: ID!
98
- }
99
-
100
- input NewCommentRelated {
101
- refId: String!
102
- ref: String!
103
- field: String!
104
- }
105
-
106
- input CommentNew {
107
- authorId: String
108
- authorName: String
109
- authorEmail: String
110
- content: String!
111
- authorUsername: String
112
- threadOf: String
113
- related: [NewCommentRelated!]!
114
- }
115
- `,
116
- // language=GraphQL
117
- query: `
118
- findAllInHierarchy(relation: Relation!, where: JSON): [CommentsInHierarchy]!
119
- findAllFlat(relation: Relation!, where: JSON): [Comment]!
120
- findAll(related: Relation, entity: ID, where: JSON): CommentsPagination!
121
- findOne(id: ID!): CommentsFindOne
122
- config: CommentsConfig
123
- contentTypeName(contentType: String!): [CommentsContentType]!
124
- `,
125
- type: {
126
- Relation: 'It is related slug given when comment was created',
127
- },
128
- // language=GraphQL
129
- mutation: `
130
- commentAdd(comment: CommentNew): Comment!
131
- commentUpdate(id: ID!, content: String!, related: NewCommentRelated): Comment!
132
- commentReportAbuse(id: ID!, relation: Relation!, reason: CommentReportReason!, content: String!): CommentReport
133
- commentLike(id: ID!, relation: Relation!): Comment
134
- commentRemove(id: ID!, relation: Relation!, authorId: ID!): CommentRemove
135
- commentBlock(id: ID!): Comment
136
- commentThreadBlock(id: ID!): Comment
137
- commentResolveReport(reportId: ID!, commentId: ID!): CommentReport
138
- `,
139
- resolver: {
140
- Query: {
141
- findAllInHierarchy: {
142
- resolverOf: 'plugins::comments.comments.findAllInHierarchy',
143
- resolver(obj, options) {
144
- const { relation, where } = options;
145
- const query = jsonParse(where);
146
- return strapi.plugins.comments.services.comments.findAllInHierarchy({
147
- relation,
148
- query,
149
- dropBlockedThreads: true,
150
- });
151
- },
152
- },
153
- findAllFlat: {
154
- resolverOf: 'plugins::comments.comments.findAllFlat',
155
- resolver(obj, options) {
156
- const { relation, where } = options;
157
- const query = jsonParse(where);
158
- return strapi.plugins.comments.services.comments.findAllFlat(relation, query);
159
- },
160
- },
161
- findAll: {
162
- resolverOf: 'plugins::comments.comments.findAll',
163
- resolver(obj, options) {
164
- const { related, entity, where } = options;
165
- const query = jsonParse(where);
166
- return strapi.plugins.comments.services.comments.findAll({
167
- ...query,
168
- related,
169
- entity,
170
- });
171
- },
172
- },
173
- findOne: {
174
- resolverOf: 'plugins::comments.comments.findOne',
175
- resolver(obj, options) {
176
- const { id } = options;
177
- return strapi.plugins.comments.services.comments.findOneAndThread(id);
178
- },
179
- },
180
- config: {
181
- resolverOf: 'plugins::comments.comments.config',
182
- resolver(obj, options, { context }) {
183
- return strapi.plugins.comments.controllers.comments.config(context);
184
- },
185
- },
186
- contentTypeName: {
187
- resolverOf: 'plugins::comments.comments.contentTypeName',
188
- resolver(obj, options) {
189
- const { contentType } = options;
190
- return strapi.plugins.comments.services.comments.contentTypeName(contentType);
191
- },
192
- },
193
- },
194
- Mutation: {
195
- commentAdd: {
196
- resolverOf: 'plugins::comments.comments.post',
197
- policies: ['plugins::users-permissions.isAuthenticated'],
198
- resolver(obj, options, { context }) {
199
- const user = context.state.user;
200
- const { comment } = options;
201
- return strapi.plugins.comments.services.comments
202
- .create(comment, user);
203
- },
204
- },
205
- commentUpdate: {
206
- resolverOf: 'plugins::comments.comments.put',
207
- policies: ['plugins::users-permissions.isAuthenticated'],
208
- resolver(obj, options, { context }) {
209
- const user = context.state.user;
210
- const { id, ...data } = options;
211
- return strapi.plugins.comments.services.comments
212
- .update(id, data, user);
213
- },
214
- },
215
- commentReportAbuse: {
216
- resolverOf: 'plugins::comments.comments.reportAbuse',
217
- policies: ['plugins::users-permissions.isAuthenticated'],
218
- resolver(obj, options, { context }) {
219
- const user = context.state.user;
220
- const { id, relation, reason, content } = options;
221
- return strapi.plugins.comments.services.comments
222
- .reportAbuse(id, relation, { reason, content }, user);
223
- },
224
- },
225
- commentLike: {
226
- resolverOf: 'plugins::comments.comments.pointsUp',
227
- policies: ['plugins::users-permissions.isAuthenticated'],
228
- resolver(obj, options, { context }) {
229
- const user = context.state.user;
230
- const { id, relation } = options;
231
- return strapi.plugins.comments.services.comments
232
- .pointsUp(id, relation, user);
233
- },
234
- },
235
- commentRemove: {
236
- resolverOf: 'plugins::comments.comments.removeComment',
237
- resolver(obj, options) {
238
- const { id, relation, authorId } = options;
239
- return strapi.plugins.comments.services.comments
240
- .markAsRemoved(relation, id, authorId);
241
- },
242
- },
243
- commentBlock: {
244
- resolverOf: 'plugins::comments.comments.blockComment',
245
- resolver(obj, options) {
246
- const { id } = options;
247
- return strapi.plugins.comments.services.comments
248
- .blockComment(id);
249
- },
250
- },
251
- commentThreadBlock: {
252
- resolverOf: 'plugins::comments.comments.blockCommentThread',
253
- resolver(obj, options) {
254
- const { id } = options;
255
- return strapi.plugins.comments.services.comments
256
- .blockCommentThread(id);
257
- },
258
- },
259
- commentResolveReport: {
260
- resolverOf: 'plugins::comments.comments.resolveAbuseReport',
261
- resolver(obj, options) {
262
- const { reportId, commentId } = options;
263
- return strapi.plugins.comments.services.comments
264
- .resolveAbuseReport(reportId, commentId);
265
- },
266
- },
267
- },
268
- },
269
- };
270
-
@@ -1,211 +0,0 @@
1
- 'use strict';
2
-
3
- const { parseParams, throwError } = require('./utils/functions');
4
- const _ = require('lodash');
5
-
6
- /**
7
- * comments.js controller
8
- *
9
- * @description: A set of functions called "actions" of the `comments` plugin.
10
- */
11
-
12
- module.exports = {
13
-
14
- getService() {
15
- return strapi.plugins.comments.services.comments;
16
- },
17
-
18
- /**
19
- * Default action.
20
- *
21
- * @return {Object}
22
- */
23
- async findAll(ctx) {
24
- return strapi.plugins.comments.services.comments.findAll(ctx.query);
25
- },
26
-
27
- async findAllFlat(ctx) {
28
- const { params = {}, query } = ctx;
29
- const { relation } = parseParams(params);
30
- try {
31
- return await strapi.plugins.comments.services.comments.findAllFlat(relation, query);
32
- } catch (e) {
33
- throwError(ctx, e);
34
- }
35
- },
36
-
37
- async findAllInHierarchy(ctx) {
38
- const { params = {}, query } = ctx;
39
- const { relation } = parseParams(params);
40
- try {
41
- return await strapi.plugins.comments.services.comments.findAllInHierarchy({
42
- relation,
43
- query,
44
- dropBlockedThreads: true,
45
- });
46
- } catch (e) {
47
- throwError(ctx, e);
48
- }
49
- },
50
-
51
- async post(ctx) {
52
- const { request, state = {} } = ctx;
53
- const { user } = state;
54
- const { body = {} } = request;
55
- try {
56
- const entity = await strapi.plugins.comments.services.comments.create(body, user);
57
- if (entity) {
58
- return entity;
59
- }
60
- } catch (e) {
61
- throwError(ctx, e);
62
- }
63
- },
64
-
65
- async put(ctx) {
66
- const { request, state, params = {} } = ctx;
67
- const { body = {} } = request;
68
- const { user } = state;
69
- const { commentId } = parseParams(params);
70
- try {
71
- return await strapi.plugins.comments.services.comments.update(commentId, body, user);
72
- } catch (e) {
73
- throwError(ctx, e);
74
- }
75
- },
76
-
77
- async pointsUp(ctx) {
78
- const { state, params = {} } = ctx;
79
- const { user } = state;
80
- const { relation, commentId } = parseParams(params);
81
- try {
82
- return await strapi.plugins.comments.services.comments.pointsUp(commentId, relation, user);
83
- } catch (e) {
84
- throwError(ctx, e);
85
- }
86
- },
87
-
88
- async reportAbuse(ctx) {
89
- const { request, state, params = {} } = ctx;
90
- const { body = {} } = request;
91
- if (!body.content) {
92
- return ctx.badRequest(null, 'Content field is required');
93
- }
94
- const { user } = state;
95
- const { relation, commentId } = parseParams(params);
96
- try {
97
- return await strapi.plugins.comments.services.comments.reportAbuse(commentId, relation, body, user);
98
- } catch (e) {
99
- throwError(ctx, e);
100
- }
101
- },
102
-
103
- async removeComment(ctx) {
104
- const { params: { relationId, commentId }, query: { authorId } } = ctx;
105
- if (authorId) {
106
- try {
107
- return await this.getService().markAsRemoved(
108
- relationId,
109
- commentId,
110
- authorId,
111
- );
112
- } catch (e) {
113
- if (!e.isBoom) {
114
- throwError(ctx, e);
115
- }
116
- throw e;
117
- }
118
- }
119
- return ctx.badRequest('Not provided authorId');
120
- },
121
-
122
- //
123
- // Moderation
124
- //
125
-
126
- async findOne(ctx) {
127
- const { params = {} } = ctx;
128
- const { id } = parseParams(params);
129
- try {
130
- return await strapi.plugins.comments.services.comments.findOneAndThread(id);
131
- } catch (e) {
132
- throwError(ctx, e);
133
- }
134
- },
135
-
136
- async blockComment(ctx) {
137
- const { params = {} } = ctx;
138
- const { id } = parseParams(params);
139
- try {
140
- return await strapi.plugins.comments.services.comments.blockComment(id);
141
- } catch (e) {
142
- throwError(ctx, e);
143
- }
144
- },
145
-
146
- async blockCommentThread(ctx) {
147
- const { params = {} } = ctx;
148
- const { id } = parseParams(params);
149
- try {
150
- return await strapi.plugins.comments.services.comments.blockCommentThread(id);
151
- } catch (e) {
152
- throwError(ctx, e);
153
- }
154
- },
155
-
156
- async resolveAbuseReport(ctx) {
157
- const { params = {} } = ctx;
158
- const { id, commentId } = parseParams(params);
159
- try {
160
- return await strapi.plugins.comments.services.comments.resolveAbuseReport(id, commentId);
161
- } catch (e) {
162
- throwError(ctx, e);
163
- }
164
- },
165
-
166
- async config(ctx) {
167
- const configRelatedContentTypes = _.get(strapi.config, ['plugins', 'comments', 'relatedContentTypes'], {});
168
- const contentsTypes = this.getContentsTypes();
169
- const relatedContentTypes = Object
170
- .keys(configRelatedContentTypes)
171
- .reduce((acc, currentKey) => {
172
- const current = configRelatedContentTypes[currentKey];
173
- const { key } = contentsTypes.find(content => content.value === currentKey) || {};
174
- return {
175
- ...acc,
176
- [currentKey]: {
177
- ...current,
178
- globalName: _.snakeCase(key),
179
- },
180
- };
181
- },
182
- {},
183
- );
184
- return {
185
- relatedContentTypes,
186
- contentsTypes,
187
- };
188
- },
189
-
190
- getContentsTypes() {
191
- return Object.entries(strapi.contentTypes)
192
- .filter(([, contentType]) => (
193
- contentType.associations || []).some(_ => _.plugin === 'comments' && _.collection === 'comment'),
194
- )
195
- .reduce((acc, [, contentType]) => [
196
- ...acc,
197
- { key: contentType.globalName, value: contentType.collectionName }],
198
- [],
199
- );
200
- },
201
-
202
- async contentTypeName(ctx) {
203
- const { params: { contentTypeName } } = ctx;
204
- try {
205
- const result = await strapi.plugins.comments.services.comments.contentTypeName(contentTypeName);
206
- return { list: result };
207
- } catch (e) {
208
- throwError(ctx, e);
209
- }
210
- },
211
- };
package/models/comment.js DELETED
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/models.html#life-cycle-callbacks)
5
- * to customize this model
6
- */
7
-
8
- module.exports = {};