Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
2a53577d
Verified
Commit
2a53577d
authored
Jun 13, 2018
by
Kaspar Vollenweider
👻
Browse files
change volunteer invitation mechanism to invite imported volunteer
- imported volunteer get invitation on changed primary_email
parent
02001e8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/controllers/volunteers_controller.rb
View file @
2a53577d
...
...
@@ -98,8 +98,7 @@ class VolunteersController < ApplicationController
def
account
@volunteer
.
contact
.
primary_email
=
volunteer_params
[
:contact_attributes
][
:primary_email
]
if
@volunteer
.
save
invite_volunteer_user
if
@volunteer
.
save
&&
@volunteer
.
user
&
.
invited_to_sign_up?
redirect_back
(
fallback_location:
edit_volunteer_path
(
@volunteer
),
notice:
'Freiwillige/r erhält eine Accountaktivierungs-Email.'
)
elsif
@volunteer
.
contact
.
errors
.
messages
[
:primary_email
]
...
...
app/models/volunteer.rb
View file @
2a53577d
...
...
@@ -8,8 +8,8 @@ class Volunteer < ApplicationRecord
include
AcceptanceAttributes
before_validation
:handle_user_with_external_change
,
if: :external_changed?
before_save
:build_user_if_accepted
after_save
:invite_user_if_
accep
ted
before_save
:build_user_if_accepted
_or_import_invited
after_save
:invite_user_if_
not_invi
ted
SINGLE_ACCOMPANIMENTS
=
[
:man
,
:woman
,
:family
,
:kid
,
:teenager
,
:unaccompanied
].
freeze
REJECTIONS
=
[
:us
,
:her
,
:other
].
freeze
...
...
@@ -388,18 +388,25 @@ class Volunteer < ApplicationRecord
kinds
.
uniq
end
def
build_user_if_accepted
return
if
!
will_save_change_to_attribute?
(
:acceptance
,
to:
'accepted'
)
||
external?
||
user
.
present
?
def
build_user_if_accepted
_or_import_invited
return
unless
user_invitation_needed
?
if
User
.
exists?
(
email:
contact
.
primary_email
)
return
errors
.
add
(
:user
,
"Es existiert bereits ein User mit der Email
#{
contact
.
primary_email
}
!"
)
end
self
.
user
=
User
.
new
(
email:
contact
.
primary_email
,
password:
Devise
.
friendly_token
,
role:
'volunteer'
)
end
def
invite_user_if_accepted
user
.
invite!
if
internal?
&&
saved_change_to_attribute?
(
:acceptance
,
to:
'accepted'
)
def
user_invitation_needed?
return
if
external?
||
user
.
present?
will_save_change_to_attribute?
(
:acceptance
,
to:
'accepted'
)
||
(
import
.
present?
&&
contact
.
will_save_change_to_attribute?
(
:primary_email
))
end
def
invite_user_if_not_invited
if
internal?
&&
user
.
present?
&&
!
user
.
invited_to_sign_up?
user
.
invite!
end
end
def
user_deleted?
user
&
.
deleted?
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment