diff --git a/lib/registrations/registration_checker.rb b/lib/registrations/registration_checker.rb index c8e297119f..7b6b8de358 100644 --- a/lib/registrations/registration_checker.rb +++ b/lib/registrations/registration_checker.rb @@ -191,6 +191,9 @@ def validate_update_status!(new_status, competition, current_user, target_user, # User reactivating registration if new_status == Registrations::Helper::STATUS_PENDING raise WcaExceptions::RegistrationError.new(:unauthorized, Registrations::ErrorCodes::USER_INSUFFICIENT_PERMISSIONS) unless registration.cancelled? + raise WcaExceptions::RegistrationError.new(:forbidden, Registrations::ErrorCodes::REGISTRATION_CLOSED) if + registration.cancelled? && !competition.registration_currently_open? + return # No further checks needed if status is pending end diff --git a/spec/factories/competitions.rb b/spec/factories/competitions.rb index 4d33353665..b4652efc10 100644 --- a/spec/factories/competitions.rb +++ b/spec/factories/competitions.rb @@ -267,6 +267,7 @@ registration_close { 1.weeks.ago.change(usec: 0) } starts { 1.month.from_now } ends { starts } + use_wca_registration { true } end trait :registration_not_opened do @@ -277,7 +278,6 @@ end trait :editable_registrations do - registration_open allow_registration_edits { true } event_change_deadline_date { 2.weeks.from_now.change(usec: 0) } end diff --git a/spec/lib/registrations/registration_checker_spec.rb b/spec/lib/registrations/registration_checker_spec.rb index 1f5b07df42..88b214447b 100644 --- a/spec/lib/registrations/registration_checker_spec.rb +++ b/spec/lib/registrations/registration_checker_spec.rb @@ -1486,6 +1486,25 @@ .not_to raise_error end + it 'cancelled user cant re-register if registration is closed' do + closed_comp = FactoryBot.create(:competition, :registration_closed, :editable_registrations) + cancelled_reg = FactoryBot.create(:registration, :cancelled, competition: closed_comp) + + update_request = FactoryBot.build( + :update_request, + user_id: cancelled_reg.user_id, + competition_id: cancelled_reg.competition.id, + competing: { 'status' => 'pending' }, + ) + + expect { + Registrations::RegistrationChecker.update_registration_allowed!(update_request, Competition.find(update_request['competition_id']), User.find(update_request['submitted_by'])) + }.to raise_error(WcaExceptions::RegistrationError) do |error| + expect(error.status).to eq(:forbidden) + expect(error.error).to eq(Registrations::ErrorCodes::REGISTRATION_CLOSED) + end + end + RSpec.shared_examples 'invalid user status updates' do |initial_status, new_status| it "user cant change 'status' => #{initial_status} to: #{new_status}" do registration = FactoryBot.create(:registration, initial_status, competition: default_competition) diff --git a/spec/requests/api_registrations_spec.rb b/spec/requests/api_registrations_spec.rb index 304ece1d2b..5c6636ed41 100644 --- a/spec/requests/api_registrations_spec.rb +++ b/spec/requests/api_registrations_spec.rb @@ -131,8 +131,8 @@ expect(history.first[:action]).to eq('Competitor delete') end - it 'user can change events in a favourites competition', :tag do - favourites_comp = FactoryBot.create(:competition, :with_event_limit, :editable_registrations) + it 'user can change events in a favourites competition' do + favourites_comp = FactoryBot.create(:competition, :with_event_limit, :editable_registrations, :registration_open) favourites_reg = FactoryBot.create(:registration, competition: favourites_comp, user: user, event_ids: %w(333 333oh 555 pyram minx)) new_event_ids = %w(333 333oh 555 pyram 444)