通过了单元测试嗯
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
from typing import Iterable
|
||||
import nonebot
|
||||
from nonebot.adapters import Event
|
||||
|
||||
@ -9,8 +8,6 @@ from konabot.common.permsys.migrates import execute_migration
|
||||
from konabot.common.permsys.repo import PermRepo
|
||||
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
|
||||
db = DatabaseManager(DATA_PATH / "perm.sqlite3")
|
||||
|
||||
|
||||
@ -26,8 +23,12 @@ class PermManager:
|
||||
if isinstance(entities, PermEntity):
|
||||
entities = [entities]
|
||||
|
||||
key = key.removesuffix("*").removesuffix(".")
|
||||
key_split = key.split(".")
|
||||
keys = [".".join(key_split[: i + 1]) for i in range(len(key_split))][::-1]
|
||||
key_split = [s for s in key_split if len(s) > 0]
|
||||
keys = [".".join(key_split[: i + 1]) for i in range(len(key_split))][::-1] + [
|
||||
"*"
|
||||
]
|
||||
|
||||
async with self.db.get_conn() as conn:
|
||||
repo = PermRepo(conn)
|
||||
@ -44,6 +45,11 @@ class PermManager:
|
||||
return p
|
||||
return False
|
||||
|
||||
async def update_permission(self, entity: PermEntity, key: str, perm: bool | None):
|
||||
async with self.db.get_conn() as conn:
|
||||
repo = PermRepo(conn)
|
||||
await repo.update_perm_info(entity, key, perm)
|
||||
|
||||
|
||||
def perm_manager(_db: DatabaseManager | None = None) -> PermManager:
|
||||
if _db is None:
|
||||
@ -51,12 +57,14 @@ def perm_manager(_db: DatabaseManager | None = None) -> PermManager:
|
||||
return PermManager(_db)
|
||||
|
||||
|
||||
@driver.on_startup
|
||||
async def _():
|
||||
async with db.get_conn() as conn:
|
||||
await execute_migration(conn)
|
||||
def create_startup():
|
||||
driver = nonebot.get_driver()
|
||||
|
||||
@driver.on_startup
|
||||
async def _():
|
||||
async with db.get_conn() as conn:
|
||||
await execute_migration(conn)
|
||||
|
||||
@driver.on_shutdown
|
||||
async def _():
|
||||
await db.close_all_connections()
|
||||
@driver.on_shutdown
|
||||
async def _():
|
||||
await db.close_all_connections()
|
||||
|
||||
Reference in New Issue
Block a user