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