diff --git a/app/controllers/sac_cas/event/register_controller.rb b/app/controllers/sac_cas/event/register_controller.rb new file mode 100644 index 000000000..81d9597d3 --- /dev/null +++ b/app/controllers/sac_cas/event/register_controller.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Copyright (c) 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 + +module SacCas::Event::RegisterController + def save_entry + if super + person.send_reset_password_instructions + end + end +end diff --git a/lib/hitobito_sac_cas/wagon.rb b/lib/hitobito_sac_cas/wagon.rb index 769704587..3b75d6755 100644 --- a/lib/hitobito_sac_cas/wagon.rb +++ b/lib/hitobito_sac_cas/wagon.rb @@ -156,6 +156,7 @@ class Wagon < Rails::Engine Event::KindsController.prepend SacCas::Event::KindsController Event::KindCategoriesController.prepend SacCas::Event::KindCategoriesController Event::ParticipationsController.prepend SacCas::Event::ParticipationsController + Event::RegisterController.prepend SacCas::Event::RegisterController Event::RolesController.prepend SacCas::Event::RolesController GroupsController.permitted_attrs << :mitglied_termination_by_section_only GroupsController.permitted_attrs << {section_offering_ids: []} diff --git a/spec/controllers/event/register_controller_spec.rb b/spec/controllers/event/register_controller_spec.rb new file mode 100644 index 000000000..220bf87bd --- /dev/null +++ b/spec/controllers/event/register_controller_spec.rb @@ -0,0 +1,55 @@ +# Copyright (c) 2024, Schweizer Alpen-Club. 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. + +require "spec_helper" + +describe Event::RegisterController do + include ActiveJob::TestHelper + + let(:event) do + events(:top_event).tap do |e| + e.update_column(:external_applications, true) + end + end + let(:group) { event.groups.first } + + let(:attrs) { + { + first_name: "Max", + last_name: "Muster", + street: "Musterplatz", + housenumber: "23", + email: "max.muster@example.com", + zip_code: "8000", + town: "Zürich", + country: "CH", + birthday: "01.01.1980", + phone_numbers_attributes: { + "0": { + number: "+41 79 123 45 56", + public: true, + translated_label: "Mobile" + } + } + }.with_indifferent_access + } + + context "PUT register" do + context "with valid data" do + it "creates person and sends password reset instructions" do + event.update!(required_contact_attrs: []) + + expect(Devise::Mailer).to receive(:reset_password_instructions).and_call_original + + expect do + put :register, params: {group_id: group.id, id: event.id, event_participation_contact_data: attrs} + end.to change { Person.count }.by(1) + + is_expected.to redirect_to(new_group_event_participation_path(group, event)) + expect(flash[:notice]).to include "Deine persönlichen Daten wurden aufgenommen. Bitte ergänze nun noch die Angaben" + end + end + end +end