Not signed in (Sign In)

Categories

Vanilla 1.1.5 is a product of Lussumo. More Information: Documentation, Community Support.

Help keep Vanilla free:
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    •  
      CommentAuthormattucf
    • CommentTimeAug 28th 2008
     # 1
    The familiar scenario:

    1. Admin enables extension, and assigns permissions specific to that extension to a role.
    2. Admin disables the extension.
    3. Role settings still show the checkbox for the permission.
    4. Admin unchecks permission.
    5. Permission neither disappears, nor is it disabled.
    6. Admin sighs deeply, because manually fixing the problem is a pain.

    The cause:

    The record in the database for the associated role contains a permission that Vanilla doesn't understand, but Vanilla takes steps during a role save to ensure that it's not affected, assuming it belongs to another application. Further complicating the issue, the Role object doesn't know anything about what's in the database while reading form data, so any unchecked orphan permissions are not initialized with a default value, and thus take on the value from the database during save.

    A possible solution: don't store permissions that evaluate to boolean false, and fix Vanilla to properly deal with orphans that are unchecked. Will test this soon (haven't yet), but I think it'll work.

    Insert at line 67 (before array serialization) of People.Class.Role.php (using svn rev - 738):

    // Remove permissions that were unset.
    // Note: Regardless of which application created the permission, all should be able to remove it.
    while (list($key,$value) = each($this->Permissions)){
    if (!ForceBool($this->Permissions($key)){
    unset($this->Permissions($key));
    }
    }

    Insert at line 79 (right after getting the role id from form data):

    if ($RoleID != 0){
    // Get the current permissions from the database before reading form data.
    // Ensures that behavior is consistent with how permissions are saved and displayed.
    $RoleManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'RoleManager');
    $ExistingRole = $RoleManager->GetRoleById($RoleID);
    $this->Permissions = array_merge($this->Permissions,$ExistingRole->Permissions);
    }
    •  
      CommentAuthorDinoboff
    • CommentTimeAug 29th 2008 edited
     # 2
    About the first part, I understand you would like to remove permissions from user if they are set to false?
    It don't think it will work with permissions which the default is set to true: for a permission set to True by default, each time you tried remove the permission, it will be removed from $this->Permissions and use the default value, true, next time the permission are loaded from the database.

    I guess you would need something like that:

    // Remove permissions that were unset.
    // Note: Regardless of which application created the permission, all should be able to remove it.
    while(list($PermissionName) = each($this->Permissions)) {
    if (ForceBool($this->Permissions[$PermissionName])
    === ForceBool($this->Context->Configuration[$PermissionName])
    ) {
    unset($this->Permissions[$PermissionName]);
    }
    }
    •  
      CommentAuthormattucf
    • CommentTimeSep 2nd 2008
     # 3
    I think it would need to go in GetPropertiesFromDataSet, but you're right, there would need to be logic to check for the absence of a permission that defaults to 1.

    I'd like to explore this further, but I'm gonna have to do a fresh install from svn, cause I think I might be getting bit by an extension or something...

    I fixed a couple errors in my code above and did a test run, and got the desired result in terms of what's stored in the database, but the permissions form for that role no longer showed up right. When a role object is created, it's supposed to fill its permissions array with defaults from the Configuration array, which it does do as far as I can tell; however, all those default settings are getting blown away somehow, by the time GetPropertiesFromDataSet is called. It's bizarre. :-/
    •  
      CommentAuthorWallPhone
    • CommentTimeSep 3rd 2008
     # 4
    Obsessive compulsive?

    Note that the 'Can use the cleanup extension' role permission has been orphaned in the core since Vanilla 1.

    ::adds note to remove it in the bug tracker::
    •  
      CommentAuthormattucf
    • CommentTimeSep 3rd 2008
     # 5
    Obsessive compulsive?


    Yes. :-)

    I kinda had an idea in mind I wanted to pitch to you guys, though. Maybe I won't have time to work through the details after all, but I never liked the way Vanilla did permissions, if for no other reason than the full data structure is stored in a single database column, instead of handling permissions as a separate table. I also think it's easiest to manage permissions when you're only keeping track of what a role *is* allowed to do, and the rest is only important in the settings screens.
Add your comments
    Username Password
  • Format comments as