From 01a07a5077ad5a9a7e330bb4b10abc351da705d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Mon, 10 Feb 2025 15:58:01 +0100 Subject: [PATCH 1/4] Add useful error message in application market controller (#367) --- .../event/application_market_controller.rb | 8 ++++ ..._s_data_sharing_not_accepted_error.js.haml | 6 +++ config/locales/views.pbs.de.yml | 2 + .../application_market_controller_spec.rb | 40 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 app/views/event/application_market/j_s_data_sharing_not_accepted_error.js.haml create mode 100644 spec/features/application_market_controller_spec.rb diff --git a/app/controllers/pbs/event/application_market_controller.rb b/app/controllers/pbs/event/application_market_controller.rb index 392b39860..4cdfd156e 100644 --- a/app/controllers/pbs/event/application_market_controller.rb +++ b/app/controllers/pbs/event/application_market_controller.rb @@ -9,6 +9,14 @@ module Pbs::Event::ApplicationMarketController included do alias_method_chain :put_on_waiting_list, :setter alias_method_chain :remove_from_waiting_list, :setter + + def assigner_add_participant + if event.j_s_data_sharing_acceptance_required? && participation.j_s_data_sharing_accepted_at.nil? + render "j_s_data_sharing_not_accepted_error", status: :unprocessable_entity + else + assigner.add_participant + end + end end def remove_from_waiting_list_with_setter diff --git a/app/views/event/application_market/j_s_data_sharing_not_accepted_error.js.haml b/app/views/event/application_market/j_s_data_sharing_not_accepted_error.js.haml new file mode 100644 index 000000000..d4484a37d --- /dev/null +++ b/app/views/event/application_market/j_s_data_sharing_not_accepted_error.js.haml @@ -0,0 +1,6 @@ +-# Copyright (c) 2012-2025, Jungwacht Blauring Schweiz. This file is part of +-# hitobito 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. + +alert('#{t(:"event.application_market.j_s_data_sharing_not_accepted")}'); diff --git a/config/locales/views.pbs.de.yml b/config/locales/views.pbs.de.yml index 15d7cfaa7..cb20a84ca 100644 --- a/config/locales/views.pbs.de.yml +++ b/config/locales/views.pbs.de.yml @@ -77,6 +77,8 @@ de: coach_title: 8. Coach event: + application_market: + j_s_data_sharing_not_accepted: Diese Person hat bei der Anmledung für den anderen Kurs die J+S Datenweitergabe nicht akzeptiert, dieser ist für diesen Kurs Pflicht, die Anmeldung ist daher leider nicht möglich. attendances: index: info: Erfasse hier die Anzahl BSV-Tage für jede Person. diff --git a/spec/features/application_market_controller_spec.rb b/spec/features/application_market_controller_spec.rb new file mode 100644 index 000000000..8cc0e77c8 --- /dev/null +++ b/spec/features/application_market_controller_spec.rb @@ -0,0 +1,40 @@ +# Copyright (c) 2019-2025 Pfadibewegung Schweiz. This file is part of +# hitobito_pbs 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_pbs. + +require "spec_helper" + +describe Event::ApplicationMarketController, js: true do + let(:event) { Fabricate(:course, kind: event_kinds(:lpk)) } + + let(:group) { event.groups.first } + + let(:appl_waiting) do + Fabricate(:event_participation, + application: Fabricate(:event_application, waiting_list: true, priority_1: event, priority_2: nil), + event: Fabricate(:course, kind: event_kinds(:lpk)), + person: people(:al_schekka)) + end + + before do + # init required data + appl_waiting + end + + it "displays custom error alert when person from national waiting list did not accept J&S data sharing" do + allow_any_instance_of(Event).to receive(:j_s_data_sharing_acceptance_required?).and_return(true) + sign_in(people(:bulei)) + visit group_event_application_market_index_path(group_id: group.id, event_id: event.id) + find("#waiting_list").set(true) + click_button("Aktualisieren") + expect(page).to have_text("Schekka AL") + find(".fa-arrow-left").click + sleep(3) + alert_text = page.driver.browser.switch_to.alert.text + expect(alert_text).to include( + "Diese Person hat bei der Anmledung für den anderen Kurs die J+S Datenweitergabe nicht akzeptiert, dieser ist für diesen Kurs Pflicht, " \ + "die Anmeldung ist daher leider nicht möglich." + ) + end +end From 2b00532e8a760101b0924dc682be4db14ea968ba Mon Sep 17 00:00:00 2001 From: Nils Rauch Date: Fri, 14 Feb 2025 10:58:41 +0100 Subject: [PATCH 2/4] Refactor spec --- spec/features/application_market_controller_spec.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/features/application_market_controller_spec.rb b/spec/features/application_market_controller_spec.rb index 8cc0e77c8..965cf1eec 100644 --- a/spec/features/application_market_controller_spec.rb +++ b/spec/features/application_market_controller_spec.rb @@ -10,18 +10,13 @@ let(:group) { event.groups.first } - let(:appl_waiting) do + let!(:appl_waiting) do Fabricate(:event_participation, application: Fabricate(:event_application, waiting_list: true, priority_1: event, priority_2: nil), event: Fabricate(:course, kind: event_kinds(:lpk)), person: people(:al_schekka)) end - before do - # init required data - appl_waiting - end - it "displays custom error alert when person from national waiting list did not accept J&S data sharing" do allow_any_instance_of(Event).to receive(:j_s_data_sharing_acceptance_required?).and_return(true) sign_in(people(:bulei)) From 5ee5a1434414255cfe7f5fab475711e1da80bd47 Mon Sep 17 00:00:00 2001 From: Nils Rauch Date: Fri, 14 Feb 2025 11:38:42 +0100 Subject: [PATCH 3/4] Do not respond with unprocessable_error to not confuse browser Otherwise the browser will tell the user there has been a technical error --- app/controllers/pbs/event/application_market_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/pbs/event/application_market_controller.rb b/app/controllers/pbs/event/application_market_controller.rb index 4cdfd156e..df78debde 100644 --- a/app/controllers/pbs/event/application_market_controller.rb +++ b/app/controllers/pbs/event/application_market_controller.rb @@ -12,7 +12,7 @@ module Pbs::Event::ApplicationMarketController def assigner_add_participant if event.j_s_data_sharing_acceptance_required? && participation.j_s_data_sharing_accepted_at.nil? - render "j_s_data_sharing_not_accepted_error", status: :unprocessable_entity + render "j_s_data_sharing_not_accepted_error" else assigner.add_participant end From a44037c045885c4bac1b101f8fcf36e300ab22f4 Mon Sep 17 00:00:00 2001 From: Nils Rauch Date: Fri, 14 Feb 2025 11:40:36 +0100 Subject: [PATCH 4/4] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc48964f8..0dfc012e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Hitobito PBS Changelog +## unreleased + +* Das Hinzufügen eines Teilnehmenden via nationale Warteliste, prüft neu korrekt auf die J+S Datenfreigabe und gibt eine sprechende Fehlermeldung (hitobito_pbs#367) + ## Version 2.2 * LKB/Coach in Event-Resource der API aufgenommen (hitobito_pbs#325)