refactor: Replace strawberry.types.Info with just Info

This commit is contained in:
Inex Code 2024-07-15 16:59:15 +04:00
parent 94b0276f74
commit cc4b411657

View file

@ -4,6 +4,7 @@
import asyncio import asyncio
from typing import AsyncGenerator, List from typing import AsyncGenerator, List
import strawberry import strawberry
from strawberry.types import Info
from selfprivacy_api.graphql import IsAuthenticated from selfprivacy_api.graphql import IsAuthenticated
from selfprivacy_api.graphql.mutations.deprecated_mutations import ( from selfprivacy_api.graphql.mutations.deprecated_mutations import (
@ -144,11 +145,11 @@ class Mutation(
# A cruft for Websockets # A cruft for Websockets
def authenticated(info: strawberry.types.Info) -> bool: def authenticated(info: Info) -> bool:
return IsAuthenticated().has_permission(source=None, info=info) return IsAuthenticated().has_permission(source=None, info=info)
def reject_if_unauthenticated(info: strawberry.types.Info): def reject_if_unauthenticated(info: Info):
if not authenticated(info): if not authenticated(info):
raise Exception(IsAuthenticated().message) raise Exception(IsAuthenticated().message)
@ -161,24 +162,20 @@ class Subscription:
demands it while the spec is vague in this area.""" demands it while the spec is vague in this area."""
@strawberry.subscription @strawberry.subscription
async def job_updates( async def job_updates(self, info: Info) -> AsyncGenerator[List[ApiJob], None]:
self, info: strawberry.types.Info
) -> AsyncGenerator[List[ApiJob], None]:
reject_if_unauthenticated(info) reject_if_unauthenticated(info)
return job_update_generator() return job_update_generator()
@strawberry.subscription @strawberry.subscription
# Used for testing, consider deletion to shrink attack surface # Used for testing, consider deletion to shrink attack surface
async def count(self, info: strawberry.types.Info) -> AsyncGenerator[int, None]: async def count(self, info: Info) -> AsyncGenerator[int, None]:
reject_if_unauthenticated(info) reject_if_unauthenticated(info)
for i in range(10): for i in range(10):
yield i yield i
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
@strawberry.subscription @strawberry.subscription
async def log_entries( async def log_entries(self, info: Info) -> AsyncGenerator[LogEntry, None]:
self, info: strawberry.types.Info
) -> AsyncGenerator[LogEntry, None]:
reject_if_unauthenticated(info) reject_if_unauthenticated(info)
return log_stream() return log_stream()