diff --git a/backend/api/reviews/__init__.py b/backend/api/reviews/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/api/reviews/mutations/__init__.py b/backend/api/reviews/mutations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/api/reviews/mutations/vote_proposal.py b/backend/api/reviews/mutations/vote_proposal.py new file mode 100644 index 0000000000..d9dbdc087a --- /dev/null +++ b/backend/api/reviews/mutations/vote_proposal.py @@ -0,0 +1,51 @@ +from typing import Annotated + +import strawberry + +from api.context import Context +from api.reviews.permissions import CanReviewSession +from api.reviews.types import ReviewProposal, review_proposals_queryset +from api.types import NotFound +from reviews import models + + +@strawberry.input +class VoteProposalInput: + review_session_id: strawberry.ID + proposal_id: strawberry.ID + score_option_id: strawberry.ID | None + comment: str + + +VoteProposalResult = Annotated[ + ReviewProposal | NotFound, + strawberry.union(name="VoteProposalResult"), +] + + +@strawberry.field(permission_classes=[CanReviewSession]) +def vote_proposal( + info: strawberry.Info[Context], input: VoteProposalInput +) -> VoteProposalResult: + review_session = models.ReviewSession.objects.get(id=input.review_session_id) + user = info.context.request.user + proposal = ( + review_proposals_queryset(review_session).filter(id=input.proposal_id).first() + ) + score_option = ( + review_session.availablescoreoption_set.filter(id=input.score_option_id).first() + if input.score_option_id + else None + ) + + if not proposal or (input.score_option_id and not score_option): + return NotFound() + + models.UserReview.objects.update_or_create( + user=user, + review_session=review_session, + proposal=proposal, + defaults={"score": score_option, "comment": input.comment}, + ) + + return ReviewProposal.from_model(proposal, review_session, user) diff --git a/backend/api/reviews/permissions.py b/backend/api/reviews/permissions.py new file mode 100644 index 0000000000..4fc657ec80 --- /dev/null +++ b/backend/api/reviews/permissions.py @@ -0,0 +1,24 @@ +from api.permissions import IsStaffPermission +from reviews import models + + +class CanReviewSession(IsStaffPermission): + message = "Cannot review this session" + + def has_permission(self, source, info, **kwargs): + if not super().has_permission(source, info, **kwargs): + return False + + if input := kwargs.get("input"): + review_session_id = input.review_session_id + else: + review_session_id = kwargs.get("review_session_id") + + review_session = models.ReviewSession.objects.filter( + id=review_session_id + ).first() + + if not review_session or not review_session.is_proposals_review: + return False + + return review_session.user_can_review(info.context.request.user) diff --git a/backend/api/reviews/queries/__init__.py b/backend/api/reviews/queries/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/api/reviews/queries/next_proposal_to_review.py b/backend/api/reviews/queries/next_proposal_to_review.py new file mode 100644 index 0000000000..50167ff032 --- /dev/null +++ b/backend/api/reviews/queries/next_proposal_to_review.py @@ -0,0 +1,31 @@ +import strawberry + +from api.context import Context +from api.reviews.permissions import CanReviewSession +from reviews import models +from reviews.adapters import ProposalsReviewAdapter + + +@strawberry.field(permission_classes=[CanReviewSession]) +def next_proposal_to_review( + info: strawberry.Info[Context], + review_session_id: strawberry.ID, + exclude_tags: list[strawberry.ID], + seen: list[strawberry.ID], +) -> strawberry.ID | None: + review_session = models.ReviewSession.objects.get(id=review_session_id) + user = info.context.request.user + adapter = ProposalsReviewAdapter() + exclude = [int(tag_id) for tag_id in exclude_tags] + seen_ids = [int(proposal_id) for proposal_id in seen] + + next_id = adapter.get_next_to_review_item_id( + review_session, user, exclude=exclude, seen=seen_ids + ) + + if next_id is None and seen_ids: + next_id = adapter.get_next_to_review_item_id( + review_session, user, exclude=exclude, seen=seen_ids[-1:] + ) + + return strawberry.ID(str(next_id)) if next_id else None diff --git a/backend/api/reviews/queries/review_proposal.py b/backend/api/reviews/queries/review_proposal.py new file mode 100644 index 0000000000..5dd6aafd18 --- /dev/null +++ b/backend/api/reviews/queries/review_proposal.py @@ -0,0 +1,23 @@ +import strawberry + +from api.context import Context +from api.reviews.permissions import CanReviewSession +from api.reviews.types import ReviewProposal, review_proposals_queryset +from reviews import models + + +@strawberry.field(permission_classes=[CanReviewSession]) +def review_proposal( + info: strawberry.Info[Context], + review_session_id: strawberry.ID, + proposal_id: strawberry.ID, +) -> ReviewProposal | None: + review_session = models.ReviewSession.objects.get(id=review_session_id) + proposal = review_proposals_queryset(review_session).filter(id=proposal_id).first() + + if not proposal: + return None + + return ReviewProposal.from_model( + proposal, review_session, info.context.request.user + ) diff --git a/backend/api/reviews/queries/review_session.py b/backend/api/reviews/queries/review_session.py new file mode 100644 index 0000000000..1e55648daf --- /dev/null +++ b/backend/api/reviews/queries/review_session.py @@ -0,0 +1,12 @@ +import strawberry + +from api.reviews.permissions import CanReviewSession +from api.reviews.types import ReviewSession +from reviews import models + + +@strawberry.field(permission_classes=[CanReviewSession]) +def review_session(review_session_id: strawberry.ID) -> ReviewSession: + return ReviewSession.from_model( + models.ReviewSession.objects.get(id=review_session_id) + ) diff --git a/backend/api/reviews/schema.py b/backend/api/reviews/schema.py new file mode 100644 index 0000000000..76c7972921 --- /dev/null +++ b/backend/api/reviews/schema.py @@ -0,0 +1,13 @@ +from strawberry.tools import create_type + +from api.reviews.mutations.vote_proposal import vote_proposal +from api.reviews.queries.next_proposal_to_review import next_proposal_to_review +from api.reviews.queries.review_proposal import review_proposal +from api.reviews.queries.review_session import review_session + +ReviewsQuery = create_type( + "ReviewsQuery", + [review_session, review_proposal, next_proposal_to_review], +) + +ReviewsMutations = create_type("ReviewsMutations", [vote_proposal]) diff --git a/backend/api/reviews/tests/__init__.py b/backend/api/reviews/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/backend/api/reviews/tests/conftest.py b/backend/api/reviews/tests/conftest.py new file mode 100644 index 0000000000..7abc704329 --- /dev/null +++ b/backend/api/reviews/tests/conftest.py @@ -0,0 +1,30 @@ +import pytest +from django.contrib.auth.models import Permission + +from reviews.models import ReviewSession +from reviews.tests.factories import AvailableScoreOptionFactory, ReviewSessionFactory +from users.tests.factories import UserFactory + + +@pytest.fixture +def make_reviewer(): + def _make_reviewer(conference): + user = UserFactory(is_staff=True) + user.admin_conferences.add(conference) + user.user_permissions.add( + *Permission.objects.filter( + codename__in=["review_reviewsession", "view_submission"] + ) + ) + return user + + return _make_reviewer + + +@pytest.fixture +def proposals_review_session(): + review_session = ReviewSessionFactory( + session_type=ReviewSession.SessionType.PROPOSALS + ) + AvailableScoreOptionFactory(review_session=review_session, numeric_value=1) + return review_session diff --git a/backend/api/reviews/tests/test_next_proposal_to_review.py b/backend/api/reviews/tests/test_next_proposal_to_review.py new file mode 100644 index 0000000000..1bc3657acd --- /dev/null +++ b/backend/api/reviews/tests/test_next_proposal_to_review.py @@ -0,0 +1,49 @@ +import pytest + +from reviews.tests.factories import UserReviewFactory +from submissions.tests.factories import SubmissionFactory + +pytestmark = pytest.mark.django_db + +QUERY = """query($sessionId: ID!, $seen: [ID!]!) { + nextProposalToReview(reviewSessionId: $sessionId, excludeTags: [], seen: $seen) +}""" + + +def _next(client, review_session, seen): + return client.query( + QUERY, + variables={"sessionId": review_session.id, "seen": [str(id) for id in seen]}, + )["data"]["nextProposalToReview"] + + +def test_skipped_proposals_come_back_once_nothing_new_is_left( + admin_graphql_api_client, make_reviewer, proposals_review_session +): + review_session = proposals_review_session + reviewer = make_reviewer(review_session.conference) + first = SubmissionFactory(conference=review_session.conference) + second = SubmissionFactory(conference=review_session.conference) + admin_graphql_api_client.force_login(reviewer) + + assert _next(admin_graphql_api_client, review_session, [first.id]) == str(second.id) + assert _next( + admin_graphql_api_client, review_session, [first.id, second.id] + ) == str(first.id) + + +def test_nothing_left_when_everything_is_voted( + admin_graphql_api_client, make_reviewer, proposals_review_session +): + review_session = proposals_review_session + reviewer = make_reviewer(review_session.conference) + proposal = SubmissionFactory(conference=review_session.conference) + UserReviewFactory( + review_session=review_session, + proposal=proposal, + user=reviewer, + score=review_session.availablescoreoption_set.get(), + ) + admin_graphql_api_client.force_login(reviewer) + + assert _next(admin_graphql_api_client, review_session, [proposal.id]) is None diff --git a/backend/api/reviews/tests/test_permissions.py b/backend/api/reviews/tests/test_permissions.py new file mode 100644 index 0000000000..c8ccdecad7 --- /dev/null +++ b/backend/api/reviews/tests/test_permissions.py @@ -0,0 +1,89 @@ +import pytest + +from conferences.tests.factories import ConferenceFactory +from reviews.models import ReviewSession, UserReview +from reviews.tests.factories import ReviewSessionFactory +from submissions.tests.factories import SubmissionFactory + +pytestmark = pytest.mark.django_db + +OPERATIONS = { + "reviewSession": ( + "query($sessionId: ID!) { reviewSession(reviewSessionId: $sessionId) { id } }", + lambda session_id, proposal_id, option_id: {"sessionId": session_id}, + ), + "reviewProposal": ( + """query($sessionId: ID!, $proposalId: ID!) { + reviewProposal(reviewSessionId: $sessionId, proposalId: $proposalId) { id } + }""", + lambda session_id, proposal_id, option_id: { + "sessionId": session_id, + "proposalId": proposal_id, + }, + ), + "nextProposalToReview": ( + """query($sessionId: ID!) { + nextProposalToReview(reviewSessionId: $sessionId, excludeTags: [], seen: []) + }""", + lambda session_id, proposal_id, option_id: {"sessionId": session_id}, + ), + "voteProposal": ( + """mutation($input: VoteProposalInput!) { + voteProposal(input: $input) { __typename } + }""", + lambda session_id, proposal_id, option_id: { + "input": { + "reviewSessionId": session_id, + "proposalId": proposal_id, + "scoreOptionId": option_id, + "comment": "", + } + }, + ), +} + + +@pytest.mark.parametrize("operation", OPERATIONS) +@pytest.mark.parametrize( + "caller", + [ + "anonymous", + "user", + "staff_without_permissions", + "reviewer_of_another_conference", + "reviewer_of_a_grants_session", + ], +) +def test_refuses_users_who_cannot_review( + admin_graphql_api_client, + user, + admin_user, + make_reviewer, + proposals_review_session, + operation, + caller, +): + review_session = proposals_review_session + option = review_session.availablescoreoption_set.get() + proposal = SubmissionFactory(conference=review_session.conference) + + if caller == "user": + admin_graphql_api_client.force_login(user) + elif caller == "staff_without_permissions": + admin_graphql_api_client.force_login(admin_user) + elif caller == "reviewer_of_another_conference": + admin_graphql_api_client.force_login(make_reviewer(ConferenceFactory())) + elif caller == "reviewer_of_a_grants_session": + review_session = ReviewSessionFactory( + conference=review_session.conference, + session_type=ReviewSession.SessionType.GRANTS, + ) + admin_graphql_api_client.force_login(make_reviewer(review_session.conference)) + + query, build_variables = OPERATIONS[operation] + response = admin_graphql_api_client.query( + query, variables=build_variables(review_session.id, proposal.id, option.id) + ) + + assert response["errors"][0]["message"] == "Cannot review this session" + assert not UserReview.objects.exists() diff --git a/backend/api/reviews/tests/test_review_proposal.py b/backend/api/reviews/tests/test_review_proposal.py new file mode 100644 index 0000000000..4a7380c3a2 --- /dev/null +++ b/backend/api/reviews/tests/test_review_proposal.py @@ -0,0 +1,150 @@ +import pytest + +from conferences.tests.factories import ConferenceFactory +from grants.tests.factories import GrantFactory +from participants.tests.factories import ParticipantFactory +from reviews.tests.factories import AvailableScoreOptionFactory, UserReviewFactory +from submissions.tests.factories import SubmissionFactory +from users.tests.factories import UserFactory +from voting.tests.factories.ranking import RankSubmissionFactory + +pytestmark = pytest.mark.django_db + +QUERY = """query($sessionId: ID!, $proposalId: ID!) { + reviewProposal(reviewSessionId: $sessionId, proposalId: $proposalId) { + id + title { en it } + elevatorPitchHtml { en } + tags { name } + rankings { tag rank total } + isMine + speaker { + fullName + gender + country + bio + grant { status } + proposalsCount + otherProposals { id } + } + votes { reviewerName isMine scoreLabel scoreValue comment } + myVote { scoreOptionId comment } + } +}""" + + +def _review_proposal(client, review_session, proposal): + return client.query( + QUERY, variables={"sessionId": review_session.id, "proposalId": proposal.id} + ) + + +@pytest.mark.parametrize( + "gender,shown_gender", [("female", "Female"), ("not_say", None)] +) +def test_review_proposal( + admin_graphql_api_client, + make_reviewer, + proposals_review_session, + gender, + shown_gender, +): + review_session = proposals_review_session + conference = review_session.conference + reviewer = make_reviewer(conference) + speaker = UserFactory(full_name="Ada Lovelace", gender=gender, country="IT") + proposal = SubmissionFactory( + conference=conference, + speaker=speaker, + languages=["en"], + tags=["python"], + elevator_pitch={ + "en": "**Fast**\n\n\n- one\n- two\n\nEnd", + "it": "", + }, + ) + other_proposal = SubmissionFactory(conference=conference, speaker=speaker) + SubmissionFactory(conference=conference, speaker=speaker, status="cancelled") + ParticipantFactory(conference=conference, user=speaker, bio="Hi") + GrantFactory(conference=conference, user=speaker, status="approved") + RankSubmissionFactory( + submission=proposal, + tag=proposal.tags.get(), + rank=3, + total_submissions_per_tag=40, + ) + yes = AvailableScoreOptionFactory( + review_session=review_session, numeric_value=2, label="Yes" + ) + UserReviewFactory( + review_session=review_session, + proposal=proposal, + user=UserFactory(full_name="Other Reviewer"), + score=None, + comment="Not my area", + ) + UserReviewFactory( + review_session=review_session, + proposal=proposal, + user=reviewer, + score=yes, + comment="Mine", + ) + admin_graphql_api_client.force_login(reviewer) + + data = _review_proposal(admin_graphql_api_client, review_session, proposal)["data"][ + "reviewProposal" + ] + + assert data["title"] == {"en": proposal.title.localize("en"), "it": None} + assert data["elevatorPitchHtml"] == { + "en": "Fast
alert(1)End" + } + assert data["tags"] == [{"name": "python"}] + assert data["rankings"] == [{"tag": "python", "rank": 3, "total": 40}] + assert data["isMine"] is False + assert data["speaker"] == { + "fullName": "Ada Lovelace", + "gender": shown_gender, + "country": "Italy", + "bio": "Hi", + "grant": {"status": "Approved"}, + "proposalsCount": 2, + "otherProposals": [{"id": str(other_proposal.id)}], + } + assert data["votes"] == [ + { + "reviewerName": "Other Reviewer", + "isMine": False, + "scoreLabel": None, + "scoreValue": None, + "comment": "Not my area", + }, + { + "reviewerName": reviewer.full_name, + "isMine": True, + "scoreLabel": "Yes", + "scoreValue": 2, + "comment": "Mine", + }, + ] + assert data["myVote"] == {"scoreOptionId": str(yes.id), "comment": "Mine"} + + +@pytest.mark.parametrize("case", ["cancelled", "another_conference"]) +def test_review_proposal_not_found( + admin_graphql_api_client, make_reviewer, proposals_review_session, case +): + review_session = proposals_review_session + if case == "cancelled": + proposal = SubmissionFactory( + conference=review_session.conference, status="cancelled" + ) + else: + proposal = SubmissionFactory(conference=ConferenceFactory()) + admin_graphql_api_client.force_login(make_reviewer(review_session.conference)) + + response = _review_proposal(admin_graphql_api_client, review_session, proposal) + + assert not response.get("errors") + assert response["data"]["reviewProposal"] is None diff --git a/backend/api/reviews/tests/test_vote_proposal.py b/backend/api/reviews/tests/test_vote_proposal.py new file mode 100644 index 0000000000..b217795180 --- /dev/null +++ b/backend/api/reviews/tests/test_vote_proposal.py @@ -0,0 +1,106 @@ +import pytest + +from reviews.models import UserReview +from reviews.tests.factories import AvailableScoreOptionFactory, UserReviewFactory +from submissions.tests.factories import SubmissionFactory + +pytestmark = pytest.mark.django_db + +MUTATION = """mutation($input: VoteProposalInput!) { + voteProposal(input: $input) { + __typename + ... on ReviewProposal { myVote { scoreOptionId comment } } + } +}""" + + +def _vote(client, review_session, proposal, option, comment=""): + return client.query( + MUTATION, + variables={ + "input": { + "reviewSessionId": review_session.id, + "proposalId": proposal.id, + "scoreOptionId": option.id, + "comment": comment, + } + }, + )["data"]["voteProposal"] + + +def test_vote_proposal_updates_the_same_vote_keeping_private_comment( + admin_graphql_api_client, make_reviewer, proposals_review_session +): + review_session = proposals_review_session + reviewer = make_reviewer(review_session.conference) + proposal = SubmissionFactory(conference=review_session.conference) + no = review_session.availablescoreoption_set.get() + yes = AvailableScoreOptionFactory(review_session=review_session, numeric_value=2) + UserReviewFactory( + review_session=review_session, + proposal=proposal, + user=reviewer, + score=no, + comment="Old", + private_comment="Secret", + ) + admin_graphql_api_client.force_login(reviewer) + + result = _vote(admin_graphql_api_client, review_session, proposal, yes, "New") + + assert result["myVote"] == {"scoreOptionId": str(yes.id), "comment": "New"} + vote = UserReview.objects.get() + assert vote.score == yes + assert vote.comment == "New" + assert vote.private_comment == "Secret" + + +@pytest.mark.parametrize("case", ["option_of_another_session", "cancelled_proposal"]) +def test_vote_proposal_not_found( + admin_graphql_api_client, make_reviewer, proposals_review_session, case +): + review_session = proposals_review_session + option = review_session.availablescoreoption_set.get() + proposal = SubmissionFactory(conference=review_session.conference) + if case == "option_of_another_session": + option = AvailableScoreOptionFactory() + else: + proposal = SubmissionFactory( + conference=review_session.conference, status="cancelled" + ) + admin_graphql_api_client.force_login(make_reviewer(review_session.conference)) + + result = _vote(admin_graphql_api_client, review_session, proposal, option) + + assert result["__typename"] == "NotFound" + assert not UserReview.objects.exists() + + +def test_vote_proposal_no_vote_clears_the_score( + admin_graphql_api_client, make_reviewer, proposals_review_session +): + review_session = proposals_review_session + reviewer = make_reviewer(review_session.conference) + proposal = SubmissionFactory(conference=review_session.conference) + UserReviewFactory( + review_session=review_session, + proposal=proposal, + user=reviewer, + score=review_session.availablescoreoption_set.get(), + ) + admin_graphql_api_client.force_login(reviewer) + + result = admin_graphql_api_client.query( + MUTATION, + variables={ + "input": { + "reviewSessionId": review_session.id, + "proposalId": proposal.id, + "scoreOptionId": None, + "comment": "My own talk", + } + }, + )["data"]["voteProposal"] + + assert result["myVote"] == {"scoreOptionId": None, "comment": "My own talk"} + assert UserReview.objects.get().score is None diff --git a/backend/api/reviews/types.py b/backend/api/reviews/types.py new file mode 100644 index 0000000000..1104819be3 --- /dev/null +++ b/backend/api/reviews/types.py @@ -0,0 +1,307 @@ +import re +from urllib.parse import urljoin + +import strawberry +from django.conf import settings +from django.db.models import Prefetch +from django.template.defaultfilters import linebreaksbr +from django.urls import reverse + +from countries import countries +from grants import models as grants_models +from markdownify.templatetags.markdownify import markdownify +from participants import models as participants_models +from reviews import models +from submissions import models as submissions_models + + +@strawberry.type +class ScoreOption: + id: strawberry.ID + label: str + numeric_value: int + + +@strawberry.type +class ReviewTag: + id: strawberry.ID + name: str + + +@strawberry.type +class ReviewSession: + id: strawberry.ID + score_options: list[ScoreOption] + tags: list[ReviewTag] + + @classmethod + def from_model(cls, review_session: models.ReviewSession): + score_options = review_session.availablescoreoption_set.order_by( + "-numeric_value" + ) + used_tag_ids = ( + submissions_models.Submission.objects.for_conference( + review_session.conference_id + ) + .values_list("tags__id", flat=True) + .distinct() + ) + tags = submissions_models.SubmissionTag.objects.filter( + id__in=used_tag_ids + ).order_by("name") + + return cls( + id=review_session.id, + score_options=[ + ScoreOption( + id=option.id, + label=option.label, + numeric_value=option.numeric_value, + ) + for option in score_options + ], + tags=[ReviewTag(id=tag.id, name=tag.name) for tag in tags], + ) + + +@strawberry.type +class TextInLanguages: + en: str | None + it: str | None + + +@strawberry.type +class Ranking: + tag: str + rank: int + total: int + + +@strawberry.type +class ReviewVote: + id: strawberry.ID + reviewer_name: str + is_mine: bool + score_label: str | None + score_value: int | None + comment: str + + +@strawberry.type +class MyVote: + score_option_id: strawberry.ID | None + comment: str + + +@strawberry.type +class SpeakerGrant: + status: str + admin_url: str + + +@strawberry.type +class OtherProposal: + id: strawberry.ID + title: str + + +@strawberry.type +class ReviewSpeaker: + id: strawberry.ID + full_name: str + gender: str | None + country: str | None + photo_url: str | None + bio: str | None + website: str | None + twitter_handle: str | None + instagram_handle: str | None + mastodon_handle: str | None + linkedin_url: str | None + facebook_url: str | None + speaker_level: str | None + previous_talk_video: str | None + participant_admin_url: str | None + grant: SpeakerGrant | None + proposals_count: int + max_proposals: int | None + other_proposals: list[OtherProposal] + + +@strawberry.type +class ReviewProposal: + id: strawberry.ID + title: TextInLanguages + elevator_pitch_html: TextInLanguages + abstract_html: TextInLanguages + notes: str + tags: list[ReviewTag] + type: str + audience_level: str + duration: int + languages: list[str] + rankings: list[Ranking] + website_url: str + admin_url: str + is_mine: bool + speaker: ReviewSpeaker + votes: list[ReviewVote] + my_vote: MyVote | None + + @classmethod + def from_model( + cls, + proposal: submissions_models.Submission, + review_session: models.ReviewSession, + user, + ): + languages = [language.code for language in proposal.languages.all()] + votes = list( + models.UserReview.objects.filter( + review_session=review_session, proposal=proposal + ) + .select_related("user", "score") + .order_by("created") + ) + my_vote = next((vote for vote in votes if vote.user_id == user.id), None) + + return cls( + id=proposal.id, + title=_in_languages(proposal.title, languages), + elevator_pitch_html=_in_languages( + proposal.elevator_pitch, languages, _markdown_to_html + ), + abstract_html=_in_languages( + proposal.abstract, languages, _markdown_to_html + ), + notes=proposal.notes, + tags=[ReviewTag(id=tag.id, name=tag.name) for tag in proposal.tags.all()], + type=proposal.type.name, + audience_level=proposal.audience_level.name, + duration=proposal.duration.duration, + languages=languages, + rankings=[ + Ranking( + tag=ranking.tag.name if ranking.tag else "", + rank=ranking.rank, + total=ranking.total_submissions_per_tag, + ) + for ranking in proposal.rankings.select_related("tag").order_by( + "tag__name" + ) + ], + website_url=urljoin( + settings.FRONTEND_URL, f"/submission/{proposal.hashid}" + ), + admin_url=reverse( + "admin:submissions_submission_change", args=(proposal.id,) + ), + is_mine=proposal.speaker_id == user.id, + speaker=_build_speaker(proposal), + votes=[ + ReviewVote( + id=vote.id, + reviewer_name=vote.user.display_name, + is_mine=vote.user_id == user.id, + score_label=vote.score.label if vote.score else None, + score_value=vote.score.numeric_value if vote.score else None, + comment=vote.comment, + ) + for vote in votes + ], + my_vote=MyVote(score_option_id=my_vote.score_id, comment=my_vote.comment) + if my_vote + else None, + ) + + +def _in_languages( + text, language_codes: list[str], render=lambda value: value +) -> TextInLanguages: + return TextInLanguages( + en=render(text.localize("en")) if "en" in language_codes else None, + it=render(text.localize("it")) if "it" in language_codes else None, + ) + + +LIST_TAG_WHITESPACE = re.compile(r"\s*()\s*") + + +def _markdown_to_html(text: str) -> str: + # Without this, linebreaksbr adds a
next to every list tag. + html = LIST_TAG_WHITESPACE.sub(r"\1", markdownify(text)) + return linebreaksbr(html, autoescape=False) + + +def _build_speaker(proposal: submissions_models.Submission) -> ReviewSpeaker: + speaker = proposal.speaker + conference = proposal.conference + participant = participants_models.Participant.objects.filter( + user_id=speaker.id, conference_id=conference.id + ).first() + grant = ( + grants_models.Grant.objects.of_user(speaker.id) + .for_conference(conference.id) + .first() + ) + speaker_proposals = list( + submissions_models.Submission.objects.non_cancelled() + .for_conference(conference.id) + .of_user(speaker.id) + .order_by("created") + ) + country = countries.get(code=speaker.country) if speaker.country else None + + return ReviewSpeaker( + id=speaker.id, + full_name=speaker.full_name, + gender=speaker.get_gender_display() + if speaker.gender and speaker.gender != "not_say" + else None, + country=country.name if country else None, + photo_url=participant.photo_url if participant else None, + bio=participant.bio if participant else None, + website=participant.website if participant else None, + twitter_handle=participant.twitter_handle if participant else None, + instagram_handle=participant.instagram_handle if participant else None, + mastodon_handle=participant.mastodon_handle if participant else None, + linkedin_url=participant.linkedin_url if participant else None, + facebook_url=participant.facebook_url if participant else None, + speaker_level=participant.get_speaker_level_display() + if participant and participant.speaker_level + else None, + previous_talk_video=participant.previous_talk_video if participant else None, + participant_admin_url=reverse( + "admin:participants_participant_change", args=(participant.id,) + ) + if participant + else None, + grant=SpeakerGrant( + status=grant.get_status_display(), + admin_url=reverse("admin:grants_grant_change", args=(grant.id,)), + ) + if grant + else None, + proposals_count=len(speaker_proposals), + max_proposals=conference.max_proposals_per_user, + other_proposals=[ + OtherProposal(id=other.id, title=other.title.localize("en")) + for other in speaker_proposals + if other.id != proposal.id + ], + ) + + +def review_proposals_queryset(review_session: models.ReviewSession): + return ( + submissions_models.Submission.objects.non_cancelled() + .for_conference(review_session.conference_id) + .select_related("speaker", "conference", "type", "audience_level", "duration") + .prefetch_related( + "languages", + Prefetch( + "tags", + queryset=submissions_models.SubmissionTag.objects.order_by("name"), + ), + ) + ) diff --git a/backend/api/schema.py b/backend/api/schema.py index 3f4c39132a..30dee4eb8a 100644 --- a/backend/api/schema.py +++ b/backend/api/schema.py @@ -27,6 +27,7 @@ from .sponsors.schema import SponsorsMutation from .visa.query import VisaQuery from .visa.mutation import VisaMutation +from .reviews.schema import ReviewsQuery, ReviewsMutations @strawberry.type @@ -44,6 +45,7 @@ class Query( UserQuery, CMSQuery, VisaQuery, + ReviewsQuery, ): pass @@ -65,6 +67,7 @@ class Mutation( AssociationMembershipMutation, SponsorsMutation, VisaMutation, + ReviewsMutations, ): pass diff --git a/backend/schema.graphql b/backend/schema.graphql index cf5e2b603a..52572adcf5 100644 --- a/backend/schema.graphql +++ b/backend/schema.graphql @@ -770,6 +770,12 @@ type Mutation { sendSponsorLead(input: SendSponsorLeadInput!): SendSponsorLeadOutput! updateInvitationLetterDocument(input: UpdateInvitationLetterDocumentInput!): UpdateInvitationLetterDocumentResult! requestInvitationLetter(input: RequestInvitationLetterInput!): RequestInvitationLetterResult! + voteProposal(input: VoteProposalInput!): VoteProposalResult! +} + +type MyVote { + scoreOptionId: ID + comment: String! } type NewsArticle { @@ -845,6 +851,11 @@ type Option { name: String! } +type OtherProposal { + id: ID! + title: String! +} + type PageInfo { totalPages: Int! totalItems: Int! @@ -962,6 +973,9 @@ type Query { newsArticle(hostname: String!, slug: String!, language: String!): NewsArticle pagePreview(contentType: String!, token: String!): GenericPagePreviewNewsArticlePreview invitationLetterDocument(id: ID!): InvitationLetterDocument + reviewSession(reviewSessionId: ID!): ReviewSession! + reviewProposal(reviewSessionId: ID!, proposalId: ID!): ReviewProposal + nextProposalToReview(reviewSessionId: ID!, excludeTags: [ID!]!, seen: [ID!]!): ID } type Question { @@ -992,6 +1006,12 @@ type RankSubmission { score: Decimal! } +type Ranking { + tag: String! + rank: Int! + total: Int! +} + type RegisterErrors { errors: Registererrors! } @@ -1062,6 +1082,68 @@ type Resetpassworderrors { newPassword: [String!]! } +type ReviewProposal { + id: ID! + title: TextInLanguages! + elevatorPitchHtml: TextInLanguages! + abstractHtml: TextInLanguages! + notes: String! + tags: [ReviewTag!]! + type: String! + audienceLevel: String! + duration: Int! + languages: [String!]! + rankings: [Ranking!]! + websiteUrl: String! + adminUrl: String! + isMine: Boolean! + speaker: ReviewSpeaker! + votes: [ReviewVote!]! + myVote: MyVote +} + +type ReviewSession { + id: ID! + scoreOptions: [ScoreOption!]! + tags: [ReviewTag!]! +} + +type ReviewSpeaker { + id: ID! + fullName: String! + gender: String + country: String + photoUrl: String + bio: String + website: String + twitterHandle: String + instagramHandle: String + mastodonHandle: String + linkedinUrl: String + facebookUrl: String + speakerLevel: String + previousTalkVideo: String + participantAdminUrl: String + grant: SpeakerGrant + proposalsCount: Int! + maxProposals: Int + otherProposals: [OtherProposal!]! +} + +type ReviewTag { + id: ID! + name: String! +} + +type ReviewVote { + id: ID! + reviewerName: String! + isMine: Boolean! + scoreLabel: String + scoreValue: Int + comment: String! +} + type Room { id: ID! name: String! @@ -1178,6 +1260,12 @@ enum ScheduleSlotType { BREAK } +type ScoreOption { + id: ID! + label: String! + numericValue: Int! +} + type SearchEventsForScheduleResult { results: [SubmissionKeynote!]! } @@ -1353,6 +1441,11 @@ enum Spacing { _3XL } +type SpeakerGrant { + status: String! + adminUrl: String! +} + type SpecialGuestSection { id: ID! title: String! @@ -1512,6 +1605,11 @@ type Subscribetonewslettererrors { nonFieldErrors: [String!]! } +type TextInLanguages { + en: String + it: String +} + type TextSection { id: ID! title: String! @@ -1800,6 +1898,15 @@ type UserNeedsConferenceTicket { message: String! } +input VoteProposalInput { + reviewSessionId: ID! + proposalId: ID! + scoreOptionId: ID + comment: String! +} + +union VoteProposalResult = ReviewProposal | NotFound + type VoteType { id: ID! value: Int!