mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-25 06:03:40 +09:00
fix(user): allow unblocking users promoted to admin (#39192)
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.
This commit is contained in:
+10
-5
@@ -45,15 +45,20 @@ func UpdateBlockingNote(ctx context.Context, id int64, note string) error {
|
||||
}
|
||||
|
||||
func IsUserBlockedBy(ctx context.Context, blockee *User, blockerIDs ...int64) bool {
|
||||
if len(blockerIDs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if blockee.IsAdmin {
|
||||
return false
|
||||
}
|
||||
|
||||
cond := builder.Eq{"user_blocking.blockee_id": blockee.ID}.
|
||||
return HasBlocking(ctx, blockee.ID, blockerIDs...)
|
||||
}
|
||||
|
||||
// HasBlocking reports whether a blocking relationship exists regardless of the blockee's admin status.
|
||||
func HasBlocking(ctx context.Context, blockeeID int64, blockerIDs ...int64) bool {
|
||||
if len(blockerIDs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
cond := builder.Eq{"user_blocking.blockee_id": blockeeID}.
|
||||
And(builder.In("user_blocking.blocker_id", blockerIDs))
|
||||
|
||||
has, _ := db.GetEngine(ctx).Where(cond).Exist(&Blocking{})
|
||||
|
||||
Reference in New Issue
Block a user