-
-
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 #1417 #1420
Merged
flovilmart
merged 5 commits into
parse-community:master
from
drew-gross:fix-nested-special-keys
Apr 8, 2016
Merged
Fixes #1417 #1420
Changes from all commits
Commits
Show all changes
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import log from './logger'; | ||
import _ from 'lodash'; | ||
var mongodb = require('mongodb'); | ||
var Parse = require('parse/node').Parse; | ||
|
||
|
@@ -149,8 +150,6 @@ export function transformKeyValue(schema, className, restKey, restValue, options | |
throw 'There was a problem transforming an ACL.'; | ||
} | ||
|
||
|
||
|
||
// Handle arrays | ||
if (restValue instanceof Array) { | ||
if (options.query) { | ||
|
@@ -613,6 +612,21 @@ function transformUpdateOperator(operator, flatten) { | |
} | ||
} | ||
|
||
const specialKeysForUntransform = [ | ||
'_id', | ||
'_hashed_password', | ||
'_acl', | ||
'_email_verify_token', | ||
'_perishable_token', | ||
'_tombstone', | ||
'_session_token', | ||
'updatedAt', | ||
'_updated_at', | ||
'createdAt', | ||
'_created_at', | ||
'expiresAt', | ||
'_expiresAt', | ||
]; | ||
|
||
// Converts from a mongo-format object to a REST-format object. | ||
// Does not strip out anything based on a lack of authentication. | ||
|
@@ -630,10 +644,9 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals | |
if (mongoObject === null) { | ||
return null; | ||
} | ||
|
||
if (mongoObject instanceof Array) { | ||
return mongoObject.map((o) => { | ||
return untransformObject(schema, className, o, true); | ||
return mongoObject.map(arrayEntry => { | ||
return untransformObject(schema, className, arrayEntry, true); | ||
}); | ||
} | ||
|
||
|
@@ -647,6 +660,10 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals | |
|
||
var restObject = untransformACL(mongoObject); | ||
for (var key in mongoObject) { | ||
if (isNestedObject && _.includes(specialKeysForUntransform, key)) { | ||
restObject[key] = untransformObject(schema, className, mongoObject[key], true); | ||
continue; | ||
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. we're not setting restObject[key] = mongoObject[key] |
||
} | ||
switch(key) { | ||
case '_id': | ||
restObject['objectId'] = '' + mongoObject[key]; | ||
|
@@ -728,8 +745,7 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals | |
break; | ||
} | ||
} | ||
restObject[key] = untransformObject(schema, className, | ||
mongoObject[key], true); | ||
restObject[key] = untransformObject(schema, className, mongoObject[key], true); | ||
} | ||
} | ||
|
||
|
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.
why don't we do something like
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.
Yeah I will refactor
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.
maybe move
let transformableKeys
some where else, and if we get crazy we could have a structure like: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.
I went with something simpler. Moving this logic all to the mongo adapter will be a better time to fix it up.