Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix join online video button after remove customer feature #433

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

lcduong
Copy link
Contributor

@lcduong lcduong commented Nov 14, 2024

This PR to rework join online video button feature in ticket shop.
As before, the token to join online video using customer's id for identifier in video, but since customer feature is removed, we will using User's email or Order's email as User identifier in video.

Summary by Sourcery

Rework the 'join online video' button feature by replacing the customer identifier with the user's email or order's email. Introduce a new API view to check customer orders for an event and refactor the video plugin check for better code clarity.

Bug Fixes:

  • Fix the 'join online video' button functionality by using the user's email or order's email as the identifier instead of the removed customer feature.

Enhancements:

  • Refactor the video plugin check to improve code readability and reliability.

Copy link

sourcery-ai bot commented Nov 14, 2024

Reviewer's Guide by Sourcery

This PR refactors the online video joining functionality to use email-based identification instead of the previously removed customer feature. The implementation adds a new API endpoint for customer order validation and updates the token generation logic to use encoded email addresses as identifiers.

Sequence diagram for the new CustomerOrderCheckView API endpoint

sequenceDiagram
    actor User
    participant API as CustomerOrderCheckView
    participant DB as Database

    User->>API: POST /<organizer>/<event>/ticket-check
    API->>DB: Get Organizer by slug
    DB-->>API: Organizer
    API->>DB: Get Event by slug and organizer
    DB-->>API: Event
    API->>DB: Get User by email
    DB-->>API: User
    API->>DB: Get Orders by event and user email
    DB-->>API: Order List
    alt Order List is empty
        API-->>User: 404 Customer has no orders for this event
    else Order List is not empty
        alt Order status is 'p'
            API-->>User: 200 Customer has paid orders
        else Order status is not 'p'
            API-->>User: 400 Customer did not paid orders
        end
    end
Loading

Updated class diagram for the event views

classDiagram
    class CustomerOrderCheckView {
        +post(request, *args, **kwargs)
    }
    class EventViewMixin {
        +get_context_data(**kwargs)
        +validate_access(request, *args, **kwargs)
        +generate_token_url(request, order_position, order)
    }

    CustomerOrderCheckView <|-- APIView
    EventViewMixin <|-- APIView

    note for CustomerOrderCheckView "New class for handling order checks using email as identifier"
    note for EventViewMixin "Refactored to use user email instead of customer for access validation and token generation"
Loading

File-Level Changes

Change Details Files
Added new API endpoint for validating customer orders
  • Created CustomerOrderCheckView class with POST method
  • Implemented validation for organizer and event existence
  • Added logic to check if user has paid orders for the event
  • Returns appropriate HTTP responses based on validation results
src/pretix/api/views/event.py
src/pretix/api/urls.py
Updated video access validation logic
  • Replaced customer-based validation with user email-based validation
  • Modified order filtering to use email instead of customer reference
  • Simplified video plugin enablement check
src/pretix/presale/views/event.py
Modified token generation for video access
  • Changed identifier generation to use encoded email instead of customer identifier
  • Added fallback to pseudonymization_id when email is not available
src/pretix/presale/views/event.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@lcduong lcduong marked this pull request as ready for review November 14, 2024 04:55
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @lcduong - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider standardizing error responses to use either Response or JsonResponse consistently throughout CustomerOrderCheckView for better maintainability.
  • Please add documentation explaining the choice of case-insensitive email matching (iexact) and any security considerations of using email as an identifier.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

return JsonResponse(status=404, data={"error": "Customer not found."})

# Get all orders of customer which belong to this event
order_list = (Order.objects.filter(Q(event=event)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider adding a case-insensitive index on email field to optimize iexact queries

This applies to both CustomerOrderCheckView and validate_access method queries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant