Commit cbdd6f8885fb7cb9a1e77651eed7d84a130d43d6
Committed by
Luciano Prestes
1 parent
64768cd4
Exists in
merge_deactive_and_ban
deactive_and_active_profile: Send email to both person and organization
(ActionItem3287) Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
3 changed files
with
27 additions
and
11 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -81,12 +81,16 @@ class ProfileEditorController < MyProfileController |
81 | 81 | |
82 | 82 | def deactivate_profile |
83 | 83 | if environment.admins.include?(current_person) |
84 | - person = Person.find(params[:id]) | |
84 | + profile = environment.profiles.find(params[:id]) | |
85 | 85 | |
86 | - if person.user.deactivate | |
87 | - person.reason_to_deactivate = [params[:reason]] | |
88 | - person.save | |
89 | - UserMailer.ban_user_mail_with_reason(profile.user, params[:reason]).deliver | |
86 | + if profile.disable | |
87 | + profile.reason_to_deactivate = [params[:reason]] | |
88 | + profile.save | |
89 | + | |
90 | + users = get_users_to_send_mail(profile) | |
91 | + users.each do |u| | |
92 | + UserMailer.ban_user_mail_with_reason(u, params[:reason], profile).deliver | |
93 | + end | |
90 | 94 | session[:notice] = _("The profile '#{profile.name}' was disabled.") |
91 | 95 | else |
92 | 96 | session[:notice] = _('Could not disable profile.') |
... | ... | @@ -98,9 +102,9 @@ class ProfileEditorController < MyProfileController |
98 | 102 | |
99 | 103 | def activate_profile |
100 | 104 | if environment.admins.include?(current_person) |
101 | - person = Person.find(params[:id]) | |
105 | + profile = environment.profiles.find(params[:id]) | |
102 | 106 | |
103 | - if person.user.activate | |
107 | + if profile.enable | |
104 | 108 | session[:notice] = _("The profile '#{profile.name}' was activated.") |
105 | 109 | else |
106 | 110 | session[:notice] = _('Could not activate the profile.') |
... | ... | @@ -118,4 +122,16 @@ class ProfileEditorController < MyProfileController |
118 | 122 | |
119 | 123 | redirect_to back |
120 | 124 | end |
125 | + | |
126 | + def get_users_to_send_mail profile | |
127 | + users = [] | |
128 | + if profile.organization? | |
129 | + profile.admins.each do |person| | |
130 | + users << person.user | |
131 | + end | |
132 | + elsif profile.person? | |
133 | + users << profile.user | |
134 | + end | |
135 | + users | |
136 | + end | |
121 | 137 | end | ... | ... |
app/mailers/user_mailer.rb
... | ... | @@ -41,12 +41,12 @@ class UserMailer < ActionMailer::Base |
41 | 41 | ) |
42 | 42 | end |
43 | 43 | |
44 | - def ban_user_mail_with_reason(user, reason) | |
45 | - subject = _("[%{environment}] User deactivated") % { :environment => user.environment.name } | |
44 | + def ban_user_mail_with_reason(user, reason, deactivated_profile) | |
45 | + subject = _("[%{environment}] Profile deactivated") % { :environment => user.environment.name } | |
46 | 46 | @reason = reason |
47 | 47 | @recipient = user.name |
48 | 48 | @name = user.name |
49 | - @email = user.email | |
49 | + @deactivated_name = deactivated_profile.name | |
50 | 50 | @environment = user.environment.name |
51 | 51 | @url = url_for(:host => user.environment.default_hostname, :controller => 'home') |
52 | 52 | mail( | ... | ... |
app/views/user_mailer/ban_user_mail_with_reason.text.erb