title: The right way to manage user privileges (user hierarchy)
body: <p>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.</p>
  
  <p>My ideas is to have a separate PRIVILEGES table, like this:</p>
  
  <pre><code>+-----------------+--------+
  |privilege        |  value |
  +-----------------+--------+
  |create sub users |    1   |
  |edit own profile |    2   |
  |add new site     |    3   |
  |delete site      |    4   |
  +-----------------+--------+
  </code></pre>
  
  <p>Then when the main user selects privileges update the sub users privilege column with the value, for example:</p>
  
  <pre><code>+--------------+-----------+
  |user_id       | privilege |
  +--------------+-----------+
  |user_1        |     4     | 
  |user_2        |     2     |
  |user_3        |     1     |
  |user_4        |     2     |
  +--------------+-----------+
  </code></pre>
  
  <p>But the values do not give unique amounts. For example:</p>
  
  <pre><code>privileges
  1 -&gt; create sub users
  +
  2 -&gt; edit own profile
  = privilege 3 (create sub users, edit own profile)
  </code></pre>
  
  <p>but also there is another privilege for value 3 (add new site) so this will not work.</p>
  
  <p><strong>So my question is: How do I make any possible privilege combination unique?</strong></p>
  
  <p>Is there a smarter way to manage privileges?</p>