Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/api/blog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@strawberry.type
class BlogQuery:
@strawberry.field
def blog_posts(self, info) -> list[PostType]:
def blog_posts(self, info: Info) -> list[PostType]:
return [
PostType(
id=post.id,
Expand Down
4 changes: 3 additions & 1 deletion backend/api/cms/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import strawberry
from strawberry import ID

from api.context import Info
from api.pages.types import Page

from ..helpers.i18n import make_localized_resolver
Expand All @@ -25,5 +27,5 @@ class Menu:
title: str = strawberry.field(resolver=make_localized_resolver("title"))

@strawberry.field
def links(self, info) -> list[MenuLink]:
def links(self, info: Info) -> list[MenuLink]:
return self.links.all()
7 changes: 3 additions & 4 deletions backend/api/context.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from dataclasses import dataclass
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, TypeAlias

from django.http.request import HttpRequest
from strawberry.types import Info as StrawberryInfo

from voting.models.vote import Vote

Expand All @@ -15,6 +16,4 @@ class Context:
_my_votes: Optional[Dict[int, Vote]] = None


@dataclass
class Info:
context: Context
Info: TypeAlias = StrawberryInfo[Context, Any]
4 changes: 3 additions & 1 deletion backend/api/helpers/images.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Optional

from api.context import Info

def resolve_image(root, info) -> Optional[str]:

def resolve_image(root, info: Info) -> Optional[str]:
if not root.image:
return None

Expand Down
4 changes: 3 additions & 1 deletion backend/api/job_board/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import strawberry

from api.context import Info


@strawberry.type
class JobListing:
Expand All @@ -14,7 +16,7 @@ class JobListing:
apply_url: str

@strawberry.field
def company_logo(self, info) -> Optional[str]:
def company_logo(self, info: Info) -> Optional[str]:
if not self.company_logo_url:
return None

Expand Down
13 changes: 7 additions & 6 deletions backend/api/participants/types.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import TYPE_CHECKING, Annotated

from submissions.models import Submission as SubmissionModel
from strawberry.scalars import JSON
import strawberry
from strawberry import ID
from strawberry.scalars import JSON

from api.context import Info
from api.submissions.permissions import CanSeeSubmissionPrivateFields
from submissions.models import Submission as SubmissionModel

if TYPE_CHECKING:
from api.submissions.types import Submission
Expand Down Expand Up @@ -35,29 +36,29 @@ class Participant:

@strawberry.field
def proposals(
self, info
self, info: Info
) -> list[Annotated["Submission", strawberry.lazy("api.submissions.types")]]:
return SubmissionModel.objects.for_conference(self._conference_id).filter(
speaker_id=self._user_id,
status=SubmissionModel.STATUS.accepted,
)

@strawberry.field
def speaker_availabilities(self, info) -> JSON | None:
def speaker_availabilities(self, info: Info) -> JSON | None:
if not CanSeeSubmissionPrivateFields().has_permission(self, info):
return None

return self._speaker_availabilities

@strawberry.field
def speaker_level(self, info) -> str | None:
def speaker_level(self, info: Info) -> str | None:
if not CanSeeSubmissionPrivateFields().has_permission(self, info):
return None

return self._speaker_level

@strawberry.field
def previous_talk_video(self, info) -> str | None:
def previous_talk_video(self, info: Info) -> str | None:
if not CanSeeSubmissionPrivateFields().has_permission(self, info):
return None

Expand Down
2 changes: 1 addition & 1 deletion backend/api/schedule/types/day.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def slots(
return list(self.slots.all())

@strawberry.field
def running_events(self, info) -> list[ScheduleItem]:
def running_events(self, info: Info) -> list[ScheduleItem]:
current_slot = self.slots.filter(
hour__lte=timezone.now().astimezone(self.conference.timezone)
).last()
Expand Down
8 changes: 4 additions & 4 deletions backend/api/schedule/types/schedule_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def spaces_left(self) -> int:
return self.actual_attendees_total_capacity - self.attendees.count()

@strawberry.field
def user_has_spot(self, info) -> bool:
def user_has_spot(self, info: Info) -> bool:
user_id = info.context.request.user.id
return self.attendees.filter(user_id=user_id).exists()

Expand Down Expand Up @@ -114,18 +114,18 @@ def keynote(
return Keynote.from_django_model(self.keynote, info)

@strawberry.field
def rooms(self, info) -> list[Room]:
def rooms(self, info: Info) -> list[Room]:
return self.rooms.all()

@strawberry.field
def image(self, info) -> str | None:
def image(self, info: Info) -> str | None:
if not self.image:
return None

return info.context.request.build_absolute_uri(self.image.url)

@strawberry.field(name="slidoUrl")
def _slido_url(self, info) -> str:
def _slido_url(self, info: Info) -> str:
if self.slido_url:
return self.slido_url

Expand Down
9 changes: 6 additions & 3 deletions backend/api/schedule/types/slot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from enum import Enum
from django.utils import timezone
from datetime import datetime, time, timedelta

from django.utils import timezone

from api.context import Info
from api.schedule.types.schedule_item import ScheduleItem


Expand Down Expand Up @@ -31,12 +34,12 @@ def is_live(self) -> bool:
return self.hour < now.time() < end

@strawberry.field
def end_hour(self, info) -> time:
def end_hour(self) -> time:
return (
datetime.combine(timezone.datetime.today(), self.hour)
+ timedelta(minutes=self.duration)
).time()

@strawberry.field
def items(self, info) -> list[ScheduleItem]:
def items(self, info: Info) -> list[ScheduleItem]:
return self.items.all()
5 changes: 3 additions & 2 deletions backend/api/sponsors/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import strawberry
from strawberry import ID

from api.context import Info
from sponsors.models import SponsorLevel as SponsorLevelModel


Expand All @@ -13,11 +14,11 @@ class Sponsor:
name: str

@strawberry.field
def link(self, info) -> str:
def link(self, info: Info) -> str:
return self.link

@strawberry.field
def image(self, info) -> str:
def image(self, info: Info) -> str:
if not self.image:
return ""

Expand Down
12 changes: 6 additions & 6 deletions backend/api/submissions/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ def speaker(self, info: Info) -> SubmissionSpeaker | None:
)

@strawberry.field
def id(self, info) -> strawberry.ID:
def id(self, info: Info) -> strawberry.ID:
return self.hashid

@strawberry.field
def can_edit(self, info) -> bool:
def can_edit(self, info: Info) -> bool:
return self.can_edit(info.context.request)

@strawberry.field
def my_vote(self, info) -> VoteType | None:
def my_vote(self, info: Info) -> VoteType | None:
request = info.context.request

if not request.user.is_authenticated:
Expand All @@ -189,15 +189,15 @@ def my_vote(self, info) -> VoteType | None:
return None

@strawberry.field
def languages(self, info) -> list[Language] | None:
def languages(self, info: Info) -> list[Language] | None:
return self.languages.all()

@strawberry.field
def tags(self, info) -> list[SubmissionTag] | None:
def tags(self, info: Info) -> list[SubmissionTag] | None:
return self.tags.all()

@strawberry.field
def materials(self, info) -> list[ProposalMaterial]:
def materials(self, info: Info) -> list[ProposalMaterial]:
return [
ProposalMaterial.from_django(material)
for material in self.materials.order_by("created").all()
Expand Down
17 changes: 7 additions & 10 deletions backend/api/tests/test_extensions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from graphql import GraphQLError
import time
import time_machine
from unittest.mock import Mock
from api.context import Info
from unittest.mock import MagicMock
import pytest
from strawberry.types import Info as StrawberryInfo
from api.extensions import RateLimit
from django.test import override_settings
from django.core.cache import cache
Expand Down Expand Up @@ -38,10 +38,8 @@ def test_parsing_rate_limit(value, expected_output):
}
)
def test_removes_obsolete_history_records():
info = Info(context=Mock())
info = MagicMock(spec=StrawberryInfo)
info.field_name = "field_name"
info.context.request = Mock()
info.context.request.user = Mock()
info.context.request.user.id = 1

rate_limit = RateLimit(rate="10/m")
Expand All @@ -65,16 +63,15 @@ def test_removes_obsolete_history_records():
}
)
def test_blocks_too_many_requests():
info = Info(context=Mock())
info = MagicMock(spec=StrawberryInfo)
info.field_name = "field_name"
info.context.request = Mock()
info.context.request.user = Mock()
info.context.request.user.id = 1

rate_limit = RateLimit(rate="10/m")

with time_machine.travel("2021-01-01 00:01:00", tick=False), pytest.raises(
GraphQLError
with (
time_machine.travel("2021-01-01 00:01:00", tick=False),
pytest.raises(GraphQLError),
):
current_time = time.time()

Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies = [
"django-queryinspect<2.0.0,>=1.1.0",
"lxml==6.0.0",
"unidecode<2.0.0,>=1.1.1",
"strawberry-graphql==0.257.0",
"strawberry-graphql==0.312.2",
"Werkzeug>=1.0.1,<4.0.0",
"django-import-export<4.0.0,>=3.2.0",
"dal-admin-filters==1.1.0",
Expand Down
Loading
Loading