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

Prevent cancelled user from registering if registration is closed #10379

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions lib/registrations/registration_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/factories/competitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/registrations/registration_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api_registrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading