From 47cc15f8ad0f9c12be8a312b3d1a81a318470bbe Mon Sep 17 00:00:00 2001 From: yml Date: Thu, 26 Nov 2026 20:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E8=B4=A6=E5=8F=B7=E5=88=86?= =?UTF-8?q?=E9=85=8D):=20=E9=9A=90=E8=97=8F=E5=81=9C=E7=94=A8=E5=AE=A2?= =?UTF-8?q?=E6=9C=8D=E5=B9=B6=E6=A0=A1=E9=AA=8C=E5=8F=91=E6=94=BE=E7=9B=AE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 分配概览只返回启用中的客服;停用用户不能出现在客服列表或作为定量发放目标。 --- tests/test_account_assign_filter.py | 39 +++++++++++++++++++++++++++++ web/backend/routers/accounts.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) 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()