Skip to content

Commit 7bff03c

Browse files
committed
Change options name
1 parent 622dffa commit 7bff03c

File tree

4 files changed

+102
-92
lines changed

4 files changed

+102
-92
lines changed

spec/DatabaseController.spec.js

Lines changed: 70 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ describe('DatabaseController', function () {
363363
});
364364
});
365365

366-
describe('disableCollation', () => {
366+
describe('enableCollationCaseComparison', () => {
367367
const dummyStorageAdapter = {
368368
find: () => Promise.resolve([]),
369369
watch: () => Promise.resolve(),
@@ -374,69 +374,75 @@ describe('DatabaseController', function () {
374374
Config.get(Parse.applicationId).schemaCache.clear();
375375
});
376376

377-
it('should force caseInsensitive to false with disableCollation option', async () => {
377+
it('should force caseInsensitive to false with enableCollationCaseComparison option', async () => {
378378
const databaseController = new DatabaseController(dummyStorageAdapter, {
379-
disableCollation: true,
379+
enableCollationCaseComparison: true,
380380
});
381381
const spy = spyOn(dummyStorageAdapter, 'find');
382382
spy.and.callThrough();
383383
await databaseController.find('SomeClass', {}, { caseInsensitive: true });
384384
expect(spy.calls.all()[0].args[3].caseInsensitive).toEqual(false);
385385
});
386386

387-
it('should support caseInsensitive without disableCollation option', async () => {
387+
it('should support caseInsensitive without enableCollationCaseComparison option', async () => {
388388
const databaseController = new DatabaseController(dummyStorageAdapter, {});
389389
const spy = spyOn(dummyStorageAdapter, 'find');
390390
spy.and.callThrough();
391391
await databaseController.find('_User', {}, { caseInsensitive: true });
392392
expect(spy.calls.all()[0].args[3].caseInsensitive).toEqual(true);
393393
});
394394

395-
it_only_db('mongo')('should create insensitive indexes without disableCollation', async () => {
396-
await reconfigureServer({
397-
databaseURI: 'mongodb://localhost:27017/disableCollationFalse',
398-
databaseAdapter: undefined,
399-
});
400-
const user = new Parse.User();
401-
await user.save({
402-
username: 'example',
403-
password: 'password',
404-
405-
});
406-
const schemas = await Parse.Schema.all();
407-
const UserSchema = schemas.find(({ className }) => className === '_User');
408-
expect(UserSchema.indexes).toEqual({
409-
_id_: { _id: 1 },
410-
username_1: { username: 1 },
411-
case_insensitive_username: { username: 1 },
412-
case_insensitive_email: { email: 1 },
413-
email_1: { email: 1 },
414-
});
415-
});
416-
417-
it_only_db('mongo')('should not create insensitive indexes with disableCollation', async () => {
418-
await reconfigureServer({
419-
disableCollation: true,
420-
databaseURI: 'mongodb://localhost:27017/disableCollationTrue',
421-
databaseAdapter: undefined,
422-
});
423-
const user = new Parse.User();
424-
await user.save({
425-
username: 'example',
426-
password: 'password',
427-
428-
});
429-
const schemas = await Parse.Schema.all();
430-
const UserSchema = schemas.find(({ className }) => className === '_User');
431-
expect(UserSchema.indexes).toEqual({
432-
_id_: { _id: 1 },
433-
username_1: { username: 1 },
434-
email_1: { email: 1 },
435-
});
436-
});
395+
it_only_db('mongo')(
396+
'should create insensitive indexes without enableCollationCaseComparison',
397+
async () => {
398+
await reconfigureServer({
399+
databaseURI: 'mongodb://localhost:27017/enableCollationCaseComparisonFalse',
400+
databaseAdapter: undefined,
401+
});
402+
const user = new Parse.User();
403+
await user.save({
404+
username: 'example',
405+
password: 'password',
406+
407+
});
408+
const schemas = await Parse.Schema.all();
409+
const UserSchema = schemas.find(({ className }) => className === '_User');
410+
expect(UserSchema.indexes).toEqual({
411+
_id_: { _id: 1 },
412+
username_1: { username: 1 },
413+
case_insensitive_username: { username: 1 },
414+
case_insensitive_email: { email: 1 },
415+
email_1: { email: 1 },
416+
});
417+
}
418+
);
419+
420+
it_only_db('mongo')(
421+
'should not create insensitive indexes with enableCollationCaseComparison',
422+
async () => {
423+
await reconfigureServer({
424+
enableCollationCaseComparison: true,
425+
databaseURI: 'mongodb://localhost:27017/enableCollationCaseComparisonTrue',
426+
databaseAdapter: undefined,
427+
});
428+
const user = new Parse.User();
429+
await user.save({
430+
username: 'example',
431+
password: 'password',
432+
433+
});
434+
const schemas = await Parse.Schema.all();
435+
const UserSchema = schemas.find(({ className }) => className === '_User');
436+
expect(UserSchema.indexes).toEqual({
437+
_id_: { _id: 1 },
438+
username_1: { username: 1 },
439+
email_1: { email: 1 },
440+
});
441+
}
442+
);
437443
});
438444

439-
describe('transformEmailToLowerCase', () => {
445+
describe('convertEmailToLowercase', () => {
440446
const dummyStorageAdapter = {
441447
createObject: () => Promise.resolve({ ops: [{}] }),
442448
findOneAndUpdate: () => Promise.resolve({}),
@@ -456,7 +462,7 @@ describe('DatabaseController', function () {
456462
updatedAt: { iso: undefined, __type: 'Date' },
457463
};
458464

459-
it('should not transform email to lower case without transformEmailToLowerCase option on create', async () => {
465+
it('should not transform email to lower case without convertEmailToLowercase option on create', async () => {
460466
const databaseController = new DatabaseController(dummyStorageAdapter, {});
461467
const spy = spyOn(dummyStorageAdapter, 'createObject');
462468
spy.and.callThrough();
@@ -469,9 +475,9 @@ describe('DatabaseController', function () {
469475
});
470476
});
471477

472-
it('should transform email to lower case with transformEmailToLowerCase option on create', async () => {
478+
it('should transform email to lower case with convertEmailToLowercase option on create', async () => {
473479
const databaseController = new DatabaseController(dummyStorageAdapter, {
474-
transformEmailToLowerCase: true,
480+
convertEmailToLowercase: true,
475481
});
476482
const spy = spyOn(dummyStorageAdapter, 'createObject');
477483
spy.and.callThrough();
@@ -484,7 +490,7 @@ describe('DatabaseController', function () {
484490
});
485491
});
486492

487-
it('should not transform email to lower case without transformEmailToLowerCase option on update', async () => {
493+
it('should not transform email to lower case without convertEmailToLowercase option on update', async () => {
488494
const databaseController = new DatabaseController(dummyStorageAdapter, {});
489495
const spy = spyOn(dummyStorageAdapter, 'findOneAndUpdate');
490496
spy.and.callThrough();
@@ -494,9 +500,9 @@ describe('DatabaseController', function () {
494500
});
495501
});
496502

497-
it('should transform email to lower case with transformEmailToLowerCase option on update', async () => {
503+
it('should transform email to lower case with convertEmailToLowercase option on update', async () => {
498504
const databaseController = new DatabaseController(dummyStorageAdapter, {
499-
transformEmailToLowerCase: true,
505+
convertEmailToLowercase: true,
500506
});
501507
const spy = spyOn(dummyStorageAdapter, 'findOneAndUpdate');
502508
spy.and.callThrough();
@@ -506,8 +512,8 @@ describe('DatabaseController', function () {
506512
});
507513
});
508514

509-
it('should not find a case insensitive user by email with transformEmailToLowerCase', async () => {
510-
await reconfigureServer({ transformEmailToLowerCase: true });
515+
it('should not find a case insensitive user by email with convertEmailToLowercase', async () => {
516+
await reconfigureServer({ convertEmailToLowercase: true });
511517
const user = new Parse.User();
512518
await user.save({ email: '[email protected]', password: 'password' });
513519

@@ -523,7 +529,7 @@ describe('DatabaseController', function () {
523529
});
524530
});
525531

526-
describe('transformUsernameToLowerCase', () => {
532+
describe('convertUsernameToLowercase', () => {
527533
const dummyStorageAdapter = {
528534
createObject: () => Promise.resolve({ ops: [{}] }),
529535
findOneAndUpdate: () => Promise.resolve({}),
@@ -543,7 +549,7 @@ describe('DatabaseController', function () {
543549
updatedAt: { iso: undefined, __type: 'Date' },
544550
};
545551

546-
it('should not transform username to lower case without transformUsernameToLowerCase option on create', async () => {
552+
it('should not transform username to lower case without convertUsernameToLowercase option on create', async () => {
547553
const databaseController = new DatabaseController(dummyStorageAdapter, {});
548554
const spy = spyOn(dummyStorageAdapter, 'createObject');
549555
spy.and.callThrough();
@@ -556,9 +562,9 @@ describe('DatabaseController', function () {
556562
});
557563
});
558564

559-
it('should transform username to lower case with transformUsernameToLowerCase option on create', async () => {
565+
it('should transform username to lower case with convertUsernameToLowercase option on create', async () => {
560566
const databaseController = new DatabaseController(dummyStorageAdapter, {
561-
transformUsernameToLowerCase: true,
567+
convertUsernameToLowercase: true,
562568
});
563569
const spy = spyOn(dummyStorageAdapter, 'createObject');
564570
spy.and.callThrough();
@@ -571,7 +577,7 @@ describe('DatabaseController', function () {
571577
});
572578
});
573579

574-
it('should not transform username to lower case without transformUsernameToLowerCase option on update', async () => {
580+
it('should not transform username to lower case without convertUsernameToLowercase option on update', async () => {
575581
const databaseController = new DatabaseController(dummyStorageAdapter, {});
576582
const spy = spyOn(dummyStorageAdapter, 'findOneAndUpdate');
577583
spy.and.callThrough();
@@ -581,9 +587,9 @@ describe('DatabaseController', function () {
581587
});
582588
});
583589

584-
it('should transform username to lower case with transformUsernameToLowerCase option on update', async () => {
590+
it('should transform username to lower case with convertUsernameToLowercase option on update', async () => {
585591
const databaseController = new DatabaseController(dummyStorageAdapter, {
586-
transformUsernameToLowerCase: true,
592+
convertUsernameToLowercase: true,
587593
});
588594
const spy = spyOn(dummyStorageAdapter, 'findOneAndUpdate');
589595
spy.and.callThrough();
@@ -593,8 +599,8 @@ describe('DatabaseController', function () {
593599
});
594600
});
595601

596-
it('should not find a case insensitive user by username with transformUsernameToLowerCase', async () => {
597-
await reconfigureServer({ transformUsernameToLowerCase: true });
602+
it('should not find a case insensitive user by username with convertUsernameToLowercase', async () => {
603+
await reconfigureServer({ convertUsernameToLowercase: true });
598604
const user = new Parse.User();
599605
await user.save({ username: 'EXAMPLE', password: 'password' });
600606

src/Controllers/DatabaseController.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,16 @@ const relationSchema = {
368368
fields: { relatedId: { type: 'String' }, owningId: { type: 'String' } },
369369
};
370370

371-
const transformEmailToLowerCase = (object, className, options) => {
372-
if (className === '_User' && options.transformEmailToLowerCase) {
371+
const convertEmailToLowercase = (object, className, options) => {
372+
if (className === '_User' && options.convertEmailToLowercase) {
373373
if (typeof object['email'] === 'string') {
374374
object['email'] = object['email'].toLowerCase();
375375
}
376376
}
377377
};
378378

379-
const transformUsernameToLowerCase = (object, className, options) => {
380-
if (className === '_User' && options.transformUsernameToLowerCase) {
379+
const convertUsernameToLowercase = (object, className, options) => {
380+
if (className === '_User' && options.convertUsernameToLowercase) {
381381
if (typeof object['username'] === 'string') {
382382
object['username'] = object['username'].toLowerCase();
383383
}
@@ -589,8 +589,8 @@ class DatabaseController {
589589
}
590590
}
591591
update = transformObjectACL(update);
592-
transformEmailToLowerCase(update, className, this.options);
593-
transformUsernameToLowerCase(update, className, this.options);
592+
convertEmailToLowercase(update, className, this.options);
593+
convertUsernameToLowercase(update, className, this.options);
594594
transformAuthData(className, update, schema);
595595
if (validateOnly) {
596596
return this.adapter.find(className, schema, query, {}).then(result => {
@@ -840,8 +840,8 @@ class DatabaseController {
840840
const originalObject = object;
841841
object = transformObjectACL(object);
842842

843-
transformEmailToLowerCase(object, className, this.options);
844-
transformUsernameToLowerCase(object, className, this.options);
843+
convertEmailToLowercase(object, className, this.options);
844+
convertUsernameToLowercase(object, className, this.options);
845845
object.createdAt = { iso: object.createdAt, __type: 'Date' };
846846
object.updatedAt = { iso: object.updatedAt, __type: 'Date' };
847847

src/Options/Definitions.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ module.exports.ParseServerOptions = {
139139
help: 'A collection prefix for the classes',
140140
default: '',
141141
},
142+
convertEmailToLowercase: {
143+
env: 'PARSE_SERVER_CONVERT_EMAIL_TO_LOWERCASE',
144+
help:
145+
'Optional. If set to `true`, the `email` property of a user is automatically converted to lowercase before being stored in the database. Consequently, queries must match the case as stored in the database, which would be lowercase in this scenario. If `false`, the `email` property is stored as set, without any case modifications. Default is `false`.',
146+
action: parsers.booleanParser,
147+
default: false,
148+
},
149+
convertUsernameToLowercase: {
150+
env: 'PARSE_SERVER_CONVERT_USERNAME_TO_LOWERCASE',
151+
help:
152+
'Optional. If set to `true`, the `username` property of a user is automatically converted to lowercase before being stored in the database. Consequently, queries must match the case as stored in the database, which would be lowercase in this scenario. If `false`, the `username` property is stored as set, without any case modifications. Default is `false`.',
153+
action: parsers.booleanParser,
154+
default: false,
155+
},
142156
customPages: {
143157
env: 'PARSE_SERVER_CUSTOM_PAGES',
144158
help: 'custom pages for password validation and reset',
@@ -175,12 +189,6 @@ module.exports.ParseServerOptions = {
175189
action: parsers.booleanParser,
176190
default: true,
177191
},
178-
disableCollation: {
179-
env: 'PARSE_SERVER_DISABLE_COLLATION',
180-
help:
181-
'Disable case insensitivity (collation) on queries and indexes, needed if you use MongoDB serverless or AWS DocumentDB.',
182-
action: parsers.booleanParser,
183-
},
184192
dotNetKey: {
185193
env: 'PARSE_SERVER_DOT_NET_KEY',
186194
help: 'Key for Unity and .Net SDK',
@@ -209,6 +217,13 @@ module.exports.ParseServerOptions = {
209217
action: parsers.booleanParser,
210218
default: true,
211219
},
220+
enableCollationCaseComparison: {
221+
env: 'PARSE_SERVER_ENABLE_COLLATION_CASE_COMPARISON',
222+
help:
223+
'Optional. If set to `true`, the collation rule of case comparison for queries and indexes is enabled. Enable this option to run Parse Server with MongoDB Atlas Serverless or AWS Amazon DocumentDB. If `false`, the collation rule of case comparison is disabled. Default is `false`.',
224+
action: parsers.booleanParser,
225+
default: false,
226+
},
212227
enableExpressErrorHandler: {
213228
env: 'PARSE_SERVER_ENABLE_EXPRESS_ERROR_HANDLER',
214229
help: 'Enables the default express error handler for all errors',
@@ -539,18 +554,6 @@ module.exports.ParseServerOptions = {
539554
help: 'Starts the liveQuery server',
540555
action: parsers.booleanParser,
541556
},
542-
transformEmailToLowerCase: {
543-
env: 'PARSE_SERVER_TRANSFORM_EMAIL_TO_LOWER_CASE',
544-
help:
545-
'Transform Email to lowercase on create/update/login/signup. On queries client needs to ensure to send Email in lowercase format.',
546-
action: parsers.booleanParser,
547-
},
548-
transformUsernameToLowerCase: {
549-
env: 'PARSE_SERVER_TRANSFORM_USERNAME_TO_LOWER_CASE',
550-
help:
551-
'Transform Username to lowercase on create/update/login/signup. On queries client needs to ensure to send Username in lowercase format.',
552-
action: parsers.booleanParser,
553-
},
554557
trustProxy: {
555558
env: 'PARSE_SERVER_TRUST_PROXY',
556559
help:

0 commit comments

Comments
 (0)