Skip to content

Commit

Permalink
0.2.8 (#19)
Browse files Browse the repository at this point in the history
- Исправлена ошибка связанная с декоратором, которые не позволял
адекватно вызывать методы под `require_access`.
  • Loading branch information
themanyfaceddemon authored Sep 22, 2024
1 parent 4080a82 commit faff9d2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DMBotNetwork/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
12 changes: 8 additions & 4 deletions DMBotNetwork/main/utils/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@

from .cl_unit import ClUnit
from .server_db import ServerDB
from functools import wraps


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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit faff9d2

Please sign in to comment.