my_rate-stat
All checks were successful
Deploy on push / deploy (push) Successful in 6s

This commit is contained in:
2024-11-12 17:56:20 +03:00
parent 34511a8edf
commit 8116160b4d
7 changed files with 83 additions and 7 deletions

View File

@@ -54,12 +54,8 @@ class JWTAuthenticate(AuthenticationBackend):
def login_required(func):
@wraps(func)
async def wrap(parent, info: GraphQLResolveInfo, *args, **kwargs):
# debug only
# print('[auth.authenticate] login required for %r with info %r' % (func, info))
auth: AuthCredentials = info.context["request"].auth
# print(auth)
if not auth or not auth.logged_in:
# raise Unauthorized(auth.error_message or "Please login")
return {"error": "Please login first"}
return await func(parent, info, *args, **kwargs)
@@ -79,3 +75,22 @@ def permission_required(resource, operation, func):
return await func(parent, info, *args, **kwargs)
return wrap
def login_accepted(func):
@wraps(func)
async def wrap(parent, info: GraphQLResolveInfo, *args, **kwargs):
auth: AuthCredentials = info.context["request"].auth
# Если есть авторизация, добавляем данные автора в контекст
if auth and auth.logged_in:
# Существующие данные auth остаются
pass
else:
# Очищаем данные автора из контекста если авторизация отсутствует
info.context["author"] = None
info.context["user_id"] = None
return await func(parent, info, *args, **kwargs)
return wrap

View File

@@ -95,7 +95,6 @@ class User(Base):
ratings = relationship(UserRating, foreign_keys=UserRating.user)
roles = relationship(lambda: Role, secondary=UserRole.__tablename__)
def get_permission(self):
scope = {}
for role in self.roles: