?
avatar veperr
veperr
9 Aug 2020

Using Namespace: Joomla\CMS\User\UserHelper
the function UserHelper::removeUserFromGroup
simply does not work

Steps to reproduce the issue

  1. create a group, get groupId
  2. create a user, get userId
  3. add user to group
  4. try to remove user from group using:
    UserHelper::removeUserFromGroup($userId, $groupId)

Expected result

The User would be removed from the group

Actual result

The user is not removed from the group

System information (as much as possible)

Ubuntu 20.04.1 LTS
Apache 2.4.41
PHP 7.4.3
Joomla 4.0 beta 3

Additional comments

The following custom function I wrote works:
private function removeUserFromGroup($userId, $groupId){
$user = User::getInstance($userId);
// $user = new User($userId);
// $user->load($userId);
$userGrps = Access::getGroupsByUser($userId, false);

unset($userGrps[array_search($groupId, $userGrps)]);

$user->groups = $userGrps;
$user->save();

// Store the data.
if (!$user->save())
{
    $this->setError($user->getError());
    
    return false;
}
return $user->id;

}

Thank you!

avatar veperr veperr - open - 9 Aug 2020
avatar joomla-cms-bot joomla-cms-bot - labeled - 9 Aug 2020
avatar alikon
alikon - comment - 12 Aug 2020

i cannot confirm, i've tested with CLI
Screenshot from 2020-08-12 10-01-07

avatar alikon
alikon - comment - 12 Aug 2020

ouch wait ....
despite the successfull removed message that user is still in that usergroup ....

avatar alikon alikon - change - 13 Aug 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-08-13 06:36:27
Closed_By alikon
avatar alikon
alikon - comment - 13 Aug 2020

please test #30355

avatar alikon alikon - close - 13 Aug 2020

Add a Comment

Login with GitHub to post a comment