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

Auto-close registrations after enough paid registrations #10772

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

dunkOnIT
Copy link
Contributor

@dunkOnIT dunkOnIT commented Feb 4, 2025

No description provided.

@dunkOnIT dunkOnIT marked this pull request as ready for review February 4, 2025 14:34
@dunkOnIT dunkOnIT added the STATUS: blocked Progress cannot continue - reason for block should be specified in comments label Feb 17, 2025
@dunkOnIT
Copy link
Contributor Author

Blocked pending a change to allow setting competition form fields to NULL

@dunkOnIT dunkOnIT removed the STATUS: blocked Progress cannot continue - reason for block should be specified in comments label Feb 17, 2025
return false if auto_close_threshold.nil?
threshold_reached = registrations.with_payments.count >= auto_close_threshold && auto_close_threshold > 0
# update!(closing_full_registration: true, registration_close: Time.now) if threshold_reached
threshold_reached && update!(closing_full_registration: true, registration_close: Time.now)
Copy link
Member

Choose a reason for hiding this comment

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

The ! version of update! has a (potentially) dangerous implication: If, for some reasons, the validations for the update payload (the updated attributes) fail, it will throw a hard error.

And since this method is being called in the after_create hook of registration_payment, this would result in the creating transaction for that payment to be halted and rolled back. So if push came to shove, people could be unable to pay because of an oversight in our tests / edge cases that we haven't considered.

Fun fact: You have tests which try for both return values (true and false) but the false only ever happens when the first condition threshold_reached falsifies the entire &&. In reality, the signature is like "true or throw" more than an actually legitimate "true or false".

Copy link
Member

Choose a reason for hiding this comment

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

TL;DR:

Suggested change
threshold_reached && update!(closing_full_registration: true, registration_close: Time.now)
threshold_reached && update(closing_full_registration: true, registration_close: Time.now)

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.

Automatically close registration when {n} paid registrations are received
2 participants