diff --git a/tests/test_account_assign_filter.py b/tests/test_account_assign_filter.py index 4a71826..bec7197 100644 --- a/tests/test_account_assign_filter.py +++ b/tests/test_account_assign_filter.py @@ -337,6 +337,45 @@ class TestAssignmentPools(_Base): assert skin["commodity_name"] == "选项皮肤" assert skin["account_count"] == 1 + def test_assignment_summary_hides_inactive_support_users(self): + inactive = User( + username="deleted-support", + password_hash="h", + role="support", + is_active=False, + ) + self.session.add(inactive) + self.session.commit() + + result = assignments_summary(db=self.session, current=self.admin) + + support_ids = {user["id"] for user in result["support_users"]} + assert self.support.id in support_ids + assert inactive.id not in support_ids + + def test_dispatch_rejects_inactive_support(self): + inactive = User( + username="deleted-dispatch-target", + password_hash="h", + role="support", + is_active=False, + ) + self.session.add(inactive) + self.session.commit() + + with pytest.raises(HTTPException) as exc_info: + dispatch_assignments( + AssignmentDispatch( + assigned_to=inactive.id, + quantity=1, + ), + db=self.session, + current=self.admin, + ) + + assert exc_info.value.status_code == 400 + assert "已停用" in exc_info.value.detail + class TestAllMatchingAssign(_Base): def test_assigns_every_matching_unassigned(self): diff --git a/web/backend/routers/accounts.py b/web/backend/routers/accounts.py index 1bc1e63..b31e4ef 100644 --- a/web/backend/routers/accounts.py +++ b/web/backend/routers/accounts.py @@ -1459,7 +1459,7 @@ def assignments_summary( _assignable_account_filter(), ), ) - .filter(User.role == "support") + .filter(User.role == "support", User.is_active.is_(True)) .group_by(User.id, User.username) .order_by(func.count(Account.id).desc()) .all()