From faff9d20dbf45aaf09e84be58a4f90b38fedad77 Mon Sep 17 00:00:00 2001 From: The many faced demon <154847721+themanyfaceddemon@users.noreply.github.com> Date: Sun, 22 Sep 2024 16:36:29 +0300 Subject: [PATCH] 0.2.8 (#19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Исправлена ошибка связанная с декоратором, которые не позволял адекватно вызывать методы под `require_access`. --- DMBotNetwork/__init__.py | 2 +- DMBotNetwork/main/utils/decorator.py | 12 ++++++++---- setup.py | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/DMBotNetwork/__init__.py b/DMBotNetwork/__init__.py index 3b08843..e7f84ac 100644 --- a/DMBotNetwork/__init__.py +++ b/DMBotNetwork/__init__.py @@ -5,4 +5,4 @@ from .main.utils.server_db import ServerDB __all__ = ["Client", "Server", "ClUnit", "require_access", "ServerDB"] -__version__ = "0.2.7" +__version__ = "0.2.8" diff --git a/DMBotNetwork/main/utils/decorator.py b/DMBotNetwork/main/utils/decorator.py index f7ddf15..02975e0 100644 --- a/DMBotNetwork/main/utils/decorator.py +++ b/DMBotNetwork/main/utils/decorator.py @@ -2,6 +2,7 @@ from .cl_unit import ClUnit from .server_db import ServerDB +from functools import wraps def require_access(req_access: List[str] | str): @@ -9,26 +10,29 @@ def require_access(req_access: List[str] | str): A decorator that ensures the user has the required access level(s) before executing the function. Args: - req_access (List[str] | str): The required access level(s). Can be a single string or a list of strings + req_access (List[str] | str): The required access level(s). Can be a single string or a list of strings representing the access levels needed to execute the function. Returns: function: The decorated function that checks user access before execution. Raises: - PermissionError: If the user does not have the necessary access permissions, + PermissionError: If the user does not have the necessary access permissions, this exception is raised with a message indicating the missing permissions. """ - if isinstance(req_access, str): req_access = [req_access] def decorator(func): + @wraps(func) async def wrapper(cl_unit: ClUnit, *args, **kwargs): if await ServerDB.check_access_login(cl_unit.login, req_access): return await func(cl_unit, *args, **kwargs) + else: - raise PermissionError(f"Access error. Insufficient permissions for the following: {'; '.join(req_access)}") + raise PermissionError( + f"Access error. Insufficient permissions for the following: {'; '.join(req_access)}" + ) return wrapper diff --git a/setup.py b/setup.py index 108ea31..e6eef4d 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="DMBotNetwork", - version="0.2.7", + version="0.2.8", packages=find_packages(), install_requires=["aiosqlite", "aiofiles", "bcrypt", "msgpack"], author="Angels And Demons dev team",