Skip to content

fix(user): allow unblocking users promoted to admin - #39192

Open
loveulvu wants to merge 1 commit into
go-gitea:mainfrom
loveulvu:fix/39189-unblock-admin
Open

fix(user): allow unblocking users promoted to admin#39192
loveulvu wants to merge 1 commit into
go-gitea:mainfrom
loveulvu:fix/39189-unblock-admin

Conversation

@loveulvu

Copy link
Copy Markdown
Contributor

Fixes #39189.

IsUserBlockedBy intentionally treats admin users as not blocked, but CanUnblockUser was also using it to determine whether a blocking relationship exists. If a previously blocked user is later promoted to admin, the existing user_blocking record remains but can no longer be removed.

This change separates those two concerns by adding HasBlocking for checking the persisted blocking relationship. CanUnblockUser uses that relationship check while IsUserBlockedBy keeps its existing admin-user behavior.

A regression test verifies that an admin is still not considered blocked while an existing blocking relationship can still be unblocked.

Tests:

  • go test ./models/user ./services/user -count=1

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 31, 2026
@lunny
lunny requested a lite review from Copilot August 31, 2026 18:41
@lunny lunny added the backport/v1.27 This PR should be backported to Gitea 1.27 label Aug 31, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change cleanly separates “effective blocked status” from “blocking relationship exists” and includes a targeted regression test for the reported failure mode.

Pull request overview

This PR fixes an edge case in the user blocking feature where a previously-blocked user promoted to admin could no longer be unblocked because admin users are intentionally treated as “not blocked” by IsUserBlockedBy.

Changes:

  • Introduces user_model.HasBlocking to check for an existing persisted blocking relationship independent of admin status.
  • Updates CanUnblockUser to use HasBlocking so unblock can proceed even if the blockee is now an admin.
  • Adds a regression test ensuring admins are still treated as not blocked while existing block relationships remain removable.
File summaries
File Description
services/user/block.go Switches unblock eligibility to check the persisted relationship (HasBlocking) rather than effective blocked status (IsUserBlockedBy).
services/user/block_test.go Adds regression coverage for unblock-after-promotion-to-admin behavior.
models/user/block.go Refactors IsUserBlockedBy to delegate to new HasBlocking, preserving admin “not blocked” semantics.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v1.27 This PR should be backported to Gitea 1.27 lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot Unblock after Blocking a user

4 participants