From 28e4ff8957170c61f5cd0b7e7ab4f8e40e1afc80 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 21 Feb 2009 19:22:31 +0000 Subject: Merged r2426 and r2484 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.8-stable@2512 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/users_controller.rb | 6 +++++- app/models/mail_handler.rb | 15 +++++++++++---- app/models/mailer.rb | 9 +++++++++ app/views/mailer/account_activated.text.html.rhtml | 2 ++ app/views/mailer/account_activated.text.plain.rhtml | 2 ++ doc/CHANGELOG | 6 ++++++ test/functional/users_controller_test.rb | 16 ++++++++++++++++ test/unit/mail_handler_test.rb | 5 +++++ 8 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 app/views/mailer/account_activated.text.html.rhtml create mode 100644 app/views/mailer/account_activated.text.plain.rhtml diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4c9302824..7d0550aca 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/mail_handler.rb b/app/models/mail_handler.rb index 402c46127..cc016502e 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -163,10 +163,17 @@ class MailHandler < ActionMailer::Base end def get_keyword(attr, options={}) - if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i - $1.strip - elsif !@@handler_options[:issue][attr].blank? - @@handler_options[:issue][attr] + @keywords ||= {} + if @keywords.has_key?(attr) + @keywords[attr] + else + @keywords[attr] = begin + if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr}:[ \t]*(.+)\s*$/i, '') + $1.strip + elsif !@@handler_options[:issue][attr].blank? + @@handler_options[:issue][attr] + end + end end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 9a0f3a501..d52199092 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -127,6 +127,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 000000000..6dc952238 --- /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 000000000..4dac4fb80 --- /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/doc/CHANGELOG b/doc/CHANGELOG index b1b3e39a3..7b94aa9d3 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -5,6 +5,12 @@ Copyright (C) 2006-2009 Jean-Philippe Lang http://www.redmine.org/ +== 2009-xx-xx v0.8.2 + +* Send an email to the user when an administrator activates a registered user +* Strip keywords from received email body + + == 2009-02-15 v0.8.1 * Select watchers on new issue form diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index c774c164c..e4fafe9c4 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -64,6 +64,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 post :destroy_membership, :id => 2, :membership_id => 1 assert_redirected_to 'users/edit/2' diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 0df64425b..02f823d6b 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -47,7 +47,11 @@ class MailHandlerTest < Test::Unit::TestCase assert_equal 'New ticket on a given project', issue.subject assert_equal User.find_by_login('jsmith'), issue.author assert_equal Project.find(2), issue.project + assert_equal IssueStatus.find_by_name('Resolved'), issue.status assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') + # keywords should be removed from the email body + assert !issue.description.match(/^Project:/i) + assert !issue.description.match(/^Status:/i) end def test_add_issue_with_status @@ -111,6 +115,7 @@ class MailHandlerTest < Test::Unit::TestCase issue.reload assert_equal 'New ticket with custom field values', issue.subject assert_equal 'Value for a custom field', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value + assert !issue.description.match(/^searchable field:/i) end def test_add_issue_with_cc -- cgit v1.2.3