Patch #216 ยป redmine-email-settings.patch
| app/controllers/admin_controller.rb (working copy) | ||
|---|---|---|
| 56 | 56 |
@flags[:default_admin_changed] = User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?
|
| 57 | 57 |
@flags[:file_repository_writable] = File.writable?(Attachment.storage_path) |
| 58 | 58 |
@flags[:textile_available] = ActionView::Helpers::TextHelper.method_defined? "textilize" |
| 59 |
@flags[:default_email_changed] = Setting.mail_configured? |
|
| 59 | 60 |
end |
| 60 | 61 |
end |
| app/controllers/email_settings_controller.rb (revision 0) | ||
|---|---|---|
| 1 |
# redMine - project management software |
|
| 2 |
# Copyright (C) 2006-2007 Jean-Philippe Lang |
|
| 3 |
# |
|
| 4 |
# This program is free software; you can redistribute it and/or |
|
| 5 |
# modify it under the terms of the GNU General Public License |
|
| 6 |
# as published by the Free Software Foundation; either version 2 |
|
| 7 |
# of the License, or (at your option) any later version. |
|
| 8 |
# |
|
| 9 |
# This program is distributed in the hope that it will be useful, |
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 12 |
# GNU General Public License for more details. |
|
| 13 |
# |
|
| 14 |
# You should have received a copy of the GNU General Public License |
|
| 15 |
# along with this program; if not, write to the Free Software |
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 17 | ||
| 18 |
class EmailSettingsController < ApplicationController |
|
| 19 |
layout 'base' |
|
| 20 |
before_filter :require_admin |
|
| 21 | ||
| 22 |
def index |
|
| 23 |
edit |
|
| 24 |
render :action => 'edit' |
|
| 25 |
end |
|
| 26 | ||
| 27 |
def edit |
|
| 28 |
if request.post? and params[:settings] and params[:settings].is_a? Hash |
|
| 29 |
params[:settings].each { |name, value| Setting[name] = value }
|
|
| 30 |
Setting[:mail_configured] = 1 |
|
| 31 |
EmailSettingsHelper.setup_email |
|
| 32 |
redirect_to :action => 'edit' and return |
|
| 33 |
end |
|
| 34 |
end |
|
| 35 |
end |
|
| app/helpers/email_settings_helper.rb (revision 0) | ||
|---|---|---|
| 1 |
module EmailSettingsHelper |
|
| 2 |
def EmailSettingsHelper.setup_email |
|
| 3 |
case Setting.mailer_type |
|
| 4 |
when "smtp" |
|
| 5 |
ActionMailer::Base.smtp_settings = {:address => Setting.smtp_address, :port => Setting.smtp_port, :domain => Setting.smtp_domain, :user_name => Setting.smtp_username, :password => Setting.smtp_password, :authentication => Setting.smtp_authentication_type}
|
|
| 6 |
ActionMailer::Base.delivery_method = "smtp" |
|
| 7 |
ActionMailer::Base.perform_deliveries = true |
|
| 8 |
when "sendmail" |
|
| 9 |
ActionMailer::Base.sendmail_settings = {:location => Setting.sendmail_location, :arguments => Setting.sendmail_arguments}
|
|
| 10 |
ActionMailer::Base.delivery_method = "sendmail" |
|
| 11 |
ActionMailer::Base.perform_deliveries = true |
|
| 12 |
else |
|
| 13 |
ActionMailer::Base.delivery_method = "test" |
|
| 14 |
ActionMailer::Base.perform_deliveries = false |
|
| 15 |
end |
|
| 16 |
end |
|
| 17 |
end |
|
| app/views/admin/_menu.rhtml (working copy) | ||
|---|---|---|
| 8 | 8 |
<%= link_to l(:field_mail_notification), {:controller => 'admin', :action => 'mail_options' }, :class => "menuItem" %>
|
| 9 | 9 |
<%= link_to l(:label_authentication), {:controller => 'auth_sources' }, :class => "menuItem" %>
|
| 10 | 10 |
<%= link_to l(:label_settings), {:controller => 'settings' }, :class => "menuItem" %>
|
| 11 |
<%= link_to l(:label_email_settings), {:controller => 'email_settings' }, :class => "menuItem" %>
|
|
| 11 | 12 |
<%= link_to l(:label_information_plural), {:controller => 'admin', :action => 'info' }, :class => "menuItem" %>
|
| 12 | 13 |
</div> |
| 13 | 14 |
<div id="menuTrackers" class="menu"> |
| app/views/admin/index.rhtml (working copy) | ||
|---|---|---|
| 40 | 40 |
<%= link_to l(:label_settings), :controller => 'settings' %> |
| 41 | 41 |
</p> |
| 42 | 42 | |
| 43 |
<p class="icon22 icon22-notifications"> |
|
| 44 |
<%= link_to l(:label_email_settings), :controller => 'email_settings' %> |
|
| 45 |
</p> |
|
| 46 | ||
| 43 | 47 |
<p class="icon22 icon22-info"> |
| 44 | 48 |
<%= link_to l(:label_information_plural), :controller => 'admin', :action => 'info' %> |
| 45 | 49 |
</p> |
| app/views/admin/info.rhtml (working copy) | ||
|---|---|---|
| 5 | 5 |
<table class="list"> |
| 6 | 6 |
<tr class="odd"><td>File repository writable</td><td><%= image_tag (@flags[:file_repository_writable] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> |
| 7 | 7 |
<tr class="even"><td>Default administrator account changed</td><td><%= image_tag (@flags[:default_admin_changed] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> |
| 8 |
<tr class="odd"><td>Textile available</td><td><%= image_tag (@flags[:textile_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> |
|
| 8 |
<tr class=odd><td>Default email settings changed</td><td><%= image_tag (@flags[:default_email_changed] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> |
|
| 9 |
<tr class="even"><td>Textile available</td><td><%= image_tag (@flags[:textile_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr> |
|
| 9 | 10 |
</table> |
| app/views/email_settings/edit.rhtml (revision 0) | ||
|---|---|---|
| 1 |
<h2><%= l(:label_email_settings) %></h2> |
|
| 2 |
|
|
| 3 |
<div id="settings"> |
|
| 4 |
<% form_tag({:action => 'edit'}, :class => "tabular") do %>
|
|
| 5 |
<div class="box"> |
|
| 6 |
<p><label><%= l(:setting_email_mailer_type) %></label> |
|
| 7 |
<%= select_tag 'settings[mailer_type]', options_for_select( [[l(:general_disabled), "test"], ["SMTP", "smtp"], ["Sendmail", "sendmail"]], Setting.mailer_type) %></p> |
|
| 8 |
|
|
| 9 |
<div id="sendmail-settings"> |
|
| 10 |
<p><label><%= l(:setting_email_sendmail_location) %></label> |
|
| 11 |
<%= text_field_tag 'settings[sendmail_location]', Setting.sendmail_location, :size => 60 %></p> |
|
| 12 |
|
|
| 13 |
<p><label><%= l(:setting_email_sendmail_arguments) %></label> |
|
| 14 |
<%= text_field_tag 'settings[sendmail_arguments]', Setting.sendmail_arguments, :size => 60 %></p> |
|
| 15 |
</div> |
|
| 16 |
<div id="smtp-settings"> |
|
| 17 |
<p><label><%= l(:setting_email_smtp_address) %></label> |
|
| 18 |
<%= text_field_tag 'settings[smtp_address]', Setting.smtp_address, :size => 60 %></p> |
|
| 19 |
|
|
| 20 |
<p><label><%= l(:setting_email_smtp_port) %></label> |
|
| 21 |
<%= text_field_tag 'settings[smtp_port]', Setting.smtp_port, :size => 10 %></p> |
|
| 22 |
|
|
| 23 |
<p><label><%= l(:setting_email_smtp_domain) %></label> |
|
| 24 |
<%= text_field_tag 'settings[smtp_domain]', Setting.smtp_domain, :size => 60 %></p> |
|
| 25 |
|
|
| 26 |
<p><label><%= l(:setting_email_smtp_authentication_type) %></label> |
|
| 27 |
<%= select_tag 'settings[smtp_authentication_type]', options_for_select( [["No login", "plain"], ["Login", "login"], ["CRAM_MD5", "cram_md5"]], Setting.smtp_authentication_type) %></p> |
|
| 28 |
|
|
| 29 |
<div id="smtp-login-settings"> |
|
| 30 |
<p><label><%= l(:setting_email_smtp_username) %></label> |
|
| 31 |
<%= text_field_tag 'settings[smtp_username]', Setting.smtp_username, :size => 20 %></p> |
|
| 32 |
|
|
| 33 |
<p><label><%= l(:setting_email_smtp_password) %></label> |
|
| 34 |
<%= text_field_tag 'settings[smtp_password]', Setting.smtp_password, :size => 20 %></p> |
|
| 35 |
</div> |
|
| 36 |
</div> |
|
| 37 |
</div> |
|
| 38 |
<%= submit_tag l(:button_save) %> |
|
| 39 |
<% end %> |
|
| 40 |
</div> |
|
| 41 |
<script type="text/javascript"> |
|
| 42 |
<%= "$('sendmail-settings').hide();" if Setting.mailer_type != "sendmail" %>
|
|
| 43 |
<%= "$('smtp-settings').hide();" if Setting.mailer_type != "smtp" %>
|
|
| 44 |
<%= "$('smtp-login-settings').hide();" if Setting.smtp_authentication_type == "plain" %>
|
|
| 45 |
Event.observe('settings[mailer_type]', 'change', function(evt) {
|
|
| 46 |
var mailerType = $F('settings[mailer_type]');
|
|
| 47 |
if (mailerType == 'smtp') {
|
|
| 48 |
$('sendmail-settings').hide();
|
|
| 49 |
$('smtp-settings').show();
|
|
| 50 |
} else if (mailerType == 'sendmail') {
|
|
| 51 |
$('sendmail-settings').show();
|
|
| 52 |
$('smtp-settings').hide();
|
|
| 53 |
} else {
|
|
| 54 |
$('sendmail-settings').hide();
|
|
| 55 |
$('smtp-settings').hide();
|
|
| 56 |
} |
|
| 57 |
}); |
|
| 58 |
Event.observe('settings[smtp_authentication_type]', 'change', function(evt) {
|
|
| 59 |
if ($F('settings[smtp_authentication_type]') == 'plain') {
|
|
| 60 |
$('smtp-login-settings').hide();
|
|
| 61 |
} else {
|
|
| 62 |
$('smtp-login-settings').show();
|
|
| 63 |
} |
|
| 64 |
}); |
|
| 65 |
</script> |
|
| app/views/email_settings/edit.rhtml (revision 0) | ||
|---|---|---|
| 1 |
<h2><%= l(:label_email_settings) %></h2> |
|
| 2 |
|
|
| 3 |
<div id="settings"> |
|
| 4 |
<% form_tag({:action => 'edit'}, :class => "tabular") do %>
|
|
| 5 |
<div class="box"> |
|
| 6 |
<p><label><%= l(:setting_email_mailer_type) %></label> |
|
| 7 |
<%= select_tag 'settings[mailer_type]', options_for_select( [[l(:general_disabled), "test"], ["SMTP", "smtp"], ["Sendmail", "sendmail"]], Setting.mailer_type) %></p> |
|
| 8 |
|
|
| 9 |
<div id="sendmail-settings"> |
|
| 10 |
<p><label><%= l(:setting_email_sendmail_location) %></label> |
|
| 11 |
<%= text_field_tag 'settings[sendmail_location]', Setting.sendmail_location, :size => 60 %></p> |
|
| 12 |
|
|
| 13 |
<p><label><%= l(:setting_email_sendmail_arguments) %></label> |
|
| 14 |
<%= text_field_tag 'settings[sendmail_arguments]', Setting.sendmail_arguments, :size => 60 %></p> |
|
| 15 |
</div> |
|
| 16 |
<div id="smtp-settings"> |
|
| 17 |
<p><label><%= l(:setting_email_smtp_address) %></label> |
|
| 18 |
<%= text_field_tag 'settings[smtp_address]', Setting.smtp_address, :size => 60 %></p> |
|
| 19 |
|
|
| 20 |
<p><label><%= l(:setting_email_smtp_port) %></label> |
|
| 21 |
<%= text_field_tag 'settings[smtp_port]', Setting.smtp_port, :size => 10 %></p> |
|
| 22 |
|
|
| 23 |
<p><label><%= l(:setting_email_smtp_domain) %></label> |
|
| 24 |
<%= text_field_tag 'settings[smtp_domain]', Setting.smtp_domain, :size => 60 %></p> |
|
| 25 |
|
|
| 26 |
<p><label><%= l(:setting_email_smtp_authentication_type) %></label> |
|
| 27 |
<%= select_tag 'settings[smtp_authentication_type]', options_for_select( [["No login", "plain"], ["Login", "login"], ["CRAM_MD5", "cram_md5"]], Setting.smtp_authentication_type) %></p> |
|
| 28 |
|
|
| 29 |
<div id="smtp-login-settings"> |
|
| 30 |
<p><label><%= l(:setting_email_smtp_username) %></label> |
|
| 31 |
<%= text_field_tag 'settings[smtp_username]', Setting.smtp_username, :size => 20 %></p> |
|
| 32 |
|
|
| 33 |
<p><label><%= l(:setting_email_smtp_password) %></label> |
|
| 34 |
<%= text_field_tag 'settings[smtp_password]', Setting.smtp_password, :size => 20 %></p> |
|
| 35 |
</div> |
|
| 36 |
</div> |
|
| 37 |
</div> |
|
| 38 |
<%= submit_tag l(:button_save) %> |
|
| 39 |
<% end %> |
|
| 40 |
</div> |
|
| 41 |
<script type="text/javascript"> |
|
| 42 |
<%= "$('sendmail-settings').hide();" if Setting.mailer_type != "sendmail" %>
|
|
| 43 |
<%= "$('smtp-settings').hide();" if Setting.mailer_type != "smtp" %>
|
|
| 44 |
<%= "$('smtp-login-settings').hide();" if Setting.smtp_authentication_type == "plain" %>
|
|
| 45 |
Event.observe('settings[mailer_type]', 'change', function(evt) {
|
|
| 46 |
var mailerType = $F('settings[mailer_type]');
|
|
| 47 |
if (mailerType == 'smtp') {
|
|
| 48 |
$('sendmail-settings').hide();
|
|
| 49 |
$('smtp-settings').show();
|
|
| 50 |
} else if (mailerType == 'sendmail') {
|
|
| 51 |
$('sendmail-settings').show();
|
|
| 52 |
$('smtp-settings').hide();
|
|
| 53 |
} else {
|
|
| 54 |
$('sendmail-settings').hide();
|
|
| 55 |
$('smtp-settings').hide();
|
|
| 56 |
} |
|
| 57 |
}); |
|
| 58 |
Event.observe('settings[smtp_authentication_type]', 'change', function(evt) {
|
|
| 59 |
if ($F('settings[smtp_authentication_type]') == 'plain') {
|
|
| 60 |
$('smtp-login-settings').hide();
|
|
| 61 |
} else {
|
|
| 62 |
$('smtp-login-settings').show();
|
|
| 63 |
} |
|
| 64 |
}); |
|
| 65 |
</script> |
|
| config/environment.rb (working copy) | ||
|---|---|---|
| 2 | 2 | |
| 3 | 3 |
# Uncomment below to force Rails into production mode when |
| 4 | 4 |
# you don't control web/app server and can't set it the proper way |
| 5 |
# ENV['RAILS_ENV'] ||= 'production'
|
|
| 5 |
# ENV['RAILS_ENV'] ||= 'production' |
|
| 6 | 6 | |
| 7 | 7 |
# Bootstrap the Rails environment, frameworks, and default configuration |
| 8 | 8 |
require File.join(File.dirname(__FILE__), 'boot') |
| ... | ... | |
| 38 | 38 |
# (enables use of different database adapters for development and test environments) |
| 39 | 39 |
# config.active_record.schema_format = :ruby |
| 40 | 40 | |
| 41 |
# See Rails::Configuration for more options |
|
| 42 |
|
|
| 43 |
# SMTP server configuration |
|
| 44 |
config.action_mailer.smtp_settings = {
|
|
| 45 |
:address => "127.0.0.1", |
|
| 46 |
:port => 25, |
|
| 47 |
:domain => "somenet.foo", |
|
| 48 |
:authentication => :login, |
|
| 49 |
:user_name => "redmine", |
|
| 50 |
:password => "redmine", |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
config.action_mailer.perform_deliveries = true |
|
| 54 |
|
|
| 55 |
# Tell ActionMailer not to deliver emails to the real world. |
|
| 56 |
# The :test delivery method accumulates sent emails in the |
|
| 57 |
# ActionMailer::Base.deliveries array. |
|
| 58 |
#config.action_mailer.delivery_method = :test |
|
| 59 |
config.action_mailer.delivery_method = :smtp |
|
| 41 |
# See Rails::Configuration for more options |
|
| 42 |
|
|
| 43 |
# SMTP server configuration |
|
| 44 |
config.action_mailer.delivery_method = :test |
|
| 45 |
config.action_mailer.perform_deliveries = false |
|
| 60 | 46 |
end |
| 61 | 47 | |
| 62 | 48 |
ActiveRecord::Errors.default_error_messages = {
|
| ... | ... | |
| 82 | 68 |
GLoc.load_localized_strings |
| 83 | 69 |
GLoc.set_config(:raise_string_not_found_errors => false) |
| 84 | 70 | |
| 85 | ||
| 71 |
EmailSettingsHelper.setup_email |
|
| config/settings.yml (working copy) | ||
|---|---|---|
| 52 | 52 |
default: 15 |
| 53 | 53 |
autofetch_changesets: |
| 54 | 54 |
default: 1 |
| 55 |
mail_configured: |
|
| 56 |
default: 0 |
|
| 57 |
mailer_type: |
|
| 58 |
default: test |
|
| 59 |
sendmail_location: |
|
| 60 |
default: "/usr/sbin/sendmail" |
|
| 61 |
sendmail_arguments: |
|
| 62 |
default: "" |
|
| 63 |
smtp_address: |
|
| 64 |
default: localhost |
|
| 65 |
smtp_port: |
|
| 66 |
format: int |
|
| 67 |
default: 25 |
|
| 68 |
smtp_domain: |
|
| 69 |
default: "" |
|
| 70 |
smtp_username: |
|
| 71 |
default: "" |
|
| 72 |
smtp_password: |
|
| 73 |
default: "" |
|
| 74 |
smtp_authentication_type: |
|
| 75 |
default: plain |
|
| lang/en.yml (working copy) | ||
|---|---|---|
| 49 | 49 |
general_csv_encoding: ISO-8859-1 |
| 50 | 50 |
general_pdf_encoding: ISO-8859-1 |
| 51 | 51 |
general_day_names: Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday |
| 52 |
general_disabled: Disabled |
|
| 52 | 53 | |
| 53 | 54 |
notice_account_updated: Account was successfully updated. |
| 54 | 55 |
notice_account_invalid_creditentials: Invalid user or password |
| ... | ... | |
| 161 | 162 |
setting_wiki_compression: Wiki history compression |
| 162 | 163 |
setting_feeds_limit: Feed content limit |
| 163 | 164 |
setting_autofetch_changesets: Autofetch SVN commits |
| 165 |
setting_email_mailer_type: Email server type |
|
| 166 |
setting_email_sendmail_location: Sendmail program location |
|
| 167 |
setting_email_sendmail_arguments: Sendmail program arguments |
|
| 168 |
setting_email_smtp_address: SMTP server address |
|
| 169 |
setting_email_smtp_port: SMTP server port |
|
| 170 |
setting_email_smtp_domain: SMTP HELO domain |
|
| 171 |
setting_email_smtp_authentication_type: SMTP authentication type |
|
| 172 |
setting_email_smtp_username: SMTP server username |
|
| 173 |
setting_email_smtp_password: SMTP server password |
|
| 164 | 174 | |
| 165 | 175 |
label_user: User |
| 166 | 176 |
label_user_plural: Users |
| ... | ... | |
| 253 | 263 |
label_news_view_all: View all news |
| 254 | 264 |
label_change_log: Change log |
| 255 | 265 |
label_settings: Settings |
| 266 |
label_email_settings: Email Settings |
|
| 256 | 267 |
label_overview: Overview |
| 257 | 268 |
label_version: Version |
| 258 | 269 |
label_version_new: New version |
| test/functional/email_settings_controller_test.rb (revision 0) | ||
|---|---|---|
| 1 |
require File.dirname(__FILE__) + '/../test_helper' |
|
| 2 |
require 'email_settings_controller' |
|
| 3 | ||
| 4 |
# Re-raise errors caught by the controller. |
|
| 5 |
class EmailSettingsController; def rescue_action(e) raise e end; end |
|
| 6 | ||
| 7 |
class EmailSettingsControllerTest < Test::Unit::TestCase |
|
| 8 |
def setup |
|
| 9 |
@controller = EmailSettingsController.new |
|
| 10 |
@request = ActionController::TestRequest.new |
|
| 11 |
@response = ActionController::TestResponse.new |
|
| 12 |
end |
|
| 13 | ||
| 14 |
# Replace this with your real tests. |
|
| 15 |
def test_truth |
|
| 16 |
assert true |
|
| 17 |
end |
|
| 18 |
end |
|