fix(load_path): 库名sage→pipeline + 注册todo_badge/index_tab静态JS权限 + 补role关联(修复/**漏关联)

This commit is contained in:
yumoqing 2026-08-24 15:24:59 +08:00
parent 50725d7e61
commit 8e6510b775

View File

@ -53,6 +53,8 @@ PERMS = [
# app root (any)
("/**", "app", "any"),
("/index.ui", "app", "any"),
("/todo_badge.js", "app", "any"),
("/index_tab.js", "app", "any"),
("/pipeline-sdlc/index.ui", "pipeline_sdlc", "any"),
("/pipeline_core/index.ui", "pipeline_core", "any"),
("/pipeline_ops/index.ui", "pipeline_ops", "any"),
@ -65,34 +67,40 @@ async def register():
DBPools(config.databases)
initEnv()
env = ServerEnv()
env.get_module_dbname = lambda m: "sage"
env.get_module_dbname = lambda m: "pipeline"
async with DBPools().sqlorContext("sage") as sor:
async with DBPools().sqlorContext("pipeline") as sor:
total = 0
for path, module, role_name in PERMS:
sql = "SELECT id FROM permission WHERE path=" + repr(path) + " LIMIT 1"
existing = await sor.sqlExe(sql, {})
pid = None
if existing:
continue
pid = getID()
await sor.C("permission", {
"id": pid, "name": module + ":" + path,
"path": path, "permtype": module
})
pid = existing[0].id
else:
pid = getID()
await sor.C("permission", {
"id": pid, "name": module + ":" + path,
"path": path, "permtype": module
})
total += 1
# 补 role 关联permission 已存在但 rolepermission 缺失时也要补,修复 /** 等历史漏关联)
role_sql = "SELECT id FROM role WHERE name=" + repr(role_name) + " LIMIT 1"
role_recs = await sor.sqlExe(role_sql, {})
if role_recs:
await sor.C("rolepermission", {
"id": getID(),
"roleid": role_recs[0].id,
"permid": pid
})
total += 1
rp_sql = ("SELECT id FROM rolepermission WHERE roleid=" + repr(role_recs[0].id)
+ " AND permid=" + repr(pid) + " LIMIT 1")
rp_existing = await sor.sqlExe(rp_sql, {})
if not rp_existing:
await sor.C("rolepermission", {
"id": getID(),
"roleid": role_recs[0].id,
"permid": pid
})
print(f"Registered {total} new permissions")
# Verify
async with DBPools().sqlorContext("sage") as sor:
async with DBPools().sqlorContext("pipeline") as sor:
cnt = await sor.sqlExe(
"SELECT COUNT(*) as n FROM permission WHERE path LIKE '/pipeline%' OR path LIKE '/showcase%'", {})
print(f"Total pipeline permissions: {cnt[0].n}")