Commit 1b710711 authored by Zsolt Benke's avatar Zsolt Benke
Browse files

Store new email addresses on invite

parent 0fadb297
Pipeline #21259 failed with stage
in 56 minutes and 53 seconds
......@@ -391,8 +391,19 @@ class Volunteer < ApplicationRecord
!user.present? && accepted?
end
def email_valid_for_invite?
invite_email&.match(Devise.email_regexp)
end
def invite_email
user&.email || import&.email
end
def invite_user
user.invite! if ready_for_invitation?
if ready_for_invitation?
user.update_attribute(:email, contact.primary_email)
user.invite!
end
end
private
......
......@@ -4,8 +4,8 @@ p.text-warning Dieses Freiwilligenprofil wurde von Access importiert.
p.text-warning Ein Useraccount wurde bereits erstellt.
- if volunteer.user_needed_for_invitation? || volunteer.pending_invitation?
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
- if volunteer.email_valid_for_invite?
p Für die Emailadresse #{mail_to "#{volunteer.invite_email}", volunteer.invite_email} einen Account erstellen
- elsif volunteer.import.email.present?
p.text-danger Scheinbar ist die importierte Mailadresse nicht gültig.
- else
......@@ -19,6 +19,6 @@ p.text-warning Dieses Freiwilligenprofil wurde von Access importiert.
= 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 : '',
= c.input_field :primary_email, value: volunteer.email_valid_for_invite? ? volunteer.invite_email : '',
class: 'form-control'
= f.button :submit, value: 'Einladung an angegebene E-Mail verschicken'
......@@ -302,7 +302,7 @@ class VolunteersTest < ApplicationSystemTestCase
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
ActionMailer::Base.deliveries.clear
visit volunteers_path
assert page.has_text? 'Kein Login'
......@@ -321,22 +321,46 @@ class VolunteersTest < ApplicationSystemTestCase
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
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal import.email, ActionMailer::Base.deliveries.first.to.first
assert_equal volunteer.reload.user.email, import.email
assert_equal volunteer.contact.primary_email, import.email
# invite volunteer second time
ActionMailer::Base.deliveries.clear
new_address = 'new_address@example.com'
fill_in 'Mailadresse', with: new_address
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_text? "Für die Emailadresse #{new_address} einen Account erstellen"
assert page.has_field? 'Mailadresse', with: new_address
assert page.has_css? '#reinvite_field', visible: false
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal new_address, ActionMailer::Base.deliveries.first.to.first
assert_equal volunteer.reload.user.email, new_address
assert_equal volunteer.contact.primary_email, new_address
# invite volunteer third time
ActionMailer::Base.deliveries.clear
new_address = 'new_address2@example.com'
fill_in 'Mailadresse', with: new_address
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 #{new_address} einen Account erstellen"
assert page.has_field? 'Mailadresse', with: new_address
assert page.has_css? '#reinvite_field', visible: false
assert_equal 3, ActionMailer::Base.deliveries.size
assert_equal 1, ActionMailer::Base.deliveries.size
assert_equal new_address, ActionMailer::Base.deliveries.first.to.first
assert_equal volunteer.reload.user.email, new_address
assert_equal volunteer.contact.primary_email, new_address
# 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_text? "Für die Emailadresse #{new_address} einen Account erstellen"
refute page.has_css? '#reinvite_field', visible: false
end
......
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