From 55dc4f74ff0d11706bb00f8c7517ff39671ff9dd Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 7 Dec 2024 09:32:54 +0200 Subject: [PATCH 1/6] prevent user from registering if reg is closed and registration is cancelled --- app/views/registrations/register.html.erb | 2 +- lib/registrations/registration_checker.rb | 2 ++ spec/factories/competitions.rb | 2 +- .../registration_checker_spec.rb | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/views/registrations/register.html.erb b/app/views/registrations/register.html.erb index 1d59ddff2e..34f50cea5f 100644 --- a/app/views/registrations/register.html.erb +++ b/app/views/registrations/register.html.erb @@ -32,7 +32,7 @@ <% end %> <% else %> <% user_may_register = current_user.cannot_register_for_competition_reasons(@competition).length == 0 %> - <% if @competition.should_render_register_v2?(current_user) %> + <% if @competition.should_render_register_v2?(current_user) && !@registration.competing_status_cancelled? %> <%= react_component('RegistrationsV2/Register', { competitionInfo: @competition.to_competition_info , userInfo: @current_user, userCanPreRegister: @competition.user_can_pre_register?(@current_user), diff --git a/lib/registrations/registration_checker.rb b/lib/registrations/registration_checker.rb index 3630f18ac2..2b5d264db4 100644 --- a/lib/registrations/registration_checker.rb +++ b/lib/registrations/registration_checker.rb @@ -187,6 +187,8 @@ 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.deleted? + raise WcaExceptions::RegistrationError.new(:forbidden, Registrations::ErrorCodes::REGISTRATION_CLOSED) if + registration.deleted? && !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 306fd8e8eb..636e27f8c2 100644 --- a/spec/lib/registrations/registration_checker_spec.rb +++ b/spec/lib/registrations/registration_checker_spec.rb @@ -1485,6 +1485,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) From 91ec65a9fa27fa797238eba6d3456b95bdfcf5f5 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 7 Dec 2024 09:58:13 +0200 Subject: [PATCH 2/6] fixes tests --- spec/requests/api_registrations_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) From 656ce483b7b857e6645d27998b2e6c015ea2aa73 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sat, 7 Dec 2024 22:46:17 +0200 Subject: [PATCH 3/6] moved cancelled check to Register component --- app/views/registrations/register.html.erb | 2 +- .../components/RegistrationsV2/Register/index.jsx | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/views/registrations/register.html.erb b/app/views/registrations/register.html.erb index 34f50cea5f..1d59ddff2e 100644 --- a/app/views/registrations/register.html.erb +++ b/app/views/registrations/register.html.erb @@ -32,7 +32,7 @@ <% end %> <% else %> <% user_may_register = current_user.cannot_register_for_competition_reasons(@competition).length == 0 %> - <% if @competition.should_render_register_v2?(current_user) && !@registration.competing_status_cancelled? %> + <% if @competition.should_render_register_v2?(current_user) %> <%= react_component('RegistrationsV2/Register', { competitionInfo: @competition.to_competition_info , userInfo: @current_user, userCanPreRegister: @competition.user_can_pre_register?(@current_user), diff --git a/app/webpacker/components/RegistrationsV2/Register/index.jsx b/app/webpacker/components/RegistrationsV2/Register/index.jsx index 1fadef42e1..37f3a50318 100644 --- a/app/webpacker/components/RegistrationsV2/Register/index.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/index.jsx @@ -74,7 +74,12 @@ function Register({ return ; } - if (registration || userCanPreRegister || competitionInfo['registration_currently_open?'] || timerEnded) { + if ( + (registration && registration.competing.registration_status != `cancelled`) || + userCanPreRegister || + competitionInfo['registration_currently_open?'] || + timerEnded + ) { return ( <> From b4e75d3ce91bc5023f1d2e35c76964f85092fd00 Mon Sep 17 00:00:00 2001 From: Duncan Date: Sun, 8 Dec 2024 20:03:35 +0200 Subject: [PATCH 4/6] reverted frontend changes --- .../components/RegistrationsV2/Register/index.jsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/webpacker/components/RegistrationsV2/Register/index.jsx b/app/webpacker/components/RegistrationsV2/Register/index.jsx index 37f3a50318..1fadef42e1 100644 --- a/app/webpacker/components/RegistrationsV2/Register/index.jsx +++ b/app/webpacker/components/RegistrationsV2/Register/index.jsx @@ -74,12 +74,7 @@ function Register({ return ; } - if ( - (registration && registration.competing.registration_status != `cancelled`) || - userCanPreRegister || - competitionInfo['registration_currently_open?'] || - timerEnded - ) { + if (registration || userCanPreRegister || competitionInfo['registration_currently_open?'] || timerEnded) { return ( <> From e8d34803040a369b92fb44793a969ec2da93faf8 Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 10 Dec 2024 06:41:33 +0200 Subject: [PATCH 5/6] rubocop --- db/schema.rb | 5 ++++- lib/registrations/registration_checker.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 76cf2d624c..c1d62ec5ff 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_11_24_050607) do +ActiveRecord::Schema[7.2].define(version: 2024_12_07_210016) do create_table "Competitions", id: { type: :string, limit: 32, default: "" }, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", limit: 50, default: "", null: false t.string "cityName", limit: 50, default: "", null: false @@ -82,6 +82,9 @@ t.boolean "forbid_newcomers", default: false, null: false t.string "forbid_newcomers_reason" t.integer "registration_version", default: 0, null: false + t.integer "newcomer_reserved_spots", default: 0, null: false + t.boolean "auto_accept_registrations", default: false, null: false + t.integer "auto_accept_disable_threshold", default: 0, null: false t.index ["cancelled_at"], name: "index_Competitions_on_cancelled_at" t.index ["countryId"], name: "index_Competitions_on_countryId" t.index ["end_date"], name: "index_Competitions_on_end_date" diff --git a/lib/registrations/registration_checker.rb b/lib/registrations/registration_checker.rb index 7dc840e808..7b6b8de358 100644 --- a/lib/registrations/registration_checker.rb +++ b/lib/registrations/registration_checker.rb @@ -193,7 +193,7 @@ def validate_update_status!(new_status, competition, current_user, target_user, 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 From eaefd453ece4cbaaeb65ce05c4284859879dd2ac Mon Sep 17 00:00:00 2001 From: Duncan <52967253+dunkOnIT@users.noreply.github.com> Date: Tue, 10 Dec 2024 07:10:21 +0200 Subject: [PATCH 6/6] Update schema.rb --- db/schema.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index c1d62ec5ff..76cf2d624c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_12_07_210016) do +ActiveRecord::Schema[7.2].define(version: 2024_11_24_050607) do create_table "Competitions", id: { type: :string, limit: 32, default: "" }, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", limit: 50, default: "", null: false t.string "cityName", limit: 50, default: "", null: false @@ -82,9 +82,6 @@ t.boolean "forbid_newcomers", default: false, null: false t.string "forbid_newcomers_reason" t.integer "registration_version", default: 0, null: false - t.integer "newcomer_reserved_spots", default: 0, null: false - t.boolean "auto_accept_registrations", default: false, null: false - t.integer "auto_accept_disable_threshold", default: 0, null: false t.index ["cancelled_at"], name: "index_Competitions_on_cancelled_at" t.index ["countryId"], name: "index_Competitions_on_countryId" t.index ["end_date"], name: "index_Competitions_on_end_date"