Esempio n. 1
0
def pastaporto_user_info_can_vote(pastaporto: Pastaporto,
                                  conference: Conference):
    user_info = pastaporto.user_info

    # User is staff
    if user_info.is_staff:
        return True

    # User is a speaker
    if Submission.objects.filter(speaker_id=user_info.id,
                                 conference=conference).exists():
        return True

    # User has admission ticket for the current conference
    if user_has_admission_ticket(
            email=user_info.email,
            event_organizer=conference.pretix_organizer_id,
            event_slug=conference.pretix_event_id,
    ):
        return True

    # User has a ticket for another event in pretix
    for included_voting_event in conference.included_voting_events.all():
        if user_has_admission_ticket(
                email=user_info.email,
                event_organizer=included_voting_event.pretix_organizer_id,
                event_slug=included_voting_event.pretix_event_id,
        ):
            return True

    # User is a member of Python Italia
    if user_is_python_italia_member(user_info.id):
        return True

    return False
Esempio n. 2
0
def test_user_has_admission_ticket(mocker, has_ticket):
    connections_mock = mocker.patch("pretix.db.connections")
    connections_mock.__getitem__.return_value.cursor.return_value.__enter__.return_value.fetchone.return_value = (  # noqa
        has_ticket, )

    assert (user_has_admission_ticket("*****@*****.**",
                                      "this-is-an-email") is has_ticket)
Esempio n. 3
0
def test_user_has_admission_ticket(mocker, has_ticket):
    connections_mock = mocker.patch("pretix.db.connections")
    connections_mock.__getitem__.return_value.cursor.return_value.__enter__.return_value.fetchone.return_value = (  # noqa
        has_ticket, )

    assert (user_has_admission_ticket(
        email="*****@*****.**",
        event_organizer="organizer",
        event_slug="slug",
    ) is has_ticket)
Esempio n. 4
0
def convert_user_to_endpoint(user: User) -> Endpoint:
    pretix_conferences = Conference.objects.exclude(pretix_event_id__exact="")
    submissions = Submission.objects.filter(speaker_id=user.id).values(
        "conference__code", "status"
    )
    schedule_items = ScheduleItem.objects.filter(
        Q(submission__speaker_id=user.id) | Q(additional_speakers__user_id=user.id)
    ).values("conference__code", "title")

    talks_by_conference: typing.DefaultDict[str, typing.List[str]] = defaultdict(list)

    for item in schedule_items:
        talks_by_conference[item["conference__code"]].append(item["title"])

    return Endpoint(
        id=str(user.id),
        name=user.name,
        full_name=user.full_name,
        email=user.email,
        is_staff=user.is_staff,
        has_sent_submission_to=list(
            set([submission["conference__code"] for submission in submissions])
        ),
        has_item_in_schedule=list(talks_by_conference),
        has_ticket=[
            conference.code
            for conference in pretix_conferences
            if user_has_admission_ticket(
                email=user.email,
                event_organizer=conference.pretix_organizer_id,
                event_slug=conference.pretix_event_id,
            )
        ],
        has_cancelled_talks=list(
            set(
                [
                    submission["conference__code"]
                    for submission in submissions
                    if submission["status"] == Submission.STATUS.cancelled
                ]
            )
        ),
        talks_by_conference=talks_by_conference,
    )
Esempio n. 5
0
def test_user_always_has_ticket_when_db_is_simulated():
    assert (user_has_admission_ticket(
        email="*****@*****.**",
        event_organizer="organizer",
        event_slug="event",
    ) is True)
Esempio n. 6
0
def test_user_always_has_ticket_when_db_is_simulated():
    assert (user_has_admission_ticket("*****@*****.**",
                                      "this-is-an-email") is True)
Esempio n. 7
0
 def has_conference_ticket(self, conference):
     return user_has_admission_ticket(self.email,
                                      conference.pretix_event_id)