3

Hello I do not know if this is a bug or something but we just updated to craft 2.3 and got an issue which we did not have previously. In user settings we can set the default permissions group but when we do create a new user this group is not applied to that user.Im not sure why this is, maybe something more needs to be done beginning Craft 2.3 but the simple flow of creating a new user worked previously. Upon the user account creation the default group would be set automatically.

EDIT:

Thank you for your answers. I was mistaken it is assigning the group but I cant get that group on an event trigger.

    craft()->on('users.saveUser', function(Event $event) {
        $user = $event->params['user'];
        var_dump($user->getGroups()); exit();
    });

I am doing the above in my plugins main PHP file and for some reason before updating it would give me the users group as the default one already assigned. After the update I get a empty array even though going to the control panel after registering I can see that the new user has the group assigned.

5

The setting still works, but keep in mind that for it to take effect, A) you have to be registering a user through a custom registration form on the front end, and B) you have to be logged out. Without those conditions, it’s not technically public registration.

Default user group assignment has always taken place after the user was saved, and after the users.onSaveUser event was called. See these highlighted lines from UsersController::actionSaveUser() – the onSaveUser event gets called by craft()->request->saveUser(), and default group assignment happens in $this->_assignDefaultGroupToUser().

  • Hi Brandon, thanks for your answer. Could you look at the question again as I have updated it. – Moin Qidwai Dec 11 '14 at 2:52
  • @MoinQidwai Updated my answer. – Brandon Kelly Dec 11 '14 at 14:42
  • Oh ok are there any plans on creating a onAfterSaveUser event later on in craft? Thanks for your time and the awesome update to craft. – Moin Qidwai Dec 12 '14 at 3:29
  • @MoinQidwai I just added a new onAssignDefaultGroupToUser event for the next release :) – Brandon Kelly Dec 12 '14 at 15:10
  • Seriously Awesome. Thanks for your hard work. – Moin Qidwai Dec 13 '14 at 5:49
2

Brandon's answer is correct, as far as how Craft natively handles auto-assignment of user groups.

However, if you'd like to automatically assign user groups to new users when you are creating them while logged into the Control Panel, you can use this plugin built specifically for this purpose:

This will allow you to pre-select user groups, and those groups will be automatically assigned when you create a new user.

  • Hey thanks for your answer. I have updated my question. – Moin Qidwai Dec 11 '14 at 2:51
  • That issue is because of the order in which the POST data is set... I've seen a few people get caught up by that (myself included). Solving that problem is the sole purpose of the Auto-Assign User Group plugin... feel free to download it and check out the workaround! The plugin will actually insert that data into the POST late in the process, making sure it gets saved properly. – Lindsey D Dec 11 '14 at 3:19

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.