Commit 6dbf566129baedfd5d79046eb79b3e34dc840a7f
1 parent
18665da3
Exists in
merge_deactive_and_ban
deactive_and_active_profile: Send reason in email to deactivate profile
(ActionItem3287) Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Showing
5 changed files
with
79 additions
and
12 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -81,9 +81,12 @@ class ProfileEditorController < MyProfileController |
81 | 81 | |
82 | 82 | def deactivate_profile |
83 | 83 | if environment.admins.include?(current_person) |
84 | - profile = Profile.find(params[:id]) | |
84 | + person = Person.find(params[:id]) | |
85 | 85 | |
86 | - if profile.disable | |
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 | |
87 | 90 | session[:notice] = _("The profile '#{profile.name}' was disabled.") |
88 | 91 | else |
89 | 92 | session[:notice] = _('Could not disable profile.') |
... | ... | @@ -95,9 +98,9 @@ class ProfileEditorController < MyProfileController |
95 | 98 | |
96 | 99 | def activate_profile |
97 | 100 | if environment.admins.include?(current_person) |
98 | - profile = Profile.find(params[:id]) | |
101 | + person = Person.find(params[:id]) | |
99 | 102 | |
100 | - if profile.enable | |
103 | + if person.user.activate | |
101 | 104 | session[:notice] = _("The profile '#{profile.name}' was activated.") |
102 | 105 | else |
103 | 106 | session[:notice] = _('Could not activate the profile.') | ... | ... |
app/mailers/user_mailer.rb
... | ... | @@ -41,6 +41,21 @@ 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 } | |
46 | + @reason = reason | |
47 | + @recipient = user.name | |
48 | + @name = user.name | |
49 | + @email = user.email | |
50 | + @environment = user.environment.name | |
51 | + @url = url_for(:host => user.environment.default_hostname, :controller => 'home') | |
52 | + mail( | |
53 | + to: user.email, | |
54 | + from: "#{user.environment.name} <#{user.environment.contact_email}>", | |
55 | + subject: _(subject) % { :environment => user.environment.name } | |
56 | + ) | |
57 | + end | |
58 | + | |
44 | 59 | class Job < Struct.new(:user, :method) |
45 | 60 | def perform |
46 | 61 | UserMailer.send(method, user).deliver | ... | ... |
app/views/profile_editor/edit.html.erb
... | ... | @@ -82,11 +82,39 @@ |
82 | 82 | |
83 | 83 | <% end %> |
84 | 84 | |
85 | + | |
85 | 86 | <div class='deactivate-profile hidden'> |
86 | - <%= label_tag 'reason', _("Reason to deactivate profile:")%><br /> | |
87 | - <%= text_area_tag('profile_data[reason_to_deactivate]', nil, :class=>"expand-field") %> | |
88 | - <% button_bar(:id => 'deactivate-profile') do %> | |
89 | - <%= button(:remove, _('Confirm Deactivation'), {:action => :deactivate_profile, :id=>profile.id, :reason=>@profile.reason_to_deactivate}, :id=>'confirm_deactivation_button') %> | |
90 | - <%= button(:cancel, _('Cancel'), nil, :id=>'cancel_deactivation_button') %> | |
91 | - <% end %> | |
92 | - </div> | |
87 | + <input type="text" class="hidden" id="profile-id" value="<%= profile.id %>"> | |
88 | + <%= label_tag 'reason', _("Reason to deactivate profile:")%><br /> | |
89 | + <%= text_area_tag(:reason, nil, :class=>"expand-field", :id => "reason-field") %> | |
90 | + <% button_bar(:id => 'deactivate-profile') do %> | |
91 | + <%= button(:remove, _('Confirm Deactivation'), nil, :id=>'confirm_deactivation_button') %> | |
92 | + <%= button(:cancel, _('Cancel'), nil, :id=>'cancel_deactivation_button') %> | |
93 | + <% end %> | |
94 | +</div> | |
95 | + | |
96 | + | |
97 | +<script type="text/javascript"> | |
98 | + function call_deactivate_profile(event){ | |
99 | + event.preventDefault(); | |
100 | + var reason_field = jQuery("#reason-field").val(); | |
101 | + var profile_id = jQuery("#profile-id").val(); | |
102 | + if (confirm('<%= _("Are you sure ?") %>')) { | |
103 | + jQuery.ajax({ | |
104 | + type: "POST", | |
105 | + url: "<%= url_for :controller=>'profile_editor', :action=>'deactivate_profile' %>", | |
106 | + data: { | |
107 | + reason:reason_field, | |
108 | + id:profile_id | |
109 | + }, | |
110 | + success : function(data) { | |
111 | + location.reload(); //reload the page on the success | |
112 | + } | |
113 | + }); | |
114 | + } | |
115 | + } | |
116 | + | |
117 | + jQuery(document).ready(function(){ | |
118 | + jQuery("#confirm_deactivation_button").click(call_deactivate_profile); | |
119 | + }); | |
120 | +</script> | ... | ... |
app/views/user_mailer/ban_user_mail_with_reason.text.erb
0 → 100644
... | ... | @@ -0,0 +1,13 @@ |
1 | +<%= _('Hello %s,') % @name %> | |
2 | + | |
3 | +<%= _('Your email %s was just deactivated.') % [@email] %> | |
4 | + | |
5 | +<%= _('For the following reason:') %> | |
6 | +<%= _('%s') % @reason %> | |
7 | +<%= @webmail %> | |
8 | + | |
9 | +<%= _('Greetings,') %> | |
10 | + | |
11 | +-- | |
12 | +<%= _('%s team.') % @environment %> | |
13 | +<%= @url %> | ... | ... |
public/javascripts/deactivate_profile.js
... | ... | @@ -4,6 +4,14 @@ function show_reason_fields(event){ |
4 | 4 | jQuery(".deactivate-profile").switchClass("hidden", "show"); |
5 | 5 | } |
6 | 6 | |
7 | +function hide_reason_fields(event){ | |
8 | + event.preventDefault(); | |
9 | + jQuery(".deactivate-profile").hide(); | |
10 | + jQuery(".deactivate-profile").switchClass("show", "hidden"); | |
11 | +} | |
12 | + | |
7 | 13 | jQuery(document).ready(function(){ |
8 | 14 | jQuery("#deactivate_profile_button").click(show_reason_fields); |
9 | -}); | |
10 | 15 | \ No newline at end of file |
16 | + jQuery("#cancel_deactivation_button").click(hide_reason_fields); | |
17 | + // jQuery("#confirm_deactivation_button").click(call_deactivate_profile); | |
18 | +}); | ... | ... |