I want to allow users of my application to add sub-users and set privileges for what each sub-user is allowed to view or do.
My ideas is to have a separate PRIVILEGES table, like this:
+-----------------+--------+
|privilege | value |
+-----------------+--------+
|create sub users | 1 |
|edit own profile | 2 |
|add new site | 3 |
|delete site | 4 |
+-----------------+--------+
Then when the main user selects privileges update the sub users privilege column with the value, for example:
+--------------+-----------+
|user_id | privilege |
+--------------+-----------+
|user_1 | 4 |
|user_2 | 2 |
|user_3 | 1 |
|user_4 | 2 |
+--------------+-----------+
But the values do not give unique amounts. For example:
privileges
1 -> create sub users
+
2 -> edit own profile
= privilege 3 (create sub users, edit own profile)
but also there is another privilege for value 3 (add new site) so this will not work.
So my question is: How do I make any possible privilege combination unique?
Is there a smarter way to manage privileges?