Skip to content

Conversation

@jevinjojo
Copy link
Contributor

@jevinjojo jevinjojo commented Dec 13, 2025

Issue

Screenshot 2025-12-13 102000

Description

  • Adds input validation to gift card settings to prevent negative values from being entered and saved.

Summary by Sourcery

Enforce non-negative configuration values for gift card settings to prevent invalid negative inputs being stored.

Bug Fixes:

  • Prevent negative values from being configured for gift card code length by enforcing a minimum of 1.
  • Disallow negative values for default gift card expiry years by enforcing a minimum of 0.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 13, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds server-side numeric validation for gift card configuration fields to disallow negative values, ensuring gift card codes length is at least 1 and expiry years is non-negative.

Class diagram for updated gift card settings configuration

classDiagram
    class SettingField {
        +string key
        +string type
        +string label
        +string description
        +any default
        +int min_value
    }

    class GiftcardCodeLengthSetting {
        +string key = giftcard_code_length
        +string type = integer
        +int min_value = 1
    }

    class GiftcardExpiryYearsSetting {
        +string key = giftcard_expiry_years
        +string type = integer
        +int min_value = 0
    }

    SettingField <|-- GiftcardCodeLengthSetting
    SettingField <|-- GiftcardExpiryYearsSetting
Loading

Flow diagram for gift card settings validation on save

flowchart TD
    Admin["Admin updates gift card settings"] --> UI["Gift card settings form"]
    UI --> Backend["Submit settings to backend"]
    Backend --> ValidateCodeLen["Validate giftcard_code_length (min_value = 1)"]
    Backend --> ValidateExpiryYears["Validate giftcard_expiry_years (min_value = 0)"]

    ValidateCodeLen -->|value >= 1| CodeLenOK["giftcard_code_length valid"]
    ValidateCodeLen -->|value < 1| CodeLenError["Reject: code length must be at least 1"]

    ValidateExpiryYears -->|value >= 0| ExpiryOK["giftcard_expiry_years valid"]
    ValidateExpiryYears -->|value < 0| ExpiryError["Reject: expiry years cannot be negative"]

    CodeLenOK --> CheckAll{"All validations passed?"}
    ExpiryOK --> CheckAll

    CodeLenError --> CheckAll
    ExpiryError --> CheckAll

    CheckAll -->|yes| Save["Persist settings"]
    CheckAll -->|no| ReturnErrors["Return validation errors to UI"]

    Save --> UI
    ReturnErrors --> UI
Loading

File-Level Changes

Change Details Files
Enforced a minimum positive length for generated gift card codes in configuration settings.
  • Updated the gift card code length configuration field to specify a minimum allowed value of 1
  • Ensures users cannot configure gift card code length to zero or a negative number
app/eventyay/base/configurations/default_setting.py
Allowed configuration of gift card expiry years while preventing negative values.
  • Updated the gift card expiry years configuration field to specify a minimum allowed value of 0
  • Ensures users can leave expiry unset or set to zero or more years, but not negative
app/eventyay/base/configurations/default_setting.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1491 Ensure gift card code length setting only accepts positive integers (1 or higher) and prevents negative values from being entered or saved.
#1491 Ensure gift card validity years setting only accepts non-negative integers (0 or higher) and prevents negative values from being entered or saved.

Possibly linked issues


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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

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
Contributor

@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 there - I've reviewed your changes - here's some feedback:

  • Consider updating the help text for giftcard_code_length and giftcard_expiry_years to explicitly mention the enforced minimum values so the UI guidance matches the new validation constraints.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider updating the help text for `giftcard_code_length` and `giftcard_expiry_years` to explicitly mention the enforced minimum values so the UI guidance matches the new validation constraints.

## Individual Comments

### Comment 1
<location> `app/eventyay/base/configurations/default_setting.py:2439` </location>
<code_context>
                 'If you set a number here, gift cards will by default expire at the end of the year after this '
                 'many years. If you keep it empty, gift cards do not have an explicit expiry date.'
             ),
+            min_value=0,
         ),
     },
</code_context>

<issue_to_address>
**issue (bug_risk):** Clarify semantics of `0` vs empty value for gift card expiry configuration.

With `min_value=0`, a value of 0 is now valid in addition to leaving the field empty. Please make it explicit whether 0 is intended to mean “no expiry”, “expire immediately”, or something else. If only empty/None should mean “no expiry”, consider `min_value=1` and handling empty as the special case; otherwise, ensure the downstream logic clearly distinguishes 0 from empty.
</issue_to_address>

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.

'If you set a number here, gift cards will by default expire at the end of the year after this '
'many years. If you keep it empty, gift cards do not have an explicit expiry date.'
),
min_value=0,
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Clarify semantics of 0 vs empty value for gift card expiry configuration.

With min_value=0, a value of 0 is now valid in addition to leaving the field empty. Please make it explicit whether 0 is intended to mean “no expiry”, “expire immediately”, or something else. If only empty/None should mean “no expiry”, consider min_value=1 and handling empty as the special case; otherwise, ensure the downstream logic clearly distinguishes 0 from empty.

@mariobehling mariobehling requested a review from Copilot December 15, 2025 07:04
Copy link
Contributor

Copilot AI left a 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 adds validation to prevent negative values in gift card configuration settings by introducing minimum value constraints on two fields: gift card code length and gift card expiry years.

  • Adds min_value=1 validation for giftcard_length to ensure gift card codes have at least one character
  • Adds min_value=0 validation for giftcard_expiry_years to prevent negative expiry durations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Gift Card Settings Allow Negative Values

2 participants