fix(load_path): 库名sage→pipeline + 注册todo_badge/index_tab静态JS权限 + 补role关联(修复/**漏关联)
This commit is contained in:
parent
50725d7e61
commit
8e6510b775
@ -53,6 +53,8 @@ PERMS = [
|
|||||||
# app root (any)
|
# app root (any)
|
||||||
("/**", "app", "any"),
|
("/**", "app", "any"),
|
||||||
("/index.ui", "app", "any"),
|
("/index.ui", "app", "any"),
|
||||||
|
("/todo_badge.js", "app", "any"),
|
||||||
|
("/index_tab.js", "app", "any"),
|
||||||
("/pipeline-sdlc/index.ui", "pipeline_sdlc", "any"),
|
("/pipeline-sdlc/index.ui", "pipeline_sdlc", "any"),
|
||||||
("/pipeline_core/index.ui", "pipeline_core", "any"),
|
("/pipeline_core/index.ui", "pipeline_core", "any"),
|
||||||
("/pipeline_ops/index.ui", "pipeline_ops", "any"),
|
("/pipeline_ops/index.ui", "pipeline_ops", "any"),
|
||||||
@ -65,34 +67,40 @@ async def register():
|
|||||||
DBPools(config.databases)
|
DBPools(config.databases)
|
||||||
initEnv()
|
initEnv()
|
||||||
env = ServerEnv()
|
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
|
total = 0
|
||||||
for path, module, role_name in PERMS:
|
for path, module, role_name in PERMS:
|
||||||
sql = "SELECT id FROM permission WHERE path=" + repr(path) + " LIMIT 1"
|
sql = "SELECT id FROM permission WHERE path=" + repr(path) + " LIMIT 1"
|
||||||
existing = await sor.sqlExe(sql, {})
|
existing = await sor.sqlExe(sql, {})
|
||||||
|
pid = None
|
||||||
if existing:
|
if existing:
|
||||||
continue
|
pid = existing[0].id
|
||||||
|
else:
|
||||||
pid = getID()
|
pid = getID()
|
||||||
await sor.C("permission", {
|
await sor.C("permission", {
|
||||||
"id": pid, "name": module + ":" + path,
|
"id": pid, "name": module + ":" + path,
|
||||||
"path": path, "permtype": module
|
"path": path, "permtype": module
|
||||||
})
|
})
|
||||||
|
total += 1
|
||||||
|
# 补 role 关联(permission 已存在但 rolepermission 缺失时也要补,修复 /** 等历史漏关联)
|
||||||
role_sql = "SELECT id FROM role WHERE name=" + repr(role_name) + " LIMIT 1"
|
role_sql = "SELECT id FROM role WHERE name=" + repr(role_name) + " LIMIT 1"
|
||||||
role_recs = await sor.sqlExe(role_sql, {})
|
role_recs = await sor.sqlExe(role_sql, {})
|
||||||
if role_recs:
|
if role_recs:
|
||||||
await sor.C("rolepermission", {
|
rp_sql = ("SELECT id FROM rolepermission WHERE roleid=" + repr(role_recs[0].id)
|
||||||
"id": getID(),
|
+ " AND permid=" + repr(pid) + " LIMIT 1")
|
||||||
"roleid": role_recs[0].id,
|
rp_existing = await sor.sqlExe(rp_sql, {})
|
||||||
"permid": pid
|
if not rp_existing:
|
||||||
})
|
await sor.C("rolepermission", {
|
||||||
total += 1
|
"id": getID(),
|
||||||
|
"roleid": role_recs[0].id,
|
||||||
|
"permid": pid
|
||||||
|
})
|
||||||
|
|
||||||
print(f"Registered {total} new permissions")
|
print(f"Registered {total} new permissions")
|
||||||
# Verify
|
# Verify
|
||||||
async with DBPools().sqlorContext("sage") as sor:
|
async with DBPools().sqlorContext("pipeline") as sor:
|
||||||
cnt = await sor.sqlExe(
|
cnt = await sor.sqlExe(
|
||||||
"SELECT COUNT(*) as n FROM permission WHERE path LIKE '/pipeline%' OR path LIKE '/showcase%'", {})
|
"SELECT COUNT(*) as n FROM permission WHERE path LIKE '/pipeline%' OR path LIKE '/showcase%'", {})
|
||||||
print(f"Total pipeline permissions: {cnt[0].n}")
|
print(f"Total pipeline permissions: {cnt[0].n}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user