Skip to content

Commit c5fdd91

Browse files
authored
Makes sure we don't duplicate user ACL's keys (#2651)
* Adds repro for issue #2246 * Provide fix for issue #2246 * Nit with Set to deduplicate the acl array * remove debuging console.log
1 parent e8aa1ad commit c5fdd91

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

spec/schemas.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,4 +1631,40 @@ describe('schemas', () => {
16311631
done();
16321632
});
16331633
});
1634+
1635+
it('regression test for #2246', done => {
1636+
let profile = new Parse.Object('UserProfile');
1637+
let user = new Parse.User();
1638+
function initialize() {
1639+
return user.save({
1640+
username: 'user',
1641+
password: 'password'
1642+
}).then(() => {
1643+
return profile.save({user}).then(() => {
1644+
return user.save({
1645+
userProfile: profile
1646+
}, {useMasterKey: true});
1647+
});
1648+
});
1649+
}
1650+
1651+
initialize().then(() => {
1652+
return setPermissionsOnClass('UserProfile', {
1653+
'readUserFields': ['user'],
1654+
'writeUserFields': ['user']
1655+
}, true);
1656+
}).then(() => {
1657+
return Parse.User.logIn('user', 'password')
1658+
}).then(() => {
1659+
let query = new Parse.Query('_User');
1660+
query.include('userProfile');
1661+
return query.get(user.id);
1662+
}).then((user) => {
1663+
expect(user.get('userProfile')).not.toBeUndefined();
1664+
done();
1665+
}, (err) => {
1666+
jfail(err);
1667+
done();
1668+
});
1669+
});
16341670
});

src/Controllers/DatabaseController.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ DatabaseController.prototype.addPointerPermissions = function(schema, className,
859859
// the ACL should have exactly 1 user
860860
if (perms && perms[field] && perms[field].length > 0) {
861861
// No user set return undefined
862+
// If the length is > 1, that means we didn't dedup users correctly
862863
if (userACL.length != 1) {
863864
return;
864865
}

src/RestQuery.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ RestQuery.prototype.getUserAndRoleACL = function() {
149149
return Promise.resolve();
150150
}
151151
return this.auth.getUserRoles().then((roles) => {
152-
roles.push(this.auth.user.id);
153-
this.findOptions.acl = roles;
152+
// Concat with the roles to prevent duplications on multiple calls
153+
const aclSet = new Set([].concat(this.findOptions.acl, roles));
154+
this.findOptions.acl = Array.from(aclSet);
154155
return Promise.resolve();
155156
});
156157
};

0 commit comments

Comments
 (0)