From af8beb575828cbf93682f875e243b79600035e1f Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 20 Apr 2026 19:40:42 +0200 Subject: [PATCH] fix(user): skip last-admin guard when target is already unreachable GuardLastAdmin counted only active, non-deletion-scheduled admins, but gated only on target.IsAdmin. Demoting or deleting an already-disabled or deletion-scheduled admin would then be blocked whenever exactly one active admin remained, even though removing a user who isn't in the reachable set can't reduce the count. Return early when the target isn't part of the counted set. --- pkg/user/user.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/user/user.go b/pkg/user/user.go index 96863f398..2d46341f8 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -670,6 +670,11 @@ func GuardLastAdmin(s *xorm.Session, target *User) error { if !target.IsAdmin { return nil } + // target is not in the counted "reachable admin" set — removing them + // doesn't change the invariant, so the guard is a no-op. + if target.Status != StatusActive || !target.DeletionScheduledAt.IsZero() { + return nil + } session := s.Where("is_admin = ?", true). And("status = ?", StatusActive).