MyBB Community Forums

Full Version: Permission System Changes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the current system, it seems that a forum's permissions are inherited from a parent forum, unless explicitly overridden, and the parent forum inherit from all group permissions. This has the following hassle:

Suppose I want to add a forum in which only members of a certain group is allowed access to, using the stock forum software and not any plugins. First I need to add the group. Since I don't want membership in this group to affect access to other forums, I remove permissions from this group. Then, for the forum, I set the permissions for the group, but for all other groups, remove permissions. Later, if I add another user group, I have to go back to the forum and remove permissions from that group to that forum, since it automatically inherits.

If each forum object has a flag to inherit permissions from a parent object, then a forum set to not inherit permissions would only apply permissions to groups that are explicitly set on that object. Child forums could still inherit from this forum. Later adding a user group would not affect the forum since the user group has no permissions set for that forum in particular. That user group would not be able to access the forum.

The following pseudo-code sort of illustrates my idea:
// Determine which forums to consider for permissions
// based on inheriting permissions and parents
forums_to_consider = array()

while(current_forum)
{
    forums_to_consider[] = current_forum
    if(current_forum_inherits_permissions_from_parent)
    {
        if(current_forum_has_parent) current_forum = parent_of_current_forum;
        else { forums_to_consider[] = "DEFAULT" ; break; } // Allow inheriting from group permissions for top level forums
    }
    else
    {
        break;
    }
}

// Determine permissions, YES/NO overrides NA, NO overrides YES in the same forum
// for multiple memberships.  Child forum overrides parent forum except for NA.
foreach(permissions as perm)
{
    resultperms[perm] = NA;
    final[perm] = FALSE;
}
foreach(forum_to_consider as forum)
{
    foreach(membership_groups as group)
    {
        perms = get_permissions(group, forum)
        if(!perms) continue;

         foreach(permissions as perm)
         {
            if(final[perm]) continue; // Child forum already set permission

            // Anything overrides NA, NO overrides YES
            if(resultperms[perm] == NA)
                resultperms[perm] = perms[perm]
            elif(resultperms[perm] == YES && perms[perm] == NO)
                resultperms[perm] == NO;
          }
    }

   // Did we set permission in this forum? If so, parent forum should not replace it.
   foreach(permissions as perm)
   {
       if(resultperms[perm] != NA)
           final[perm] = TRUE;
   }
}

// After done, anything left as N/A becomes NO
foreach(permissions as perm)
{
    if(resultperms[perm] == NA) resultperms[perm] = NO;
}

function get_permissions(group, forum)
{
   if(group == "DEFAULT")
     get_permissions_from_default_group_permissions
   else
     get_permissions_from_forum_group_permissions_if_set
}