Skip to content

Commit

Permalink
Adds fix for issue affecting update with CLP
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Dec 31, 2018
1 parent 2d7b992 commit fe05339
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
16 changes: 16 additions & 0 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,22 @@ describe('schemas', () => {
.catch(done.fail);
});

it('regression test for #5177', async () => {
Parse.Cloud.beforeSave('AClass', () => {});
await setPermissionsOnClass(
'AClass',
{
update: { '*': true },
},
false
);
const obj = new Parse.Object('AClass');
await obj.save({ key: 1 }, { useMasterKey: true });
obj.increment('key', 10);
await obj.save();
expect(obj.get('key')).toBe(11);
});

it('regression test for #2246', done => {
const profile = new Parse.Object('UserProfile');
const user = new Parse.User();
Expand Down
5 changes: 2 additions & 3 deletions src/Controllers/DatabaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,6 @@ class DatabaseController {
distinct,
pipeline,
readPreference,
isWrite,
}: any = {}
): Promise<any> {
const isMaster = acl === undefined;
Expand Down Expand Up @@ -1217,7 +1216,7 @@ class DatabaseController {
);
}
if (!query) {
if (op == 'get') {
if (op === 'get') {
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Object not found.'
Expand All @@ -1227,7 +1226,7 @@ class DatabaseController {
}
}
if (!isMaster) {
if (isWrite) {
if (op === 'update' || op === 'delete') {
query = addWriteACL(query, aclGroup);
} else {
query = addReadACL(query, aclGroup);
Expand Down
10 changes: 0 additions & 10 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function RestQuery(
this.clientSDK = clientSDK;
this.response = null;
this.findOptions = {};
this.isWrite = false;

if (!this.auth.isMaster) {
if (this.className == '_Session') {
Expand Down Expand Up @@ -257,12 +256,6 @@ RestQuery.prototype.buildRestWhere = function() {
});
};

// Marks the query for a write attempt, so we read the proper ACL (write instead of read)
RestQuery.prototype.forWrite = function() {
this.isWrite = true;
return this;
};

// Uses the Auth object to get the list of roles, adds the user id
RestQuery.prototype.getUserAndRoleACL = function() {
if (this.auth.isMaster) {
Expand Down Expand Up @@ -645,9 +638,6 @@ RestQuery.prototype.runFind = function(options = {}) {
if (options.op) {
findOptions.op = options.op;
}
if (this.isWrite) {
findOptions.isWrite = true;
}
return this.config.database
.find(this.className, this.restWhere, findOptions)
.then(results => {
Expand Down
7 changes: 3 additions & 4 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ function del(config, auth, className, objectId) {
const hasLiveQuery = checkLiveQuery(className, config);
if (hasTriggers || hasLiveQuery || className == '_Session') {
return new RestQuery(config, auth, className, { objectId })
.forWrite()
.execute({ op: 'delete' })
.then(response => {
if (response && response.results && response.results.length) {
Expand Down Expand Up @@ -224,9 +223,9 @@ function update(config, auth, className, restWhere, restObject, clientSDK) {
const hasLiveQuery = checkLiveQuery(className, config);
if (hasTriggers || hasLiveQuery) {
// Do not use find, as it runs the before finds
return new RestQuery(config, auth, className, restWhere)
.forWrite()
.execute();
return new RestQuery(config, auth, className, restWhere).execute({
op: 'update',
});
}
return Promise.resolve({});
})
Expand Down

0 comments on commit fe05339

Please sign in to comment.