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.
    •  
      CommentAuthorBen
    • CommentTimeNov 8th 2007 edited
     # 1
    Users with the 'Can change User Role' permission should not be able to change the roles of users with a higher ranked role than themselves, as defined by the sortable role list.

    I'm sure this was meant to be included in the core, otherwise there isn't really a use for the sortable list.
    •  
      CommentAuthorBen
    • CommentTimeNov 10th 2007
     # 2
    *bump
    •  
      CommentAuthorThaRiddla
    • CommentTimeNov 10th 2007
     # 3
    I'm not entirely sure that the roles in Vanilla are meant to be a ranked system...it seems more to me that it's a true/false type of thing where if you have someone who has change roles enabled, it's a global variable no matter your rank.

    For instance, if you have 2 author-type roles with different titles, just because author 1 is above author 2 does that mean that they should have more power? That doesn't seem right.

    Since there isn't anything in the documentation about it, I'm not 100%.
    •  
      CommentAuthorBen
    • CommentTimeNov 13th 2007
     # 4
    Well it's mainly that if you're creating a forum for some group of people with a strict hierarchy, they like to keep it. I need to assign role privileges so that those lower down the ranks can bump up people who are below them, but can't immediately boost themselves up to Administrator, mainly as a prevention of havoc.
    • CommentAuthorbestfoot
    • CommentTimeNov 19th 2007
     # 5
    Well, I have created a role, but when I drag to reorder, it doesn't stick. Does anybody else have this issue?

    Should my discussion go elsewhere? I am finding the forum hard to navigate other than with search.
    •  
      CommentAuthorBen
    • CommentTimeNov 30th 2007 edited
     # 6
    I'm just going to bump this again..

    I have 2 ranks in a forum who should be able to edit Roles, but they're still restricted concerning most of the administrative features.
    My problem is that although the roles can be clearly ordered in a hierarchical fashion, if I assign role changing privileges to the lower-ranked of these two roles, they can still edit the role of the ones above them. It's possible for them to ban the roles above them and raise themselves to Administrator where they can edit all sorts of settings I'd rather they didn't; if they were so inclined of course.

    I just want them to only be able to raise the Role of those beneath them.. a Corporal shouldn't be able to promote a Private to Captain, or dismiss the General...
    •  
      CommentAuthorBen
    • CommentTimeNov 30th 2007
     # 7
    There should be a way to do this.. there's a column in the Role table entitled 'Priority', generated by the order you arrange the Roles in through drag & drop.
    • CommentAuthorgerry22
    • CommentTimeJan 6th 2008 edited
     # 8
    ok yes, i'd like to be able to do this too.

    I don't think you can change your own role, but if you have a "Change user roles" permission you could sign up to the forum with a new account and assign that account an admin role and once you have the admin role you can do everything.

    I don't like this for lots of reasons.

    If a user has a "Change user roles" permission, wouldn't it be better to only allow them to assign roles up to and including their rank/priority or "pay grade"?
  1.  # 9
    that's odd

    I had the same concerns as you when I have the moderators of my forum the power to change roles. For the sake of argument we'll say my forum has three roles: admin (me - can anything); moderator (can do a bunch of stuff mods do) and user.

    I tested it and discovered they were unable to change my role (as admin) and were unable to change themselves to admin or indeed change users to admin (although I haven't tested to see if they can change users into moderators but I would worry about that as I trust them.

    So therefore I didn't have a problem and I assumed the functionality was in built as you requested in the first post - unless I'm reading this all wrong

    if so, sorry - and please ignore ;)
    • CommentAuthorDG55
    • CommentTimeJan 11th 2008
     # 10
    I'm having this same issue.

    I hear what your saying conradslater, but I cant say my forum works in the same way. Basically the priority level (order) of each role doesnt seem to affect who can give who what role.

    Any answers or add ons for this issue?

    Its crazy that a moderater can change a members role to one which is higher than themselfs!

    Cheers.
    • CommentAuthorgerry22
    • CommentTimeJan 12th 2008 edited
     # 11
    yes it is crazy, it shouldn't be an addon that solves this problem, it should be in the core.
    • CommentAuthorDG55
    • CommentTimeJan 12th 2008
     # 12
    Agreed. But how do we get this into the development cycle, or at least for the meantime - make an extension for this?
    •  
      CommentAuthorBen
    • CommentTimeJan 12th 2008
     # 13
    I'd suggest someone adds it to the bug tracker.
    • CommentAuthorDG55
    • CommentTimeJan 13th 2008
     # 14
    How do we do this?
  2.  # 15
    I can do it. I'm sure this issue has come up so many times in the past and been resolved though. It's strange it works for some and not others...
    • CommentAuthorfysicsluvr
    • CommentTimeJan 13th 2008
     # 16
    @minisweeper
    I think what IS in the core is not being able to edit the role of admin, or maybe only the first account (1). but what ISN'T in the core is not being able to change the role of someone w/ a higher hierarchy; at least that's the conclusion I have come to.
    • CommentAuthorDG55
    • CommentTimeJan 14th 2008
     # 17
    I see what you mean there. This would explain the confusion.

    I really hope something can be sorted. I'm hoping to use Vanilla for one of my sites due to be released within the next few months, but this sort of thing is essential really.

    Since there is the functionality built into the database tables (priority), is there an easy way to create an extension for the time being?
    • CommentAuthorgerry22
    • CommentTimeJan 14th 2008 edited
     # 18
    i don't know how to make an extension of it, i think you would need some delegates added, but this seems to work maybe someone can use it and make the extension:

    you have to edit three files.

    First: library/People/People.Class.RoleManager lines 30-37 - Add a "Priority" field to the select statment array on line 33

    30 function GetRoleBuilder($GetUnauthenticated = '0') {
    31 $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
    32 $s->SetMainTable('Role', 'r');
    33 $s->AddSelect(array('Priority', 'RoleID', 'Name', 'Icon', 'Description', 'PERMISSION_SIGN_IN', 'PERMISSION_RECEIVE_APPLICATION_NOTIFICATION', 'PERMISSION_HTML_ALLOWED', 'Permissions', 'Unauthenticated'), 'r');
    34 $s->AddWhere('r', 'Active', '', '1', '=');
    35 if (!$GetUnauthenticated) $s->AddWhere('r', 'Unauthenticated', '', '0', '=');
    36 return $s;
    37 }



    Next: library/People/People.Class.Role - Add a Priority property to the Role class
    so three edits will do it -
    add this property

    var $Priority;

    this line to the Clear method

    $this->Priority = 0;

    and this line to the GetPropertiesFromDataSet method

    $this->Priority = ForceInt(@$DataSet['Priority'], 0);



    And last but not least: library/Vanilla/Vanilla.Control.AccountRoleForm.php - you need to compare the users role level(priority) against the role level(priority) being assigned

    you need to change the following piece of code

    36 if ($this->PostBackAction == 'ProcessRole' && $this->IsValidFormPostBack() && $this->Context->Session->UserID != $User->UserID && $this->Context->Session->User->Permission('PERMISSION_CHANGE_USER_ROLE')) {
    37 $urh = $this->Context->ObjectFactory->NewObject($this->Context, 'UserRoleHistory');
    38 $urh->GetPropertiesFromForm();
    39 if ($UserManager->AssignRole($urh)) $Redirect = 1;
    40 }


    to note: line 39 is the only line changed

    36 if ($this->PostBackAction == 'ProcessRole' && $this->IsValidFormPostBack() && $this->Context->Session->UserID != $User->UserID && $this->Context->Session->User->Permission('PERMISSION_CHANGE_USER_ROLE')) {
    37 $urh = $this->Context->ObjectFactory->NewObject($this->Context, 'UserRoleHistory');
    38 $urh->GetPropertiesFromForm();

    $rm = $this->Context->ObjectFactory->NewContextObject($this->Context, 'RoleManager');

    $UserRole = $rm->GetRoleById($this->Context->Session->User->RoleID);
    $NewRole = $rm->GetRoleById(($urh->RoleID));

    if ($NewRole->Priority > $UserRole->Priority) {
    $this->Context->WarningCollector->Add('You cannot change a users role to a level higher than yours.');
    } elseif ($UserManager->AssignRole($urh)) {
    $Redirect = 1;
    }
    40 }
    • CommentAuthorDG55
    • CommentTimeJan 14th 2008
     # 19
    Thanks Gerry! This is fantastic, well done.

    I'm a bit cautious of making changes like that though, as I just know they will break when we upgrade the version.

    Can we somehow 'suggest' your code for the next update of Vanilla?
    • CommentAuthorDG55
    • CommentTimeJan 14th 2008 edited
     # 20
    Just checked out your fix Gerry, and it works great for refusing access to a higher level than yourself (great work! see image), but unfortunately it still lets you 'demote' a level higher than you.

    So e.g. a moderator can change an administrator to member. Is it easy to change this aspect using the same method?

    Cheers.




    I suppose what we have to do is add another elseif to the last file. So we would say if CurrentUserRole priority is lower than UserRole priority, then it returns a different error. 'You cannot change the role of a user higher than yourself'.

    CurrentUserRole being the role of the person who is trying to edit someone else.
    UserRole being the role of the person who you are editing.
    • CommentAuthorgerry22
    • CommentTimeJan 14th 2008 edited
     # 21
    ok, this should do it.


    $rm = $this->Context->ObjectFactory->NewContextObject($this->Context, 'RoleManager');
    $um = $this->Context->ObjectFactory->NewContextObject($this->Context, 'UserManager');

    $UserRole = $rm->GetRoleById($this->Context->Session->User->RoleID);
    $NewRole = $rm->GetRoleById(($urh->RoleID));
    $sOldRole = $um->GetUserById($urh->UserID);
    $OldRole = $rm->GetRoleById($sOldRole->RoleID);

    if ($NewRole->Priority > $UserRole->Priority) {
    $this->Context->WarningCollector->Add('You cannot change a users role to a level higher than yours.');
    } elseif ($OldRole->Priority >= $UserRole->Priority) {
    $this->Context->WarningCollector->Add('You cannot change the role of a user of a higher or equal level role than you.');
    } elseif ($UserManager->AssignRole($urh)) {
    $Redirect = 1;
    }


    there's already a UserManager, so:

    $rm = $this->Context->ObjectFactory->NewContextObject($this->Context, 'RoleManager');

    $UserRole = $rm->GetRoleById($this->Context->Session->User->RoleID);
    $NewRole = $rm->GetRoleById(($urh->RoleID));
    $sOldRole = $UserManager->GetUserById($urh->UserID);
    $OldRole = $rm->GetRoleById($sOldRole->RoleID);

    if ($NewRole->Priority > $UserRole->Priority) {
    $this->Context->WarningCollector->Add('You cannot change a users role to a level higher than yours.');
    } elseif ($OldRole->Priority >= $UserRole->Priority) {
    $this->Context->WarningCollector->Add('You cannot change the role of a user with a higher or equal level role than you.');
    } elseif ($UserManager->AssignRole($urh)) {
    $Redirect = 1;
    }
    •  
      CommentAuthorFyorl
    • CommentTimeJan 14th 2008 edited
     # 22
    I actually fixed this off-hand while writing a separate extension. It's neatly packaged and doesn't affect the core code as it uses a delegate.

    It will boot people back to the index if they attempt to change the role of someone of equal priority or otherwise it will cut off the roles from the drop-down menu which are of a higher or equal priority to the user's rank.

    It can be circumvented by fabricating your own form data to send but I don't intend to close that security hole unless someone really, really wants me to. Anyway, here's the code and I'll package it as an extension if there's enough interest:

    function WoWGF_FixRoleList($form) {
    $Context = $form -> Context;
    $Other = $form -> User;
    if(!$form -> IsPostBack) return;
    $sql = "
    SELECT `RoleID`
    FROM `{$Context->Configuration['DATABASE_TABLE_PREFIX']}User`
    WHERE `UserID`='{$Context->Session->UserID}'
    ";
    $data = $Context -> Database -> Execute($sql, '', '', '');
    $rid = mysql_result($data, 0, 'RoleID');
    if($rid == 4) return; // Don't cripple the administrator's privileges

    $sql = "
    SELECT *
    FROM `{$Context->Configuration['DATABASE_TABLE_PREFIX']}Role`
    ";
    $data = $Context -> Database -> Execute($sql, '', '', '');

    while($row = mysql_fetch_assoc($data)) $priorities[$row['RoleID']] = $row['Priority'];

    if($priorities[$rid] <= $priorities[$Other -> RoleID]) {
    Redirect(GetUrl($Context -> Configuration, '.'));
    exit;
    }

    foreach($priorities as $roleID => $priority) {
    if($priority >= $priorities[$rid]) $form -> RoleSelect -> RemoveOption($roleID);
    }

    }
    $Context -> AddToDelegate('AccountRoleForm', 'Constructor', 'WoWGF_FixRoleList');


    I don't really check this community much as I'm pretty new to Vanilla but Ben mentioned he'd created this topic and there was some discussion. Since I had this lying around I thought I might as well throw it in here. Anyway, point is, if you need to contact me your best bet is email.
    • CommentAuthorDG55
    • CommentTimeJan 15th 2008 edited
     # 23
    Great Gerry! Good work! This is pretty much perfect now.

    One thing I noticed though, and im not sure if this is related to this hack, but none of my members with role-changing access can change their own role? When you select the new role (lower than your current one), put in a note, and hit the button - it just takes you back to the same role-changing page without any errors or notices. Weird huh?

    Any way you can get your code into the next upgrade?
    •  
      CommentAuthorFyorl
    • CommentTimeJan 15th 2008
     # 24
    Actually that's probably the intended result if his logic works the same as mine. If you try to change your own role then it will detect that you have a role priority that is equal to the role of the user you're trying to change (which is you!). Since you shouldn't be able to change the role of people who have the same role as you, it won't let you.

    Also, if you're worried about upgrading Vanilla then I'll stick my code in an extension (just a quick copy n' paste) and you can just install it. It doesn't hack the source code at all so Vanilla will update fine.
    • CommentAuthorDG55
    • CommentTimeJan 15th 2008 edited
     # 25
    Hmm, then dont we need something which detects whether your editing your own too? Why doesnt it show the error though, its odd.

    Fyorl, I think it would be great if you could package this as an extension, even more so if you could patch the security hole. Also, is it not possible to just show an error when you try to change someone who is higher or equal to you? Booting you back to the index isn't really that great, moderators will just think the forum is broken. I've seen quite a few posts about this on this forum, so I suppose there's quite a bit of demand for it unless we get this feature in the next update (which I sort of doubt).
    •  
      CommentAuthorBen
    • CommentTimeJan 15th 2008 edited
     # 26
    Why would anyone want to edit their own role? You'd only be able to drop yourself down to a lower one, you wouldn't be able to promote yourself, so what would be the point?
    •  
      CommentAuthorFyorl
    • CommentTimeJan 15th 2008 edited
     # 27
    Yeah sure I can make this an extension and I'll look around for a delegate in the role-changing code so I can patch the security hole via extension too.

    Also, I'll make sure it gives out error messages instead of kicking people back to the index.

    Edit: Yeah I agree with Ben. I can allow people to edit their own role but they'd only be able to make themselves a lower role.

    Just to clarify, Adminstrators can do anything, they are ignored when the priority-checking logic is applied. That's assuming the administrator RoleID is always 4. From what Ben's told me, it is.
  3.  # 28
    Just for the sake of argument I wouldnt necessarily assume the admin roleID is *always* 4 (particularly since it's reasonably easy to confirm either way)
    I'm pretty sure not letting users change their own role is a feature of the core anyway to stop an admin accidentally removing his privelidges.
    •  
      CommentAuthorFyorl
    • CommentTimeJan 15th 2008
     # 29
    I'm not sure how easy it is to confirm really. You can't check for the role title of 'administrator' because people can give custom role titles. I'll have a look at some of the permissions and see if some are admin-only. Otherwise there is no real way to check which role is the administrator and so that functionality will have to be removed or configured with the extension.

    Anyone who has the 'change roles' permission can change anyone's role to anything (including their own). There is no checking for this in the core functionality which is why I wrote this.
    • CommentAuthorgerry22
    • CommentTimeJan 15th 2008 edited
     # 30
    @Fyrol - these are the permissions checked at the top of settings.php, so i think it's safe to say that an administrator has all these permissions, but you're right i don't think there is one specific permission to administrator


    // Ensure the user is allowed to view this page (they must have at least one of the following permissions)
    $RequiredPermissions = array('PERMISSION_CHECK_FOR_UPDATES',
    'PERMISSION_APPROVE_APPLICANTS',
    'PERMISSION_MANAGE_REGISTRATION',
    'PERMISSION_ADD_ROLES',
    'PERMISSION_EDIT_ROLES',
    'PERMISSION_REMOVE_ROLES',
    'PERMISSION_ADD_CATEGORIES',
    'PERMISSION_EDIT_CATEGORIES',
    'PERMISSION_REMOVE_CATEGORIES',
    'PERMISSION_SORT_CATEGORIES',
    'PERMISSION_CHANGE_APPLICATION_SETTINGS',
    'PERMISSION_MANAGE_EXTENSIONS',
    'PERMISSION_MANAGE_LANGUAGE',
    'PERMISSION_MANAGE_STYLES',
    'PERMISSION_MANAGE_THEMES');
    • CommentAuthorDG55
    • CommentTimeJan 16th 2008 edited
     # 31
    Great Fyrol, looking forward to this extension.

    I agree about changing your own role, I'm not bothered about this functionality really - but then why is the link to change your own role there in the first place?

    Although on the other hand, if you think about it, if you had two administrators - there would be absolutely no way to demote one of them. Since 1- you cant change your own role, and 2- you cant demote someone who is on the same (highest) level as you!

    The only way you can demote other administrators is if you remove the hack/extension and then do it.

    Which is sort of backwards really, so I suppose this is where the demoting yourself feature comes in handy (in case an administrator wanted to step down as admin but wants to retain their membership).

    Just a thought.
    •  
      CommentAuthorFyorl
    • CommentTimeJan 16th 2008
     # 32
    Actually, if you read the bottom of one of my posts (or the comments in the code) Administrators can do anything. They are ignored by the priority-changing logic. You just need to make sure your adminstrator role has a RoleID of 4 (which it is by default apparently).
    • CommentAuthorDG55
    • CommentTimeJan 16th 2008
     # 33
    Oh ok, missed that.

    Great. And I suppose since the role id is 4 by default, this will be fine. Although isn't there a way to select the 'highest priority' one instead of the one which is roleId 4? This would stop any hideous bugs occurring when the roleId is not 4 for some reason. This would be ideal, but not essential.

    Cheers.
    •  
      CommentAuthorFyorl
    • CommentTimeJan 16th 2008
     # 34
    Good point actually. That would probably be a fairly good way of detecting administrator status. I'll go update it now.
    •  
      CommentAuthorFyorl
    • CommentTimeJan 16th 2008
     # 35
    OK, done. No complicated install instructions, get it here.
    • CommentAuthorDG55
    • CommentTimeJan 17th 2008
     # 36
    Great! Although is it right that you cannot change someones role to the same level as yours? So moderators cant make other people moderators?

    Also, it still boots you back to the homepage when you try to edit the role of someone on your same level. Is it easy to have an error instead?

    Good work though!
Add your comments
    Username Password
  • Format comments as