bump project

This commit is contained in:
2026-05-01 21:24:21 +03:30
parent dc4b1a1400
commit 139b3e26da
83 changed files with 2455 additions and 18349 deletions

28
app/services/security.py Normal file
View File

@@ -0,0 +1,28 @@
from __future__ import annotations
from collections.abc import Callable
from functools import wraps
from typing import TypeVar
from flask import abort
from flask_login import current_user, login_required
from app.models import Role
F = TypeVar("F", bound=Callable)
def roles_required(*roles: str | Role) -> Callable[[F], F]:
allowed_roles = {role.value if isinstance(role, Role) else role for role in roles}
def decorator(view: F) -> F:
@wraps(view)
@login_required
def wrapped(*args, **kwargs):
if not current_user.is_authenticated or current_user.role not in allowed_roles:
abort(403)
return view(*args, **kwargs)
return wrapped # type: ignore[return-value]
return decorator