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

skipWithMasterKey on Built-In Validator #6972

Merged
merged 3 commits into from
Oct 26, 2020

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Oct 26, 2020

Sorry for the overwhelming amount of content posted.

Small improvement to the Validator, related to #6968.

I find myself often writing this often in cloud functions:

Parse.Cloud.beforeSave(Parse.User, req => {
  if (req.master) {
    return req.object
  }
  // other logic
});

Parse.Cloud.beforeFind(Parse.User, req => {
  if (req.master) {
    return req.query
  }
  // other logic
});

Parse.Cloud.afterFind(Parse.User, req => {
  if (req.master) {
    return req.objects
  }
  // other logic
});

This PR allows for triggers to be skipped if a masterKey is provided, and if skipWithMasterKey is true:

Parse.Cloud.beforeSave('History', req => {
// logic will only get called if req.master is false
},{
  skipWithMasterKey:true
});

Also a small improvement to the beforeFind trigger: Throwing a string will return error code 141 instead of error code 1.

Thank you as always for your time!

@ghost
Copy link

ghost commented Oct 26, 2020

Danger run resulted in 1 fail and 1 markdown; to find out more, see the checks page.

Generated by 🚫 dangerJS

@codecov
Copy link

codecov bot commented Oct 26, 2020

Codecov Report

Merging #6972 into master will decrease coverage by 0.07%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6972      +/-   ##
==========================================
- Coverage   93.88%   93.80%   -0.08%     
==========================================
  Files         169      169              
  Lines       12353    12402      +49     
==========================================
+ Hits        11597    11634      +37     
- Misses        756      768      +12     
Impacted Files Coverage Δ
src/cloud-code/Parse.Cloud.js 98.59% <ø> (ø)
src/triggers.js 93.70% <80.00%> (-0.78%) ⬇️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 92.92% <0.00%> (-0.67%) ⬇️
src/Options/Definitions.js 100.00% <0.00%> (ø)
src/Routers/FunctionsRouter.js 94.11% <0.00%> (ø)
src/Adapters/Files/GridFSBucketAdapter.js 80.32% <0.00%> (+2.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6ac3b6...a61814c. Read the comment docs.

@dblythy dblythy changed the title ResolveMaster on Built-In Validator ResolveMasterKey on Built-In Validator Oct 26, 2020
@davimacedo
Copy link
Member

What do you think about skipWithMasterKey instead of resolveMasterKey?

@dblythy dblythy changed the title ResolveMasterKey on Built-In Validator skipWithMasterKey on Built-In Validator Oct 26, 2020
@dblythy
Copy link
Member Author

dblythy commented Oct 26, 2020

Changes made @davimacedo

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM!

@davimacedo davimacedo merged commit 6fc3afc into parse-community:master Oct 26, 2020
dblythy added a commit to dblythy/docs that referenced this pull request Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants