From 31098af84bf88f5a18c5dcb814cdbd9b89bf9a9c Mon Sep 17 00:00:00 2001 From: adk23333 <2633103794@qq.com> Date: Thu, 21 Dec 2023 01:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AD=A3=E5=BC=8F=E7=BB=99=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sio_model.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/sio_model.py b/sio_model.py index db3a909..4bd08b1 100644 --- a/sio_model.py +++ b/sio_model.py @@ -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