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
This commit is contained in:
Jean-Philippe Lang 2009-02-21 19:22:31 +00:00
parent 3d1bd79ffb
commit 28e4ff8957
8 changed files with 56 additions and 5 deletions

View File

@ -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]))

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
<p><%= l(:notice_account_activated) %></p>
<p><%= l(:label_login) %>: <%= link_to @login_url, @login_url %></p>

View File

@ -0,0 +1,2 @@
<%= l(:notice_account_activated) %>
<%= l(:label_login) %>: <%= @login_url %>

View File

@ -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

View File

@ -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'

View File

@ -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