Recently Ive been working on some systems that require several user types, Ill call them roles. Roles are essential to most applications because for one, youll want to have a hierarchy of users and what they can do in the system. Im sure most developers have already implemented this in some systems they develop. One of the vital aspects of a role is the permission. A permission is like a clearance for a user. A user must have permissions to have access to a specific part or parts in a system, this will later be referred to as access-levels.
A very good question is, why should we use a role module. I could mention a few that most of us are aware of.
1. Elimination of duplicate codes. Instead of re-creating sectionspages per user type we can create a single page with several conditions based on access-levels
2. Grouping of users. If you group users by roles it will be easier to categorize them and sort them by level in a hierarchy.
3. Ease of Use. When you change the access level or permission of a role, it will apply to all users under the role, thus you dont have to update each user.
Although the creation of a role module would take a lot more time in developing a system it will save you a lot of time later when it comes to providing a set of rules and limitations for a group of users.
There are several ways to implement a role module. Here is an example of a role-management module:
This image was taken from the project management tool Redmine.
I got the idea from Redmines role-management module and I tried to imitate it by creating my own. Here is my implementation of a role module.
And in the code
And that should suffice on how my role-management works. If you happen to know a better or a more efficient approach to this Id be more than glad to know about it.