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

Schedule menu in ticket shop should consider schedule state from talk #354

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

lcduong
Copy link
Contributor

@lcduong lcduong commented Oct 1, 2024

This PR related to issue #353
Implement:

  1. API to handle schedule state trigged by Talk system.
  2. Remove schedule/session/speaker link set in event settings - auto set when is_show_schedule is True (triggered by Talk system.)

Summary by Sourcery

Implement an API to manage schedule state changes from the Talk system and automate the configuration of schedule-related links based on the schedule's visibility status.

New Features:

  • Introduce an API endpoint to handle schedule state changes triggered by the Talk system, allowing the schedule menu to reflect the current state.

Enhancements:

  • Automatically set schedule, session, and speaker links when 'is_show_schedule' is true, removing the need for manual configuration in event settings.

Copy link

sourcery-ai bot commented Oct 1, 2024

Reviewer's Guide by Sourcery

This pull request implements changes to handle the schedule state triggered by the Talk system. It introduces a new API endpoint to manage the schedule's public visibility and removes manual schedule/session/speaker link settings, replacing them with automatic links when the schedule is made public. The changes primarily affect the event settings, API views, and frontend templates.

Sequence Diagram

sequenceDiagram
    participant TS as Talk System
    participant API as Pretix API
    participant E as Event
    participant FE as Frontend

    TS->>API: POST /schedule-public
    API->>API: Validate token & permissions
    API->>E: Update talk_schedule_public setting
    API-->>TS: Return success/error response
    FE->>E: Request event data
    E-->>FE: Return event data (including talk_schedule_public)
    FE->>FE: Show/hide schedule links based on talk_schedule_public
Loading

File-Level Changes

Change Details Files
Implement new API endpoint for managing schedule visibility
  • Add new function 'talk_schedule_public' to handle POST requests
  • Implement token-based authentication and permission checking
  • Update event settings to set 'talk_schedule_public' based on request data
  • Add error handling for various scenarios (token expiration, invalid token, etc.)
src/pretix/api/views/event.py
src/pretix/api/urls.py
Remove manual schedule, session, and speaker link settings
  • Remove 'schedule_link', 'session_link', and 'speaker_link' from event settings
  • Remove corresponding fields from forms and serializers
  • Remove these fields from templates
src/pretix/base/configurations/default_setting.py
src/pretix/control/forms/event.py
src/pretix/api/serializers/event.py
src/pretix/control/templates/pretixcontrol/event/settings.html
Add automatic schedule, session, and speaker URL generation
  • Add properties 'talk_schedule_url', 'talk_session_url', and 'talk_speaker_url' to Event model
  • Use TALK_HOSTNAME setting to generate URLs
src/pretix/base/models/event.py
Update frontend to use new automatic URLs
  • Replace static links with dynamic links using new Event model properties
  • Add condition to show links only when 'talk_schedule_public' setting is true
src/pretix/presale/templates/pretixpresale/event/index.html

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.

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

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 using a more robust authentication method or established library for token validation instead of the custom check_token_permission function to enhance security.
  • The removal of manual schedule, session, and speaker link settings might reduce flexibility for some users. Consider providing an option to override the automatically generated URLs if needed.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues 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.

@csrf_exempt
@require_POST
@scopes_disabled()
def talk_schedule_public(request, *args, **kwargs):
Copy link

Choose a reason for hiding this comment

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

suggestion: Refine exception handling and function structure

Consider catching specific exceptions instead of using bare except clauses. This function is quite long; consider breaking it down into smaller, more focused functions for better readability and maintainability.

def talk_schedule_public(request, *args, **kwargs):
    try:
        return _process_talk_schedule(request, *args, **kwargs)
    except InvalidToken:
        return JsonResponse({"error": "Invalid token"}, status=401)
    except PermissionDenied:
        return JsonResponse({"error": "Permission denied"}, status=403)
    except Exception as e:
        logger.error(f"Error processing talk schedule: {str(e)}")
        return JsonResponse({"error": "Internal server error"}, status=500)

def _process_talk_schedule(request, *args, **kwargs):

@@ -964,6 +964,24 @@ def has_paid_things(self):
return Item.objects.filter(event=self, default_price__gt=0).exists()\
or ItemVariation.objects.filter(item__event=self, default_price__gt=0).exists()

@property
def talk_schedule_url(self):
Copy link

Choose a reason for hiding this comment

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

suggestion: Improve URL construction for talk-related properties

Ensure that settings.TALK_HOSTNAME is properly defined. Consider using Django's reverse() function or a similar URL construction method instead of string concatenation for more robust URL generation.

    def talk_schedule_url(self):
        from django.urls import reverse
        return reverse('talk:schedule', kwargs={'event_slug': self.slug})

implement API handle schedule public state
remove schedule,session,speaker link set
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