Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing permissions based on reputation [closed]

I'm creating a website in which there are projects, users, and permissions for each user or groups of users. What this is is a community collaboration tool, and I have 4 different permissions:

  • Creator - make changes, accept changes, change permissions
  • Accept changes
  • Make changes
  • View

How could I implement, in a database, this kind of permission system, for groups of users?

Edit: Groups/permissions are defined by reputation, like on StackOverflow.

Edit 2 - more in detail: Each file needs to have a permission, projects need default permissions for newly created files, and I also need to set up MySQL database permissions.

like image 377
Ry- Avatar asked May 14 '11 22:05

Ry-


1 Answers

user_table id, etc  permission table id, user_id, permission_type 

with this structure, each user could have several permission types associated with their account, one for each set of features they could have access to. you would never need to change the table structure in order to add new types of permissions.

to take this a step further, you could make each type of permission a binary number. this way you could make a set of permissions be represented by one integer by using bitwise operators.

for instance if you had the constants

PERMISSION_CHANGE_PERMISSIONS = bindec('001') = 1 PERMISSION_MAKE_CHANGES = bindec('010') = 2 PERMISSION_ACCEPT_CHANGES = bindec('100') = 4 

you could combine these values into one integer using a bitwise operator "|"

(PERMISSION_CHANGE_PERMISSIONS | PERMISSION_MAKE_CHANGES) = bindec('011') = 3 = $users_combined_permissions 

then to check if they have a specific permission, use the bitwise operator "&"

($users_combined_permissions & PERMISSION_MAKE_CHANGES) = true 

if you did that, you would only need one db record for each set of permissions.

like image 74
dqhendricks Avatar answered Sep 25 '22 07:09

dqhendricks