完善风控登录权限和模型能力配置
This commit is contained in:
@@ -46,12 +46,12 @@ if str(PROJECT_ROOT) not in sys.path:
|
||||
|
||||
from app.core.config import get_settings # noqa: E402
|
||||
|
||||
# (permission_code, resource, action, 授予的角色)
|
||||
PERMISSIONS: tuple[tuple[str, str, str, tuple[str, ...]], ...] = (
|
||||
("risk:alert:read", "risk", "alert", ("risk_operator", "admin")),
|
||||
("risk:alert:write", "risk", "alert", ("risk_operator", "admin")),
|
||||
("risk:alert:scan", "risk", "alert", ("risk_operator", "admin")),
|
||||
("risk:report:mail", "risk", "report", ("risk_operator", "admin")),
|
||||
# (permission_id, permission_code, resource, action, 授予的角色)
|
||||
PERMISSIONS: tuple[tuple[int, str, str, str, tuple[str, ...]], ...] = (
|
||||
(9047, "risk:alert:read", "risk", "alert", ("risk_operator", "admin")),
|
||||
(9048, "risk:alert:write", "risk", "alert", ("risk_operator", "admin")),
|
||||
(9049, "risk:alert:scan", "risk", "alert", ("risk_operator", "admin")),
|
||||
(9050, "risk:report:mail", "risk", "report", ("risk_operator", "admin")),
|
||||
)
|
||||
DATA_SCOPE = "all"
|
||||
|
||||
@@ -75,7 +75,7 @@ async def main() -> int:
|
||||
try:
|
||||
cursor = connection.cursor()
|
||||
now = dt.datetime.now(dt.UTC).replace(tzinfo=None)
|
||||
for code, resource, action, roles in PERMISSIONS:
|
||||
for permission_id, code, resource, action, roles in PERMISSIONS:
|
||||
await cursor.execute(
|
||||
"SELECT id FROM sys_permission WHERE permission_code = %s", (code,)
|
||||
)
|
||||
@@ -83,18 +83,21 @@ async def main() -> int:
|
||||
if row is None:
|
||||
await cursor.execute(
|
||||
"INSERT INTO sys_permission"
|
||||
" (permission_code, resource, `action`, data_scope, created_at, updated_at)"
|
||||
" VALUES (%s, %s, %s, %s, %s, %s)",
|
||||
(code, resource, action, DATA_SCOPE, now, now),
|
||||
" (id, permission_code, resource, `action`, data_scope,"
|
||||
" created_at, updated_at)"
|
||||
" VALUES (%s, %s, %s, %s, %s, %s, %s)",
|
||||
(permission_id, code, resource, action, DATA_SCOPE, now, now),
|
||||
)
|
||||
await cursor.execute(
|
||||
"SELECT id FROM sys_permission WHERE permission_code = %s", (code,)
|
||||
)
|
||||
row = await cursor.fetchone()
|
||||
print(f"[权限] 已创建 {code}(scope={DATA_SCOPE})")
|
||||
else:
|
||||
existing_id = int(row[0])
|
||||
if existing_id != permission_id:
|
||||
raise RuntimeError(
|
||||
f"权限码 {code} 已存在但主键为 {existing_id},"
|
||||
f"与约定主键 {permission_id} 不一致;请先执行 "
|
||||
"python tools/seed_test_rbac.py"
|
||||
)
|
||||
print(f"[权限] {code} 已存在")
|
||||
permission_id = int(row[0])
|
||||
|
||||
for role_code in roles:
|
||||
await cursor.execute("SELECT id FROM sys_role WHERE role_code = %s", (role_code,))
|
||||
@@ -122,5 +125,5 @@ async def main() -> int:
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
||||
sys.exit(asyncio.run(main()))
|
||||
if __name__ == "__main__":
|
||||
sys.exit(asyncio.run(main()))
|
||||
|
||||
Reference in New Issue
Block a user