-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #1271 #1295
Merged
Merged
Fixes #1271 #1295
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// A database adapter that works with data exported from the hosted | ||
// Parse database. | ||
|
||
import intersect from 'intersect'; | ||
|
||
var mongodb = require('mongodb'); | ||
var Parse = require('parse/node').Parse; | ||
|
||
|
@@ -487,18 +489,28 @@ DatabaseController.prototype.reduceRelationKeys = function(className, query) { | |
} | ||
}; | ||
|
||
DatabaseController.prototype.addInObjectIdsIds = function(ids, query) { | ||
if (typeof query.objectId == 'string') { | ||
// Add equality op as we are sure | ||
// we had a constraint on that one | ||
query.objectId = {'$eq': query.objectId}; | ||
DatabaseController.prototype.addInObjectIdsIds = function(ids = null, query) { | ||
let idsFromString = typeof query.objectId === 'string' ? [query.objectId] : null; | ||
let idsFromEq = query.objectId && query.objectId['$eq'] ? [query.objectId['$eq']] : null; | ||
let idsFromIn = query.objectId && query.objectId['$in'] ? query.objectId['$in'] : null; | ||
|
||
let allIds = [idsFromString, idsFromEq, idsFromIn, ids].filter(list => list !== null); | ||
let totalLength = allIds.reduce((memo, list) => memo + list.length, 0); | ||
|
||
let idsIntersection = []; | ||
if (totalLength > 125) { | ||
idsIntersection = intersect.big(allIds); | ||
} else { | ||
idsIntersection = intersect(allIds); | ||
} | ||
query.objectId = query.objectId || {}; | ||
let queryIn = [].concat(query.objectId['$in'] || [], ids || []); | ||
// make a set and spread to remove duplicates | ||
// replace the $in operator as other constraints | ||
// may be set | ||
query.objectId['$in'] = [...new Set(queryIn)]; | ||
|
||
// Need to make sure we don't clobber existing $lt or other constraints on objectId. | ||
// Clobbering $eq, $in and shorthand $eq (query.objectId === 'string') constraints | ||
// is expected though. | ||
if (!('objectId' in query) || typeof query.objectId === 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move that up? be tough to follow why it's correct to override when |
||
query.objectId = {}; | ||
} | ||
query.objectId['$in'] = idsIntersection; | ||
|
||
return query; | ||
} | ||
|
@@ -518,53 +530,47 @@ DatabaseController.prototype.addInObjectIdsIds = function(ids, query) { | |
// anything about users, ideally. Then, improve the format of the ACL | ||
// arg to work like the others. | ||
DatabaseController.prototype.find = function(className, query, options = {}) { | ||
var mongoOptions = {}; | ||
let mongoOptions = {}; | ||
if (options.skip) { | ||
mongoOptions.skip = options.skip; | ||
} | ||
if (options.limit) { | ||
mongoOptions.limit = options.limit; | ||
} | ||
|
||
var isMaster = !('acl' in options); | ||
var aclGroup = options.acl || []; | ||
var acceptor = function(schema) { | ||
return schema.hasKeys(className, keysForQuery(query)); | ||
}; | ||
var schema; | ||
return this.loadSchema(acceptor).then((s) => { | ||
let isMaster = !('acl' in options); | ||
let aclGroup = options.acl || []; | ||
let acceptor = schema => schema.hasKeys(className, keysForQuery(query)) | ||
let schema = null; | ||
return this.loadSchema(acceptor).then(s => { | ||
schema = s; | ||
if (options.sort) { | ||
mongoOptions.sort = {}; | ||
for (var key in options.sort) { | ||
var mongoKey = transform.transformKey(schema, className, key); | ||
for (let key in options.sort) { | ||
let mongoKey = transform.transformKey(schema, className, key); | ||
mongoOptions.sort[mongoKey] = options.sort[key]; | ||
} | ||
} | ||
|
||
if (!isMaster) { | ||
var op = 'find'; | ||
var k = Object.keys(query); | ||
if (k.length == 1 && typeof query.objectId == 'string') { | ||
op = 'get'; | ||
} | ||
let op = typeof query.objectId == 'string' && Object.keys(query).length === 1 ? | ||
'get' : | ||
'find'; | ||
return schema.validatePermission(className, aclGroup, op); | ||
} | ||
return Promise.resolve(); | ||
}).then(() => { | ||
return this.reduceRelationKeys(className, query); | ||
}).then(() => { | ||
return this.reduceInRelation(className, query, schema); | ||
}).then(() => { | ||
return this.adaptiveCollection(className); | ||
}).then(collection => { | ||
var mongoWhere = transform.transformWhere(schema, className, query); | ||
}) | ||
.then(() => this.reduceRelationKeys(className, query)) | ||
.then(() => this.reduceInRelation(className, query, schema)) | ||
.then(() => this.adaptiveCollection(className)) | ||
.then(collection => { | ||
let mongoWhere = transform.transformWhere(schema, className, query); | ||
if (!isMaster) { | ||
var orParts = [ | ||
let orParts = [ | ||
{"_rperm" : { "$exists": false }}, | ||
{"_rperm" : { "$in" : ["*"]}} | ||
]; | ||
for (var acl of aclGroup) { | ||
for (let acl of aclGroup) { | ||
orParts.push({"_rperm" : { "$in" : [acl]}}); | ||
} | ||
mongoWhere = {'$and': [mongoWhere, {'$or': orParts}]}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drew-gross @flovilmart
I ran into an issue migrating an app to Parse Server and I'm hoping you can shed some light on this. You can see the failing test I wrote here. On api.parse.com and Parse Server <= 2.2.4 this test passes.
I tracked the problem down to this comment. Should we really be clobbering $eq constraints here or should the test linked above pass? The hacky feeling workaround would be to replace
query.equalTo("objectId", cake1.id)
withquery.containedIn("objectId", [cake1.id])
in my test.Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeremyPlease I believe the test should pass as the query construction seem to be valid. Do you have an idea for the fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flovilmart Check out #2472 and let me know what you think.