Skip to content

Adding support for AfterFind #2962

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

Closed
wants to merge 8 commits into from
Closed

Adding support for AfterFind #2962

wants to merge 8 commits into from

Conversation

jbpringuey
Copy link
Contributor

For security reasons, I need to hide certain fields (like email) and rows from the API for use cases which are not supported by the current ACL framework. This plugin will enable all sorts of manipulation. Next step would be to support promise to maybe augment the response from other data source.

…ide certain fields or rows from result set in a more dynamic way than the current capabilities
@danibjor
Copy link

5a58724#diff-dc168077f7f927cefd5df84cb82228a6R481

variable name should be hasAfterFindHook - not hasAfterSaveHook

Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, can you address the nits and we'll be able to merge that.

@@ -640,4 +660,7 @@ function findObjectWithKey(root, key) {
}
}



Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the lines

};
logTriggerSuccessBeforeHook(triggerType, className, 'AfterFind', JSON.stringify(results), auth);
var resultsAsParseObjects = [];
for (var i=0;i<results.length;i++){
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use a map here. We avoid for loops with indexes

response.results = resultsAsParseObjects;
var triggerPromise = trigger(request, response);
var modifiedJSONResults = [];
for(var i = 0;i<response.results.length;i++){
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

for(var i = 0;i<response.results.length;i++){
modifiedJSONResults.push(response.results[i].toJSON());
}
logTriggerAfterHook(triggerType,className, JSON.stringify(modifiedJSONResults), auth);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spaces

});
});

});
Copy link
Contributor

Choose a reason for hiding this comment

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

Add trailing \n

}
logTriggerAfterHook(triggerType,className, JSON.stringify(modifiedJSONResults), auth);
if (triggerPromise && typeof triggerPromise.then === "function") {
return reject(new Parse.Error(Parse.Error.SCRIPT_FAILED, "Promise not supported by AfterFind"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Because the beforeFind trigger uses promises, and promises are more convenient that the callback, we should put it there too

kulshekhar and others added 3 commits October 30, 2016 11:12
* Close all alive connections on SIGINT/SIGTERM

* Add a comment referencing the node issue.
Currently in the logs if an invalid function is called the error
message just says "invalid function" which is decidedly unhelpful
when looking through server logs.  Now it will say
"Invalid function: "functionName""
…ide certain fields or rows from result set in a more dynamic way than the current capabilities
@facebook-github-bot
Copy link

@jbpringuey updated the pull request - view changes

@jbpringuey
Copy link
Contributor Author

messed up the rebase, it is showing other's commit too let me try to fix it

jb pringuey and others added 4 commits October 30, 2016 11:47
…ide certain fields or rows from result set in a more dynamic way than the current capabilities
* Close all alive connections on SIGINT/SIGTERM

* Add a comment referencing the node issue.
Currently in the logs if an invalid function is called the error
message just says "invalid function" which is decidedly unhelpful
when looking through server logs.  Now it will say
"Invalid function: "functionName""
@facebook-github-bot
Copy link

@jbpringuey updated the pull request - view changes

@jbpringuey
Copy link
Contributor Author

going to resubmit ...

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.

6 participants