Skip to content

Commit

Permalink
Adds fix for issue affecting update with CLP (parse-community#5269)
Browse files Browse the repository at this point in the history
* Adds fix for issue affecting update with CLP

* Disable single instance
  • Loading branch information
flovilmart authored Jan 4, 2019
1 parent 2fdd03a commit c12947a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
4 changes: 0 additions & 4 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,6 @@ describe('Parse.User testing', () => {
query.get(user.id).then(freshUser => {
equal(freshUser.id, user.id);
equal(freshUser.get('username'), 'alice');
Parse.Object.enableSingleInstance();
done();
});
});
Expand All @@ -860,7 +859,6 @@ describe('Parse.User testing', () => {
equal(freshUser.id, user.id);
// Should be alice, but it depends on batch support.
equal(freshUser.get('username'), 'bob');
Parse.Object.enableSingleInstance();
done();
});
});
Expand Down Expand Up @@ -1275,14 +1273,12 @@ describe('Parse.User testing', () => {
});

it('returns authData when authed and logged in with provider (regression test for #1498)', async done => {
Parse.Object.enableSingleInstance();
const provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
const user = await Parse.User._logInWith('facebook');
const userQuery = new Parse.Query(Parse.User);
userQuery.get(user.id).then(user => {
expect(user.get('authData')).not.toBeUndefined();
Parse.Object.disableSingleInstance();
done();
});
});
Expand Down
2 changes: 0 additions & 2 deletions spec/Schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,6 @@ describe('SchemaController', () => {
.then(obj2reloaded => {
expect(obj2reloaded.get('aString')).toEqual(undefined);
done();
Parse.Object.enableSingleInstance();
});
})
.catch(error => {
Expand Down Expand Up @@ -1100,7 +1099,6 @@ describe('SchemaController', () => {
.then(obj1 => {
expect(obj1.get('aPointer')).toEqual('Now a string');
done();
Parse.Object.enableSingleInstance();
});
});

Expand Down
17 changes: 17 additions & 0 deletions spec/schemas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,23 @@ describe('schemas', () => {
.catch(done.fail);
});

it('regression test for #5177', async () => {
Parse.Object.disableSingleInstance();
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);
const objectAgain = await obj.save();
expect(objectAgain.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 @@ -259,12 +258,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 @@ -647,9 +640,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 c12947a

Please sign in to comment.