fix: Cloud Code trigger beforeSave does not work with Parse.Role (#8320)
This commit is contained in:
@@ -1558,6 +1558,22 @@ describe('Cloud Code', () => {
|
||||
expect(obj.get('foo')).toBe('bar');
|
||||
});
|
||||
|
||||
it('create role with name and ACL and a beforeSave', async () => {
|
||||
Parse.Cloud.beforeSave(Parse.Role, ({ object }) => {
|
||||
return object;
|
||||
});
|
||||
|
||||
const obj = new Parse.Role('TestRole', new Parse.ACL({ '*': { read: true, write: true } }));
|
||||
await obj.save();
|
||||
|
||||
expect(obj.getACL()).toEqual(new Parse.ACL({ '*': { read: true, write: true } }));
|
||||
expect(obj.get('name')).toEqual('TestRole');
|
||||
await obj.fetch();
|
||||
|
||||
expect(obj.getACL()).toEqual(new Parse.ACL({ '*': { read: true, write: true } }));
|
||||
expect(obj.get('name')).toEqual('TestRole');
|
||||
});
|
||||
|
||||
it('can unset in afterSave', async () => {
|
||||
Parse.Cloud.beforeSave('TestObject', ({ object }) => {
|
||||
if (!object.existed()) {
|
||||
|
||||
@@ -86,7 +86,10 @@ function RestWrite(config, auth, className, query, data, originalData, clientSDK
|
||||
// Shared SchemaController to be reused to reduce the number of loadSchema() calls per request
|
||||
// Once set the schemaData should be immutable
|
||||
this.validSchemaController = null;
|
||||
this.pendingOps = {};
|
||||
this.pendingOps = {
|
||||
operations: null,
|
||||
identifier: null,
|
||||
};
|
||||
}
|
||||
|
||||
// A convenient method to perform all the steps of processing the
|
||||
@@ -227,10 +230,13 @@ RestWrite.prototype.runBeforeSaveTrigger = function () {
|
||||
}
|
||||
|
||||
const { originalObject, updatedObject } = this.buildParseObjects();
|
||||
|
||||
const identifier = updatedObject._getStateIdentifier();
|
||||
const stateController = Parse.CoreManager.getObjectStateController();
|
||||
const [pending] = stateController.getPendingOps(updatedObject._getStateIdentifier());
|
||||
this.pendingOps = { ...pending };
|
||||
const [pending] = stateController.getPendingOps(identifier);
|
||||
this.pendingOps = {
|
||||
operations: { ...pending },
|
||||
identifier,
|
||||
};
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
@@ -1586,7 +1592,7 @@ RestWrite.prototype.runAfterSaveTrigger = function () {
|
||||
.then(result => {
|
||||
const jsonReturned = result && !result._toFullJSON;
|
||||
if (jsonReturned) {
|
||||
this.pendingOps = {};
|
||||
this.pendingOps.operations = {};
|
||||
this.response.response = result;
|
||||
} else {
|
||||
this.response.response = this._updateResponseWithData(
|
||||
@@ -1690,10 +1696,9 @@ RestWrite.prototype.cleanUserAuthData = function () {
|
||||
};
|
||||
|
||||
RestWrite.prototype._updateResponseWithData = function (response, data) {
|
||||
const { updatedObject } = this.buildParseObjects();
|
||||
const stateController = Parse.CoreManager.getObjectStateController();
|
||||
const [pending] = stateController.getPendingOps(updatedObject._getStateIdentifier());
|
||||
for (const key in this.pendingOps) {
|
||||
const [pending] = stateController.getPendingOps(this.pendingOps.identifier);
|
||||
for (const key in this.pendingOps.operations) {
|
||||
if (!pending[key]) {
|
||||
data[key] = this.originalData ? this.originalData[key] : { __op: 'Delete' };
|
||||
this.storage.fieldsChangedByTrigger.push(key);
|
||||
|
||||
Reference in New Issue
Block a user