Skip to content

fix: Unable to create new role if beforeSave hook exists #8474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
25707a1
issue: Unable to create new role when beforeSave hook is present for …
yog27ray Mar 10, 2023
7afb2d3
fix: Unable to create new role if `beforeSave` hook exists
yog27ray Mar 11, 2023
9692e05
revert change
yog27ray Mar 11, 2023
ea35a77
fix: Unable to create new role if `beforeSave` hook exists
yog27ray Mar 11, 2023
412852b
empty
yog27ray Mar 11, 2023
bb5fe27
empty
yog27ray Mar 11, 2023
be62d6a
empty
yog27ray Mar 11, 2023
f88d1ed
empty
yog27ray Mar 11, 2023
f02adee
empty
yog27ray Mar 12, 2023
09f0059
empty
yog27ray Mar 12, 2023
b5c48e5
empty
yog27ray Mar 12, 2023
567a135
empty
yog27ray Mar 12, 2023
f0848ce
empty
yog27ray Mar 12, 2023
959d93d
empty
yog27ray Mar 12, 2023
65d85bf
empty
yog27ray Mar 12, 2023
7170018
empty
yog27ray Mar 12, 2023
24bf112
empty
yog27ray Mar 12, 2023
afb4dfe
empty
yog27ray Mar 12, 2023
3b0c84c
empty
yog27ray Mar 12, 2023
169364c
empty
yog27ray Mar 13, 2023
d6d6cf8
empty
yog27ray Mar 13, 2023
f02b5ec
empty
yog27ray Mar 13, 2023
9eaaecf
empty
yog27ray Mar 13, 2023
fb5bd6a
empty
yog27ray Mar 13, 2023
074edc9
empty
yog27ray Mar 13, 2023
1841eec
empty
yog27ray Mar 13, 2023
54a5620
empty
yog27ray Mar 13, 2023
a8763e1
empty
yog27ray Mar 13, 2023
935fbe4
empty
yog27ray Mar 14, 2023
61a5a14
empty
yog27ray Mar 14, 2023
48ac6a5
empty
yog27ray Mar 14, 2023
312d960
empty
yog27ray Mar 14, 2023
28c15ed
empty
yog27ray Mar 14, 2023
aa95484
empty
yog27ray Mar 14, 2023
1cb6842
empty
yog27ray Mar 14, 2023
954b037
empty
yog27ray Mar 14, 2023
3fd3754
empty
yog27ray Mar 14, 2023
de0a877
empty
yog27ray Mar 14, 2023
e80ddfe
empty
yog27ray Mar 14, 2023
e674157
empty
yog27ray Mar 14, 2023
3e88e5f
empty
yog27ray Mar 14, 2023
efcd879
empty
yog27ray Mar 14, 2023
a15e63f
empty
yog27ray Mar 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/ParseRole.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
21 changes: 13 additions & 8 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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
Expand Down Expand Up @@ -219,10 +222,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(() => {
Expand Down Expand Up @@ -1569,7 +1575,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(
Expand Down Expand Up @@ -1673,10 +1679,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);
Expand Down