For my implementation using mongodb, I will follow the same methodology I've used in the past: role definitions and role permissions.
Mongoose schema definitions:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Roles | |
this.roles = { | |
description: { type: String }, | |
text: { type: String }, | |
id: { type: String }, | |
parent: { type: String }, | |
leaf: { type: Boolean } | |
}; | |
this.p_roles = { | |
account_id: { type: ObjectId }, | |
role_id: { type: ObjectId } | |
}; | |
// Groups | |
this.groups = { | |
description: { type: String } | |
}; | |
this.p_groups = { | |
account_id: { type: ObjectId }, | |
role_id: { type: ObjectId } | |
}; |
So, very simply, a role has a description, and its _id is stored in the permission collection for the specific account_id. A user's account_id is stored in a session server side. Then, whenever a user requests client javascript or GET/POST data for a specific role, a check to p_roles will be made.