Project

General

Profile

Patch #216 ยป redmine-email-settings.patch

Ted Wise, 2008-02-03 11:00

View differences:

app/controllers/admin_controller.rb (working copy)
@flags[:default_admin_changed] = User.find(:first, :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?
@flags[:file_repository_writable] = File.writable?(Attachment.storage_path)
@flags[:textile_available] = ActionView::Helpers::TextHelper.method_defined? "textilize"
@flags[:default_email_changed] = Setting.mail_configured?
end
end
app/controllers/email_settings_controller.rb (revision 0)
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class EmailSettingsController < ApplicationController
layout 'base'
before_filter :require_admin
def index
edit
render :action => 'edit'
end
def edit
if request.post? and params[:settings] and params[:settings].is_a? Hash
params[:settings].each { |name, value| Setting[name] = value }
Setting[:mail_configured] = 1
EmailSettingsHelper.setup_email
redirect_to :action => 'edit' and return
end
end
end
app/helpers/email_settings_helper.rb (revision 0)
module EmailSettingsHelper
def EmailSettingsHelper.setup_email
case Setting.mailer_type
when "smtp"
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}
ActionMailer::Base.delivery_method = "smtp"
ActionMailer::Base.perform_deliveries = true
when "sendmail"
ActionMailer::Base.sendmail_settings = {:location => Setting.sendmail_location, :arguments => Setting.sendmail_arguments}
ActionMailer::Base.delivery_method = "sendmail"
ActionMailer::Base.perform_deliveries = true
else
ActionMailer::Base.delivery_method = "test"
ActionMailer::Base.perform_deliveries = false
end
end
end
app/views/admin/_menu.rhtml (working copy)
<%= link_to l(:field_mail_notification), {:controller => 'admin', :action => 'mail_options' }, :class => "menuItem" %>
<%= link_to l(:label_authentication), {:controller => 'auth_sources' }, :class => "menuItem" %>
<%= link_to l(:label_settings), {:controller => 'settings' }, :class => "menuItem" %>
<%= link_to l(:label_email_settings), {:controller => 'email_settings' }, :class => "menuItem" %>
<%= link_to l(:label_information_plural), {:controller => 'admin', :action => 'info' }, :class => "menuItem" %>
</div>
<div id="menuTrackers" class="menu">
app/views/admin/index.rhtml (working copy)
<%= link_to l(:label_settings), :controller => 'settings' %>
</p>
<p class="icon22 icon22-notifications">
<%= link_to l(:label_email_settings), :controller => 'email_settings' %>
</p>
<p class="icon22 icon22-info">
<%= link_to l(:label_information_plural), :controller => 'admin', :action => 'info' %>
</p>
app/views/admin/info.rhtml (working copy)
<table class="list">
<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>
<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>
<tr class="odd"><td>Textile available</td><td><%= image_tag (@flags[:textile_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
<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>
<tr class="even"><td>Textile available</td><td><%= image_tag (@flags[:textile_available] ? 'true.png' : 'false.png'), :style => "vertical-align:bottom;" %></td></tr>
</table>
app/views/email_settings/edit.rhtml (revision 0)
<h2><%= l(:label_email_settings) %></h2>
<div id="settings">
<% form_tag({:action => 'edit'}, :class => "tabular") do %>
<div class="box">
<p><label><%= l(:setting_email_mailer_type) %></label>
<%= select_tag 'settings[mailer_type]', options_for_select( [[l(:general_disabled), "test"], ["SMTP", "smtp"], ["Sendmail", "sendmail"]], Setting.mailer_type) %></p>
<div id="sendmail-settings">
<p><label><%= l(:setting_email_sendmail_location) %></label>
<%= text_field_tag 'settings[sendmail_location]', Setting.sendmail_location, :size => 60 %></p>
<p><label><%= l(:setting_email_sendmail_arguments) %></label>
<%= text_field_tag 'settings[sendmail_arguments]', Setting.sendmail_arguments, :size => 60 %></p>
</div>
<div id="smtp-settings">
<p><label><%= l(:setting_email_smtp_address) %></label>
<%= text_field_tag 'settings[smtp_address]', Setting.smtp_address, :size => 60 %></p>
<p><label><%= l(:setting_email_smtp_port) %></label>
<%= text_field_tag 'settings[smtp_port]', Setting.smtp_port, :size => 10 %></p>
<p><label><%= l(:setting_email_smtp_domain) %></label>
<%= text_field_tag 'settings[smtp_domain]', Setting.smtp_domain, :size => 60 %></p>
<p><label><%= l(:setting_email_smtp_authentication_type) %></label>
<%= select_tag 'settings[smtp_authentication_type]', options_for_select( [["No login", "plain"], ["Login", "login"], ["CRAM_MD5", "cram_md5"]], Setting.smtp_authentication_type) %></p>
<div id="smtp-login-settings">
<p><label><%= l(:setting_email_smtp_username) %></label>
<%= text_field_tag 'settings[smtp_username]', Setting.smtp_username, :size => 20 %></p>
<p><label><%= l(:setting_email_smtp_password) %></label>
<%= text_field_tag 'settings[smtp_password]', Setting.smtp_password, :size => 20 %></p>
</div>
</div>
</div>
<%= submit_tag l(:button_save) %>
<% end %>
</div>
<script type="text/javascript">
<%= "$('sendmail-settings').hide();" if Setting.mailer_type != "sendmail" %>
<%= "$('smtp-settings').hide();" if Setting.mailer_type != "smtp" %>
<%= "$('smtp-login-settings').hide();" if Setting.smtp_authentication_type == "plain" %>
Event.observe('settings[mailer_type]', 'change', function(evt) {
var mailerType = $F('settings[mailer_type]');
if (mailerType == 'smtp') {
$('sendmail-settings').hide();
$('smtp-settings').show();
} else if (mailerType == 'sendmail') {
$('sendmail-settings').show();
$('smtp-settings').hide();
} else {
$('sendmail-settings').hide();
$('smtp-settings').hide();
}
});
Event.observe('settings[smtp_authentication_type]', 'change', function(evt) {
if ($F('settings[smtp_authentication_type]') == 'plain') {
$('smtp-login-settings').hide();
} else {
$('smtp-login-settings').show();
}
});
</script>
app/views/email_settings/edit.rhtml (revision 0)
<h2><%= l(:label_email_settings) %></h2>
<div id="settings">
<% form_tag({:action => 'edit'}, :class => "tabular") do %>
<div class="box">
<p><label><%= l(:setting_email_mailer_type) %></label>
<%= select_tag 'settings[mailer_type]', options_for_select( [[l(:general_disabled), "test"], ["SMTP", "smtp"], ["Sendmail", "sendmail"]], Setting.mailer_type) %></p>
<div id="sendmail-settings">
<p><label><%= l(:setting_email_sendmail_location) %></label>
<%= text_field_tag 'settings[sendmail_location]', Setting.sendmail_location, :size => 60 %></p>
<p><label><%= l(:setting_email_sendmail_arguments) %></label>
<%= text_field_tag 'settings[sendmail_arguments]', Setting.sendmail_arguments, :size => 60 %></p>
</div>
<div id="smtp-settings">
<p><label><%= l(:setting_email_smtp_address) %></label>
<%= text_field_tag 'settings[smtp_address]', Setting.smtp_address, :size => 60 %></p>
<p><label><%= l(:setting_email_smtp_port) %></label>
<%= text_field_tag 'settings[smtp_port]', Setting.smtp_port, :size => 10 %></p>
<p><label><%= l(:setting_email_smtp_domain) %></label>
<%= text_field_tag 'settings[smtp_domain]', Setting.smtp_domain, :size => 60 %></p>
<p><label><%= l(:setting_email_smtp_authentication_type) %></label>
<%= select_tag 'settings[smtp_authentication_type]', options_for_select( [["No login", "plain"], ["Login", "login"], ["CRAM_MD5", "cram_md5"]], Setting.smtp_authentication_type) %></p>
<div id="smtp-login-settings">
<p><label><%= l(:setting_email_smtp_username) %></label>
<%= text_field_tag 'settings[smtp_username]', Setting.smtp_username, :size => 20 %></p>
<p><label><%= l(:setting_email_smtp_password) %></label>
<%= text_field_tag 'settings[smtp_password]', Setting.smtp_password, :size => 20 %></p>
</div>
</div>
</div>
<%= submit_tag l(:button_save) %>
<% end %>
</div>
<script type="text/javascript">
<%= "$('sendmail-settings').hide();" if Setting.mailer_type != "sendmail" %>
<%= "$('smtp-settings').hide();" if Setting.mailer_type != "smtp" %>
<%= "$('smtp-login-settings').hide();" if Setting.smtp_authentication_type == "plain" %>
Event.observe('settings[mailer_type]', 'change', function(evt) {
var mailerType = $F('settings[mailer_type]');
if (mailerType == 'smtp') {
$('sendmail-settings').hide();
$('smtp-settings').show();
} else if (mailerType == 'sendmail') {
$('sendmail-settings').show();
$('smtp-settings').hide();
} else {
$('sendmail-settings').hide();
$('smtp-settings').hide();
}
});
Event.observe('settings[smtp_authentication_type]', 'change', function(evt) {
if ($F('settings[smtp_authentication_type]') == 'plain') {
$('smtp-login-settings').hide();
} else {
$('smtp-login-settings').show();
}
});
</script>
config/environment.rb (working copy)
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# ENV['RAILS_ENV'] ||= 'production'
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
......
# (enables use of different database adapters for development and test environments)
# config.active_record.schema_format = :ruby
# See Rails::Configuration for more options
# SMTP server configuration
config.action_mailer.smtp_settings = {
:address => "127.0.0.1",
:port => 25,
:domain => "somenet.foo",
:authentication => :login,
:user_name => "redmine",
:password => "redmine",
}
config.action_mailer.perform_deliveries = true
# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
#config.action_mailer.delivery_method = :test
config.action_mailer.delivery_method = :smtp
# See Rails::Configuration for more options
# SMTP server configuration
config.action_mailer.delivery_method = :test
config.action_mailer.perform_deliveries = false
end
ActiveRecord::Errors.default_error_messages = {
......
GLoc.load_localized_strings
GLoc.set_config(:raise_string_not_found_errors => false)
EmailSettingsHelper.setup_email
config/settings.yml (working copy)
default: 15
autofetch_changesets:
default: 1
mail_configured:
default: 0
mailer_type:
default: test
sendmail_location:
default: "/usr/sbin/sendmail"
sendmail_arguments:
default: ""
smtp_address:
default: localhost
smtp_port:
format: int
default: 25
smtp_domain:
default: ""
smtp_username:
default: ""
smtp_password:
default: ""
smtp_authentication_type:
default: plain
lang/en.yml (working copy)
general_csv_encoding: ISO-8859-1
general_pdf_encoding: ISO-8859-1
general_day_names: Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday
general_disabled: Disabled
notice_account_updated: Account was successfully updated.
notice_account_invalid_creditentials: Invalid user or password
......
setting_wiki_compression: Wiki history compression
setting_feeds_limit: Feed content limit
setting_autofetch_changesets: Autofetch SVN commits
setting_email_mailer_type: Email server type
setting_email_sendmail_location: Sendmail program location
setting_email_sendmail_arguments: Sendmail program arguments
setting_email_smtp_address: SMTP server address
setting_email_smtp_port: SMTP server port
setting_email_smtp_domain: SMTP HELO domain
setting_email_smtp_authentication_type: SMTP authentication type
setting_email_smtp_username: SMTP server username
setting_email_smtp_password: SMTP server password
label_user: User
label_user_plural: Users
......
label_news_view_all: View all news
label_change_log: Change log
label_settings: Settings
label_email_settings: Email Settings
label_overview: Overview
label_version: Version
label_version_new: New version
test/functional/email_settings_controller_test.rb (revision 0)
require File.dirname(__FILE__) + '/../test_helper'
require 'email_settings_controller'
# Re-raise errors caught by the controller.
class EmailSettingsController; def rescue_action(e) raise e end; end
class EmailSettingsControllerTest < Test::Unit::TestCase
def setup
@controller = EmailSettingsController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
# Replace this with your real tests.
def test_truth
assert true
end
end
    (1-1/1)