Skip to content

Commit

Permalink
Update _acl when transform ACL for parse.com compatible. parse-commun…
Browse files Browse the repository at this point in the history
  • Loading branch information
carmenlau committed Apr 1, 2016
1 parent 57156cf commit 019483b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,17 @@ function transformUpdate(schema, className, restUpdate) {

var mongoUpdate = {};
var acl = transformACL(restUpdate);
if (acl._rperm || acl._wperm) {
if (acl._rperm || acl._wperm || acl._acl) {
mongoUpdate['$set'] = {};
if (acl._rperm) {
mongoUpdate['$set']['_rperm'] = acl._rperm;
}
if (acl._wperm) {
mongoUpdate['$set']['_wperm'] = acl._wperm;
}
if (acl._acl) {
mongoUpdate['$set']['_acl'] = acl._acl;
}
}

for (var restKey in restUpdate) {
Expand Down Expand Up @@ -284,16 +287,22 @@ function transformACL(restObject) {
var acl = restObject['ACL'];
var rperm = [];
var wperm = [];
var _acl = {};
for (var entry in acl) {
if (acl[entry].read) {
rperm.push(entry);
_acl[entry] = _acl[entry] || {};
_acl[entry]['r'] = true;
}
if (acl[entry].write) {
wperm.push(entry);
_acl[entry] = _acl[entry] || {};
_acl[entry]['w'] = true;
}
}
output._rperm = rperm;
output._wperm = wperm;
output._acl = _acl;
delete restObject.ACL;
return output;
}
Expand Down

0 comments on commit 019483b

Please sign in to comment.