strapi-plugin-comments 2.0.0 → 2.0.4
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/.husky/pre-commit +4 -0
- package/README.md +33 -5
- package/__mocks__/initSetup.js +31 -2
- package/admin/src/hooks/useConfig.js +49 -0
- package/admin/src/index.js +31 -2
- package/admin/src/pages/Details/components/DetailsEntity/index.js +3 -1
- package/admin/src/pages/Details/index.js +7 -7
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +2 -2
- package/admin/src/pages/Settings/components/RestartAlert/styles.js +8 -0
- package/admin/src/pages/Settings/index.js +376 -0
- package/admin/src/pages/Settings/utils/api.js +60 -0
- package/admin/src/permissions.js +3 -0
- package/admin/src/translations/en.json +44 -1
- package/admin/src/utils/handleAPIError.js +3 -2
- package/admin/src/utils/index.js +2 -1
- package/admin/src/utils/parseRegExp.js +10 -0
- package/package.json +8 -5
- package/server/bootstrap.js +24 -0
- package/server/config/index.js +1 -0
- package/server/controllers/admin.js +42 -8
- package/server/controllers/client.js +4 -4
- package/server/controllers/utils/parsers.js +3 -1
- package/server/graphql/index.js +7 -8
- package/server/graphql/queries/findAllFlat.js +4 -2
- package/server/graphql/queries/findAllInHierarchy.js +3 -3
- package/server/graphql/resolvers-config.js +2 -4
- package/server/graphql/types/report-reason.js +10 -10
- package/server/register.js +1 -3
- package/server/routes/admin.js +32 -0
- package/server/services/__tests__/common.test.js +95 -14
- package/server/services/admin.js +57 -6
- package/server/services/client.js +14 -8
- package/server/services/common.js +69 -11
- package/server/services/utils/__tests__/functions.test.js +12 -1
- package/server/services/utils/functions.js +9 -1
- package/server/utils/constants.js +10 -0
- package/strapi-server.js +12 -5
- package/.circleci/config.yml +0 -48
- package/.eslintrc +0 -35
- package/.github/pull_request_template.md +0 -13
- package/.nvmrc +0 -1
- package/codecov.yml +0 -4
- package/public/assets/logo.png +0 -0
- package/public/assets/preview.png +0 -0
|
@@ -10,6 +10,48 @@ module.exports = {
|
|
|
10
10
|
return getPluginService(name);
|
|
11
11
|
},
|
|
12
12
|
|
|
13
|
+
async config(ctx) {
|
|
14
|
+
try {
|
|
15
|
+
return await this.getService().config();
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throwError(ctx, e);
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
async settingsConfig(ctx) {
|
|
22
|
+
try {
|
|
23
|
+
return this.getService().config(true);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
throwError(ctx, e);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
async settingsUpdateConfig(ctx) {
|
|
30
|
+
try {
|
|
31
|
+
const { request: { body } } = ctx;
|
|
32
|
+
return this.getService().updateConfig(body);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
throwError(ctx, e);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
async settingsRestoreConfig(ctx) {
|
|
39
|
+
try {
|
|
40
|
+
return this.getService().restoreConfig();
|
|
41
|
+
} catch (e) {
|
|
42
|
+
throwError(ctx, e);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async settingsRestart(ctx) {
|
|
47
|
+
try {
|
|
48
|
+
await this.getService().restart();
|
|
49
|
+
return ctx.send({ status: 200 });
|
|
50
|
+
} catch (e) {
|
|
51
|
+
throwError(ctx, e);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
|
|
13
55
|
async findAll(ctx) {
|
|
14
56
|
return this.getService()
|
|
15
57
|
.findAll(ctx.query);
|
|
@@ -101,14 +143,6 @@ module.exports = {
|
|
|
101
143
|
}
|
|
102
144
|
},
|
|
103
145
|
|
|
104
|
-
async config(ctx) {
|
|
105
|
-
try {
|
|
106
|
-
return await this.getService().config();
|
|
107
|
-
} catch (e) {
|
|
108
|
-
throwError(ctx, e);
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
|
|
112
146
|
getContentsTypes() {
|
|
113
147
|
return Object.entries(strapi.contentTypes)
|
|
114
148
|
.filter(([, contentType]) => (
|
|
@@ -11,23 +11,23 @@ module.exports = {
|
|
|
11
11
|
},
|
|
12
12
|
|
|
13
13
|
async findAllFlat(ctx) {
|
|
14
|
-
const { params = {}, query } = ctx;
|
|
14
|
+
const { params = {}, query, sort, pagination } = ctx;
|
|
15
15
|
const { relation } = parseParams(params);
|
|
16
16
|
try {
|
|
17
17
|
return this.getService('common')
|
|
18
|
-
.findAllFlat(flatInput(relation, query));
|
|
18
|
+
.findAllFlat(flatInput(relation, query, sort, pagination));
|
|
19
19
|
} catch (e) {
|
|
20
20
|
throwError(ctx, e);
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
|
|
24
24
|
async findAllInHierarchy(ctx) {
|
|
25
|
-
const { params = {}, query } = ctx;
|
|
25
|
+
const { params = {}, query, sort } = ctx;
|
|
26
26
|
const { relation } = parseParams(params);
|
|
27
27
|
try {
|
|
28
28
|
return await this.getService('common')
|
|
29
29
|
.findAllInHierarchy({
|
|
30
|
-
...flatInput(relation, query),
|
|
30
|
+
...flatInput(relation, query, sort),
|
|
31
31
|
dropBlockedThreads: true,
|
|
32
32
|
});
|
|
33
33
|
} catch (e) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
-
flatInput(relation, query) {
|
|
4
|
+
flatInput(relation, query, sort, pagination) {
|
|
5
5
|
return {
|
|
6
6
|
query: {
|
|
7
7
|
...query,
|
|
@@ -13,6 +13,8 @@ module.exports = {
|
|
|
13
13
|
populate: { authorUser: true },
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
|
+
pagination,
|
|
17
|
+
sort,
|
|
16
18
|
};
|
|
17
19
|
},
|
|
18
20
|
|
package/server/graphql/index.js
CHANGED
|
@@ -6,17 +6,16 @@ const getMutations = require('./mutations');
|
|
|
6
6
|
const getResolversConfig = require('./resolvers-config');
|
|
7
7
|
const { getModelUid } = require('../services/utils/functions');
|
|
8
8
|
|
|
9
|
-
module.exports = () => {
|
|
9
|
+
module.exports = async ({ strapi, config}) => {
|
|
10
10
|
const extensionService = strapi.plugin('graphql').service('extension');
|
|
11
|
-
|
|
12
11
|
extensionService.shadowCRUD(getModelUid('comment')).disable();
|
|
13
12
|
extensionService.shadowCRUD(getModelUid('comment-report')).disable();
|
|
14
|
-
|
|
15
|
-
extensionService.use(({ nexus }) => {
|
|
16
|
-
const types = getTypes({ strapi, nexus });
|
|
17
|
-
const queries = getQueries({ strapi, nexus });
|
|
18
|
-
const mutations = getMutations({ strapi, nexus });
|
|
19
|
-
const resolversConfig = getResolversConfig({ strapi });
|
|
13
|
+
|
|
14
|
+
extensionService.use(({ strapi, nexus }) => {
|
|
15
|
+
const types = getTypes({ strapi, nexus, config });
|
|
16
|
+
const queries = getQueries({ strapi, nexus, config });
|
|
17
|
+
const mutations = getMutations({ strapi, nexus, config });
|
|
18
|
+
const resolversConfig = getResolversConfig({ strapi, config });
|
|
20
19
|
|
|
21
20
|
return {
|
|
22
21
|
types: [types, queries, mutations],
|
|
@@ -18,11 +18,13 @@ module.exports = ({ strapi, nexus }) => {
|
|
|
18
18
|
sort: args.SortArg,
|
|
19
19
|
},
|
|
20
20
|
async resolve(obj, args) {
|
|
21
|
-
const { relation, filters } = args;
|
|
21
|
+
const { relation, filters, sort, pagination } = args;
|
|
22
22
|
return await getPluginService('common')
|
|
23
23
|
.findAllFlat(flatInput(
|
|
24
24
|
relation,
|
|
25
|
-
getPluginService('gql').graphQLFiltersToStrapiQuery(filters, contentType)
|
|
25
|
+
getPluginService('gql').graphQLFiltersToStrapiQuery(filters, contentType),
|
|
26
|
+
sort,
|
|
27
|
+
pagination
|
|
26
28
|
), undefined);
|
|
27
29
|
},
|
|
28
30
|
};
|
|
@@ -13,16 +13,16 @@ module.exports = ({ strapi, nexus }) => {
|
|
|
13
13
|
type: nonNull(list('CommentNested')),
|
|
14
14
|
args: {
|
|
15
15
|
relation: nonNull(stringArg()),
|
|
16
|
-
// filters: filtersArg,
|
|
17
16
|
sort: args.SortArg,
|
|
18
17
|
},
|
|
19
18
|
async resolve(obj, args) {
|
|
20
|
-
const { relation, filters } = args;
|
|
19
|
+
const { relation, filters, sort } = args;
|
|
21
20
|
return await getPluginService('common')
|
|
22
21
|
.findAllInHierarchy({
|
|
23
22
|
...flatInput(
|
|
24
23
|
relation,
|
|
25
|
-
getPluginService('gql').graphQLFiltersToStrapiQuery(filters, contentType)
|
|
24
|
+
getPluginService('gql').graphQLFiltersToStrapiQuery(filters, contentType),
|
|
25
|
+
sort
|
|
26
26
|
),
|
|
27
27
|
dropBlockedThreads: true,
|
|
28
28
|
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = () => {
|
|
6
|
-
const auth = getPluginService('common').getConfig('gql.auth', false);
|
|
3
|
+
module.exports = ({ config }) => {
|
|
4
|
+
const { gql: { auth = false } = {}} = config;
|
|
7
5
|
return {
|
|
8
6
|
'Query.findAllFlat': { auth },
|
|
9
7
|
'Query.findAllInHierarchy': { auth },
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
module.exports = ({ nexus, config }) => {
|
|
2
|
+
const { reportReasons } = config;
|
|
3
|
+
return nexus.enumType({
|
|
4
|
+
name: "ReportReason",
|
|
5
|
+
description: 'Reason of abuse report',
|
|
6
|
+
members: {
|
|
7
|
+
...reportReasons
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
};
|
package/server/register.js
CHANGED
package/server/routes/admin.js
CHANGED
|
@@ -89,4 +89,36 @@ module.exports = [
|
|
|
89
89
|
policies: [],
|
|
90
90
|
},
|
|
91
91
|
},
|
|
92
|
+
{
|
|
93
|
+
method: 'GET',
|
|
94
|
+
path: '/settings/config',
|
|
95
|
+
handler: 'admin.settingsConfig',
|
|
96
|
+
config: {
|
|
97
|
+
policies: [],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
method: 'PUT',
|
|
102
|
+
path: '/settings/config',
|
|
103
|
+
handler: 'admin.settingsUpdateConfig',
|
|
104
|
+
config: {
|
|
105
|
+
policies: [],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
method: 'DELETE',
|
|
110
|
+
path: '/settings/config',
|
|
111
|
+
handler: 'admin.settingsRestoreConfig',
|
|
112
|
+
config: {
|
|
113
|
+
policies: [],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
method: 'GET',
|
|
118
|
+
path: '/settings/restart',
|
|
119
|
+
handler: 'admin.settingsRestart',
|
|
120
|
+
config: {
|
|
121
|
+
policies: [],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
92
124
|
];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { CONFIG_PARAMS } = require('../../utils/constants');
|
|
1
2
|
const PluginError = require('../../utils/error');
|
|
2
3
|
const { getPluginService } = require('../../utils/functions');
|
|
3
4
|
|
|
@@ -16,18 +17,48 @@ afterEach(() => {
|
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
describe('Test Comments service functions utils', () => {
|
|
20
|
+
describe('Get plugin store', () => {
|
|
21
|
+
beforeEach(() => setup());
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
test('Should return store', async () => {
|
|
24
|
+
const pluginStore = await getPluginService('common').getPluginStore();
|
|
25
|
+
expect(pluginStore).toHaveProperty('get');
|
|
26
|
+
expect(pluginStore).toHaveProperty('set');
|
|
27
|
+
expect(pluginStore).toHaveProperty('delete');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
describe('Get plugin config', () => {
|
|
32
|
+
describe('Local config', () => {
|
|
33
|
+
beforeEach(() => setup({
|
|
34
|
+
test: 'sample',
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
test('Should return config value', async () => {
|
|
38
|
+
const result = await getPluginService('common').getConfig('test');
|
|
39
|
+
expect(result).toEqual('sample');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('Should return default config prop value if not set', async () => {
|
|
43
|
+
const result = await getPluginService('common').getConfig('another', 'defaultValue');
|
|
44
|
+
expect(result).toEqual('defaultValue');
|
|
45
|
+
});
|
|
27
46
|
});
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
describe('Store config', () => {
|
|
49
|
+
beforeEach(() => setup({
|
|
50
|
+
test: 'sample',
|
|
51
|
+
}, true));
|
|
52
|
+
|
|
53
|
+
test('Should return config value', async () => {
|
|
54
|
+
const result = await getPluginService('common').getConfig('test');
|
|
55
|
+
expect(result).toEqual('sample');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('Should return default config prop value if not set', async () => {
|
|
59
|
+
const result = await getPluginService('common').getConfig('another', 'defaultValue');
|
|
60
|
+
expect(result).toEqual('defaultValue');
|
|
61
|
+
});
|
|
31
62
|
});
|
|
32
63
|
});
|
|
33
64
|
|
|
@@ -131,12 +162,12 @@ describe('Test Comments service functions utils', () => {
|
|
|
131
162
|
|
|
132
163
|
const text = 'Lorem ipsum dolor sit fuck amet';
|
|
133
164
|
|
|
134
|
-
test('Should find bad words usage and throw error PluginError', () => {
|
|
165
|
+
test('Should find bad words usage and throw error PluginError', async () => {
|
|
135
166
|
expect.assertions(7);
|
|
136
167
|
try {
|
|
137
|
-
getPluginService('common').checkBadWords(text);
|
|
168
|
+
await getPluginService('common').checkBadWords(text);
|
|
138
169
|
} catch (e) {
|
|
139
|
-
expect(getPluginService('common').getConfig('badWords')).toEqual(undefined);
|
|
170
|
+
expect(await getPluginService('common').getConfig('badWords')).toEqual(undefined);
|
|
140
171
|
expect(e).toBeInstanceOf(PluginError);
|
|
141
172
|
expect(e).toHaveProperty('status', 400);
|
|
142
173
|
expect(e).toHaveProperty('name', 'Strapi:Plugin:Comments');
|
|
@@ -157,9 +188,59 @@ describe('Test Comments service functions utils', () => {
|
|
|
157
188
|
|
|
158
189
|
const text = 'Lorem ipsum dolor sit fuck amet';
|
|
159
190
|
|
|
160
|
-
test('Should skip bad words filtering because of configuration change', () => {
|
|
161
|
-
expect(getPluginService('common').getConfig('badWords')).toEqual(false);
|
|
162
|
-
expect(getPluginService('common').checkBadWords(text)).toEqual(text);
|
|
191
|
+
test('Should skip bad words filtering because of configuration change', async () => {
|
|
192
|
+
expect(await getPluginService('common').getConfig('badWords')).toEqual(false);
|
|
193
|
+
expect(await getPluginService('common').checkBadWords(text)).toEqual(text);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('Parse relation string (store config)', () => {
|
|
198
|
+
const [uid, id] = ['api::my-collection.my-content-type', '1'];
|
|
199
|
+
const validCollection = `${uid}:${id}`;
|
|
200
|
+
|
|
201
|
+
const [wrongUid, wrongId] = ['api::wrong.type', '2'];
|
|
202
|
+
const testCollection = `${wrongUid}:${wrongId}`;
|
|
203
|
+
|
|
204
|
+
describe('Store config', () => {
|
|
205
|
+
beforeEach(() => setup({ enabledCollections: [uid] }, true));
|
|
206
|
+
|
|
207
|
+
test('Should pass', async () => {
|
|
208
|
+
expect(await getPluginService('common').parseRelationString(validCollection));
|
|
209
|
+
expect(await getPluginService('common').getConfig(CONFIG_PARAMS.ENABLED_COLLECTIONS)).toContain(uid);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('Should fail with 403', async () => {
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
await getPluginService('common').parseRelationString(testCollection);
|
|
216
|
+
} catch(e) {
|
|
217
|
+
expect(await getPluginService('common').getConfig(CONFIG_PARAMS.ENABLED_COLLECTIONS)).toContain(uid);
|
|
218
|
+
expect(await getPluginService('common').getConfig(CONFIG_PARAMS.ENABLED_COLLECTIONS)).not.toContain(wrongUid);
|
|
219
|
+
expect(e).toBeInstanceOf(PluginError);
|
|
220
|
+
expect(e).toHaveProperty('status', 403);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('Local config', () => {
|
|
226
|
+
beforeEach(() => setup({ enabledCollections: [uid] }));
|
|
227
|
+
|
|
228
|
+
test('Should pass', async () => {
|
|
229
|
+
expect(await getPluginService('common').parseRelationString(validCollection));
|
|
230
|
+
expect(await getPluginService('common').getConfig(CONFIG_PARAMS.ENABLED_COLLECTIONS)).toContain(uid);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('Should fail with 403', async () => {
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
await getPluginService('common').parseRelationString(testCollection);
|
|
237
|
+
} catch(e) {
|
|
238
|
+
expect(await getPluginService('common').getConfig(CONFIG_PARAMS.ENABLED_COLLECTIONS)).toContain(uid);
|
|
239
|
+
expect(await getPluginService('common').getConfig(CONFIG_PARAMS.ENABLED_COLLECTIONS)).not.toContain(wrongUid);
|
|
240
|
+
expect(e).toBeInstanceOf(PluginError);
|
|
241
|
+
expect(e).toHaveProperty('status', 403);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
163
244
|
});
|
|
164
245
|
});
|
|
165
246
|
});
|
package/server/services/admin.js
CHANGED
|
@@ -21,17 +21,68 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
21
21
|
},
|
|
22
22
|
|
|
23
23
|
// Config
|
|
24
|
-
async config() {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
entryLabel,
|
|
29
|
-
approvalFlow,
|
|
24
|
+
async config(viaSettingsPage = false) {
|
|
25
|
+
const pluginStore = await this.getCommonService().getPluginStore();
|
|
26
|
+
const config = await pluginStore.get({ key: 'config' });
|
|
27
|
+
const additionalConfiguration = {
|
|
30
28
|
regex: Object.keys(REGEX).reduce((prev, curr) => ({
|
|
31
29
|
...prev,
|
|
32
30
|
[curr]: REGEX[curr].toString(),
|
|
33
31
|
}), {}),
|
|
34
32
|
};
|
|
33
|
+
|
|
34
|
+
const isGQLPluginEnabled = !isNil(strapi.plugin('graphql'));
|
|
35
|
+
|
|
36
|
+
if (config) {
|
|
37
|
+
return {
|
|
38
|
+
...config,
|
|
39
|
+
...additionalConfiguration,
|
|
40
|
+
isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const entryLabel = this.getCommonService().getLocalConfig('entryLabel');
|
|
45
|
+
const approvalFlow = this.getCommonService().getLocalConfig('approvalFlow');
|
|
46
|
+
const reportReasons = this.getCommonService().getLocalConfig('reportReasons');
|
|
47
|
+
const result = {
|
|
48
|
+
entryLabel,
|
|
49
|
+
approvalFlow,
|
|
50
|
+
reportReasons,
|
|
51
|
+
...additionalConfiguration,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (viaSettingsPage) {
|
|
55
|
+
const enabledCollections = this.getCommonService().getLocalConfig('enabledCollections');
|
|
56
|
+
const moderatorRoles = this.getCommonService().getLocalConfig('moderatorRoles');
|
|
57
|
+
return {
|
|
58
|
+
...result,
|
|
59
|
+
enabledCollections,
|
|
60
|
+
moderatorRoles,
|
|
61
|
+
isGQLPluginEnabled,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
async updateConfig(body) {
|
|
69
|
+
const pluginStore = await this.getCommonService().getPluginStore();
|
|
70
|
+
|
|
71
|
+
await pluginStore.set({ key: 'config', value: body });
|
|
72
|
+
|
|
73
|
+
return this.config();
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
async restoreConfig() {
|
|
77
|
+
const pluginStore = await this.getCommonService().getPluginStore();
|
|
78
|
+
|
|
79
|
+
await pluginStore.delete({key: 'config'})
|
|
80
|
+
|
|
81
|
+
return this.config();
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
async restart() {
|
|
85
|
+
setImmediate(() => strapi.reload());
|
|
35
86
|
},
|
|
36
87
|
|
|
37
88
|
// Find all comments
|
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
getRelatedGroups,
|
|
11
11
|
resolveUserContextError,
|
|
12
12
|
} = require('./utils/functions');
|
|
13
|
-
const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
13
|
+
const { APPROVAL_STATUS, REGEX, CONFIG_PARAMS } = require('./../utils/constants')
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Comments Plugin - Client services
|
|
@@ -31,16 +31,15 @@ module.exports = ({ strapi }) => ({
|
|
|
31
31
|
throw new PluginError(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const [ uid,
|
|
35
|
-
const parsedRelatedId = parseInt(relatedStringId);
|
|
36
|
-
const relatedId = isNumber(parsedRelatedId) ? parsedRelatedId : relatedStringId;
|
|
34
|
+
const [ uid, relatedId ] = await this.getCommonService().parseRelationString(relation);
|
|
37
35
|
|
|
38
36
|
const relatedEntity = await strapi.db.query(uid).findOne(relatedId);
|
|
39
37
|
if (!relatedEntity) {
|
|
40
38
|
throw new PluginError(400, `Relation for field "related" does not exist. Check your payload please.`);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
const
|
|
41
|
+
const approvalFlow = await this.getCommonService().getConfig(CONFIG_PARAMS.APPROVAL_FLOW, []);
|
|
42
|
+
const isApprovalFlowEnabled = approvalFlow.includes(uid) ||
|
|
44
43
|
relatedEntity.requireCommentsApproval;
|
|
45
44
|
|
|
46
45
|
const linkToThread = !isNil(threadOf) ? await this.getCommonService().findOne({
|
|
@@ -57,7 +56,7 @@ module.exports = ({ strapi }) => ({
|
|
|
57
56
|
throw resolveUserContextError(user);
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
if (this.getCommonService().checkBadWords(content) && singleRelationFulfilled) {
|
|
59
|
+
if (await this.getCommonService().checkBadWords(content) && singleRelationFulfilled) {
|
|
61
60
|
const { author = {}, ...rest } = data;
|
|
62
61
|
let authorData = {};
|
|
63
62
|
if (validContext && user) {
|
|
@@ -115,6 +114,8 @@ module.exports = ({ strapi }) => ({
|
|
|
115
114
|
throw new PluginError(400, `Request property "relation" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
116
115
|
}
|
|
117
116
|
|
|
117
|
+
await this.getCommonService().parseRelationString(relation);
|
|
118
|
+
|
|
118
119
|
const existingEntity = await this.getCommonService().findOne({
|
|
119
120
|
id,
|
|
120
121
|
related: relation,
|
|
@@ -127,7 +128,7 @@ module.exports = ({ strapi }) => ({
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
if (isEqualEntity(existingEntity, data, user) && content) {
|
|
130
|
-
if (this.getCommonService().checkBadWords(content)) {
|
|
131
|
+
if (await this.getCommonService().checkBadWords(content)) {
|
|
131
132
|
const entity = await strapi.db.query(getModelUid('comment')).update({
|
|
132
133
|
where: { id },
|
|
133
134
|
data: { content },
|
|
@@ -144,6 +145,9 @@ module.exports = ({ strapi }) => ({
|
|
|
144
145
|
if (!this.getCommonService().isValidUserContext(user)) {
|
|
145
146
|
throw resolveUserContextError(user);
|
|
146
147
|
}
|
|
148
|
+
|
|
149
|
+
await this.getCommonService().parseRelationString(relation);
|
|
150
|
+
|
|
147
151
|
const reportAgainstEntity = await this.getCommonService().findOne({
|
|
148
152
|
id,
|
|
149
153
|
related: relation,
|
|
@@ -185,6 +189,8 @@ module.exports = ({ strapi }) => ({
|
|
|
185
189
|
throw new PluginError(403, `You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`);
|
|
186
190
|
}
|
|
187
191
|
|
|
192
|
+
await this.getCommonService().parseRelationString(relation);
|
|
193
|
+
|
|
188
194
|
let entity;
|
|
189
195
|
try {
|
|
190
196
|
const byAuthor = user?.id ? {
|
|
@@ -216,7 +222,7 @@ module.exports = ({ strapi }) => ({
|
|
|
216
222
|
},
|
|
217
223
|
|
|
218
224
|
async sendAbuseReportEmail(reason, content) {
|
|
219
|
-
const rolesToBeNotified = this.getCommonService().getConfig(
|
|
225
|
+
const rolesToBeNotified = await this.getCommonService().getConfig(CONFIG_PARAMS.MODERATOR_ROLES) || ['strapi-super-admin'];
|
|
220
226
|
|
|
221
227
|
const adminUserModel = strapi.db.query('admin::user');
|
|
222
228
|
const emails = await adminUserModel.findMany({
|