Skip to content

Commit

Permalink
Distinguish between V1 and V2 competitions for Competition ID changes (
Browse files Browse the repository at this point in the history
…#10092)

* Read V2 registration usage from form state

* Allow pre-registrations for V1 or otherwise for announced comps only

* Disable frontend ID change based on V1 or V2 status
  • Loading branch information
gregorbg authored Oct 21, 2024
1 parent 218003a commit 4342388
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
9 changes: 8 additions & 1 deletion app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,14 @@ def info_for(user)
end

def user_can_pre_register?(user)
(delegates.include?(user) || trainee_delegates.include?(user) || organizers.include?(user)) && self.confirmed_or_visible?
# The user has to be either a registered Delegate or organizer of the competition
is_competition_manager = delegates.include?(user) || trainee_delegates.include?(user) || organizers.include?(user)
# We allow pre-registration at any time for the old registration system (because we have control over the foreign keys there)
# Otherwise, if it's using the new system, we only allow registrations when it's announced
# because the probability of an ID change is pretty low in that case and when it does happen, WST can handle it
system_compatible = !uses_new_registration_service? || announced?

is_competition_manager && system_compatible
end

attr_accessor :being_cloned_from_id
Expand Down
1 change: 0 additions & 1 deletion app/views/competitions/_competition_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<%= react_component("CompetitionForm", {
competition: @competition.to_form_data,
usesV2Registrations: @competition.uses_v2_registrations,
canChangeRegistrationSystem: @competition.can_change_registration_system?,
hasAnyRegistrations: @competition.any_registrations?,
storedEvents: @competition.events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useFormObject } from '../../wca/FormBuilder/provider/FormObjectProvider

export default function EventRestrictions() {
const {
usesV2Registrations,
isCloning,
isPersisted,
storedEvents,
Expand All @@ -27,6 +26,9 @@ export default function EventRestrictions() {
qualificationResults,
eventLimitation,
},
admin: {
usesV2Registrations,
},
} = useFormObject();

const mainEventOptions = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import { useFormObject } from '../../wca/FormBuilder/provider/FormObjectProvider
export default function NameDetails() {
const { hasAnyRegistrations, isPersisted, isAdminView } = useStore();

const { name } = useFormObject();
const { name, admin: { usesV2Registrations } } = 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;

return (
<>
{isPersisted && <InputString id="competitionId" disabled={disableIdAndShortName || hasAnyRegistrations} />}
{isPersisted && <InputString id="competitionId" disabled={disableIdAndShortName || !regSystemSupportsIdChange} />}
<InputString id="name" required />
{isPersisted && (
<InputString
Expand Down
2 changes: 0 additions & 2 deletions app/webpacker/components/CompetitionForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function CompetitionForm() {

export default function Wrapper({
competition = null,
usesV2Registrations = false,
canChangeRegistrationSystem = false,
hasAnyRegistrations = false,
storedEvents = [],
Expand Down Expand Up @@ -104,7 +103,6 @@ export default function Wrapper({
<StoreProvider
reducer={_.identity}
initialState={{
usesV2Registrations,
canChangeRegistrationSystem,
hasAnyRegistrations,
storedEvents,
Expand Down

0 comments on commit 4342388

Please sign in to comment.