Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin cannot be demoted or removed from a group when he's the only one left #509

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

renatonascalves
Copy link
Member

@renatonascalves renatonascalves self-assigned this May 28, 2024
@emaralive
Copy link

@renatonascalves

This mostly works. However, there is an unintended consequence, at least I believe it is unintended, whereby when a Site Admin attempts to demote the sole Group Admin, the "Sorry, you are not allowed to perform this action.", after which, no other demotions can take place until a promotion takes place first. IOW:

  1. Site Admin attempts to demote the sole Group Admin - aforementioned error message is evoked.
  2. Site Admin attempts to demote a Group Mod - aforementioned error message is evoked.
  3. Site Admin promotes a Group Member to Group Mod or Admin - after this action occurs, demotions work as expected until the next attempt to demote the sole Group Admin.

This appears to only apply to the Site Admin, meaning, a Group Admin who happens not to have a User Role of Administrator, demotions work as expected.

Copy link
Contributor

@imath imath left a comment

Choose a reason for hiding this comment

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

Hi @renatonascalves

Thanks a lot for you work on this. It's fine with me, but I would do the same kind of check when a site admin tries to remove the last group admin (directly here or in another PR).

I believe for this second case it's not behaving the right way into the Web version, so I'll give it a check.

@imath
Copy link
Contributor

imath commented May 28, 2024

@emaralive good point. Maybe we should improve the error message in this case: "Group needs 1 admin at least. Please promote a user before trying to demote/remove this group admin".

@@ -396,28 +370,35 @@ public function update_item( $request ) {
$role = $request->get_param( 'role' );
$group_id = $group->id;

$bp_loggedin_user_id = bp_loggedin_user_id();

// Check if the user is a member of the group.
Copy link
Member Author

Choose a reason for hiding this comment

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

Returns an early error for clarity when a user is not part of the group. For unban actions, we need to allow since banned users are not part of the group anymore.

);
}
}

// Get updated group member.
$group_member = new BP_Groups_Member( $user->ID, $group_id );

// Setting context.
Copy link
Member Author

Choose a reason for hiding this comment

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

The API consumer should be setting this.

);

$admin_error = new WP_Error(
Copy link
Member Author

Choose a reason for hiding this comment

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

Improving the error message.

@renatonascalves
Copy link
Member Author

@emaralive and @imath I updated the pr with your suggestions. If you could take a look at the unit tests, that'd be great.

If you see a scenario I haven't tested, let me know so that we can improve it.

@emaralive
Copy link

@renatonascalves,

Superb improvement. 👍 BTW, someone might quibble over the placement (where it resides) of "at least" in the error message but, that won't be me.

Copy link
Contributor

@imath imath left a comment

Choose a reason for hiding this comment

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

Hi @renatonascalves sorry it took me so long to check it again. Thanks a lot for your improvements, let's have this in!

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.

3 participants