strapi-plugin-comments 2.0.2 → 2.0.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.
- package/.husky/pre-commit +4 -0
- package/README.md +14 -1
- package/__mocks__/initSetup.js +31 -2
- package/admin/src/hooks/useConfig.js +43 -0
- package/admin/src/index.js +31 -2
- package/admin/src/pages/Details/index.js +5 -2
- package/admin/src/pages/Settings/index.js +342 -0
- package/admin/src/pages/Settings/utils/api.js +50 -0
- package/admin/src/permissions.js +3 -0
- package/admin/src/translations/en.json +37 -1
- package/admin/src/utils/index.js +2 -1
- package/admin/src/utils/parseRegExp.js +10 -0
- package/package.json +7 -4
- package/server/bootstrap.js +24 -0
- package/server/config/index.js +1 -0
- package/server/controllers/admin.js +33 -8
- package/server/graphql/index.js +7 -8
- 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 +24 -0
- package/server/services/__tests__/common.test.js +95 -14
- package/server/services/admin.js +60 -6
- package/server/services/client.js +13 -8
- package/server/services/common.js +37 -9
- package/server/services/utils/__tests__/functions.test.js +12 -1
- package/server/services/utils/functions.js +9 -1
- package/server/utils/constants.js +9 -0
- package/strapi-server.js +12 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const PluginError = require('./../../utils/error');
|
|
2
2
|
const { REGEX } = require('./../../utils/constants')
|
|
3
|
-
const { first, isObject, isEmpty } = require('lodash');
|
|
3
|
+
const { first, isObject, isArray, isEmpty } = require('lodash');
|
|
4
4
|
|
|
5
5
|
const buildNestedStructure = (
|
|
6
6
|
entities,
|
|
@@ -93,6 +93,14 @@ module.exports = {
|
|
|
93
93
|
};
|
|
94
94
|
},
|
|
95
95
|
|
|
96
|
+
buildConfigQueryProp(prop) {
|
|
97
|
+
let queryProp = prop;
|
|
98
|
+
if (prop && isArray(prop)) {
|
|
99
|
+
queryProp = prop.join('.');
|
|
100
|
+
}
|
|
101
|
+
return queryProp;
|
|
102
|
+
},
|
|
103
|
+
|
|
96
104
|
resolveUserContextError: user => {
|
|
97
105
|
if (user) {
|
|
98
106
|
throw new PluginError(401, 'Not authenticated');
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
const CONFIG_PARAMS = {
|
|
2
|
+
ENABLED_COLLECTIONS: 'enabledCollections',
|
|
3
|
+
APPROVAL_FLOW: 'approvalFlow',
|
|
4
|
+
ENTRY_LABEL: 'entryLabel',
|
|
5
|
+
MODERATOR_ROLES: 'moderatorRoles',
|
|
6
|
+
BAD_WORDS: 'badWords',
|
|
7
|
+
};
|
|
8
|
+
|
|
1
9
|
const APPROVAL_STATUS = {
|
|
2
10
|
PENDING: "PENDING",
|
|
3
11
|
APPROVED: "APPROVED",
|
|
@@ -12,6 +20,7 @@ const REGEX = {
|
|
|
12
20
|
};
|
|
13
21
|
|
|
14
22
|
module.exports = {
|
|
23
|
+
CONFIG_PARAMS,
|
|
15
24
|
APPROVAL_STATUS,
|
|
16
25
|
REGEX,
|
|
17
26
|
};
|
package/strapi-server.js
CHANGED
|
@@ -4,7 +4,7 @@ const { isArray, isEmpty, isString } = require('lodash');
|
|
|
4
4
|
|
|
5
5
|
const server = require('./server');
|
|
6
6
|
const contentTypes = require('./content-types');
|
|
7
|
-
const { REGEX } = require('./server/utils/constants');
|
|
7
|
+
const { REGEX, CONFIG_PARAMS } = require('./server/utils/constants');
|
|
8
8
|
|
|
9
9
|
module.exports = () => ({
|
|
10
10
|
...server,
|
|
@@ -15,24 +15,31 @@ module.exports = () => ({
|
|
|
15
15
|
...server.config.default,
|
|
16
16
|
}),
|
|
17
17
|
validator: (config) => {
|
|
18
|
+
// Check enabledCollections values
|
|
19
|
+
const enabledCollectionsValid = config[CONFIG_PARAMS.ENABLED_COLLECTIONS]
|
|
20
|
+
.filter(_ => !REGEX.uid.test(_)).length === 0;
|
|
21
|
+
if (!enabledCollectionsValid) {
|
|
22
|
+
throw new Error(`'enabledCollections' must contain Content Types identifiers in the format like 'api::<collection name>.<content type name>'`);
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
// Check moderatorRoles values
|
|
19
|
-
const moderatorRolesValid = config.
|
|
26
|
+
const moderatorRolesValid = config[CONFIG_PARAMS.MODERATOR_ROLES]
|
|
20
27
|
.filter(_ => !isString(_)).length === 0;
|
|
21
28
|
if (!moderatorRolesValid) {
|
|
22
29
|
throw new Error(`'moderatorRoles' must roles keys`);
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
// Check approvalFlow values
|
|
26
|
-
const approvalFlowValid = config.
|
|
33
|
+
const approvalFlowValid = config[CONFIG_PARAMS.APPROVAL_FLOW]
|
|
27
34
|
.filter(_ => !REGEX.uid.test(_)).length === 0;
|
|
28
35
|
if (!approvalFlowValid) {
|
|
29
36
|
throw new Error(`'approvalFlow' must contain Content Types identifiers in the format like 'api::<collection name>.<content type name>'`);
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
// Check entryLabel keys and values
|
|
33
|
-
const entryLabelKeysValid = Object.keys(config.
|
|
40
|
+
const entryLabelKeysValid = Object.keys(config[CONFIG_PARAMS.ENTRY_LABEL])
|
|
34
41
|
.filter(_ => _ !== '*')
|
|
35
|
-
.filter(_ => !(REGEX.uid.test(_) && isArray(config.
|
|
42
|
+
.filter(_ => !(REGEX.uid.test(_) && isArray(config[CONFIG_PARAMS.ENTRY_LABEL][_]) && !isEmpty(config[CONFIG_PARAMS.ENTRY_LABEL][_]))).length === 0;
|
|
36
43
|
|
|
37
44
|
if (!entryLabelKeysValid) {
|
|
38
45
|
throw new Error(`'entryLabel' must contain records in the format like 'api::<collection name>.<content type name>': ['Field1', 'field_2']`);
|