strapi-plugin-comments 2.0.0-beta.5 → 2.0.0-rc.2
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 +472 -118
- package/admin/src/components/DiscussionThread/index.js +9 -3
- package/admin/src/components/DiscussionThreadItem/index.js +24 -11
- package/admin/src/components/DiscussionThreadItemActions/index.js +45 -18
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +20 -11
- package/admin/src/components/DiscussionThreadItemMeta/index.js +16 -5
- package/admin/src/components/DiscussionThreadItemWarnings/index.js +15 -9
- 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 +1 -1
- package/admin/src/index.js +1 -1
- package/admin/src/pages/Details/components/DetailsEntity/index.js +2 -2
- package/admin/src/pages/Details/components/DetailsFilters/index.js +1 -0
- package/admin/src/pages/Details/index.js +43 -37
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +38 -11
- package/admin/src/pages/Discover/index.js +72 -59
- package/admin/src/permissions.js +10 -8
- package/admin/src/translations/en.json +2 -0
- package/admin/src/utils/index.js +2 -0
- package/admin/src/utils/renderInitials.js +5 -0
- package/content-types/comment.js +0 -4
- package/package.json +4 -2
- package/permissions.js +19 -0
- package/public/assets/logo.png +0 -0
- package/public/assets/preview.png +0 -0
- package/server/bootstrap.js +38 -2
- package/server/config/index.js +7 -2
- package/server/controllers/client.js +11 -21
- package/server/controllers/utils/parsers.js +19 -0
- package/server/graphql/index.js +26 -0
- package/server/graphql/mutations/createAbuseReport.js +25 -0
- package/server/graphql/mutations/createComment.js +25 -0
- package/server/graphql/mutations/index.js +21 -0
- package/server/graphql/mutations/removeComment.js +25 -0
- package/server/graphql/mutations/updateComment.js +25 -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 +15 -0
- package/server/graphql/types/comment-author.js +9 -0
- package/server/graphql/types/comment-nested.js +15 -0
- package/server/graphql/types/comment.js +15 -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 +16 -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 +20 -16
- package/server/services/client.js +72 -49
- package/server/services/common.js +23 -12
- package/server/services/graphql.js +190 -0
- package/server/services/index.js +2 -0
- package/server/services/utils/functions.js +30 -11
- package/strapi-server.js +33 -0
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<div align="center" width="150px">
|
|
2
|
+
<img style="width: 150px; height: auto;" src="public/assets/logo.png" alt="Logo - Strapi Comments plugin" />
|
|
3
|
+
</div>
|
|
4
|
+
<div align="center">
|
|
5
|
+
<h1>Strapi v4 - Comments plugin</h1>
|
|
6
|
+
<p>Powerfull Strapi based comments moderation tool for you and your users</p>
|
|
4
7
|
<a href="https://www.npmjs.org/package/strapi-plugin-comments">
|
|
5
|
-
<img src="https://img.shields.io/
|
|
8
|
+
<img alt="GitHub package.json version" src="https://img.shields.io/github/package-json/v/VirtusLab-Open-Source/strapi-plugin-comments?label=npm&logo=npm">
|
|
6
9
|
</a>
|
|
7
10
|
<a href="https://www.npmjs.org/package/strapi-plugin-comments">
|
|
8
11
|
<img src="https://img.shields.io/npm/dm/strapi-plugin-comments.svg" alt="Monthly download on NPM" />
|
|
@@ -13,15 +16,32 @@
|
|
|
13
16
|
<a href="https://codecov.io/gh/VirtusLab-Open-Source/strapi-plugin-comments">
|
|
14
17
|
<img src="https://codecov.io/gh/VirtusLab-Open-Source/strapi-plugin-comments/coverage.svg?branch=master" alt="codecov.io" />
|
|
15
18
|
</a>
|
|
16
|
-
</
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<div style="margin: 20px 0" align="center">
|
|
24
|
+
<img style="width: 100%; height: auto;" src="public/assets/preview.png" alt="UI preview" />
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
A plugin for [Strapi Headless CMS](https://github.com/strapi/strapi) that provides end to end comments feature with their moderation panel, bad words filtering, abuse reporting and much more.
|
|
29
|
+
|
|
30
|
+
## ✨ Features
|
|
17
31
|
|
|
18
|
-
|
|
32
|
+
- **Comments Public REST + GraphQL API:** Elegant, entirely customizable and a fully extensible admin panel.
|
|
33
|
+
- **Strapi & generic users:** Support for built-in & also generic non-Strapi users that might be the comments authors.
|
|
34
|
+
- **Any Content Type relation:** Comments can by linked to any of your Content Types by default. Simply, you're controlling it.
|
|
35
|
+
- **Moderation Panel:** Search & Filter through the bucket with your auditory comments. Manage them by blocking single ones or full threads. All in combined list & hierarchical tree view of threads.
|
|
36
|
+
- **Automated Bad Words filtering:** By detault end users are not allowed to post abusing comments where bad words have been used.
|
|
37
|
+
- **Abuse Reporting & Reviewing:** Don't allow inferior language, react to reports from your community, send email notifiactions about abuse reports
|
|
19
38
|
|
|
20
|
-
|
|
21
|
-
- **Stable** - [v1.0.4](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments)
|
|
22
|
-
- **Beta** - v4 support - [v2.0.0-beta.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments/tree/feat/strapi-v4)
|
|
39
|
+
## ⚙️ Versions
|
|
23
40
|
|
|
24
|
-
|
|
41
|
+
- **Strapi v4** - (current) - [v2.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments)
|
|
42
|
+
- **Strapi v3** - [v1.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments/tree/strapi-v3)
|
|
43
|
+
|
|
44
|
+
## ⏳ Installation
|
|
25
45
|
|
|
26
46
|
(Use **yarn** to install this plugin within your Strapi project (recommended). [Install yarn with these docs](https://yarnpkg.com/lang/en/docs/install/).)
|
|
27
47
|
|
|
@@ -42,11 +62,11 @@ or just run Strapi in the development mode with `--watch-admin` option:
|
|
|
42
62
|
yarn develop --watch-admin
|
|
43
63
|
```
|
|
44
64
|
|
|
45
|
-
The **Comments** plugin should appear in the
|
|
65
|
+
The **Comments** plugin should appear in the navigation menu of Strapi after you run app again.
|
|
46
66
|
|
|
47
67
|
Enjoy 🎉
|
|
48
68
|
|
|
49
|
-
|
|
69
|
+
## 🖐 Requirements
|
|
50
70
|
|
|
51
71
|
Complete installation requirements are exact same as for Strapi itself and can be found in the documentation under [Installation Requirements](https://docs.strapi.io/developer-docs/latest/getting-started/introduction.html).
|
|
52
72
|
|
|
@@ -58,37 +78,37 @@ In our minimum support we're following [official Node.js releases timelines](htt
|
|
|
58
78
|
|
|
59
79
|
**Supported Strapi versions**:
|
|
60
80
|
|
|
61
|
-
- Strapi v4.0.
|
|
81
|
+
- Strapi v4.0.6 (recently tested)
|
|
82
|
+
- Strapi v4.x
|
|
62
83
|
|
|
63
|
-
|
|
84
|
+
> This plugin is designed for **Strapi v4** and is not working with v3.x. To get version for **Strapi v3** install version [v1.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments/tree/strapi-v3).
|
|
64
85
|
|
|
65
86
|
**We recommend always using the latest version of Strapi to start your new projects**.
|
|
66
87
|
|
|
67
|
-
##
|
|
68
|
-
|
|
69
|
-
- **Comments Public API:** Elegant, entirely customizable and a fully extensible admin panel.
|
|
70
|
-
- **Strapi & generic users:** Support for built-in & also generic non-Strapi users that might be the comments authors.
|
|
71
|
-
- **Any Content Type relation:** Comments can by linked to any of your Content Types by default. Simply, you're controlling it.
|
|
72
|
-
- **Moderation Panel:** Search & Filter through the bucket with your auditory comments. Manage them by blocking single ones or full threads. All in combined list & hierarchical tree view of threads.
|
|
73
|
-
- **Automated Bad Words filtering:** By detault end users are not allowed to post abusing comments where bad words have been used.
|
|
74
|
-
- **Abuse Reporting & Reviewing:** Don't allow inferior language, react to reports from your community, send email notifiactions about abuse reports
|
|
75
|
-
|
|
76
|
-
## Configuration
|
|
88
|
+
## 🔧 Configuration
|
|
77
89
|
To setup amend default plugin configuration we recommend to put following snippet as part of `config/plugins.js` or `config/<env>/plugins.js` file. If the file does not exist yet, you have to create it manually. If you've got already configurations for other plugins stores by this way, use just the `comments` part within exising `plugins` item.
|
|
78
90
|
|
|
79
91
|
|
|
80
92
|
```js
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
module.exports = ({ env }) => ({
|
|
94
|
+
//...
|
|
95
|
+
comments: {
|
|
96
|
+
badWords: false,
|
|
97
|
+
moderatorRoles: ["Authenticated"],
|
|
98
|
+
approvalFlow: ['api::page.page'],
|
|
99
|
+
entryLabel: {
|
|
100
|
+
'*': ['Title', 'title', 'Name', 'name', 'Subject', 'subject'],
|
|
101
|
+
'api::page.page': ['MyField'],
|
|
102
|
+
},
|
|
103
|
+
reportReasons: {
|
|
104
|
+
'MY_CUSTOM_REASON': 'MY_CUSTOM_REASON',
|
|
105
|
+
},
|
|
106
|
+
gql: {
|
|
107
|
+
// ...
|
|
108
|
+
},
|
|
89
109
|
},
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
//...
|
|
111
|
+
});
|
|
92
112
|
```
|
|
93
113
|
|
|
94
114
|
### Properties
|
|
@@ -96,14 +116,53 @@ To setup amend default plugin configuration we recommend to put following snippe
|
|
|
96
116
|
- `moderatorRoles` - Optional list of names of roles. Users with those roles will be notified by email when a new abuse report is created. This feature requires a built-in [Strapi email plugin](https://docs.strapi.io/developer-docs/latest/plugins/email.html) configured.
|
|
97
117
|
- `approvalFlow` - list of Content Types which are supporting approval flow. Values must be in format like `'api::<collection name>.<content type name>'`. For not included, posted comments are going to be immediately visible.
|
|
98
118
|
- `entryLabel` - ordered list of property names per Content Type to generate related entity label. Keys must be in format like `'api::<collection name>.<content type name>'`. Default formatting set as `*`.
|
|
119
|
+
- `reportReasons` - set of enums you would like to use for issuing abuse reports. Provided by default `'BAD_LANGUAGE'`, `'DISCRIMINATION'` and `'OTHER'`.
|
|
120
|
+
- `gql` - specific configuration for GraphQL. See [Additional GQL Configuration](#additional-gql-configuration)
|
|
99
121
|
|
|
100
122
|
## Additional GQL Configuration
|
|
123
|
+
All you need to do is to install and enable `@strapi/plugin-graphql` for you instance based on the **[official Strapi v4 docs](https://docs.strapi.io/developer-docs/latest/plugins/graphql.html#configurations)** and decide if you would like to call it by anyone (open for world) or only by authenticated users (Strapi users).
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
// ...
|
|
128
|
+
gql: {
|
|
129
|
+
auth: true, // Default: false
|
|
130
|
+
},
|
|
131
|
+
// ...
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Properties
|
|
136
|
+
- `auth` - does GraphQL Queries should be authenticated or not? Default: `false`
|
|
137
|
+
|
|
138
|
+
### Queries
|
|
139
|
+
|
|
140
|
+
See [available GQL specification section](#public-graphql-specification).
|
|
101
141
|
|
|
102
|
-
>
|
|
142
|
+
> If `auth` is set to `true` you must provide relevant authentication headers to all requests like for example:
|
|
143
|
+
>
|
|
144
|
+
> ```json
|
|
145
|
+
> {
|
|
146
|
+
> "Authorization": "Bearer <your token here>"
|
|
147
|
+
> }
|
|
148
|
+
> ```
|
|
103
149
|
|
|
104
|
-
##
|
|
150
|
+
## 👤 RBAC
|
|
151
|
+
Plugin provides granular permissions based on Strapi RBAC functionality.
|
|
152
|
+
|
|
153
|
+
### Mandatory permissions
|
|
154
|
+
For any role different than **Super Admin**, to access the **Comments panel** you must set following permissions:
|
|
155
|
+
- _Plugins_ -> _Content-type-builder_ -> _Read_ - gives you ability to fetch Content Type schema
|
|
156
|
+
- _Plugins_ -> _Comments_ -> _Comments: Read_ - gives you the basic read access to **Comments Panel**
|
|
157
|
+
|
|
158
|
+
### Optional permissions
|
|
159
|
+
Feature / Capability focused permissions:
|
|
160
|
+
- _Plugins_ -> _Comments_ -> _Comments: Moderate_ - allows you to block, unblock, approve & reject comments
|
|
161
|
+
- _Plugins_ -> _Comments_ -> _Reports: Read_ - allows you to see the list of issued abuse reports against comments
|
|
162
|
+
- _Plugins_ -> _Comments_ -> _Reports: Moderate_ - allows you to review (resolve) issued abuse reports against comments
|
|
163
|
+
|
|
164
|
+
## Base Comment model
|
|
105
165
|
|
|
106
|
-
### Generic (non Strapi User)
|
|
107
166
|
```json
|
|
108
167
|
{
|
|
109
168
|
"id": 1,
|
|
@@ -112,52 +171,31 @@ To setup amend default plugin configuration we recommend to put following snippe
|
|
|
112
171
|
"blockedThread": true,
|
|
113
172
|
"blockReason": null,
|
|
114
173
|
"authorUser": null,
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"reports": [] // Reports issued against this comment
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
### Strapi User
|
|
126
|
-
```json
|
|
127
|
-
{
|
|
128
|
-
"id": 1,
|
|
129
|
-
"content": "My comment content",
|
|
130
|
-
"blocked": true,
|
|
131
|
-
"blockedThread": null,
|
|
132
|
-
"blockReason": null,
|
|
133
|
-
"authorUser": {
|
|
134
|
-
"id": 1,
|
|
135
|
-
"username": "Sample User",
|
|
136
|
-
"email": "user@sample.com",
|
|
137
|
-
"provider": "local",
|
|
138
|
-
"confirmed": true,
|
|
139
|
-
"blocked": false,
|
|
140
|
-
"role": 1,
|
|
141
|
-
"created_at": "2020-07-10T08:38:03.157Z",
|
|
142
|
-
"updated_at": "2020-07-10T08:38:03.170Z"
|
|
174
|
+
"removed": null,
|
|
175
|
+
"approvalStatus": "APPROVED", // Only in case of enabled approval flow. Default: null
|
|
176
|
+
"author": {
|
|
177
|
+
"id": "207ccfdc-94ba-45eb-979c-790f6f49c392", // For Strapi users id reflects to the format used by your Strapi
|
|
178
|
+
"name": "Joe Doe", // For Strapi users it is equal to 'username' field
|
|
179
|
+
"email": "jdoe@sample.com",
|
|
180
|
+
"avatar": null,
|
|
143
181
|
},
|
|
144
|
-
"authorId": null,
|
|
145
|
-
"authorName": null,
|
|
146
|
-
"authorEmail": null,
|
|
147
|
-
"authorAvatar": null,
|
|
148
182
|
"createdAt": "2020-07-14T20:13:01.649Z",
|
|
149
183
|
"updatedAt": "2020-07-14T20:13:01.670Z",
|
|
150
184
|
"related": {}, // Related content type entity
|
|
151
185
|
"reports": [] // Reports issued against this comment
|
|
152
186
|
}
|
|
153
|
-
|
|
154
187
|
```
|
|
155
188
|
|
|
156
|
-
## Public API specification
|
|
189
|
+
## 🕸️ Public REST API specification
|
|
190
|
+
|
|
191
|
+
**Strapi Users vs. Generic authors**
|
|
192
|
+
> Keep in mind that if you're using auth / authz your requests to setup proper user contexts it has got higher priority in order to take author data comparing to `author` property provided as part of your payload.
|
|
157
193
|
|
|
158
194
|
### Get Comments
|
|
159
195
|
|
|
160
|
-
|
|
196
|
+
*GraphQL equivalent: [Public GraphQL API -> Get Comments](#get-comments-1)*
|
|
197
|
+
|
|
198
|
+
`GET <host>/api/comments/api::<collection name>.<content type name>:<entity id>`
|
|
161
199
|
|
|
162
200
|
Return a hierarchical tree structure of comments for specified instance of Content Type like for example `Page` with `ID: 1`
|
|
163
201
|
|
|
@@ -165,25 +203,29 @@ Return a hierarchical tree structure of comments for specified instance of Conte
|
|
|
165
203
|
|
|
166
204
|
**Example response body**
|
|
167
205
|
|
|
168
|
-
```
|
|
206
|
+
```json
|
|
169
207
|
[
|
|
170
208
|
{
|
|
171
|
-
-- Comment Model fields ---,
|
|
209
|
+
// -- Comment Model fields ---,
|
|
172
210
|
children: [
|
|
173
211
|
{
|
|
174
|
-
-- Comment Model fields ---,
|
|
175
|
-
children: [
|
|
212
|
+
// -- Comment Model fields ---,
|
|
213
|
+
children: [
|
|
214
|
+
// ...
|
|
215
|
+
]
|
|
176
216
|
},
|
|
177
|
-
...
|
|
217
|
+
// ...
|
|
178
218
|
]
|
|
179
219
|
},
|
|
180
|
-
...
|
|
220
|
+
// ...
|
|
181
221
|
]
|
|
182
222
|
```
|
|
183
223
|
|
|
184
224
|
### Get Comments (flat structure)
|
|
185
225
|
|
|
186
|
-
|
|
226
|
+
*GraphQL equivalent: [Public GraphQL API -> Get Comments (flat structure)](#get-comments-flat-structure-1)*
|
|
227
|
+
|
|
228
|
+
`GET <host>/api/comments/api::<collection name>.<content type name>:<entity id>/flat`
|
|
187
229
|
|
|
188
230
|
Return a flat structure of comments for specified instance of Content Type like for example `Page` with `ID: 1`
|
|
189
231
|
|
|
@@ -191,15 +233,15 @@ Return a flat structure of comments for specified instance of Content Type like
|
|
|
191
233
|
|
|
192
234
|
**Example response body**
|
|
193
235
|
|
|
194
|
-
```
|
|
236
|
+
```json
|
|
195
237
|
[
|
|
196
238
|
{
|
|
197
|
-
-- Comment Model fields ---
|
|
239
|
+
// -- Comment Model fields ---
|
|
198
240
|
},
|
|
199
241
|
{
|
|
200
|
-
-- Comment Model fields ---
|
|
242
|
+
// -- Comment Model fields ---
|
|
201
243
|
},
|
|
202
|
-
...
|
|
244
|
+
// ...
|
|
203
245
|
]
|
|
204
246
|
```
|
|
205
247
|
|
|
@@ -209,7 +251,9 @@ Return a flat structure of comments for specified instance of Content Type like
|
|
|
209
251
|
|
|
210
252
|
### Post a Comment
|
|
211
253
|
|
|
212
|
-
|
|
254
|
+
*GraphQL equivalent: [Public GraphQL API -> Post a Comments](#post-a-comment-1)*
|
|
255
|
+
|
|
256
|
+
`POST <host>/api/comments/api::<collection name>.<content type name>:<entity id>`
|
|
213
257
|
|
|
214
258
|
Posts a Comment related to specified instance of Content Type like for example `Page` with `ID: 1`
|
|
215
259
|
|
|
@@ -218,23 +262,25 @@ Posts a Comment related to specified instance of Content Type like for example `
|
|
|
218
262
|
**Example request body**
|
|
219
263
|
|
|
220
264
|
*Generic (non Strapi User)*
|
|
221
|
-
```
|
|
265
|
+
```json
|
|
222
266
|
{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
267
|
+
"author": {
|
|
268
|
+
"id": "<any ID like value>",
|
|
269
|
+
"name": "Joe Doe",
|
|
270
|
+
"email": "jdoe@sample.com",
|
|
271
|
+
"avatar": "<any image url>"
|
|
272
|
+
},
|
|
229
273
|
"content": "My sample response",
|
|
230
274
|
"threadOf": 2, // id of comment we would like to start / continue the thread (Optional)
|
|
231
275
|
}
|
|
232
276
|
```
|
|
233
277
|
|
|
234
278
|
*Strapi user*
|
|
235
|
-
|
|
279
|
+
|
|
280
|
+
> Author is taken directly from the request context
|
|
281
|
+
|
|
282
|
+
```json
|
|
236
283
|
{
|
|
237
|
-
"authorUser": 1, // id of a author user. Optional in case of 'enableUsers: true' in the plugin configuration
|
|
238
284
|
"content": "My sample response",
|
|
239
285
|
"threadOf": 2, // id of comment we would like to start / continue the thread (Optional)
|
|
240
286
|
}
|
|
@@ -242,9 +288,9 @@ Posts a Comment related to specified instance of Content Type like for example `
|
|
|
242
288
|
|
|
243
289
|
**Example response body**
|
|
244
290
|
|
|
245
|
-
```
|
|
291
|
+
```json
|
|
246
292
|
{
|
|
247
|
-
-- Comment Model fields ---
|
|
293
|
+
// -- Comment Model fields ---
|
|
248
294
|
}
|
|
249
295
|
```
|
|
250
296
|
|
|
@@ -254,7 +300,9 @@ Posts a Comment related to specified instance of Content Type like for example `
|
|
|
254
300
|
|
|
255
301
|
### Update Comment
|
|
256
302
|
|
|
257
|
-
|
|
303
|
+
*GraphQL equivalent: [Public GraphQL API -> Update Comments](#update-comment-1)*
|
|
304
|
+
|
|
305
|
+
`PUT <host>/api/comments/api::<collection name>.<content type name>:<entity id>/comment/<commentId>`
|
|
258
306
|
|
|
259
307
|
Updates a specified Comment content based on it `commentId` and related to specified instance of Content Type like for example `Page` with `ID: 1`
|
|
260
308
|
|
|
@@ -263,28 +311,30 @@ Updates a specified Comment content based on it `commentId` and related to speci
|
|
|
263
311
|
**Example request body**
|
|
264
312
|
|
|
265
313
|
*Generic (non Strapi User)*
|
|
266
|
-
```
|
|
314
|
+
```json
|
|
267
315
|
{
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
316
|
+
"author": {
|
|
317
|
+
"id": "<any ID like value>"
|
|
318
|
+
},
|
|
271
319
|
"content": "My sample response"
|
|
272
320
|
}
|
|
273
321
|
```
|
|
274
322
|
|
|
275
323
|
*Strapi user*
|
|
276
|
-
|
|
324
|
+
|
|
325
|
+
> Author is taken directly from the request context
|
|
326
|
+
|
|
327
|
+
```json
|
|
277
328
|
{
|
|
278
|
-
"authorUser": 1, // id of a author user. Optional in case of 'enableUsers: true' in the plugin configuration
|
|
279
329
|
"content": "My sample response"
|
|
280
330
|
}
|
|
281
331
|
```
|
|
282
332
|
|
|
283
333
|
**Example response body**
|
|
284
334
|
|
|
285
|
-
```
|
|
335
|
+
```json
|
|
286
336
|
{
|
|
287
|
-
-- Comment Model fields ---
|
|
337
|
+
// -- Comment Model fields ---
|
|
288
338
|
}
|
|
289
339
|
```
|
|
290
340
|
|
|
@@ -295,7 +345,9 @@ Updates a specified Comment content based on it `commentId` and related to speci
|
|
|
295
345
|
|
|
296
346
|
### Delete Comment
|
|
297
347
|
|
|
298
|
-
|
|
348
|
+
*GraphQL equivalent: [Public GraphQL API -> Delete Comment](#delete-comment-1)*
|
|
349
|
+
|
|
350
|
+
`DELETE <host>/api/comments/api::<collection name>.<content type name>:<entity id>/<commentId>?authorId=<authorId>`
|
|
299
351
|
|
|
300
352
|
Deletes a specified Comment based on it `commentId` and related to specified instance of Content Type like for example `Page` with `ID: 1`.
|
|
301
353
|
|
|
@@ -303,9 +355,9 @@ Deletes a specified Comment based on it `commentId` and related to specified ins
|
|
|
303
355
|
|
|
304
356
|
**Example response body**
|
|
305
357
|
|
|
306
|
-
```
|
|
358
|
+
```json
|
|
307
359
|
{
|
|
308
|
-
-- Empty Response ---
|
|
360
|
+
// -- Empty Response ---
|
|
309
361
|
}
|
|
310
362
|
```
|
|
311
363
|
|
|
@@ -314,9 +366,11 @@ Deletes a specified Comment based on it `commentId` and related to specified ins
|
|
|
314
366
|
- `409` - Conflict. Occurs when trying to delete a non existing comment.
|
|
315
367
|
|
|
316
368
|
|
|
317
|
-
### Report
|
|
369
|
+
### Issue Abuse Report against specified Comment
|
|
370
|
+
|
|
371
|
+
*GraphQL equivalent: [Public GraphQL API -> Issue Abuse Report against specified Comment](#issue-abuse-report-against-specified-comment-1)*
|
|
318
372
|
|
|
319
|
-
`POST <host>/comments/api::<collection name>.<content type name>:<entity id>/comment/<commentId>/report-abuse`
|
|
373
|
+
`POST <host>/api/comments/api::<collection name>.<content type name>:<entity id>/comment/<commentId>/report-abuse`
|
|
320
374
|
|
|
321
375
|
Reports abuse in specified Comment content based on it `commentId` and related to specified instance of Content Type like for example `Page` with `ID: 1` and requests moderator attention.
|
|
322
376
|
|
|
@@ -324,20 +378,20 @@ Reports abuse in specified Comment content based on it `commentId` and related t
|
|
|
324
378
|
|
|
325
379
|
**Example request body**
|
|
326
380
|
|
|
327
|
-
```
|
|
381
|
+
```json
|
|
328
382
|
{
|
|
329
383
|
"reason": "<reason enum>",
|
|
330
384
|
"content": "This comment is not relevant"
|
|
331
385
|
}
|
|
332
386
|
```
|
|
333
387
|
|
|
334
|
-
*Available reason enums:* `
|
|
388
|
+
*Available reason enums:* `BAD_WORDS`, `OTHER`, `DISCRIMINATION` (want more? See [configuration section](#configuration).)
|
|
335
389
|
|
|
336
390
|
**Example response body**
|
|
337
391
|
|
|
338
|
-
```
|
|
392
|
+
```json
|
|
339
393
|
{
|
|
340
|
-
-- Comment Abuse Report fields ---
|
|
394
|
+
// -- Comment Abuse Report fields ---
|
|
341
395
|
}
|
|
342
396
|
```
|
|
343
397
|
|
|
@@ -345,15 +399,315 @@ Reports abuse in specified Comment content based on it `commentId` and related t
|
|
|
345
399
|
- `200` - Successful. Response with reported abuse.
|
|
346
400
|
- `409` - Conflict. Occurs when trying to report an abuse to a non existing comment.
|
|
347
401
|
|
|
348
|
-
##
|
|
402
|
+
## 🕸️ Public GraphQL specification
|
|
403
|
+
|
|
404
|
+
**Strapi Users vs. Generic authors**
|
|
405
|
+
> Keep in mind that if you're using auth / authz your requests to setup proper user contexts it has got higher priority in order to take author data comparing to `author` property provided as part of your payload.
|
|
406
|
+
|
|
407
|
+
**Testing**
|
|
408
|
+
> To test all queries and understand the schemas use GraphQL Playground exposed by `@strapi/plugin-graphql` on `http://localhost:1337/graphql`
|
|
409
|
+
|
|
410
|
+
### Get Comments
|
|
411
|
+
|
|
412
|
+
*REST API equivalent: [Public REST API -> Get Comments](#get-comments)*
|
|
413
|
+
|
|
414
|
+
**Example request**
|
|
415
|
+
|
|
416
|
+
```graphql
|
|
417
|
+
query {
|
|
418
|
+
findAllFlat(
|
|
419
|
+
relation: "api::page.page:1"
|
|
420
|
+
filters: { content: { contains: "Test" } }
|
|
421
|
+
) {
|
|
422
|
+
id
|
|
423
|
+
content
|
|
424
|
+
blocked
|
|
425
|
+
threadOf {
|
|
426
|
+
id
|
|
427
|
+
}
|
|
428
|
+
author {
|
|
429
|
+
id
|
|
430
|
+
name
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
**Example response**
|
|
437
|
+
|
|
438
|
+
```json
|
|
439
|
+
{
|
|
440
|
+
"data": {
|
|
441
|
+
"findAllFlat": [
|
|
442
|
+
{
|
|
443
|
+
"id": 3,
|
|
444
|
+
"content": "Test",
|
|
445
|
+
"blocked": false,
|
|
446
|
+
"threadOf": null,
|
|
447
|
+
"author": {
|
|
448
|
+
"id": "123456",
|
|
449
|
+
"name": "Joe Doe"
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
// ...
|
|
453
|
+
]
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Get Comments (flat structure)
|
|
458
|
+
|
|
459
|
+
*REST API equivalent: [Public REST API -> Get Comments (flat structure)](#get-comments-flat-structure)*
|
|
460
|
+
|
|
461
|
+
**Example request**
|
|
462
|
+
|
|
463
|
+
```graphql
|
|
464
|
+
query {
|
|
465
|
+
findAllInHierarchy(relation: "api::page.page:1") {
|
|
466
|
+
id
|
|
467
|
+
content
|
|
468
|
+
blocked
|
|
469
|
+
children {
|
|
470
|
+
id
|
|
471
|
+
content
|
|
472
|
+
}
|
|
473
|
+
threadOf {
|
|
474
|
+
id
|
|
475
|
+
}
|
|
476
|
+
author {
|
|
477
|
+
id
|
|
478
|
+
name
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**Example response**
|
|
485
|
+
|
|
486
|
+
```json
|
|
487
|
+
{
|
|
488
|
+
"data": {
|
|
489
|
+
"findAllInHierarchy": [
|
|
490
|
+
{
|
|
491
|
+
"id": 1,
|
|
492
|
+
"content": "Test",
|
|
493
|
+
"blocked": false,
|
|
494
|
+
"children": [
|
|
495
|
+
{
|
|
496
|
+
"id": 6,
|
|
497
|
+
"content": "Text to search for"
|
|
498
|
+
},
|
|
499
|
+
// ...
|
|
500
|
+
],
|
|
501
|
+
"threadOf": null,
|
|
502
|
+
"author": {
|
|
503
|
+
"id": "123456",
|
|
504
|
+
"name": "Joe Doe"
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
// ...
|
|
508
|
+
]
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### Post a Comment
|
|
514
|
+
|
|
515
|
+
*REST API equivalent: [Public REST API -> Post a Comment](#post-a-comment)*
|
|
516
|
+
|
|
517
|
+
**Example request**
|
|
518
|
+
|
|
519
|
+
```graphql
|
|
520
|
+
mutation createComment {
|
|
521
|
+
createComment(
|
|
522
|
+
input: {
|
|
523
|
+
relation: "api::page.page:1"
|
|
524
|
+
content: "Hello World!"
|
|
525
|
+
threadOf: 3
|
|
526
|
+
author: { id: "12345678", name: "John Wick", email: "test@test.pl" } # Optional if using auth / authz requests
|
|
527
|
+
}
|
|
528
|
+
) {
|
|
529
|
+
id
|
|
530
|
+
content
|
|
531
|
+
threadOf {
|
|
532
|
+
id
|
|
533
|
+
}
|
|
534
|
+
author {
|
|
535
|
+
id
|
|
536
|
+
name
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
**Example response**
|
|
543
|
+
|
|
544
|
+
```json
|
|
545
|
+
{
|
|
546
|
+
"data": {
|
|
547
|
+
"createComment": {
|
|
548
|
+
"id": 34,
|
|
549
|
+
"content": "Hello World!",
|
|
550
|
+
"threadOf": {
|
|
551
|
+
"id": 3
|
|
552
|
+
},
|
|
553
|
+
"author": {
|
|
554
|
+
"id": "12345678",
|
|
555
|
+
"name": "John Wick"
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Update Comment
|
|
563
|
+
|
|
564
|
+
*REST API equivalent: [Public REST API -> Update Comment](#update-comment)*
|
|
565
|
+
|
|
566
|
+
**Example request**
|
|
567
|
+
|
|
568
|
+
```graphql
|
|
569
|
+
mutation updateComment {
|
|
570
|
+
updateComment(
|
|
571
|
+
input: {
|
|
572
|
+
id: 34
|
|
573
|
+
relation: "api::page.page:1"
|
|
574
|
+
content: "I've changed it!"
|
|
575
|
+
author: { id: "12345678" } # Optional if using auth / authz requests
|
|
576
|
+
}
|
|
577
|
+
) {
|
|
578
|
+
id
|
|
579
|
+
content
|
|
580
|
+
threadOf {
|
|
581
|
+
id
|
|
582
|
+
}
|
|
583
|
+
author {
|
|
584
|
+
id
|
|
585
|
+
name
|
|
586
|
+
}
|
|
587
|
+
createdAt
|
|
588
|
+
updatedAt
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
**Example response**
|
|
594
|
+
|
|
595
|
+
```json
|
|
596
|
+
{
|
|
597
|
+
"data": {
|
|
598
|
+
"updateComment": {
|
|
599
|
+
"id": 34,
|
|
600
|
+
"content": "I've changed it!",
|
|
601
|
+
"threadOf": {
|
|
602
|
+
"id": 3
|
|
603
|
+
},
|
|
604
|
+
"author": {
|
|
605
|
+
"id": "12345678",
|
|
606
|
+
"name": "John Wick"
|
|
607
|
+
},
|
|
608
|
+
"createdAt": "2022-01-26T07:45:35.978Z",
|
|
609
|
+
"updatedAt": "2022-01-26T07:47:44.659Z"
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Delete Comment
|
|
616
|
+
|
|
617
|
+
*REST API equivalent: [Public REST API -> Delete Comment](#delete-comment)*
|
|
618
|
+
|
|
619
|
+
**Example request**
|
|
620
|
+
|
|
621
|
+
```graphql
|
|
622
|
+
mutation removeComment {
|
|
623
|
+
removeComment(
|
|
624
|
+
input: {
|
|
625
|
+
id: 33,
|
|
626
|
+
relation: "api::page.page:1",
|
|
627
|
+
author: { id: "12345678" } # Optional if using auth / authz requests
|
|
628
|
+
}
|
|
629
|
+
) {
|
|
630
|
+
id
|
|
631
|
+
removed
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
**Example response**
|
|
637
|
+
|
|
638
|
+
```json
|
|
639
|
+
{
|
|
640
|
+
"data": {
|
|
641
|
+
"removeComment": {
|
|
642
|
+
"id": 33,
|
|
643
|
+
"removed": true
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
### Issue Abuse Report against specified Comment
|
|
650
|
+
|
|
651
|
+
*REST API equivalent: [Public REST API -> Issue Abuse Report against specified Comment](#issue-abuse-report-against-specified-comment)*
|
|
652
|
+
|
|
653
|
+
**Example request body**
|
|
654
|
+
|
|
655
|
+
```graphql
|
|
656
|
+
mutation createAbuseReport {
|
|
657
|
+
createAbuseReport(
|
|
658
|
+
input: {
|
|
659
|
+
commentId: 34
|
|
660
|
+
relation: "api::page.page:1"
|
|
661
|
+
reason: BAD_LANGUAGE
|
|
662
|
+
content: "Rude language"
|
|
663
|
+
}
|
|
664
|
+
) {
|
|
665
|
+
id
|
|
666
|
+
reason
|
|
667
|
+
content
|
|
668
|
+
related {
|
|
669
|
+
id
|
|
670
|
+
author {
|
|
671
|
+
id
|
|
672
|
+
name
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
*Available reason enums:* `BAD_WORDS`, `OTHER`, `DISCRIMINATION` (want more? See [configuration section](#configuration).)
|
|
680
|
+
|
|
681
|
+
**Example response**
|
|
682
|
+
|
|
683
|
+
```json
|
|
684
|
+
{
|
|
685
|
+
"data": {
|
|
686
|
+
"createAbuseReport": {
|
|
687
|
+
"id": 28,
|
|
688
|
+
"content": "Rude language",
|
|
689
|
+
"reason": "DISCRIMINATION",
|
|
690
|
+
"related": {
|
|
691
|
+
"id": 34,
|
|
692
|
+
"author": {
|
|
693
|
+
"id": "12345678",
|
|
694
|
+
"name": "John Wick"
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
## 🧩 Examples
|
|
349
703
|
|
|
350
|
-
Live example of plugin usage can be found in the [VirtusLab Strapi Examples](https://github.com/VirtusLab/strapi-examples/tree/master/strapi-plugin-comments) repository.
|
|
704
|
+
Live example of plugin usage can be found in the [VirtusLab Strapi Examples](https://github.com/VirtusLab/strapi-examples/tree/master/strapi-v4-plugin-comments) repository.
|
|
351
705
|
|
|
352
|
-
## Contributing
|
|
706
|
+
## 🤝 Contributing
|
|
353
707
|
|
|
354
708
|
Feel free to fork and make a Pull Request to this plugin project. All the input is warmly welcome!
|
|
355
709
|
|
|
356
|
-
## Community support
|
|
710
|
+
## 👨💻 Community support
|
|
357
711
|
|
|
358
712
|
For general help using Strapi, please refer to [the official Strapi documentation](https://strapi.io/documentation/). For additional help, you can use one of these channels to ask a question:
|
|
359
713
|
|
|
@@ -361,6 +715,6 @@ For general help using Strapi, please refer to [the official Strapi documentatio
|
|
|
361
715
|
- [Slack - VirtusLab Open Source](https://virtuslab-oss.slack.com) We're present on a public channel #strapi-molecules
|
|
362
716
|
- [GitHub](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments/issues) (Bug reports, Contributions, Questions and Discussions)
|
|
363
717
|
|
|
364
|
-
## License
|
|
718
|
+
## 📝 License
|
|
365
719
|
|
|
366
720
|
[MIT License](LICENSE.md) Copyright (c) [VirtusLab Sp. z o.o.](https://virtuslab.com/) & [Strapi Solutions](https://strapi.io/).
|