You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
962 B
42 lines
962 B
3 years ago
|
"""Славный модуль с бизнес-логикой."""
|
||
|
from models import Allowed_user
|
||
|
|
||
|
|
||
|
def auth(func):
|
||
|
"""Аутентификация.
|
||
|
|
||
|
Проверяем, что у юзера есть полномочия на выполнение действия - он
|
||
|
должен быть в белом списке.
|
||
|
|
||
|
"""
|
||
|
|
||
|
async def wrapper(message):
|
||
|
finded_user: Allowed_user
|
||
|
uid = message["from"]["id"]
|
||
|
|
||
|
finded_user = (
|
||
|
session.query(Allowed_user)
|
||
|
.filter(Allowed_user.user_id == uid)
|
||
|
.one_or_none()
|
||
|
)
|
||
|
|
||
|
if not finded_user:
|
||
|
return
|
||
|
return await func(message)
|
||
|
|
||
|
return wrapper
|
||
|
|
||
|
|
||
|
def only_admins(func):
|
||
|
"""Действия только для админов."""
|
||
|
|
||
|
async def wrapper(message):
|
||
|
uid = message["from"]["id"]
|
||
|
|
||
|
if uid not in ADMINS:
|
||
|
return
|
||
|
|
||
|
return await func(message)
|
||
|
|
||
|
return wrapper
|