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

Validate issued_at field to prevent future dates further than 1 year #4749

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

tatheerf02
Copy link
Contributor

@tatheerf02 tatheerf02 commented Oct 28, 2024

Resolves #4742

Description

Add a new validation to the issued_at field which is present on the donation, distribution, and purchase models. The new validation ensures that the field can not be set to a date that is further than one year into the future, as this causes unexpected behaviour when the models are later filtered.

An alternative solution could be to add this validation to the models themselves, but putting it in the centralized location was an existing pattern and made more sense.

Tradeoff: Are there valid use cases where we might want to have set this date to further than one year ahead?

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added new unit tests following existing patterns for all affected models and ensured they passed

Screenshots

Note: Although not pictured, I also tested that the validation is run when the date on a purchase, donation, or distribution is edited after creation.

📸 Validation error shown on new donation Screen Shot 2024-10-28 at 9 59 30 PM
📸 Validation error shown on new purchase Screen Shot 2024-10-28 at 9 59 00 PM
📸 Validation error shown on new distribution Screen Shot 2024-10-28 at 9 58 41 PM

@tatheerf02 tatheerf02 force-pushed the 4742-limit-future-issued-at branch 3 times, most recently from f6e3073 to 02b8223 Compare October 28, 2024 02:07
@cielf
Copy link
Collaborator

cielf commented Oct 28, 2024

@tatheerf02 Let's change that from "Cannot be further than 1 year" to "cannot be more than 1 year in the future".

@tatheerf02
Copy link
Contributor Author

Let's change that from "Cannot be further than 1 year" to "cannot be more than 1 year in the future".

@cielf I've changed the error message and updated the screenshots in the description 👍

Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

LGTM from a functional pov; I found an unrelated issue (which is also in main).

@cielf cielf requested review from dorner and awwaiid October 29, 2024 18:50
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

I took a glancing look at the code, and I'm not sure all the changes made to the calendar_service_spec are in scope? Passing it to @awwaiid or @dorner for an opinion, and other technical review.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Looks good. The calendar spec had to change because it had a year too far in the future, which would prevent the object from saving now.

@dorner dorner merged commit 7de8d40 into rubyforgood:main Oct 30, 2024
11 checks passed
Copy link
Contributor

github-actions bot commented Nov 3, 2024

@tatheerf02: Your PR Validate issued_at field to prevent future dates further than 1 year is part of today's Human Essentials production release: 2024.11.03.
Thank you very much for your contribution!

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.

Limit how far you can future date itemizables (i.e. donations, purchases, distributions)
3 participants