GitLab ist wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht erreichbar.

Commit 1a6feec1 authored by jplang's avatar jplang

Send an email to the user when an administrator activates a registered user (#2656).

git-svn-id: https://svn.redmine.org/redmine/trunk@2484 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 3964a90f
......@@ -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]))
......
......@@ -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
......
<p><%= l(:notice_account_activated) %></p>
<p><%= l(:label_login) %>: <%= link_to @login_url, @login_url %></p>
<%= l(:notice_account_activated) %>
<%= l(:label_login) %>: <%= @login_url %>
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment