Skip to content

Commit cc3cd23

Browse files
authored
Fix missing password policy definitions (#7225)
* improved contribution guide for parameter groups * improved resetTokenReuseIfValid docs * improved resetTokenValidityDuration docs * recreated definitions * improved parameter group wording
1 parent c8e822b commit cc3cd23

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

CONTRIBUTING.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,16 @@ Introducing new Parse Errors requires the following steps:
277277
Introducing new [Parse Server configuration][config] parameters requires the following steps:
278278

279279
1. Add parameters definitions in [/src/Options/index.js][config-index].
280-
1. If a nested configuration object has been added, add the environment variable option prefix to `getENVPrefix` in [/resources/buildConfigDefinition.js](https://github.com/parse-community/parse-server/blob/master/resources/buildConfigDefinition.js).
281-
1. Execute `npm run definitions` to automatically create the definitions in [/src/Options/Definitions.js][config-def] and [/src/Options/docs.js][config-docs].
282-
1. Add parameter value validation in [/src/Config.js](https://github.com/parse-community/parse-server/blob/master/src/Config.js).
283-
1. Add test cases to ensure the correct parameter value validation. Parse Server throws an error at launch if an invalid value is set for any configuration parameter.
284-
1. Execute `npm run docs` to generate the documentation in the `/out` directory. Take a look at the documentation whether the description and formatting of the newly introduced parameters is satisfactory.
280+
2. If the new parameter does not have one single value but is a parameter group (an object containing multiple sub-parameters):
281+
- add the environment variable prefix for the parameter group to `nestedOptionEnvPrefix` in [/resources/buildConfigDefinition.js](https://github.com/parse-community/parse-server/blob/master/resources/buildConfigDefinition.js)
282+
- add the parameter group type to `nestedOptionTypes` in [/resources/buildConfigDefinition.js](https://github.com/parse-community/parse-server/blob/master/resources/buildConfigDefinition.js)
283+
284+
For example, take a look at the existing Parse Server `security` parameter. It is a parameter group, because it has multiple sub-parameter such as `checkGroups`. Its interface is defined in [index.js][config-index] as `export interface SecurityOptions`. Therefore, the value to add to `nestedOptionTypes` would be `SecurityOptions`, the value to add to `nestedOptionEnvPrefix` would be `PARSE_SERVER_SECURITY_`.
285+
286+
3. Execute `npm run definitions` to automatically create the definitions in [/src/Options/Definitions.js][config-def] and [/src/Options/docs.js][config-docs].
287+
4. Add parameter value validation in [/src/Config.js](https://github.com/parse-community/parse-server/blob/master/src/Config.js).
288+
5. Add test cases to ensure the correct parameter value validation. Parse Server throws an error at launch if an invalid value is set for any configuration parameter.
289+
6. Execute `npm run docs` to generate the documentation in the `/out` directory. Take a look at the documentation whether the description and formatting of the newly introduced parameters is satisfactory.
285290

286291
## Code of Conduct
287292

resources/buildConfigDefinitions.js

+35-19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@
1111
*/
1212
const parsers = require('../src/Options/parsers');
1313

14+
/** The types of nested options. */
15+
const nestedOptionTypes = [
16+
'CustomPagesOptions',
17+
'DatabaseOptions',
18+
'FileUploadOptions',
19+
'IdempotencyOptions',
20+
'Object',
21+
'PagesCustomUrlsOptions',
22+
'PagesOptions',
23+
'PagesRoute',
24+
'PasswordPolicyOptions',
25+
'SecurityOptions',
26+
];
27+
28+
/** The prefix of environment variables for nested options. */
29+
const nestedOptionEnvPrefix = {
30+
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
31+
'CustomPagesOptions' : 'PARSE_SERVER_CUSTOM_PAGES_',
32+
'DatabaseOptions': 'PARSE_SERVER_DATABASE_',
33+
'FileUploadOptions' : 'PARSE_SERVER_FILE_UPLOAD_',
34+
'IdempotencyOptions' : 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
35+
'LiveQueryOptions' : 'PARSE_SERVER_LIVEQUERY_',
36+
'LiveQueryServerOptions' : 'PARSE_LIVE_QUERY_SERVER_',
37+
'PagesCustomUrlsOptions' : 'PARSE_SERVER_PAGES_CUSTOM_URL_',
38+
'PagesOptions' : 'PARSE_SERVER_PAGES_',
39+
'PagesRoute': 'PARSE_SERVER_PAGES_ROUTE_',
40+
'ParseServerOptions' : 'PARSE_SERVER_',
41+
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_',
42+
'SecurityOptions': 'PARSE_SERVER_SECURITY_',
43+
};
44+
1445
function last(array) {
1546
return array[array.length - 1];
1647
}
@@ -40,23 +71,8 @@ function getCommentValue(comment) {
4071
}
4172

4273
function getENVPrefix(iface) {
43-
const options = {
44-
'ParseServerOptions' : 'PARSE_SERVER_',
45-
'PagesOptions' : 'PARSE_SERVER_PAGES_',
46-
'PagesRoute': 'PARSE_SERVER_PAGES_ROUTE_',
47-
'PagesCustomUrlsOptions' : 'PARSE_SERVER_PAGES_CUSTOM_URL_',
48-
'CustomPagesOptions' : 'PARSE_SERVER_CUSTOM_PAGES_',
49-
'LiveQueryServerOptions' : 'PARSE_LIVE_QUERY_SERVER_',
50-
'LiveQueryOptions' : 'PARSE_SERVER_LIVEQUERY_',
51-
'IdempotencyOptions' : 'PARSE_SERVER_EXPERIMENTAL_IDEMPOTENCY_',
52-
'AccountLockoutOptions' : 'PARSE_SERVER_ACCOUNT_LOCKOUT_',
53-
'PasswordPolicyOptions' : 'PARSE_SERVER_PASSWORD_POLICY_',
54-
'FileUploadOptions' : 'PARSE_SERVER_FILE_UPLOAD_',
55-
'SecurityOptions': 'PARSE_SERVER_SECURITY_',
56-
'DatabaseOptions': 'PARSE_SERVER_DATABASE_'
57-
}
58-
if (options[iface.id.name]) {
59-
return options[iface.id.name]
74+
if (nestedOptionEnvPrefix[iface.id.name]) {
75+
return nestedOptionEnvPrefix[iface.id.name]
6076
}
6177
}
6278

@@ -169,8 +185,8 @@ function parseDefaultValue(elt, value, t) {
169185
if (type == 'NumberOrBoolean') {
170186
literalValue = t.numericLiteral(parsers.numberOrBoolParser('')(value));
171187
}
172-
const literalTypes = ['Object', 'SecurityOptions', 'PagesRoute', 'IdempotencyOptions','FileUploadOptions','CustomPagesOptions', 'PagesCustomUrlsOptions', 'PagesOptions', 'DatabaseOptions'];
173-
if (literalTypes.includes(type)) {
188+
189+
if (nestedOptionTypes.includes(type)) {
174190
const object = parsers.objectParser(value);
175191
const props = Object.keys(object).map((key) => {
176192
return t.objectProperty(key, object[value]);

0 commit comments

Comments
 (0)