Skip to content

Commit 46ac7e7

Browse files
authored
Adds fix for issue affecting update with CLP (#5269)
* Adds fix for issue affecting update with CLP * Disable single instance
1 parent 9f2fc88 commit 46ac7e7

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

spec/ParseUser.spec.js

-4
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,6 @@ describe('Parse.User testing', () => {
834834
query.get(user.id).then(freshUser => {
835835
equal(freshUser.id, user.id);
836836
equal(freshUser.get('username'), 'alice');
837-
Parse.Object.enableSingleInstance();
838837
done();
839838
});
840839
});
@@ -860,7 +859,6 @@ describe('Parse.User testing', () => {
860859
equal(freshUser.id, user.id);
861860
// Should be alice, but it depends on batch support.
862861
equal(freshUser.get('username'), 'bob');
863-
Parse.Object.enableSingleInstance();
864862
done();
865863
});
866864
});
@@ -1275,14 +1273,12 @@ describe('Parse.User testing', () => {
12751273
});
12761274

12771275
it('returns authData when authed and logged in with provider (regression test for #1498)', async done => {
1278-
Parse.Object.enableSingleInstance();
12791276
const provider = getMockFacebookProvider();
12801277
Parse.User._registerAuthenticationProvider(provider);
12811278
const user = await Parse.User._logInWith('facebook');
12821279
const userQuery = new Parse.Query(Parse.User);
12831280
userQuery.get(user.id).then(user => {
12841281
expect(user.get('authData')).not.toBeUndefined();
1285-
Parse.Object.disableSingleInstance();
12861282
done();
12871283
});
12881284
});

spec/Schema.spec.js

-2
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,6 @@ describe('SchemaController', () => {
10661066
.then(obj2reloaded => {
10671067
expect(obj2reloaded.get('aString')).toEqual(undefined);
10681068
done();
1069-
Parse.Object.enableSingleInstance();
10701069
});
10711070
})
10721071
.catch(error => {
@@ -1100,7 +1099,6 @@ describe('SchemaController', () => {
11001099
.then(obj1 => {
11011100
expect(obj1.get('aPointer')).toEqual('Now a string');
11021101
done();
1103-
Parse.Object.enableSingleInstance();
11041102
});
11051103
});
11061104

spec/schemas.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,23 @@ describe('schemas', () => {
20432043
.catch(done.fail);
20442044
});
20452045

2046+
it('regression test for #5177', async () => {
2047+
Parse.Object.disableSingleInstance();
2048+
Parse.Cloud.beforeSave('AClass', () => {});
2049+
await setPermissionsOnClass(
2050+
'AClass',
2051+
{
2052+
update: { '*': true },
2053+
},
2054+
false
2055+
);
2056+
const obj = new Parse.Object('AClass');
2057+
await obj.save({ key: 1 }, { useMasterKey: true });
2058+
obj.increment('key', 10);
2059+
const objectAgain = await obj.save();
2060+
expect(objectAgain.get('key')).toBe(11);
2061+
});
2062+
20462063
it('regression test for #2246', done => {
20472064
const profile = new Parse.Object('UserProfile');
20482065
const user = new Parse.User();

src/Controllers/DatabaseController.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,6 @@ class DatabaseController {
11411141
distinct,
11421142
pipeline,
11431143
readPreference,
1144-
isWrite,
11451144
}: any = {}
11461145
): Promise<any> {
11471146
const isMaster = acl === undefined;
@@ -1217,7 +1216,7 @@ class DatabaseController {
12171216
);
12181217
}
12191218
if (!query) {
1220-
if (op == 'get') {
1219+
if (op === 'get') {
12211220
throw new Parse.Error(
12221221
Parse.Error.OBJECT_NOT_FOUND,
12231222
'Object not found.'
@@ -1227,7 +1226,7 @@ class DatabaseController {
12271226
}
12281227
}
12291228
if (!isMaster) {
1230-
if (isWrite) {
1229+
if (op === 'update' || op === 'delete') {
12311230
query = addWriteACL(query, aclGroup);
12321231
} else {
12331232
query = addReadACL(query, aclGroup);

src/RestQuery.js

-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function RestQuery(
3030
this.clientSDK = clientSDK;
3131
this.response = null;
3232
this.findOptions = {};
33-
this.isWrite = false;
3433

3534
if (!this.auth.isMaster) {
3635
if (this.className == '_Session') {
@@ -259,12 +258,6 @@ RestQuery.prototype.buildRestWhere = function() {
259258
});
260259
};
261260

262-
// Marks the query for a write attempt, so we read the proper ACL (write instead of read)
263-
RestQuery.prototype.forWrite = function() {
264-
this.isWrite = true;
265-
return this;
266-
};
267-
268261
// Uses the Auth object to get the list of roles, adds the user id
269262
RestQuery.prototype.getUserAndRoleACL = function() {
270263
if (this.auth.isMaster) {
@@ -647,9 +640,6 @@ RestQuery.prototype.runFind = function(options = {}) {
647640
if (options.op) {
648641
findOptions.op = options.op;
649642
}
650-
if (this.isWrite) {
651-
findOptions.isWrite = true;
652-
}
653643
return this.config.database
654644
.find(this.className, this.restWhere, findOptions)
655645
.then(results => {

src/rest.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ function del(config, auth, className, objectId) {
112112
const hasLiveQuery = checkLiveQuery(className, config);
113113
if (hasTriggers || hasLiveQuery || className == '_Session') {
114114
return new RestQuery(config, auth, className, { objectId })
115-
.forWrite()
116115
.execute({ op: 'delete' })
117116
.then(response => {
118117
if (response && response.results && response.results.length) {
@@ -224,9 +223,9 @@ function update(config, auth, className, restWhere, restObject, clientSDK) {
224223
const hasLiveQuery = checkLiveQuery(className, config);
225224
if (hasTriggers || hasLiveQuery) {
226225
// Do not use find, as it runs the before finds
227-
return new RestQuery(config, auth, className, restWhere)
228-
.forWrite()
229-
.execute();
226+
return new RestQuery(config, auth, className, restWhere).execute({
227+
op: 'update',
228+
});
230229
}
231230
return Promise.resolve({});
232231
})

0 commit comments

Comments
 (0)