feat(后端): 添加授权体系、系统监控与试用期计提
按 2026-11-02 需求补齐计划交付后端能力: - 角色授权:权限目录化,接口统一准入校验,未登记默认拒绝; 管理员判断改为按数据库角色重新判定,防止权限码持有者绕过 - 系统监控:单进程采集资源、请求与异常指标,分钟级聚合, 阈值配置化;敏感配置增加 repr 保护,Redis 密码 URL 转义 - 试用期计提:按回款日判定并写入快照,年度结清与调整单联动; 人员模型补试用期、离职日期与工资版本历史字段 - 计提模板:公式骨架受控,页面维护名称与参数绑定 - T+ 采集:自动化配置表与进度查询 内置角色禁停用保护对齐模块注释;核算规则版本提为常量并 补充批量核算失败堆栈日志。 影响范围:后端全部模块、数据库迁移 V22-V28 验证:uv run ruff check 通过;922 个单元测试全部通过; 集成测试因本机 MySQL 数据卷被其他容器锁定暂未运行
This commit is contained in:
1 parent
02fb06e0af
commit
1461a8d113
149 files changed
+8736
-368
No files matched your search
@@ -89,6 +89,12 @@ def _purge_test_data() -> None:
|
||||
factory = get_session_factory()
|
||||
ensure_test_database(factory.kw["bind"].url.database, os.environ.get("PAYROLL_TEST_DATABASE"))
|
||||
with factory() as session:
|
||||
from app.models import AuthorizationSetting, ProbationDeferral, ProbationPayment
|
||||
|
||||
session.execute(delete(ProbationPayment))
|
||||
session.execute(delete(ProbationDeferral))
|
||||
|
||||
session.execute(update(AuthorizationSetting).values(maker_user_id=None, updated_by=None))
|
||||
users = list(
|
||||
session.execute(select(User.id, User.username).where(User.username.like("t\\_%"))).all()
|
||||
)
|
||||
@@ -218,7 +224,10 @@ def _purge_test_data() -> None:
|
||||
.values(company_name="衍水集团", logo_path=None)
|
||||
)
|
||||
session.commit()
|
||||
logo_dir = Path(__file__).resolve().parents[2] / "uploads" / "logo"
|
||||
logo_dir = get_settings().upload_dir / "logo"
|
||||
expected_uploads = Path(__file__).resolve().parents[3] / ".ai" / "isolated-uploads" / get_settings().mysql_database
|
||||
if not logo_dir.resolve().is_relative_to(expected_uploads.resolve()):
|
||||
raise RuntimeError("测试文件清理目标不在本次隔离目录,拒绝清理")
|
||||
if logo_dir.is_dir():
|
||||
for f in logo_dir.iterdir():
|
||||
f.unlink(missing_ok=True)
|
||||
@@ -330,8 +339,10 @@ def make_role():
|
||||
def admin(make_user, auth_headers, monkeypatch) -> dict:
|
||||
"""管理员账号(含请求头)。"""
|
||||
user = make_user([ROLE_ADMIN])
|
||||
from app.core.config import get_settings
|
||||
monkeypatch.setattr(get_settings(), "payroll_maker_user_id", user["id"])
|
||||
from app.models import AuthorizationSetting
|
||||
with get_session_factory()() as session:
|
||||
session.get(AuthorizationSetting, 1).maker_user_id = user["id"]
|
||||
session.commit()
|
||||
user["headers"] = auth_headers(user)
|
||||
return user
|
||||
|
||||
@@ -387,6 +398,10 @@ def legacy_calculation(monkeypatch):
|
||||
@pytest.fixture
|
||||
def writer(normal, admin, monkeypatch):
|
||||
"""指定一个普通角色账号为工资制作人,证明身份授权与管理员角色无关。"""
|
||||
from app.core.config import get_settings
|
||||
monkeypatch.setattr(get_settings(), "payroll_maker_user_id", normal["id"])
|
||||
from app.models import AuthorizationSetting
|
||||
with get_session_factory()() as session:
|
||||
session.get(AuthorizationSetting, 1).maker_user_id = normal["id"]
|
||||
role = session.scalar(select(Role).where(Role.role_code == "payroll_maker"))
|
||||
session.add(UserRole(user_id=normal["id"], role_id=role.id))
|
||||
session.commit()
|
||||
return normal
|
||||
Reference in new issue
Block a user