Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Allow organizers to approve registrations when there is no competitor limit #722

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/services/registration_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def validate_update_status!

raise RegistrationError.new(:unprocessable_entity, ErrorCodes::INVALID_REQUEST_DATA) unless Registration::REGISTRATION_STATES.include?(new_status)
raise RegistrationError.new(:forbidden, ErrorCodes::COMPETITOR_LIMIT_REACHED) if
new_status == 'accepted' && Registration.accepted_competitors_count(@competition_info.competition_id) == @competition_info.competitor_limit
new_status == 'accepted' && Registration.accepted_competitors_count(@competition_info.competition_id) == @competition_info.competitor_limit &&
@competition_info.competitor_limit != 0
Copy link
Member

Choose a reason for hiding this comment

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

  1. competitor_limit > 0
  2. You can put this check first, because the (relatively) expensive Registration.accepted_competitors_count doesn't even need to be run if there is no competitor limit

raise RegistrationError.new(:forbidden, ErrorCodes::ALREADY_REGISTERED_IN_SERIES) if
new_status == 'accepted' && existing_registration_in_series?

Expand Down
2 changes: 1 addition & 1 deletion lib/competition_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def guest_limit
end

def registration_open?
@competition_json['registration_open'] <= Time.now && @competition_json['registration_close'] > Time.now
@competition_json['registration_open'] <= Time.now.utc && @competition_json['registration_close'] > Time.now.utc
end

def using_wca_payment?
Expand Down
9 changes: 9 additions & 0 deletions spec/services/registration_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,15 @@
.not_to raise_error
end

it 'organizer can accept registrations if there is no limit' do
registration = FactoryBot.create(:registration, registration_status: 'pending')
competition_info = CompetitionInfo.new(FactoryBot.build(:competition, competitor_limit: 0))
update_request = FactoryBot.build(:update_request, :organizer_for_user, user_id: registration[:user_id], competing: { 'status' => 'accepted' })

expect { RegistrationChecker.update_registration_allowed!(update_request, competition_info, update_request['submitted_by']) }
.not_to raise_error
end

it 'user can change state to cancelled' do
override_registration = FactoryBot.create(:registration, user_id: 188000, registration_status: 'waiting_list')
update_request = FactoryBot.build(:update_request, user_id: override_registration[:user_id], competing: { 'status' => 'cancelled' })
Expand Down
Loading