修复(账号选号): 已分配账号不再进入自动选号池

自动选号只允许未归属账号;已分配给客服、运营或管理员的账号必须先释放归属,才能重新参与自动选号。
This commit is contained in:
yml
2026-11-26 20:51:08 +08:00
parent 47cc15f8ad
commit 174ae23ac1
3 changed files with 13 additions and 26 deletions
+9 -9
View File
@@ -200,21 +200,21 @@ def test_stale_supply_snapshot_is_rebuilt(db):
assert snapshot.checked_at == later assert snapshot.checked_at == later
def test_supply_allocatable_uses_the_same_pool_owner_filter_as_selection(db): def test_supply_allocatable_excludes_accounts_assigned_to_support(db):
customer = User( support = User(
username="supply-customer", username="supply-support",
password_hash="h", password_hash="h",
role="customer", role="support",
is_active=True, is_active=True,
) )
free = _account("supply-pool-free", points=400) free = _account("supply-pool-free", points=400)
customer_assigned = _account("supply-customer-assigned", points=400) support_assigned = _account("supply-support-assigned", points=400)
db.add(customer) db.add(support)
db.flush() db.flush()
customer_assigned.assigned_to = customer.id support_assigned.assigned_to = support.id
db.add_all([free, customer_assigned]) db.add_all([free, support_assigned])
db.flush() db.flush()
db.add_all([_state(free), _state(customer_assigned)]) db.add_all([_state(free), _state(support_assigned)])
db.add( db.add(
AccountSupplyTarget( AccountSupplyTarget(
platform="douyu", platform="douyu",
+2 -2
View File
@@ -1475,7 +1475,7 @@ class TestAccountSelection(_Base):
assert detail["task"]["executionStatus"] == "ready" assert detail["task"]["executionStatus"] == "ready"
assert detail["task"]["issueCode"] == "capability_cache_miss" assert detail["task"]["issueCode"] == "capability_cache_miss"
def test_live_candidates_include_support_accounts_and_prefer_valid_cache(self): def test_live_candidates_exclude_support_assigned_accounts(self):
support = User( support = User(
username="pool-support", username="pool-support",
password_hash="h", password_hash="h",
@@ -1517,7 +1517,7 @@ class TestAccountSelection(_Base):
required_points=1680, required_points=1680,
) )
assert [row.id for row in rows] == [valid.id, invalid.id] assert [row.id for row in rows] == [invalid.id]
def test_points_short_is_soft_and_does_not_block_allocation(self): def test_points_short_is_soft_and_does_not_block_allocation(self):
account = self.account("points-short", points=100) account = self.account("points-short", points=100)
+2 -15
View File
@@ -15,7 +15,6 @@ from ..models import (
DouyuExternalOrder, DouyuExternalOrder,
LoginAttempt, LoginAttempt,
LoginTask, LoginTask,
User,
) )
from .account_capability_service import ( from .account_capability_service import (
ACCOUNT_ELIGIBILITY_ELIGIBLE, ACCOUNT_ELIGIBILITY_ELIGIBLE,
@@ -33,7 +32,6 @@ ACTIVE_COLLAB_STATUSES: tuple[str, ...] = (
"role_error", "role_error",
"failed", "failed",
) )
POOL_OWNER_ROLES: tuple[str, ...] = ("super_admin", "operation", "support")
CK_FRESH_SECONDS = 24 * 60 * 60 CK_FRESH_SECONDS = 24 * 60 * 60
LOGIN_ATTEMPT_IN_FLIGHT_STATUSES = ("pending", "running") LOGIN_ATTEMPT_IN_FLIGHT_STATUSES = ("pending", "running")
BUSINESS_TZ = ZoneInfo("Asia/Shanghai") BUSINESS_TZ = ZoneInfo("Asia/Shanghai")
@@ -63,13 +61,6 @@ def in_flight_login_exists():
) )
def pool_owner_ids():
return select(User.id).where(
User.role.in_(POOL_OWNER_ROLES),
User.is_active.is_(True),
)
def cookie_present_filter(): def cookie_present_filter():
return and_(Account.cookie.isnot(None), Account.cookie != "") return and_(Account.cookie.isnot(None), Account.cookie != "")
@@ -257,10 +248,8 @@ def relogin_eligible_account_filter(
def assigned_to_pool_filter(): def assigned_to_pool_filter():
return or_( """自动选号只使用未分配账号;已分配给客服/运营的账号必须先从归属上释放。"""
Account.assigned_to.is_(None), return Account.assigned_to.is_(None)
Account.assigned_to.in_(pool_owner_ids()),
)
def active_lease_exists(): def active_lease_exists():
@@ -339,7 +328,6 @@ __all__ = [
"ACTIVE_COLLAB_STATUSES", "ACTIVE_COLLAB_STATUSES",
"CK_FRESH_SECONDS", "CK_FRESH_SECONDS",
"LOGIN_ATTEMPT_IN_FLIGHT_STATUSES", "LOGIN_ATTEMPT_IN_FLIGHT_STATUSES",
"POOL_OWNER_ROLES",
"active_collab_order_exists", "active_collab_order_exists",
"active_lease_exists", "active_lease_exists",
"assigned_to_pool_filter", "assigned_to_pool_filter",
@@ -350,7 +338,6 @@ __all__ = [
"cookie_present_filter", "cookie_present_filter",
"fresh_ck_cutoff", "fresh_ck_cutoff",
"fresh_eligible_state_filter", "fresh_eligible_state_filter",
"pool_owner_ids",
"recent_elite_bind_lock_exists", "recent_elite_bind_lock_exists",
"relogin_failure_kind_filter", "relogin_failure_kind_filter",
"role_change_ready_filter", "role_change_ready_filter",