Commit b9707472e879bd578c0d6425bf5c2fe4fae6e127
Committed by
Antonio Terceiro
1 parent
c281083a
Exists in
staging
and in
42 other branches
ActionItem434: must create mailbox just after enabling mail for the first time
Showing
3 changed files
with
87 additions
and
0 deletions
Show diff stats
app/models/user.rb
| @@ -29,6 +29,26 @@ class User < ActiveRecord::Base | @@ -29,6 +29,26 @@ class User < ActiveRecord::Base | ||
| 29 | user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id) | 29 | user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id) |
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | + before_update do |user| | ||
| 33 | + if !User.find(user.id).enable_email and user.enable_email and !user.environment.nil? | ||
| 34 | + User::Mailer.deliver_activation_email_notify(user) | ||
| 35 | + end | ||
| 36 | + end | ||
| 37 | + | ||
| 38 | + class Mailer < ActionMailer::Base | ||
| 39 | + def activation_email_notify(user) | ||
| 40 | + user_email = "#{user.login}@#{user.environment.default_hostname(true)}" | ||
| 41 | + recipients user_email | ||
| 42 | + from "#{user.environment.name} <#{user.environment.contact_email}>" | ||
| 43 | + subject _("[%{environment}] Welcome to %{environment} mail!") % { :environment => user.environment.name } | ||
| 44 | + body :name => user.name, | ||
| 45 | + :email => user_email, | ||
| 46 | + :webmail => MailConf.webmail_url, | ||
| 47 | + :environment => user.environment.name, | ||
| 48 | + :url => url_for(:host => user.environment.default_hostname, :controller => 'home') | ||
| 49 | + end | ||
| 50 | + end | ||
| 51 | + | ||
| 32 | def signup! | 52 | def signup! |
| 33 | User.transaction do | 53 | User.transaction do |
| 34 | self.save! | 54 | self.save! |
| @@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
| 1 | +<%= _('Hello %s,') % @name %> | ||
| 2 | + | ||
| 3 | +<%= _('Your email %s was just activated.') % [@email] %> | ||
| 4 | + | ||
| 5 | +<%= _('You can access your e-mail from anywhere, using the following address:') %> | ||
| 6 | +<%= @webmail %> | ||
| 7 | + | ||
| 8 | +-- | ||
| 9 | +<%= _('%s environment system') % @environment %> | ||
| 10 | +<%= @url %> |
| @@ -0,0 +1,57 @@ | @@ -0,0 +1,57 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class UserMailerTest < Test::Unit::TestCase | ||
| 4 | + FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures' | ||
| 5 | + CHARSET = "utf-8" | ||
| 6 | + | ||
| 7 | + def setup | ||
| 8 | + ActionMailer::Base.delivery_method = :test | ||
| 9 | + ActionMailer::Base.perform_deliveries = true | ||
| 10 | + ActionMailer::Base.deliveries = [] | ||
| 11 | + | ||
| 12 | + @expected = TMail::Mail.new | ||
| 13 | + @expected.set_content_type "text", "plain", { "charset" => CHARSET } | ||
| 14 | + end | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + should 'deliver activation email notify' do | ||
| 18 | + assert_difference ActionMailer::Base.deliveries, :size do | ||
| 19 | + u = Person.find(:first).user | ||
| 20 | + u.environment = Environment.default | ||
| 21 | + User::Mailer.deliver_activation_email_notify(u) | ||
| 22 | + end | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | + should 'deliver notify when activate email' do | ||
| 26 | + u = Person.find(:first).user | ||
| 27 | + u.environment = Environment.default | ||
| 28 | + u.enable_email = false | ||
| 29 | + u.save! | ||
| 30 | + assert_difference ActionMailer::Base.deliveries, :size do | ||
| 31 | + u.enable_email = true | ||
| 32 | + u.save! | ||
| 33 | + end | ||
| 34 | + end | ||
| 35 | + | ||
| 36 | + should 'not deliver notify when disactivate email' do | ||
| 37 | + u = Person.find(:first).user | ||
| 38 | + u.environment = Environment.default | ||
| 39 | + u.enable_email = true | ||
| 40 | + u.save! | ||
| 41 | + assert_no_difference ActionMailer::Base.deliveries, :size do | ||
| 42 | + u.enable_email = false | ||
| 43 | + u.save! | ||
| 44 | + end | ||
| 45 | + end | ||
| 46 | + | ||
| 47 | + private | ||
| 48 | + | ||
| 49 | + def read_fixture(action) | ||
| 50 | + IO.readlines("#{FIXTURES_PATH}/mail_sender/#{action}") | ||
| 51 | + end | ||
| 52 | + | ||
| 53 | + def encode(subject) | ||
| 54 | + quoted_printable(subject, CHARSET) | ||
| 55 | + end | ||
| 56 | + | ||
| 57 | +end |