Skip to content

Commit fe05339

Browse files
committed
Adds fix for issue affecting update with CLP
1 parent 2d7b992 commit fe05339

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

spec/schemas.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,22 @@ describe('schemas', () => {
20432043
.catch(done.fail);
20442044
});
20452045

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

src/Controllers/DatabaseController.js

Lines changed: 2 additions & 3 deletions
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

Lines changed: 0 additions & 10 deletions
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') {
@@ -257,12 +256,6 @@ RestQuery.prototype.buildRestWhere = function() {
257256
});
258257
};
259258

260-
// Marks the query for a write attempt, so we read the proper ACL (write instead of read)
261-
RestQuery.prototype.forWrite = function() {
262-
this.isWrite = true;
263-
return this;
264-
};
265-
266259
// Uses the Auth object to get the list of roles, adds the user id
267260
RestQuery.prototype.getUserAndRoleACL = function() {
268261
if (this.auth.isMaster) {
@@ -645,9 +638,6 @@ RestQuery.prototype.runFind = function(options = {}) {
645638
if (options.op) {
646639
findOptions.op = options.op;
647640
}
648-
if (this.isWrite) {
649-
findOptions.isWrite = true;
650-
}
651641
return this.config.database
652642
.find(this.className, this.restWhere, findOptions)
653643
.then(results => {

src/rest.js

Lines changed: 3 additions & 4 deletions
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)