Repository navigation
fix(ORS-1008): 公告管理权限码默认给超管并修正注册时机 - #331
Merged
Merged
Conversation
权限码门禁本身是对的(与其余 frontend:admin:* 一致),问题在两点: 1) 设计上只应默认给「超级管理员」+ admin 账号,但派生表里没有这一项, 超管登录后 permissions 不含该码,后台「公告管理」入口对谁都不可见; 2) ensure_announcement_permission() 原本放在 6 个后台接口的函数体首行, 而 require_permission 是 FastAPI 依赖、先于函数体执行,没权限的账号 先被 403 挡住,注册那行永远走不到(生产自锁,无法自愈)。 改动: - permission_service 新增 PERM_ANNOUNCEMENT 常量,加入 _GLOBAL_ROLE_DERIVED_PERMISSIONS["超级管理员"];admin 账号照旧直通。 - announcement 的 PERM_CODE 复用同一常量,删除 6 处函数体内 ensure 调用, 并在 docstring 里写明为什么不能在接口里注册。 - permissions.get_all_permissions 注册块补 ensure_announcement_permission(), 权限管理页仍可显式勾给非超管角色。 - 测试:接口路径写 permissions 表改为硬失败(回归钉);补超管派生、 注册 code 与闸门一致、带派生码可过闸门 3 条用例。
Rosshow
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
生产环境后台「公告管理」入口对所有账号都不可见,且系统无法自愈。活动中心(#293)上线后
announcements表一直是 0 行。根因
frontend:admin:announcement:manage,但该码既不在_GLOBAL_ROLE_DERIVED_PERMISSIONS里、也没有 DB 权限行绑定 —— 超级管理员登录后permissions不含它;admin账号直通是另一条路(生产该账号还是 inactive)。所以"设计为超管可见"这件事实际没实现。ensure_announcement_permission()被放在 6 个后台接口的函数体首行,而require_permission(...)是 FastAPI 依赖、先于函数体执行。没权限 → 403 → 永远走不到注册那行。改动
permission_service.py:新增PERM_ANNOUNCEMENT常量,加进_GLOBAL_ROLE_DERIVED_PERMISSIONS["超级管理员"]。超管登录即拿到该码,admin账号照旧直通。announcement.py:PERM_CODE复用同一常量(避免两处字符串漂移),删除 6 处函数体内的ensure_announcement_permission(),docstring 写明为什么不能在接口里注册。permissions.py:把注册挪到get_all_permissions的注册块(与 dispatch_dev / task_policy / 知识贡献同一处),权限管理页仍可显式勾给非超管角色。test_announcement_api.py:接口路径写permissions表改为硬失败(回归钉);补 3 条用例(超管派生、注册 code 与闸门一致、带派生码可过闸门)。验证
pytest tests/test_announcement_api.py -q→ 15 passedalembic.migration在新版已移除),无新增回归。上线后表现
permissions,再在角色管理里勾选即可。AdminEntries.tsx:90的hasPermission(PERM_ANNOUNCEMENT)与后端读同一个码。