From bb0d8d30a0c267272e45afa662ed9b89d42b5202 Mon Sep 17 00:00:00 2001 From: Gregor Billing Date: Wed, 16 Oct 2024 07:35:27 +0900 Subject: [PATCH] Enforce strict competition ID changes when pre-registering (#10059) * Only allow pre-register for announced competitions * Disable changing of competition ID if has registrations * Stub microservice in relevant tests * Use less strict checks for pre-registering * Harmonize Delegate and Organizer test cases --- app/models/competition.rb | 2 +- app/views/competitions/_competition_form.html.erb | 1 + .../components/CompetitionForm/FormSections/NameDetails.js | 4 ++-- app/webpacker/components/CompetitionForm/index.js | 2 ++ spec/controllers/registrations_controller_spec.rb | 2 +- spec/features/competition_management_spec.rb | 6 ++++++ 6 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/models/competition.rb b/app/models/competition.rb index fd8c954444..ba71484a1b 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -612,7 +612,7 @@ def info_for(user) end def user_can_pre_register?(user) - delegates.include?(user) || trainee_delegates.include?(user) || organizers.include?(user) + (delegates.include?(user) || trainee_delegates.include?(user) || organizers.include?(user)) && self.confirmed_or_visible? end attr_accessor :being_cloned_from_id diff --git a/app/views/competitions/_competition_form.html.erb b/app/views/competitions/_competition_form.html.erb index d9e3deb8b7..80a8dc1466 100644 --- a/app/views/competitions/_competition_form.html.erb +++ b/app/views/competitions/_competition_form.html.erb @@ -4,6 +4,7 @@ competition: @competition.to_form_data, usesV2Registrations: @competition.uses_v2_registrations, canChangeRegistrationSystem: @competition.can_change_registration_system?, + hasAnyRegistrations: @competition.any_registrations?, storedEvents: @competition.events, isAdminView: @competition_admin_view, isPersisted: @competition.persisted?, diff --git a/app/webpacker/components/CompetitionForm/FormSections/NameDetails.js b/app/webpacker/components/CompetitionForm/FormSections/NameDetails.js index 044ce07651..d2f4785c0a 100644 --- a/app/webpacker/components/CompetitionForm/FormSections/NameDetails.js +++ b/app/webpacker/components/CompetitionForm/FormSections/NameDetails.js @@ -6,7 +6,7 @@ import { competitionMaxShortNameLength } from '../../../lib/wca-data.js.erb'; import { useFormObject } from '../../wca/FormBuilder/provider/FormObjectProvider'; export default function NameDetails() { - const { isPersisted, isAdminView } = useStore(); + const { hasAnyRegistrations, isPersisted, isAdminView } = useStore(); const { name } = useFormObject(); @@ -15,7 +15,7 @@ export default function NameDetails() { return ( <> - {isPersisted && } + {isPersisted && } {isPersisted && ( Monolith V2 migration + # Can safely be removed once the wca-registrations microservice is gone. (GB 2024-10-15) + allow(Microservices::Registrations).to receive(:competitor_count_by_competition).and_return(0) + end + context "when signed in as admin" do let!(:admin) { FactoryBot.create :admin } before :each do