diff --git a/README.md b/README.md
index 84ea267f..210d5907 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ Enjoy 🎉
### 🖐 Requirements
-Complete installation requirements are exact same as for Strapi itself and can be found in the documentation under Installation Requirements.
+Complete installation requirements are exact same as for Strapi itself and can be found in the documentation under [Installation Requirements](https://strapi.io/documentation/v3.x/installation/cli.html#step-1-make-sure-requirements-are-met).
**Supported Strapi versions**:
@@ -64,13 +64,13 @@ Complete installation requirements are exact same as for Strapi itself and can b
- **Any Content Type relation:** Comments can by linked to any of your Content Types by default. Simply, you're controlling it.
- **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.
- **Automated Bad Words filtering:** By detault end users are not allowed to post abusing comments where bad words have been used.
-- **Abuse Reporting & Reviewing:** Don't allow inferior language, react to reports from your community
+- **Abuse Reporting & Reviewing:** Don't allow inferior language, react to reports from your community, send email notifiactions about abuse reports
## Content Type model relation to Comment
To enable Content Type to work with Comments, you've to add following field to your model `*.settings.json`:
-```
+```json
"comments": {
"plugin": "comments",
"collection": "comment",
@@ -80,7 +80,7 @@ To enable Content Type to work with Comments, you've to add following field to y
inside the `attributes` section like in example below:
-```
+```json
"attributes": {
...,
"comments": {
@@ -95,25 +95,28 @@ inside the `attributes` section like in example below:
## Configuration
To setup amend default plugin configuration we recommend to put following snippet as part of `config/plugins.js` or `config//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.
-```
+
+```js
...
comments: {
enableUsers: true,
- badWords: false
+ badWords: false,
+ moderatorRoles: ["Authenticated"]
},
...
```
### Properties
- `enableUsers` - Enabled support for built-in Strapi users, if endpoints are exposed with usage of `Authenticated` policy or JWT tokens are in use by the Client App. Default value: `false`.
-- `badWords` - Enabled support for (bad words filtering)[https://www.npmjs.com/package/bad-words]. Can be turned off or overwritten using (options reference)[https://www.npmjs.com/package/bad-words#constructor]. Default value: `true`.
+- `badWords` - Enabled support for [bad words filtering](https://www.npmjs.com/package/bad-words). Can be turned off or overwritten using [options reference](https://www.npmjs.com/package/bad-words#constructor). Default value: `true`.
+- `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://strapi.io/documentation/developer-docs/latest/development/plugins/email.html) configured.
## Additional GQL Configuration
> **Note**
> Introduced in `v1.0.2`
-```
+```js
...
comments: {
enableUsers: true,
@@ -144,7 +147,7 @@ To setup amend default plugin configuration we recommend to put following snippe
## Public API Comment model
### Generic (non Strapi User)
-```
+```json
{
"id": 1,
"content": "My comment content",
@@ -162,7 +165,7 @@ To setup amend default plugin configuration we recommend to put following snippe
}
```
### Strapi User
-```
+```json
{
"id": 1,
"content": "My comment content",
diff --git a/services/comments.js b/services/comments.js
index 5e645c01..0291295e 100644
--- a/services/comments.js
+++ b/services/comments.js
@@ -325,14 +325,15 @@ module.exports = {
},
// Report abuse in comment
- async reportAbuse(id, relation, payload, user) {
+ async reportAbuse(id, relation, payload, user) {
if (!isValidUserContext(user)) {
throw resolveUserContextError(user);
}
const { pluginName, plugin } = extractMeta(strapi.plugins);
const { report: reportModel } = plugin.models;
- const existingEntity = await this.findOne(id, relation);
- if (existingEntity) {
+ const existingEntity = await this.findOne(id, relation);
+ if (existingEntity) {
+ await this.sendAbuseReportEmail(payload.reason, payload.content); // Could also add some info about relation
return strapi.query(reportModel.modelName, pluginName).create({
...payload,
resolved: false,
@@ -508,5 +509,31 @@ module.exports = {
sanitizeCommentEntity: (entity) => ({
...entity,
authorUser: sanitizeEntity(entity.authorUser, { model: strapi.plugins['users-permissions'].models.user }),
- }),
+ }),
+
+ async sendAbuseReportEmail(reason, content) {
+ const pluginName = 'users-permissions';
+ const userModel = 'user';
+ const rolesToBeNotified = get(strapi.config, "plugins.comments.moderatorRoles", []);
+
+ const ormModel = strapi.query('user', pluginName);
+ const query = { 'role.name': rolesToBeNotified }
+ const users = await ormModel.find(query);
+
+ const moderatorsEmails = users.map(user => user.email);
+ const superAdmins = await strapi.query('user', 'admin').find({'roles.id': 1})
+
+ if (moderatorsEmails.length > 0) {
+ strapi.plugins['email'].services.email.send({
+ to: moderatorsEmails,
+ from: superAdmins[0].email,
+ subject: 'New abuse report on comment',
+ text: `
+ There was a new abuse report on your app.
+ Reason: ${reason}
+ Message: ${content}
+ `,
+ }).catch(err => strapi.log(err));
+ }
+ }
};