fix: Unable to create new role if beforeSave hook exists (#8474)
This commit is contained in:
@@ -601,4 +601,12 @@ describe('Parse Role testing', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should save role when beforeSave hook for _Role is present.', async done => {
|
||||||
|
Parse.Cloud.beforeSave('_Role', () => {});
|
||||||
|
const role = new Parse.Role('roleName', new Parse.ACL());
|
||||||
|
await role.save({}, { useMasterKey: true });
|
||||||
|
expect(role.id).toBeDefined();
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -87,7 +87,10 @@ function RestWrite(config, auth, className, query, data, originalData, clientSDK
|
|||||||
// Shared SchemaController to be reused to reduce the number of loadSchema() calls per request
|
// Shared SchemaController to be reused to reduce the number of loadSchema() calls per request
|
||||||
// Once set the schemaData should be immutable
|
// Once set the schemaData should be immutable
|
||||||
this.validSchemaController = null;
|
this.validSchemaController = null;
|
||||||
this.pendingOps = {};
|
this.pendingOps = {
|
||||||
|
operations: null,
|
||||||
|
identifier: null,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// A convenient method to perform all the steps of processing the
|
// A convenient method to perform all the steps of processing the
|
||||||
@@ -219,10 +222,13 @@ RestWrite.prototype.runBeforeSaveTrigger = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { originalObject, updatedObject } = this.buildParseObjects();
|
const { originalObject, updatedObject } = this.buildParseObjects();
|
||||||
|
const identifier = updatedObject._getStateIdentifier();
|
||||||
const stateController = Parse.CoreManager.getObjectStateController();
|
const stateController = Parse.CoreManager.getObjectStateController();
|
||||||
const [pending] = stateController.getPendingOps(updatedObject._getStateIdentifier());
|
const [pending] = stateController.getPendingOps(identifier);
|
||||||
this.pendingOps = { ...pending };
|
this.pendingOps = {
|
||||||
|
operations: { ...pending },
|
||||||
|
identifier,
|
||||||
|
};
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -1569,7 +1575,7 @@ RestWrite.prototype.runAfterSaveTrigger = function () {
|
|||||||
.then(result => {
|
.then(result => {
|
||||||
const jsonReturned = result && !result._toFullJSON;
|
const jsonReturned = result && !result._toFullJSON;
|
||||||
if (jsonReturned) {
|
if (jsonReturned) {
|
||||||
this.pendingOps = {};
|
this.pendingOps.operations = {};
|
||||||
this.response.response = result;
|
this.response.response = result;
|
||||||
} else {
|
} else {
|
||||||
this.response.response = this._updateResponseWithData(
|
this.response.response = this._updateResponseWithData(
|
||||||
@@ -1673,10 +1679,9 @@ RestWrite.prototype.cleanUserAuthData = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
RestWrite.prototype._updateResponseWithData = function (response, data) {
|
RestWrite.prototype._updateResponseWithData = function (response, data) {
|
||||||
const { updatedObject } = this.buildParseObjects();
|
|
||||||
const stateController = Parse.CoreManager.getObjectStateController();
|
const stateController = Parse.CoreManager.getObjectStateController();
|
||||||
const [pending] = stateController.getPendingOps(updatedObject._getStateIdentifier());
|
const [pending] = stateController.getPendingOps(this.pendingOps.identifier);
|
||||||
for (const key in this.pendingOps) {
|
for (const key in this.pendingOps.operations) {
|
||||||
if (!pending[key]) {
|
if (!pending[key]) {
|
||||||
data[key] = this.originalData ? this.originalData[key] : { __op: 'Delete' };
|
data[key] = this.originalData ? this.originalData[key] : { __op: 'Delete' };
|
||||||
this.storage.fieldsChangedByTrigger.push(key);
|
this.storage.fieldsChangedByTrigger.push(key);
|
||||||
|
|||||||
Reference in New Issue
Block a user