Skip to content

Commit

Permalink
Merge branch 'master' into feat/report-email-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
cyp3rius authored Nov 14, 2021
2 parents caf935d + dda0f51 commit 51cffe8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
41 changes: 19 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,15 @@ 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/custom.js` or `config/<env>/custom.js` file. If you've got already configurations for other plugins stores by this way, use just the `comments` part within exising `plugins` item.
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.


```js
...
plugins: {
comments: {
enableUsers: true,
badWords: false,
moderatorRoles: ["Authenticated"]
},
comments: {
enableUsers: true,
badWords: false,
moderatorRoles: ["Authenticated"]
},
...
```
Expand All @@ -119,22 +118,20 @@ To setup amend default plugin configuration we recommend to put following snippe
```js
...
plugins: {
comments: {
enableUsers: true,
badWords: false,
relatedContentTypes: {
pages: {
uuid: 'application::pages.pages',
contentManager: true,
isSingle: true, // optional
__contentType: '',
key: 'title',
value: 'id',
url: 'my-custom-url/:id' // optional
}
comments: {
enableUsers: true,
badWords: false,
relatedContentTypes: {
pages: {
uuid: 'application::pages.pages',
contentManager: true,
isSingle: true, // optional
__contentType: '',
key: 'title',
value: 'id',
url: 'my-custom-url/:id' // optional
}
},
}
},
...
```
Expand Down
17 changes: 4 additions & 13 deletions config/schema.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ const BASE_COMMENTS = `
reports: [CommentReport]
approvalStatus: CommentApprovalStatus
`;
const jsonParse = (json) => {
try {
return JSON.parse(json);
} catch (e) {
return {};
}
};

const configRelatedContentTypes = Object.keys(strapi.config
.get('plugins.comments.relatedContentTypes') || {})
.map(key => `${key}: CommentsRelatedContentType`)
Expand Down Expand Up @@ -149,10 +143,9 @@ module.exports = {
resolverOf: 'plugins::comments.comments.findAllInHierarchy',
resolver(obj, options) {
const { relation, where } = options;
const query = jsonParse(where);
return strapi.plugins.comments.services.comments.findAllInHierarchy({
relation,
query,
where,
dropBlockedThreads: true,
});
},
Expand All @@ -161,17 +154,15 @@ module.exports = {
resolverOf: 'plugins::comments.comments.findAllFlat',
resolver(obj, options) {
const { relation, where } = options;
const query = jsonParse(where);
return strapi.plugins.comments.services.comments.findAllFlat(relation, query);
return strapi.plugins.comments.services.comments.findAllFlat(relation, where);
},
},
findAll: {
resolverOf: 'plugins::comments.comments.findAll',
resolver(obj, options) {
const { related, entity, where } = options;
const query = jsonParse(where);
return strapi.plugins.comments.services.comments.findAll({
...query,
...where,
related,
entity,
});
Expand Down
16 changes: 7 additions & 9 deletions services/utils/__tests__/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ beforeEach(() => {
}
},
config: {
custom: {
plugins: {
comments: {
enableUsers: false,
}
plugins: {
comments: {
enableUsers: false,
}
}
}
Expand All @@ -31,7 +29,7 @@ beforeEach(() => {
})

describe('Test Comments service functions utils', () => {

describe('Bad Words filtering', () => {
const text = 'Lorem ipsum dolor sit fuck amet';

Expand All @@ -55,7 +53,7 @@ describe('Test Comments service functions utils', () => {
});

test('Should skip bad words filtering because of configuration change', () => {
global.strapi.config.custom.plugins.comments.badWords = false;
global.strapi.config.plugins.comments.badWords = false;

expect(checkBadWords(text)).toEqual(text);
});
Expand All @@ -74,13 +72,13 @@ describe('Test Comments service functions utils', () => {

describe('Validating user context', () => {
test('Context should be skipped based on config', () => {
global.strapi.config.custom.plugins.comments.enableUsers = false;
global.strapi.config.plugins.comments.enableUsers = false;
expect(isValidUserContext(undefined)).toEqual(true);
expect(isValidUserContext({ id: 1 })).toEqual(true);
});

test('Context should be verified based on input', () => {
global.strapi.config.custom.plugins.comments.enableUsers = true;
global.strapi.config.plugins.comments.enableUsers = true;
expect(isValidUserContext(undefined)).toEqual(false);
expect(isValidUserContext({ id: 1 })).toEqual(true);
});
Expand Down
4 changes: 2 additions & 2 deletions services/utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = {
} : item),

checkBadWords: content => {
const config = get(strapi.config, 'custom.plugins.comments.badWords', true);
const config = get(strapi.config, 'plugins.comments.badWords', true);
if (config) {
const filter = new BadWordsFilter(isObject(config) ? config : undefined);
if (content && filter.isProfane(content)) {
Expand All @@ -82,7 +82,7 @@ module.exports = {
buildNestedStructure,

isValidUserContext: (user = {}) => {
const builtInContextEnabled = get(strapi.config, 'custom.plugins.comments.enableUsers', false);
const builtInContextEnabled = get(strapi.config, 'plugins.comments.enableUsers', false);
return builtInContextEnabled ? !isNil(user.id) : true;
},

Expand Down

0 comments on commit 51cffe8

Please sign in to comment.