onehilltech / blueprint

solid framework for building APIs and backend services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve policy integration

hilljh82 opened this issue · comments

One can use the Policy.Definition in the validate property of a controller action. The current design, however, requires you to write a separate function to integrate Policy.Definition. For example:

return {
  validate: function (req, callback) {
    Policy.Definition (['policy1', 'policy2']).evaluate (req, callback);
  }
}

Instead of have writing a separate function to integrate the policies, the definition should adapt the list of policies to assignable directly to the validate property:

return {
  validate: Policy.Definition (['policy1', 'policy2'])
}

Unfortunately, this approach is not possible because the definition needs to be constructed at each call. Otherwise, the underlying callbacks for the async tasks will be called more than once, and throw an exception.