Skip to content

Commit

Permalink
Enforce strict competition ID changes when pre-registering (#10059)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gregorbg authored Oct 15, 2024
1 parent 54ea7fa commit bb0d8d3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/views/competitions/_competition_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -15,7 +15,7 @@ export default function NameDetails() {

return (
<>
{isPersisted && <InputString id="competitionId" disabled={disableIdAndShortName} />}
{isPersisted && <InputString id="competitionId" disabled={disableIdAndShortName || hasAnyRegistrations} />}
<InputString id="name" required />
{isPersisted && (
<InputString
Expand Down
2 changes: 2 additions & 0 deletions app/webpacker/components/CompetitionForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default function Wrapper({
competition = null,
usesV2Registrations = false,
canChangeRegistrationSystem = false,
hasAnyRegistrations = false,
storedEvents = [],
isAdminView = false,
isPersisted = false,
Expand Down Expand Up @@ -105,6 +106,7 @@ export default function Wrapper({
initialState={{
usesV2Registrations,
canChangeRegistrationSystem,
hasAnyRegistrations,
storedEvents,
isAdminView,
isPersisted,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe RegistrationsController, clean_db_with_truncation: true do
context "signed in as organizer" do
let!(:organizer) { FactoryBot.create(:user) }
let(:competition) { FactoryBot.create(:competition, :registration_open, organizers: [organizer], events: Event.where(id: %w(222 333))) }
let(:competition) { FactoryBot.create(:competition, :registration_open, :visible, organizers: [organizer], events: Event.where(id: %w(222 333))) }
let(:zzyzx_user) { FactoryBot.create :user, name: "Zzyzx" }
let(:registration) { FactoryBot.create(:registration, competition: competition, user: zzyzx_user) }

Expand Down
6 changes: 6 additions & 0 deletions spec/features/competition_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def wca_registration_checkbox
# Apparition browser engine does not render React state changes properly.
# We can remove this `retry` count when we migrated to a "proper" browser engine in tests.
RSpec.feature "Competition management", js: true, retry: 10 do
before(:each) do
# Stub microservice as an interim solution during our Microservice->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
Expand Down

0 comments on commit bb0d8d3

Please sign in to comment.