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.
@@ -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.moderatorRoles
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.approvalFlow
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.entryLabel)
40
+ const entryLabelKeysValid = Object.keys(config[CONFIG_PARAMS.ENTRY_LABEL])
34
41
  .filter(_ => _ !== '*')
35
- .filter(_ => !(REGEX.uid.test(_) && isArray(config.entryLabel[_]) && !isEmpty(config.entryLabel[_]))).length === 0;
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']`);