title: Best Practice for Designing User Roles and Permission System?
body: <p>I need to add user roles and permission system into my web application built using PHP/MySQL. I want to have this functionality: </p>
  
  <ol>
  <li>One root user can create sub-roots, groups, rules and normal users( all privileges) .</li>
  <li>Sub-roots can create only rules, permissions and users for his/her own group ( no groups).</li>
  <li>A user can access either content created by him or his group, based on the permission assigned to him, by group root.</li>
  </ol>
  
  <p>I need the system to be flexible enough, so that new roles and permissions are assigned to content.</p>
  
  <p>I have a <code>users</code> table storing group key along with other information. Currently I am using two feilds in each content table i.e. <code>createdBy</code> and <code>CreatedByGroup</code>, and using that as the point whether a certain user has permissions. But its not flexible enough, because for every new content, I have to go throug all data updates and permission updates. Please help me by discussing your best practices for schema design.</p>