Skip to content

Commit b433fb9

Browse files
committed
Prevents _User lock out when setting ACL on signup or afterwards (#1429)
1 parent 30197a7 commit b433fb9

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

spec/ParseUser.spec.js

+49
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,55 @@ describe('Parse.User testing', () => {
8888
});
8989
});
9090

91+
it('should respect ACL without locking user out', (done) => {
92+
let user = new Parse.User();
93+
let ACL = new Parse.ACL();
94+
ACL.setPublicReadAccess(false);
95+
ACL.setPublicWriteAccess(false);
96+
user.setUsername('asdf');
97+
user.setPassword('zxcv');
98+
user.setACL(ACL);
99+
user.signUp().then((user) => {
100+
return Parse.User.logIn("asdf", "zxcv");
101+
}).then((user) => {
102+
equal(user.get("username"), "asdf");
103+
const ACL = user.getACL();
104+
expect(ACL.getReadAccess(user)).toBe(true);
105+
expect(ACL.getWriteAccess(user)).toBe(true);
106+
expect(ACL.getPublicReadAccess()).toBe(false);
107+
expect(ACL.getPublicWriteAccess()).toBe(false);
108+
const perms = ACL.permissionsById;
109+
expect(Object.keys(perms).length).toBe(1);
110+
expect(perms[user.id].read).toBe(true);
111+
expect(perms[user.id].write).toBe(true);
112+
expect(perms['*']).toBeUndefined();
113+
// Try to lock out user
114+
let newACL = new Parse.ACL();
115+
newACL.setReadAccess(user.id, false);
116+
newACL.setWriteAccess(user.id, false);
117+
user.setACL(newACL);
118+
return user.save();
119+
}).then((user) => {
120+
return Parse.User.logIn("asdf", "zxcv");
121+
}).then((user) => {
122+
equal(user.get("username"), "asdf");
123+
const ACL = user.getACL();
124+
expect(ACL.getReadAccess(user)).toBe(true);
125+
expect(ACL.getWriteAccess(user)).toBe(true);
126+
expect(ACL.getPublicReadAccess()).toBe(false);
127+
expect(ACL.getPublicWriteAccess()).toBe(false);
128+
const perms = ACL.permissionsById;
129+
expect(Object.keys(perms).length).toBe(1);
130+
expect(perms[user.id].read).toBe(true);
131+
expect(perms[user.id].write).toBe(true);
132+
expect(perms['*']).toBeUndefined();
133+
done();
134+
}).catch((err) => {
135+
fail("Should not fail");
136+
done();
137+
})
138+
});
139+
91140
it("user login with files", (done) => {
92141
let file = new Parse.File("yolo.txt", [1,2,3], "text/plain");
93142
file.save().then((file) => {

src/RestWrite.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,11 @@ RestWrite.prototype.runDatabaseOperation = function() {
716716
}
717717

718718
if (this.query) {
719+
// Force the user to not lockout
720+
// Matched with parse.com
721+
if (this.className === '_User' && this.data.ACL) {
722+
this.data.ACL[this.query.objectId] = { read: true, write: true };
723+
}
719724
// Run an update
720725
return this.config.database.update(
721726
this.className, this.query, this.data, this.runOptions).then((resp) => {
@@ -732,10 +737,15 @@ RestWrite.prototype.runDatabaseOperation = function() {
732737
});
733738
} else {
734739
// Set the default ACL for the new _User
735-
if (!this.data.ACL && this.className === '_User') {
736-
var ACL = {};
740+
if (this.className === '_User') {
741+
var ACL = this.data.ACL;
742+
// default public r/w ACL
743+
if (!ACL) {
744+
ACL = {};
745+
ACL['*'] = { read: true, write: false };
746+
}
747+
// make sure the user is not locked down
737748
ACL[this.data.objectId] = { read: true, write: true };
738-
ACL['*'] = { read: true, write: false };
739749
this.data.ACL = ACL;
740750
}
741751

0 commit comments

Comments
 (0)