Skip to content

Commit

Permalink
Change back occurences of registration_version to less intrusive chec…
Browse files Browse the repository at this point in the history
…kbox
  • Loading branch information
gregorbg committed Oct 27, 2024
1 parent 418ce05 commit 8cb5407
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
1 change: 0 additions & 1 deletion app/controllers/competitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ def new
competitor_limit_enabled: true,
base_entry_fee_lowest_denomination: 0,
guests_entry_fee_lowest_denomination: 0,
registration_version: :v2,
)

assign_editing_user(@competition)
Expand Down
15 changes: 8 additions & 7 deletions app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class Competition < ApplicationRecord
restricted: 2,
}, prefix: true

enum :registration_version, [:v1, :v2, :v3], prefix: true, default: :v2
NEW_REG_SYSTEM_DEFAULT = :v2

enum :registration_version, [:v1, :v2, :v3], prefix: true, default: NEW_REG_SYSTEM_DEFAULT

CLONEABLE_ATTRIBUTES = %w(
cityName
Expand Down Expand Up @@ -634,7 +636,6 @@ def being_cloned_from
def build_clone
Competition.new(attributes.slice(*CLONEABLE_ATTRIBUTES)).tap do |clone|
clone.being_cloned_from_id = id
clone.registration_version = :v2

Competition.reflections.each_key do |association_name|
case association_name
Expand Down Expand Up @@ -741,11 +742,11 @@ def trainee_delegate_ids
end

def enable_v2_registrations!
update_column :registration_version, :v2
update_column :registration_version, NEW_REG_SYSTEM_DEFAULT
end

def uses_new_registration_service?
self.registration_version_v2?
self.registration_version_v2? || self.registration_version_v3?
end

def should_render_register_v2?(user)
Expand Down Expand Up @@ -2409,7 +2410,7 @@ def to_form_data
"admin" => {
"isConfirmed" => confirmed?,
"isVisible" => showAtAll?,
"registrationVersion" => registration_version.to_s,
"usesNewRegistrationSystem" => uses_new_registration_service?,
},
"cloning" => {
"fromId" => being_cloned_from_id,
Expand Down Expand Up @@ -2616,7 +2617,7 @@ def self.form_data_to_attributes(form_data)
showAtAll: form_data.dig('admin', 'isVisible'),
being_cloned_from_id: form_data.dig('cloning', 'fromId'),
clone_tabs: form_data.dig('cloning', 'cloneTabs'),
registration_version: form_data.dig('admin', 'registrationVersion'),
registration_version: form_data.dig('admin', 'usesNewRegistrationSystem') ? NEW_REG_SYSTEM_DEFAULT : :v1,
}
end

Expand Down Expand Up @@ -2848,7 +2849,7 @@ def self.form_data_json_schema
"properties" => {
"isConfirmed" => { "type" => "boolean" },
"isVisible" => { "type" => "boolean" },
"usesV2Registrations" => { "type" => "boolean" },
"usesNewRegistrationSystem" => { "type" => "boolean" },
},
},
"cloning" => {
Expand Down
12 changes: 2 additions & 10 deletions app/webpacker/components/CompetitionForm/FormSections/Admin.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import React from 'react';
import { InputBoolean, InputSelect } from '../../wca/FormBuilder/input/FormInputs';
import { InputBoolean } from '../../wca/FormBuilder/input/FormInputs';
import { useStore } from '../../../lib/providers/StoreProvider';
import SubSection from '../../wca/FormBuilder/SubSection';
import { useFormObject } from '../../wca/FormBuilder/provider/FormObjectProvider';

const registrationVersions = [{
key: 'v1', value: 'v1', text: 'Version 1',
}, {
key: 'v2', value: 'v2', text: 'Version 2',
}];

export default function Admin() {
const { isAdminView, isPersisted, canChangeRegistrationSystem } = useStore();
const { admin: { registrationVersion } } = useFormObject();
if (!isPersisted || !isAdminView) return null;

return (
<SubSection section="admin">
<InputBoolean id="isConfirmed" />
<InputBoolean id="isVisible" />
<InputSelect id="registrationVersion" options={registrationVersions} value={registrationVersions.find((x) => x.value === registrationVersion)} disabled={!canChangeRegistrationSystem} />
<InputBoolean id="usesNewRegistrationSystem" disabled={!canChangeRegistrationSystem} />
</SubSection>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function EventRestrictions() {
eventLimitation,
},
admin: {
usesV2Registrations,
usesNewRegistrationSystem,
},
} = useFormObject();

Expand All @@ -52,7 +52,7 @@ export default function EventRestrictions() {

return (
<SubSection section="eventRestrictions">
{ usesV2Registrations && (
{ usesNewRegistrationSystem && (
<SubSection section="forbidNewcomers">
<InputBoolean id="enabled" />
<ConditionalSection showIf={newcomers}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { useFormObject } from '../../wca/FormBuilder/provider/FormObjectProvider
export default function NameDetails() {
const { hasAnyRegistrations, isPersisted, isAdminView } = useStore();

const { name, admin: { usesV2Registrations } } = useFormObject();
const { name, admin: { usesNewRegistrationSystem } } = useFormObject();

const nameAlreadyShort = !name || name.length <= competitionMaxShortNameLength;
const disableIdAndShortName = !isAdminView && nameAlreadyShort;

// ID change on V1 is always possible, because we have control over the Foreign Keys.
// Otherwise, only competitions without registrations can change their ID.
const regSystemSupportsIdChange = !usesV2Registrations || !hasAnyRegistrations;
const regSystemSupportsIdChange = !usesNewRegistrationSystem || !hasAnyRegistrations;

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ en:
admin:
is_confirmed: "Do not let organizers edit this competition"
is_visible: "Make competition visible to the public"
registration_version: "Which registration service version is used"
uses_new_registrations: "Use the new Registration System"
competition_id: "ID"
name: "Name"
short_name: "Competition short name"
Expand Down Expand Up @@ -1700,7 +1700,7 @@ en:
admin:
is_confirmed: ""
is_visible: ""
registration_version: "If this is disabled, changing the registration system will cause technical issues. Please contact WST for assistance if you still need to change the registration system."
uses_new_registrations: "If this is disabled, changing the registration system will cause technical issues. Please contact WST for assistance if you still need to change the registration system."
competition_id: ""
name: "The full name of the competition including the year at the end (e.g., Danish Open 2016). Be sure to capitalize. The name must contain only alphanumeric characters, dashes(-), ampersands(&), periods(.), colons(:), apostrophes('), and spaces( )."
short_name: "A short name for displaying. If the name of the competition is below %{short_name_limit} characters this should not be edited and should be the same as the normal name."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def up
add_column :Competitions, :registration_version, :integer, default: 0, null: false

# Update values based on the old boolean column
Competition.where(uses_v2_registrations: true).update_all(registration_version: 1)
Competition.where(uses_v2_registrations: true).update_all(registration_version: Competition.registration_versions[:v2])

# Remove the old column
remove_column :Competitions, :uses_v2_registrations
Expand All @@ -16,7 +16,7 @@ def down
add_column :Competitions, :uses_v2_registrations, :boolean, default: false, null: false

# Map back enum values to the boolean
Competition.where(registration_version: 1).update_all(uses_v2_registrations: true)
Competition.where(registration_version: Competition.registration_versions[:v2]).update_all(uses_v2_registrations: true)

# Remove the enum column and rename the boolean column back
remove_column :Competitions, :registration_version
Expand Down

0 comments on commit 8cb5407

Please sign in to comment.