From: Jean-Philippe Lang Date: Fri, 20 Feb 2009 17:04:47 +0000 (+0000) Subject: Send an email to the user when an administrator activates a registered user (#2656). X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=04c428e059484c77dea3b7931051ba90cef38380;p=redminele%2Fredmine.git Send an email to the user when an administrator activates a registered user (#2656). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2484 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ced17d66..e0b508c7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -75,7 +75,11 @@ class UsersController < ApplicationController @user.admin = params[:user][:admin] if params[:user][:admin] @user.login = params[:user][:login] if params[:user][:login] @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id - if @user.update_attributes(params[:user]) + @user.attributes = params[:user] + # Was the account actived ? (do it before User#save clears the change) + was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) + if @user.save + Mailer.deliver_account_activated(@user) if was_activated flash[:notice] = l(:notice_successful_update) # Give a string to redirect_to otherwise it would use status param as the response code redirect_to(url_for(:action => 'list', :status => params[:status], :page => params[:page])) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index c0ff7a8c..c8deeffb 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -133,6 +133,15 @@ class Mailer < ActionMailer::Base :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') end + # A registered user's account was activated by an administrator + def account_activated(user) + set_language_if_valid user.language + recipients user.mail + subject l(:mail_subject_register, Setting.app_title) + body :user => user, + :login_url => url_for(:controller => 'account', :action => 'login') + end + def lost_password(token) set_language_if_valid(token.user.language) recipients token.user.mail diff --git a/app/views/mailer/account_activated.text.html.rhtml b/app/views/mailer/account_activated.text.html.rhtml new file mode 100644 index 00000000..6dc95223 --- /dev/null +++ b/app/views/mailer/account_activated.text.html.rhtml @@ -0,0 +1,2 @@ +

<%= l(:notice_account_activated) %>

+

<%= l(:label_login) %>: <%= link_to @login_url, @login_url %>

diff --git a/app/views/mailer/account_activated.text.plain.rhtml b/app/views/mailer/account_activated.text.plain.rhtml new file mode 100644 index 00000000..4dac4fb8 --- /dev/null +++ b/app/views/mailer/account_activated.text.plain.rhtml @@ -0,0 +1,2 @@ +<%= l(:notice_account_activated) %> +<%= l(:label_login) %>: <%= @login_url %> diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 42e69f48..5080c13b 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -126,6 +126,22 @@ class UsersControllerTest < Test::Unit::TestCase assert_equal 2, Member.find(1).role_id end + def test_edit_with_activation_should_send_a_notification + u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') + u.login = 'foo' + u.status = User::STATUS_REGISTERED + u.save! + ActionMailer::Base.deliveries.clear + Setting.bcc_recipients = '1' + + post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} + assert u.reload.active? + mail = ActionMailer::Base.deliveries.last + assert_not_nil mail + assert_equal ['foo.bar@somenet.foo'], mail.bcc + assert mail.body.include?(ll('fr', :notice_account_activated)) + end + def test_destroy_membership assert_routing( #TODO: use DELETE method on user_membership_path, modify form