Closed yadavji83 closed 8 years ago
You can run that manually via the sails console, or you can put it in config/bootstrap.js. It should not go in config/permissions.js. You really only need to run that command once, and then the permissions will be saved in your db, so I would lean toward the console.
@ryanwilliamquinn thanks for fast reply.
i tried this in console: PermissionService.createRole({ name: ‘collaborator’, users: ‘tjwebb’, permissions: [{ model: ‘mymodel’, action: ‘create’ }, { model: ‘myothermodel’, action: ‘read’ }] })
but it was giving me Promise {( pending )}
and when used: Promise.all( ... ).spread( ... ) it gives error: Promise.all (...).spread is not a function
.spread doesn't work because that is a specific to a particular promise library (bluebird), not the general ES6 promise implementation.
from the sails console, you can query your permissions to see if they were created:
Permissions.find({}.console.log)
// you can also see the output from the first operation like this:
PermissionService.createRole({ name: ‘collaborator’, users: ‘tjwebb’,
permissions: [{ model: ‘mymodel’, action: ‘create’ },
{ model: ‘myothermodel’, action: ‘read’ }] }).then(console.log).catch(console.log)
Finally it worked with .then.catch in console! thanks
have a question i am new to permissions and dont understand where will this code go in order to create a new role:
PermissionService.createRole({ name: ‘collaborator’, users: ‘tjwebb’, permissions: [{ model: ‘mymodel’, action: ‘create’ }, { model: ‘myothermodel’, action: ‘read’ }] })
In docs it says we can add new role 2 ways other way is: User.findOne({ username: 'tjwebb' }) .then(function (user) { return Role.create({ name: 'collaborator', users: [ user.id ] }) .then(function (role) { console.log(role); }) .catch(function (error) { console.error(error); });
But i cant understand where should i add it too
in config/permissions.js file or i have to create a new model for collaborator or what?: