正式给指令添加权限限制

This commit is contained in:
San Liy 2023-12-21 01:23:29 +08:00
parent 5a331e773d
commit 31098af84b

View File

@ -3,7 +3,7 @@ from dataclasses import dataclass
from functools import wraps
from typing import Optional, List, Union, Literal, Dict, Any
from casbin import Enforcer
from casbin import Enforcer, AsyncEnforcer
from pydantic import BaseModel, Field, model_validator
from sanic import Sanic
from sanic.log import logger
@ -117,22 +117,24 @@ class SioDecorator:
room_id = self.data['roomId']
if sender_id != self.app.ctx.sio_config.self_id:
parser = ArgumentParser(self._cmd[0])
e: AsyncEnforcer = self.app.ctx.e
if e.enforce(str(sender_id), self._cmd[0][1:]):
parser = ArgumentParser(self._cmd[0])
sqt = SioRequest(app=self.app,
parser=parser,
args=self._cmd[1:],
key=self._cmd[0],
sender_id=sender_id,
sender_name=sender_name,
content=self._content,
room_id=room_id,
data=self.data)
try:
await func(sqt)
except PrintMessage as e:
msg = Message(content=str(e), room_id=room_id)
await self.app.ctx.sio.emit('sendMessage', msg.to_json())
sqt = SioRequest(app=self.app,
parser=parser,
args=self._cmd[1:],
key=self._cmd[0],
sender_id=sender_id,
sender_name=sender_name,
content=self._content,
room_id=room_id,
data=self.data)
try:
await func(sqt)
except PrintMessage as e:
msg = Message(content=str(e), room_id=room_id)
await self.app.ctx.sio.emit('sendMessage', msg.to_json())
@dataclass