Evaluate allow/deny without performing insert/update/delete


#1

Hi,

Is that possible to evaluate result of allow & deny rules without doing database operation?

For example, I got defined “allow” rule for insert operation and I want to show/hide “insert” button in UI by evaluating allow rule in helper (helper returns CSS class “hidden” or “”).

Of course, I can repeat the same rule in helper, but that’s duplication of code - If I have complex allow/deny rules (and many UI components to show/hide) maintaining that code is nightmare.

Something like:

"insertButtonClass": function() {

  if(Collection.insertIsAllowed()) {
    return "";
  }

  return "hidden";
}

And I got:

<button id="insert-button" class="btn {{insertButtonClass}}">

Thanks!


#2

If the validation code doesn’t use data exclusively available to the server, then just create a helper class/function/object/method outside the client/server folders (available to both). You would then call the helper methods from the allow/deny rules in the server and the template helpers in the client.

If the validation code DOES use data exclusively available to the server, then put the validation in Meteor.methods and call it asynchronously from the client (only option you have), and synchronously from the server’s allow/deny rules.


#3

Thanks Manuel. I ended with solution #1