I am creating a fairly simple site with Node, Express and Mongoose. The site needs to have have user roles and permissions. My thoughts are that i'll validate permissions based on user interaction with the data base.
In mongoose is there a way to determine the type of CRUD operation currently being carried out possibly by a user?
This is my implementation. The code is reusable for client and server. I use it for my express/angular website
in app/both/both.js
Then on app/server/helper.js (act as adapter)
on app/client/helper.js, also act as adapter.
I've found a solution. It would be great to hear peoples opinions on this.
I have a permissions config object which defines each role and their permissions.
Permissions config object
Middleware function
Then i created a middleware function, when the check method gets called it gets the users role from the req object (req.user.role). It then looks at the params passed to the middleware and cross references them with those in the permissions config object.
Route with middlware
I personnally took inspiration from ghost. In my config there is the perms, and
permissions.js
export acanThis
function that take the current logged user. Here is the whole projectPart of my config file
Usage example:
Perhaps what I've done isn't good, but it works well as far as I can see.
Yes, you can access that through the
request
argument.http://nodejs.org/api/http.html#http_message_method
Edit:
Misread your question. It would probably just be better to assign user permissions and allow access to the database based upon the permissions. I don't understand what you mean by validate by means of interaction with the database. If you are already allowing them to interact with the database and they don't have the proper permissions to do so, isn't that a security issue?
Check the Node module permission for that matter. It's pretty simple concept, I hope they'll allow all CRUD methods too.