fix(borrow,outbound): 记录查看按角色收窄——普通只看自己,库管/主管/超管/跨域看全部

- decorators 新增 is_privileged_viewer(SUPER_ADMIN/SUPERVISOR/WAREHOUSE_MGR 或 crossDomain)
- 借库记录列表:非管理者强制 applicant_id=当前用户
- 出库记录列表+详情:非管理者强制只看自己/无权访问他人单(403)
This commit is contained in:
yueli
2026-09-09 09:31:01 +08:00
parent 578c15dc95
commit 9622baf76e
3 changed files with 39 additions and 2 deletions

View File

@ -1,7 +1,7 @@
from flask import Blueprint, request, jsonify, current_app
from app.services.outbound_service import OutboundService
from flask_jwt_extended import jwt_required, get_jwt_identity, get_jwt
from app.utils.decorators import permission_required, audit_log, prevent_double_submit
from app.utils.decorators import permission_required, audit_log, prevent_double_submit, is_privileged_viewer
from app.services.auth_service import AuthService
import traceback
@ -551,6 +551,11 @@ def get_outbound_request_list():
if status is not None:
status = int(status)
# ★ 数据权限:普通申请人只能看“自己的”出库记录;库管/主管/超管(或跨域)才可看他人
if not is_privileged_viewer():
identity = get_jwt_identity()
applicant_id = int(identity) if identity else None
result = OutboundApprovalService.get_request_list(
page=page,
per_page=limit,
@ -584,6 +589,12 @@ def get_outbound_request_detail(request_id):
if not approval:
return jsonify({'code': 404, 'msg': '审批单不存在'}), 404
# ★ 数据权限:普通申请人只能看自己的单;库管/主管/超管(或跨域)可看任意
if not is_privileged_viewer():
identity = get_jwt_identity()
if int(approval.applicant_id or 0) != int(identity or 0):
return jsonify({'code': 403, 'msg': '无权查看他人的出库记录'}), 403
return jsonify({
'code': 200,
'msg': '获取成功',

View File

@ -1,6 +1,6 @@
from flask import Blueprint, jsonify, request # .material -> .base refactor checked
from flask_jwt_extended import jwt_required, get_jwt_identity, get_jwt
from app.utils.decorators import permission_required, audit_log, prevent_double_submit
from app.utils.decorators import permission_required, audit_log, prevent_double_submit, is_privileged_viewer
from app.services.auth_service import AuthService
from app.services.trans_service import TransService
from app.services.borrow_service import BorrowApprovalService
@ -330,6 +330,11 @@ def get_borrow_request_list():
if status is not None:
status = int(status)
# ★ 数据权限:普通申请人只能看“自己的”借还记录;库管/主管/超管(或跨域)才可看他人
if not is_privileged_viewer():
identity = get_jwt_identity()
applicant_id = int(identity) if identity else None
result = BorrowApprovalService.get_request_list(
page=page, per_page=limit, applicant_id=applicant_id, status=status
)

View File

@ -226,6 +226,27 @@ def _has_cross_domain_permission(user_role, user_company=''):
return False
# 能查看“他人借还/出库记录”的管理者角色(库管/主管/超管)。普通申请人只能看自己的记录。
PRIVILEGED_VIEWER_ROLES = ('SUPER_ADMIN', 'SUPERVISOR', 'WAREHOUSE_MGR')
def is_privileged_viewer():
"""
判断当前登录用户是否属于“管理者视角”(可查看他人借还/出库记录)。
规则:角色为 SUPER_ADMIN/SUPERVISOR/WAREHOUSE_MGR或拥有 crossDomain 权限。
普通申请人(其余角色)只能看自己的记录(由各列表 handler 强制 applicant_id=当前用户)。
"""
from flask_jwt_extended import get_jwt
claims = get_jwt()
role = (claims.get('role') or '').upper()
if role in PRIVILEGED_VIEWER_ROLES:
return True
user_company = claims.get('company_name', '')
if _has_cross_domain_permission(role, user_company):
return True
return False
def get_current_company_filter():
"""
多租户数据权限隔离工具函数。