Skip to content

Commit

Permalink
Add automatic assignment to events, refs: #358
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWalkingLeek committed Apr 29, 2024
1 parent 4d57825 commit c7afb01
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/controllers/event/participations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def init_answers
end

def directly_assign_place?
event.places_available? && !(event.attr_used?(:priorization) && event.priorization)
event.places_available? &&
(event.attr_used?(:automatic_assignment) && event.automatic_assignment?)
end

def directly_assign_place
Expand Down
3 changes: 2 additions & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class Event < ActiveRecord::Base # rubocop:disable Metrics/ClassLength:
:external_applications, :applications_cancelable,
:signature, :signature_confirmation, :signature_confirmation_text,
:required_contact_attrs, :hidden_contact_attrs,
:participations_visible, :globally_visible]
:participations_visible, :globally_visible,
:minimum_participants, :automatic_assignment]

# All participation roles that exist for this event
# Customize in wagons using .register_role_type / .disable_role_type
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_application_fields.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
= field_set_tag do
= f.labeled_input_fields(*entry.used_attributes(:application_opening_at, :application_closing_at, :application_conditions, :maximum_participants, :minimum_participants))
= f.labeled_input_fields(*entry.used_attributes(:application_opening_at, :application_closing_at, :application_conditions, :maximum_participants, :minimum_participants, :automatic_assignment))

- entry.used?(:external_applications) do
= f.labeled_boolean_field(:external_applications, caption: t('events.form.caption_external_applications'))
Expand Down
4 changes: 4 additions & 0 deletions app/views/events/_attrs_application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
= present_labeled_attr(entry, :application_opening_at)
- entry.used?(:application_closing_at) do
= present_labeled_attr(entry, :application_closing_at)
- entry.used?(:application_closing_at) do
= present_labeled_attr(entry, :application_closing_at)
- entry.used?(:minimum_participants) do
= present_labeled_attr(entry, :minimum_participants)
= labeled_attr(entry, :booking_info)
- entry.used?(:external_applications) do
= labeled(Event.human_attribute_name(:external_applications), entry.external_application_link(@group))
Expand Down
3 changes: 2 additions & 1 deletion config/locales/models.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,10 @@ de:
applications_cancelable: Abmeldung möglich
display_booking_info: Anzeige Anmeldestand
participations_visible: Teilnehmersichtbarkeit
waiting_list: Warteliste
waiting_list: Nationale Warteliste
requires_approval: Empfehlung nötig
globally_visible: Sichtbarkeit
automatic_assignment: Automatische Zuteilung

event/contact_attrs:
required: Obligatorisch
Expand Down
2 changes: 1 addition & 1 deletion config/locales/views.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ de:
waiting_list_link:
title_active: "Entfernen von der Warteliste"
title_inactive: "Hinzufügen zur Warteliste"
label: "Warteliste"
label: "nationale Warteliste"
popover_waiting_list:
waiting_list_info: Setze diese Person auf die Warteliste für Kurse der Art %{event_kind}.

Expand Down
23 changes: 23 additions & 0 deletions db/migrate/20240423133607_add_automatic_assignment_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# Copyright (c) 2012-2024, Schweizer Alpen-Club. This file is part of
# hitobito_sac_cas and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_sac_cas.

class AddAutomaticAssignmentToEvents < ActiveRecord::Migration[6.1]
def up
add_column :events, :automatic_assignment, :boolean, null: false, default: false

Event.where(type: event_types_using_priorization, priorization: false)
.update_all(automatic_assignment: true)
end

def down
remove_column :events, :automatic_assignment
end

def event_types_using_priorization
Event.all_types.select { |e| e.attr_used?(:priorization) }
end
end
2 changes: 1 addition & 1 deletion spec/controllers/event/participations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def update_person(participation, attrs)
end

it 'without waiting list directly assigns place and creates confirmation' do
course.update!(waiting_list: false, maximum_participants: 2, participant_count: 1, priorization: false)
course.update!(waiting_list: false, maximum_participants: 2, participant_count: 1, automatic_assignment: true)

expect do
post :create, params: { group_id: group.id, event_id: course.id, event_participation: {} }
Expand Down

0 comments on commit c7afb01

Please sign in to comment.