I'm making an IRC bot in PHP. And I've come to the point when I need to determine how would user permissions/accesses would look in the database (and in the application in general).
Here are the requirements:
- There are global and local permissions, global are for all channels, while local are channel specfiic.
- There are permissions such as "root", "bot_admin" "glob_op" "op on #channel", in this example, each is weaker than the last (root is strongest, meaning that no one can take actions against root).
- I haven't completely decided on exactly how many permissions are there, and the bot will be extensible, so there needs to be an option of expanding.
Some approaches I had in mind:
- Assign each permission level a number (1, 2, 4, 8, 16) and add them together to form the access level of a specific user (even adding all of the numbers until
n-1, they would still be lower than
n). As for expanding, I could leave gaps (1, 16, 256, etc) and fill it in later. I don't think it's a very good one, as it would be hard to maintain and read later on, even if I use constants to make it more readable.
- Have each permission in its own boolean column. That seems just silly, and there's no easy way of determining the power relations between each role.
So what say you? Have a better approach I can take?