-
Notifications
You must be signed in to change notification settings - Fork 160
Fix "Limit one ticket per user" restriction in the public tickets UI #1479
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
base: enext
Are you sure you want to change the base?
Conversation
Reviewer's GuideEnforces the "limit one ticket per user" product meta in presale views and templates so that max selectable quantity is capped at 1 and the UI shows a corresponding note in product and voucher lists, including the widget API. Sequence diagram for enforcing limit one per user in product loadingsequenceDiagram
participant U as User
participant V as PresaleView
participant DB as Database
participant GP as get_grouped_products
U->>V: Request event page
V->>GP: get_grouped_products(event, voucher)
GP->>DB: Load products for event
DB-->>GP: products
GP->>DB: Query ProductMetaValue by product_ids and property name limit_one_per_user
DB-->>GP: limit_one_per_user_product_ids
loop For each product
GP->>GP: Set product.limit_one_per_user based on id
alt Product has no variations
GP->>GP: Compute product.order_max
alt product.limit_one_per_user is true
GP->>GP: Cap product.order_max at 1
GP->>GP: Adjust product.min_per_order to 1 if > 1
end
else Product has variations
GP->>GP: Adjust product.min_per_order to 1 if limit_one_per_user and min_per_order > 1
loop For each variation
GP->>GP: Compute var.order_max
alt product.limit_one_per_user is true
GP->>GP: Cap var.order_max at 1
end
end
end
end
GP-->>V: Grouped products with limit_one_per_user, order_min, order_max
V-->>U: Render templates with Limit_1_per_user text and capped quantity controls
Class diagram for Product, ProductMetaValue, and widget payload with limit_one_per_userclassDiagram
class Event
class Product {
int pk
bool has_variations
int min_per_order
int order_max
bool limit_one_per_user
tuple cached_availability
float default_price
float display_price
float min_price
float max_price
list available_variations
}
class ProductVariation {
int pk
string description
int order_max
float price
}
class ProductMetaProperty {
int id
string name
Event event
}
class ProductMetaValue {
int id
int product_id
ProductMetaProperty property
string value
}
class WidgetProductPayload {
bool require_voucher
int order_min
int order_max
bool limit_one_per_user
object price
float min_price
float max_price
}
Event "1" -- "*" Product : has
Product "1" -- "*" ProductVariation : has
Product "1" -- "*" ProductMetaValue : meta_for
ProductMetaProperty "1" -- "*" ProductMetaValue : typed_by
Product -- WidgetProductPayload : mapped_to
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- You duplicate the “Limit: 1 per user” markup in multiple templates; consider extracting this into a shared partial/macro or a small include to keep the UI text and styling consistent and easier to update.
- In
get_grouped_products, you compute and assignproduct.limit_one_per_userbut then still checkif product.pk in limit_one_per_user_product_idswhen settingvar.order_max; using the flag instead would simplify the logic and avoid repeated membership checks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You duplicate the “Limit: 1 per user” markup in multiple templates; consider extracting this into a shared partial/macro or a small include to keep the UI text and styling consistent and easier to update.
- In `get_grouped_products`, you compute and assign `product.limit_one_per_user` but then still check `if product.pk in limit_one_per_user_product_ids` when setting `var.order_max`; using the flag instead would simplify the logic and avoid repeated membership checks.
## Individual Comments
### Comment 1
<location> `app/eventyay/presale/views/event.py:366-367` </location>
<code_context>
max_per_order,
)
+ if product.pk in limit_one_per_user_product_ids:
+ var.order_max = min(var.order_max, 1)
+
</code_context>
<issue_to_address>
**suggestion:** Use the computed `product.limit_one_per_user` flag instead of re-checking the product ID in the set.
Since `product.limit_one_per_user` is already computed in this branch, use that flag here instead of `product.pk in limit_one_per_user_product_ids`. This keeps the variation path aligned with the non-variation path and avoids two sources of truth for the same condition.
```suggestion
if product.limit_one_per_user:
var.order_max = min(var.order_max, 1)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR ensures the "Limit one ticket per user" restriction is properly enforced in the public tickets UI. When an organizer enables this setting for a product, users can no longer select more than one ticket, making the UI consistent with backend checkout rules.
Key Changes:
- Enforces
order_max = 1for products and variations when the limit is enabled - Displays "Limit: 1 per user" text in the product list and voucher views
- Exposes the
limit_one_per_userflag through the widget API
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
app/eventyay/presale/views/event.py |
Adds logic to query products with limit_one_per_user meta flag, enforces order_max = 1, and adjusts min_per_order to 1 if needed |
app/eventyay/presale/views/widget.py |
Exposes limit_one_per_user flag in widget product data API |
app/eventyay/presale/templates/pretixpresale/event/fragment_product_list.html |
Displays "Limit: 1 per user" hint for products with and without variations |
app/eventyay/presale/templates/pretixpresale/event/voucher.html |
Displays "Limit: 1 per user" hint in voucher view for products with and without variations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…imit' of https://github.com/prayag78/eventyay into fix/ticket-quantity-limit
Description
This update ensures that when an organizer enables “Limit one ticket per user” users can no longer select more than one ticket, which makes the UI consistent with the checkout rules.
Fixes: #1471
Before
After
Checks
Summary by Sourcery
Enforce the per-user ticket limit in the presale UI and backend when the "limit one per user" setting is enabled for a product.
Bug Fixes:
Enhancements: