Skip to content
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

Support wildcard classname in cloud triggers #7360

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ ___
- Add building Docker image as CI check (Manuel Trezza) [#7332](https://github.com/parse-community/parse-server/pull/7332)
- Add NPM package-lock version check to CI (Manuel Trezza) [#7333](https://github.com/parse-community/parse-server/pull/7333)
- Fix incorrect LiveQuery events triggered for multiple subscriptions on the same class with different events [#7341](https://github.com/parse-community/parse-server/pull/7341)
- Add wildcard support for classname in cloud triggers [#7360](https://github.com/parse-community/parse-server/pull/7360)
___
## 4.5.0
[Full Changelog](https://github.com/parse-community/parse-server/compare/4.4.0...4.5.0)
Expand Down
14 changes: 14 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2055,4 +2055,18 @@ describe('Parse.Object testing', () => {
const object = new Parse.Object('CloudCodeIsNew');
await object.save();
});

it('should run wildcard trigger for every class', async () => {
Parse.Cloud.beforeSave('*', req => {
req.object.set("newField",true);
return req.object;
});

Parse.Cloud.afterSave('*', req => {
expect(req.object.get("newField")).toBe(true);
});

const object = new Parse.Object('WildcardClass');
await object.save();
});
});
6 changes: 5 additions & 1 deletion src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ export function getTrigger(className, triggerType, applicationId) {
if (!applicationId) {
throw 'Missing ApplicationID';
}
return get(Category.Triggers, `${triggerType}.${className}`, applicationId);
const trigger = get(Category.Triggers, `${triggerType}.${className}`, applicationId);
if (trigger) {
return trigger;
}
return get(Category.Triggers, `${triggerType}.*`, applicationId);
}

export async function runTrigger(trigger, name, request, auth) {
Expand Down