Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send reset instructions on external event registration #1412

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/controllers/sac_cas/event/register_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
Group::AboBasicLogin::BasicLogin.create!(group: abo_basic_login_group, person: person)
end
end

def abo_basic_login_group
Group::AboBasicLogin.where(layer_group_id: Group.root.id).first
end
end
28 changes: 15 additions & 13 deletions app/views/public_events/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
-# or later. See the COPYING file at the top-level directory or at
-# https://github.com/hitobito/hitobito.

.align-with-form
%h1=t(".login_to_participate")
%h2=t(".with_sac_account")
= render 'devise/sessions/form', autofocus_login: false
.align-with-form.mt-4
.mb-1=t(".is_sac_account_active")
= link_to t('.login_questions'), t(".link_fag_sac_account")
%div{data: { turbo: 'false'}}
.align-with-form
%h1=t(".login_to_participate")
%h2=t(".with_sac_account")

%h2.mt-5=t(".first_time_here")
.mb-2=t(".create_account_now")
= render 'event/register/email_check'
= render 'devise/sessions/form', autofocus_login: false
.align-with-form.mt-4
.mb-1=t(".is_sac_account_active")
= link_to t('.login_questions'), t(".link_fag_sac_account")

.align-with-form.mt-5
%h2=t(".wanna_be_a_member")
= link_to t('.request_sac_membership'), t(".request_sac_membership_link")
%h2.mt-5=t(".first_time_here")
.mb-2=t(".create_account_now")
= render 'event/register/email_check'

.align-with-form.mt-5
%h2=t(".wanna_be_a_member")
= link_to t('.request_sac_membership'), t(".request_sac_membership_link")
1 change: 1 addition & 0 deletions lib/hitobito_sac_cas/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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: []}
Expand Down
66 changes: 66 additions & 0 deletions spec/controllers/event/register_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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 }
before do
Group::AboBasicLogin.create!(
parent: groups(:abos),
self_registration_role_type: "Group::AboBasicLogin::BasicLogin"
)
end
rnestler marked this conversation as resolved.
Show resolved Hide resolved

let(:attrs) {
{
first_name: "Max",
last_name: "Muster",
street: "Musterplatz",
housenumber: "23",
email: "[email protected]",
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
}

describe "PUT register" do
context "with valid data" do
it "creates person and sends password reset instructions" do
event.update!(required_contact_attrs: [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this in the let binding above.


expect(Devise::Mailer).to receive(:reset_password_instructions).and_call_original
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(Devise::Mailer).to receive(:reset_password_instructions).and_call_original

See suggestion about have_enqueud_mail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enqueued email klappt imho nicht, weil devise das direkt und nicht background job verschickt


expect do
put :register, params: {group_id: group.id, id: event.id, event_participation_contact_data: attrs}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a put and not a post?

end.to change { Person.count }.by(1)
.and change { Group::AboBasicLogin::BasicLogin.count }.by(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.and change { Group::AboBasicLogin::BasicLogin.count }.by(1)
.and change { Group::AboBasicLogin::BasicLogin.count }.by(1)
.and have_enqueued_mail(Devise::Mailer, :reset_password_instructions)

There's also an event confirmation email that is sent, right?


person = Person.find_by(email: "[email protected]")

expect(person.roles.size).to eq(1)
expect(person.roles.first.type).to eq(Group::AboBasicLogin::BasicLogin.sti_name)
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the ticket "Newsletter (sollten schon passen)"

Can we add an expect for this?

end
end
end
Loading