Skip to content

A sails Policy conditions builder, based on criteria of the passed in model

License

Notifications You must be signed in to change notification settings

stuk88/sails-model-policy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

sails-model-policy

A sails Policy conditions builder, based on criteria of the passed in model

Example

A policy to check whether the user id is the owner of the object available through the request.

module.exports = function(req, res, next) {

  // User is allowed, proceed to the next policy, 
  // or if this is the last policy, the controller
  
  var policyValidator = ModelPolicy(req);

  if (policyValidator.queriedModelCreteria({owner:req.session.user_id}) ) {
    return next();
  }

  // User is not allowed
  res.status(403);
  return res.json({error:'not allowed'});
};

About

A sails Policy conditions builder, based on criteria of the passed in model

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published