This commit is contained in:
yilv committed 2026-09-20 17:26:43 +08:00
commit 1b46879048
4 files changed
+84 -3

No files matched your search

+1
View File
@@ -22,6 +22,7 @@ from ..core import (
success,
paginate,
)
from ..models import RawDataFolder
from ..services import integration_service as svc
logger = logging.getLogger(__name__)
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
初始化 RBAC 基础数据(权限、角色及继承关系),可重复执行
执行方式:
python scripts/seed_rbac.py
"""
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app import create_app, db
from app.models import User, Role, Permission
PERMISSIONS = [
('admin_access', '访问管理后台'),
('manage_users', '管理用户信息'),
('manage_roles', '管理角色和权限'),
('view_audit_logs', '查看审计日志'),
('manage_data', '管理数据条目'),
('view_data', '查看数据内容'),
('run_inference', '运行 AI 推理'),
('view_results', '查看推理结果'),
]
ROLES = [
('Regular User', '普通用户,仅能查看基本数据', None, ['view_data']),
('Researcher', '研究员,可以管理数据和运行推理', 'Regular User',
['manage_data', 'run_inference', 'view_results']),
('Administrator', '超级管理员,拥有所有权限', 'Researcher',
['admin_access', 'manage_users', 'manage_roles', 'view_audit_logs']),
]
def seed():
app = create_app(os.getenv('FLASK_CONFIG') or 'production')
with app.app_context():
perm_objs = {}
for name, description in PERMISSIONS:
perm = Permission.query.filter_by(name=name).first()
if not perm:
perm = Permission(name=name, description=description)
db.session.add(perm)
db.session.flush()
perm_objs[name] = perm
db.session.commit()
role_objs = {}
for name, description, parent_name, perm_names in ROLES:
role = Role.query.filter_by(name=name).first()
if not role:
role = Role(name=name, description=description)
db.session.add(role)
db.session.flush()
if not role.permissions:
role.permissions = [perm_objs[n] for n in perm_names]
if parent_name and role.parent is None:
role.parent = role_objs[parent_name]
role_objs[name] = role
db.session.commit()
admin_role = role_objs['Administrator']
for user in User.query.all():
if user.username == 'admin' and admin_role not in user.roles:
user.roles.append(admin_role)
db.session.commit()
print('RBAC 种子数据初始化完成')
for name, *_ in ROLES:
role = role_objs[name]
print(f' {name}: {" ".join(sorted(p.name for p in role.permissions))}')
if __name__ == '__main__':
seed()
+2 -2
View File
@@ -1,6 +1,6 @@
# 前端环境变量 - 生产环境
# 生产环境 API 地址(直接连接后端)
VITE_API_BASE_URL=http://8.135.66.203:5000/api
# 生产环境 API 地址(通过 Nginx 同源代理到后端)
VITE_API_BASE_URL=/api
# 如果需要修改其他生产环境配置,在此添加
# VITE_APP_TITLE=RCT 生产环境
+4 -1
View File
@@ -133,8 +133,11 @@ api.interceptors.response.use(
}
}
// 刷新令牌接口自身返回 401 时不再触发刷新流程,避免等待刷新结果造成死锁
const isRefreshRequest = (config?.url || '').includes('/auth/refresh')
// 处理 401 错误 - 尝试刷新令牌
if (error.response?.status === 401 && !config?._retryRefresh) {
if (error.response?.status === 401 && !config?._retryRefresh && !isRefreshRequest) {
config._retryRefresh = true
const refreshToken = TokenManager.getRefreshToken()