Commit 8e0a2ff2 authored by Zsolt Benke's avatar Zsolt Benke
Browse files

Imported volunteers can be reinvited via edit form

parent 8d981414
Pipeline #21180 passed with stage
in 41 minutes and 16 seconds
......@@ -99,6 +99,7 @@ class VolunteersController < ApplicationController
def account
@volunteer.contact.primary_email = volunteer_params[:contact_attributes][:primary_email]
if @volunteer.save && @volunteer.user&.invited_to_sign_up?
@volunteer.invite_user if needs_reinvite?
redirect_back(fallback_location: edit_volunteer_path(@volunteer),
notice: 'Freiwillige/r erhält eine Accountaktivierungs-Email.')
elsif @volunteer.contact.errors.messages[:primary_email]
......@@ -143,4 +144,8 @@ class VolunteersController < ApplicationController
def volunteer_params
params.require(:volunteer).permit policy(Volunteer).permitted_attributes
end
def needs_reinvite?
params[:reinvite].presence == 'true'
end
end
......@@ -383,7 +383,7 @@ class Volunteer < ApplicationRecord
internal? && user.present?
end
def reinvite_user
def invite_user
user.invite! if invitable?
end
......@@ -425,7 +425,7 @@ class Volunteer < ApplicationRecord
#
# note: we used to ask here for user.invited_to_sign_up? instaed of user.invitation_sent_at.blank but
# it lead to emails sent out twice to users that already set their password
reinvite_user unless user&.invitation_sent_at.blank?
invite_user if user&.invitation_sent_at.blank?
end
def user_deleted?
......
......@@ -2,7 +2,7 @@ h2.small Importiert
p.text-warning Dieses Freiwilligenprofil wurde von Access importiert.
- if volunteer.user
p.text-warning Ein Useraccount wurde bereits erstellt.
- elsif !volunteer.user && volunteer.accepted?
- if !volunteer.user && volunteer.accepted? || (volunteer.user && !volunteer.user.invitation_accepted?)
h3.small User Account erstellen
- if volunteer.import.email_valid?
p Für die Emailadresse #{mail_to "#{volunteer.import.email}", volunteer.import.email} einen Account erstellen
......@@ -15,6 +15,8 @@ p.text-warning Dieses Freiwilligenprofil wurde von Access importiert.
= simple_form_for(volunteer, url: account_volunteer_path(volunteer), method: :put) do |f|
.row
= f.simple_fields_for(:contact) do |c|
- if volunteer.user&.invited_to_sign_up? && !volunteer.user&.invitation_accepted?
= hidden_field_tag :reinvite, true, id: 'reinvite_field'
.form-group.col-xs-12.col-md-4
= c.label :primary_email
= c.input_field :primary_email, value: volunteer.import.email_valid? ? volunteer.import.email : '',
......
......@@ -183,7 +183,7 @@ class VolunteerTest < ActiveSupport::TestCase
assert volunteer.invitable?
assert_nil volunteer.user.invitation_accepted_at
volunteer.reinvite_user
volunteer.invite_user
assert volunteer.user.invited_to_sign_up?
assert_not_equal invitation_token, volunteer.user.invitation_token
assert_not_equal invitation_sent_at, volunteer.user.invitation_sent_at
......
......@@ -295,6 +295,51 @@ class VolunteersTest < ApplicationSystemTestCase
end
end
test 'imported volunteer can be invited more than once' do
use_rack_driver
really_destroy_with_deleted(Volunteer)
volunteer = create :volunteer
volunteer.user.really_destroy!
import = Import.create(base_origin_entity: 'tbl_Personenrollen', access_id: 1,
importable: volunteer, store: { haupt_person: { email: 'imported@example.com' } })
assert_equal 1, ActionMailer::Base.deliveries.size
visit volunteers_path
assert page.has_text? 'Kein Login'
assert page.has_text? 'Importiert'
click_link 'Anzeigen', href: volunteer_path(volunteer)
assert page.has_text? 'User Account erstellen'
assert page.has_text? "Für die Emailadresse #{import.email} einen Account erstellen"
assert page.has_field? 'Mailadresse', with: import.email
refute page.has_css? '#reinvite_field', visible: false
# invite volunteer for the first time
click_button 'Einladung an angegebene E-Mail verschicken'
assert page.has_text? 'User Account erstellen'
assert page.has_text? 'Freiwillige/r erhält eine Accountaktivierungs-Email.'
assert page.has_text? "Für die Emailadresse #{import.email} einen Account erstellen"
assert page.has_field? 'Mailadresse', with: import.email
assert page.has_css? '#reinvite_field', visible: false
assert_equal 2, ActionMailer::Base.deliveries.size
# invite volunteer second time
click_button 'Einladung an angegebene E-Mail verschicken'
assert page.has_text? 'User Account erstellen'
assert page.has_text? 'Freiwillige/r erhält eine Accountaktivierungs-Email.'
assert page.has_text? "Für die Emailadresse #{import.email} einen Account erstellen"
assert page.has_field? 'Mailadresse', with: import.email
assert page.has_css? '#reinvite_field', visible: false
assert_equal 3, ActionMailer::Base.deliveries.size
# manually accept volunteer's user
volunteer.reload.user.update(invitation_accepted_at: Time.now)
visit edit_volunteer_path(volunteer)
refute page.has_text? 'User Account erstellen'
refute page.has_text? "Für die Emailadresse #{import.email} einen Account erstellen"
refute page.has_css? '#reinvite_field', visible: false
end
test 'not resigned volunteer can not be terminated via acceptance select in edit' do
@undecided = create :volunteer, acceptance: :undecided
@invited = create :volunteer, acceptance: :invited
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment