Sail permits receiving all permissions

I am trying to send all permissions for an authenticated user via JSON from Sails.

My current code is to find permissions for one type of model:

hasPermission: function hasPermission(req, res) { var permitted = PermissionService.isAllowedToPerformAction({ method: req.param('method'), model: sails.models[req.param('model')], user: req.user }); return res.json(200, { permitted: permitted }); } 

This code does not work because isAllowedToPerformAction wants a single instance of the model. Is there a way to return a single JSON file to account for all permissions?

+8
sails-permissions
source share
1 answer
  • Try creating roles and giving them permissions.
  • Assigning Roles to Users

Ref.

 PermissionService.createRole({ name: 'carsCategoryAdmin', permissions: [ { action: 'update', model: 'review', criteria: [{ where: { category: 'cars'}}]}, { action: 'delete', model: 'review', criteria: [{ where: { category: 'cars'}}]} ], users: ['venise'] }) 

You can check the role and the corresponding permissions and users,

 Role.find({name:'carsCategoryAdmin'}) .populate('users') .populate('permissions') .exec(console.log) 

Read more @ sails-permissions-by-example

See how to get user rights with the code in the comment given by skrichten on May 10, 2014 .

+4
source share

All Articles