fix(conflicts): 解决合并冲突

This commit is contained in:
sophie committed 2026-09-29 14:29:40 +08:00
commit a1828f75e6
95 files changed
+4636 -476

No files matched your search

@@ -721,8 +721,6 @@ def can_force_create_shipping_duplicate(user: User | None) -> bool:
"""判断用户是否可强制新建重复发货通知。"""
if user is None:
return False
if str(getattr(user, 'role', '') or '') == 'admin':
return True
return bool(user.has_feature_permission('shipping_notice_force_create'))
@@ -86,7 +86,7 @@ def _resolve_cancellation_operation_id(run: ShippingOrderProcessingRun, explicit
def _is_admin(actor: User) -> bool:
"""判断操作者是否具备管理员取消权限。"""
return str(getattr(actor, 'role', '') or '') == 'admin'
return bool(actor.is_platform_admin())
def _lock_run_for_actor(*, actor: User, run_no: str) -> ShippingOrderProcessingRun:
@@ -1,4 +1,10 @@
"""确保订单识别进度事件清理的每日默认排程存在。"""
"""
services/shipping_notice/order_extraction_progress_cleanup_schedule.py
用途:确保订单识别进度事件清理的每日默认排程存在。
依赖:ScheduleTask、permission_roles.service.first_schedule_owner_user、timezone_util。
逻辑:无用户时跳过;owner 优先平台管理员。
"""
from __future__ import annotations
import logging
@@ -6,7 +12,8 @@ from datetime import datetime
from typing import Any
from app import db
from app.models import ScheduleTask, User
from app.models import ScheduleTask
from app.services.permission_roles.service import first_schedule_owner_user
from app.services.schedule.timezone_util import compute_next_run_at
_LOGGER = logging.getLogger(__name__)
@@ -24,7 +31,7 @@ def ensure_default_order_extraction_progress_cleanup_schedule(*, commit: bool =
).first()
if existing is not None:
return existing
owner = sess.query(User).filter(User.role == 'admin').order_by(User.id.asc()).first() or sess.query(User).order_by(User.id.asc()).first()
owner = first_schedule_owner_user(sess)
if owner is None:
_LOGGER.info('skip seed order-extraction progress cleanup schedule: no users yet')
return None
@@ -154,7 +154,7 @@ def save_quality_label(*, batch_id: int, run_no: str, actor_id: int, payload: An
if batch is None:
raise NotFoundError('Quality batch not found')
actor = db.session.get(User, actor_id)
if actor is None or actor.role != 'admin':
if actor is None or not actor.is_platform_admin():
raise ValidationError('Quality reviewer must be an administrator')
if (
batch.status in {'approved', 'rejected'}
@@ -215,7 +215,7 @@ def approve_quality_batch(*, batch_id: int, role: str, actor_id: int) -> Shippin
if batch.status == 'rejected':
raise ConflictError('Quality batch was rejected')
actor = db.session.get(User, actor_id)
if actor is None or actor.role != 'admin':
if actor is None or not actor.is_platform_admin():
raise ValidationError('Quality approver must be an administrator')
if not quality_metrics(batch)['eligible']:
raise ConflictError(
@@ -562,7 +562,7 @@ def _require_owner_agent(*, user: User, agent_id: int) -> Agent:
'agent_id must reference an active shipping notice agent',
code='SHIPPING_NOTICE.ORDER_EXTRACTION_AGENT_INVALID',
)
if str(user.role or '').lower() != 'admin' and agent not in user.agents:
if not user.is_platform_admin() and agent not in user.agents:
raise ForbiddenError(
'Permission denied for this agent',
code='SHIPPING_NOTICE.ORDER_EXTRACTION_AGENT_FORBIDDEN',
@@ -35,7 +35,7 @@ def is_shipping_admin(user: User) -> bool:
Returns:
True 表示管理员。
"""
return str(getattr(user, 'role', '') or '').lower() == 'admin'
return bool(user.is_platform_admin())
def resolve_execution_owner_user_ids(execution: ShippingProcessExecution) -> set[int]:
@@ -14,7 +14,7 @@ from app.services.shipping_notice.audit_service import append_shipping_audit_eve
def _is_admin(user: User) -> bool:
"""判断用户是否为收料报表管理角色。"""
return str(getattr(user, 'role', '') or '').lower() == 'admin'
return bool(user.is_platform_admin())
def can_download_receipt_report_file(report_file: ShippingReceiptReportFile, user: User) -> bool:
@@ -20,6 +20,7 @@ from sqlalchemy.exc import IntegrityError
from app import db
from app.models import AppSetting, User
from app.services.permission_roles.service import list_platform_admin_users
from app.services.shipping_notice.rpa_worker_heartbeat import (
RPA_HEARTBEAT_STORAGE_UNAVAILABLE_MESSAGE,
RPA_WORKER_OFFLINE_MESSAGE,
@@ -65,7 +66,7 @@ def _alert_fallback_admin_enabled() -> bool:
def _alert_recipients() -> list[User]:
"""
解析告警接收人。
核心逻辑:优先 FREIGHT_RPA_WORKER_ALERT_USERNAMES;未配置时可选回退已绑企微的 admin。
核心逻辑:优先 FREIGHT_RPA_WORKER_ALERT_USERNAMES;未配置时可选回退已绑企微的平台管理员。
"""
raw = str(current_app.config.get("FREIGHT_RPA_WORKER_ALERT_USERNAMES") or "").strip()
names = [part.strip() for part in raw.split(",") if part.strip()] if raw else []
@@ -82,13 +83,7 @@ def _alert_recipients() -> list[User]:
names,
)
if _alert_fallback_admin_enabled():
admins = (
db.session.query(User)
.filter(User.role == "admin", User.wecom_userid.isnot(None))
.order_by(User.id.asc())
.limit(20)
.all()
)
admins = list_platform_admin_users(wecom_bound=True, limit=20)
if admins:
logger.info(
"[rpa-heartbeat-alert] using admin fallback recipients count=%d",
@@ -106,7 +101,7 @@ def _log_recipient_gap_once() -> None:
_RECIPIENT_GAP_LOGGED = True
logger.warning(
"[rpa-heartbeat-alert] no wecom recipients: set FREIGHT_RPA_WORKER_ALERT_USERNAMES "
"or bind wecom_userid for at least one admin (FALLBACK_ADMIN=true)"
"or bind wecom_userid for at least one platform admin (FALLBACK_ADMIN=true)"
)