O
O
Optimus2017-03-25 18:21:33
MySQL
Optimus, 2017-03-25 18:21:33

What is the best way to create user roles in the database?

There are 2 partitions in the system - let's conditionally call them the first and the second.
There are users who will have access only to the first
There are users who will have access only to the second
There are users who will have access to both at once
There are SUPERusers who create the rest and give them access
The first option is to create one column in the database - a role. Options: one, two, double, super - access to the first section, second, both, super - admins
Second option: create a column in the database for each section and set 0 or 1 for each user, depending on whether he has access no.
Today section 2, and tomorrow 5, and then the first option will immediately crumble, because. the number of word combinations will become too large. Maybe more options that I did not take into account such as code 12345 in one field? The task is to rewrite as little code as possible when adding a section.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2017-03-25
@xmoonlight

Dependency tree: USER => Role (Role/"User type") => Permissions (ACL)
Let's create 2 columns in the accounts table: Role and ACL .
1. Role in account table (bitmask based / set based on powers of "2"):
0 - public
1 - guest
2 - user
4 - editor
8 - ...
65536 - SUPER USER / SUPER ADMIN
2. ACL in the account table (based on bitmask / set based on powers of "2"):
0 - no access anywhere
1 - access to 1st partition
2 - access to 2nd partition
4 -
8 -
....
Now , add up:
ACL: 1 = 1 => access to the 1st partition.
ACL: 1+2 = 3 => access to the 1st and 2nd partition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question