1

I'm setting up a site for a charity with a national branch and several sub-chapters. I'd like users of a particular chapter to be able to add/modify users, but only within their chapter's user group. It seems like with the current structure of admin permissions, I'm only able to say whether or not a user can add/edit users, and not restrict that to a particular group.

Is this possible and I'm just not seeing a setting somewhere? If not, does anyone know of a plugin that provides this functionality?

Thanks.

2

This is not currently possible through the CP (as far as I know anyway). You would need to write a plugin; and I haven't seen any plugins on straightupcraft that address this particular need, but have a look. You could also contact someone through the professionals section that might be able to help.

If you were to write your own plugin you might have a look at the documentation on hooks and events. In particular the onSaveUser event, where you could potentially force a user into a particular group, based on specific conditions that you establish.

In your plugIns init function you could create a listener for the onSaveUser event.

public function init()
{
    parent::init();
    craft()->on('users.saveUser', function(Event $event) 
    {
        $user = $event->params['user'];
        if ($allMyConditionsAreMet) 
        {
            if($allMyGroupConditionsAreMet) 
            {
                $groupId = 1;
            } 
            else 
            {
                $groupId = 2;
            }
            craft()->userGroups->assignUserToGroups($user->id, $groupId);
        };
    });
}
| improve this answer | |
  • Thanks for the help. It looks like a custom plugin will be the way to go in this case. – Coppa Oct 18 '14 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.