Skip to content

[4.0] remove user from user group#30355

Merged
wilsonge merged 3 commits intojoomla:4.0-devfrom
alikon:patch-117
Sep 15, 2020
Merged

[4.0] remove user from user group#30355
wilsonge merged 3 commits intojoomla:4.0-devfrom
alikon:patch-117

Conversation

@alikon
Copy link
Contributor

@alikon alikon commented Aug 13, 2020

Pull Request for Issue #30324.

Summary of Changes

all credits goes to @veperr

Testing Instructions

  • create a group, get groupId
  • create a user, get userId
  • add user to group
  • try to remove user from group using: UserHelper::removeUserFromGroup($userId, $groupId)

for the last point i've used the CLI command php cli/joomla.php user:removefromgroup

Actual result BEFORE applying this Pull Request

despite the successfull message from CLI command the user is not removed from that group ie it is not removed from the #__user_usergroup_map table

Expected result AFTER applying this Pull Request

the user is removed correctly from that table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_search() need to be checked for the result if ($serachResult !== false)
otherwise false will be cast to 0 that will remove wrong element

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole change is not needed. Just need to run groups through array_values().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have a better solution i'm happy to close this one....

@ceford
Copy link
Contributor

ceford commented Aug 13, 2020

I have tested this item ✅ successfully on 127ef93

Works as described.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

@sandewt
Copy link
Contributor

sandewt commented Aug 13, 2020

I have tested this item 🔴 unsuccessfully on 127ef93

Joomla! 4.0.0-beta4-dev Development [ Mañana ] 29-July-2020 18:21 GMT

See comment.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

@sandewt
Copy link
Contributor

sandewt commented Aug 13, 2020

screen shot 2020-08-13 at 16 31 04

Result:
screen shot 2020-08-13 at 16 31 05


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

@veperr
Copy link

veperr commented Aug 13, 2020

For clarification, the usage that failed for me (as reported in issue 30324) was calling UserHelper::removeUserFromGroup($userId, $groupId) from PHP code.
I did not try the CLI.

One the other hand I wrote a minimal custom function that did the job:
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;
}


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

alikon and others added 2 commits August 15, 2020 10:24
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
@alikon
Copy link
Contributor Author

alikon commented Aug 15, 2020

please retest

@sandewt
Copy link
Contributor

sandewt commented Aug 15, 2020

I have tested this item ✅ successfully on 1d44613

Joomla! 4.0.0-beta4-dev Development [ Mañana ] 29-July-2020 18:21 GMT


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

@Quy
Copy link
Contributor

Quy commented Sep 2, 2020

I have tested this item ✅ successfully on 1d44613


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

@Quy Quy changed the title [4.0] remove user from user group [4.0] remove user from user group Sep 2, 2020
@Quy
Copy link
Contributor

Quy commented Sep 2, 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30355.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Sep 2, 2020
@wilsonge wilsonge merged commit e64eec7 into joomla:4.0-dev Sep 15, 2020
@wilsonge
Copy link
Contributor

Thanks!

@joomla-cms-bot joomla-cms-bot removed RTC This Pull Request is Ready To Commit labels Sep 15, 2020
@wilsonge wilsonge added this to the Joomla 4.0 milestone Sep 15, 2020
@alikon alikon deleted the patch-117 branch September 15, 2020 11:41
sakiss pushed a commit to sakiss/joomla-cms that referenced this pull request Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

Comments