Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for mailsetting - bnc#784360 & bnc#791787 #23

Merged
merged 11 commits into from

3 participants

@vmoravec
Owner
  • Sending of test email fixed
  • Added validation of model
  • Some typo and formatting fixed
@lslezak lslezak merged commit ce7ae5b into webyast:master
@kobliha kobliha commented on the diff
plugins/mailsetting/app/views/mailsetting/show.html.erb
@@ -84,29 +83,29 @@
<div class="fieldset_body">
<div class="row">
- <label for="<%= :smtp_server %>"><%=_("Outgoing mail server")%></label>
+ <label style="float:left" for="<%= :smtp_server %>"><%=_("Outgoing mail server")%></label>
<%=f.text_field :smtp_server, :disabled => disabled, :class => "smtp_server tipsy_help", :title => _("URL of the outgoing mail server. You may also specify an alternate port number, e.g.
relay.example.com:26. Use square brackets around the host name to prevent from DNS MX lookups.") %>
@kobliha Owner
kobliha added a note

Just an idea. It could be useful if you've written an example of what is summarized here: square brackets around hostname (with/without port number).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@vmoravec vmoravec deleted the vmoravec:mailsetting-fix branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2012
  1. @vmoravec

    Add validation to mailsetting model, remove validation

    vmoravec authored
    code from the controller; correct the password confirmation field names
    to make it rails complaint for confirmation validation
Commits on Dec 20, 2012
  1. @vmoravec

    Validate params with help of a instance var to be able to

    vmoravec authored
    render the show template with the submitted result
  2. @vmoravec

    Fix floating; inline style due to unability to change

    vmoravec authored
    the styling in the asset stylesheet
  3. @vmoravec
  4. @vmoravec

    Fix sending test email

    vmoravec authored
  5. @vmoravec

    Complete the namespace

    vmoravec authored
  6. @vmoravec

    Do not forget on gettext

    vmoravec authored
  7. @vmoravec
  8. @vmoravec
Commits on Jan 2, 2013
  1. @vmoravec

    Do not refer to a non-existent status page;

    vmoravec authored
    such feature must be implemented yet
  2. @vmoravec

    Do not disable form on submit;

    vmoravec authored
    fixed disabled form after incorrect email input
This page is out of date. Refresh to see the latest.
View
66 plugins/mailsetting/app/controllers/mailsetting_controller.rb
@@ -1,20 +1,20 @@
#--
# Copyright (c) 2009-2010 Novell, Inc.
-#
+#
# All Rights Reserved.
-#
+#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License
# as published by the Free Software Foundation.
-#
+#
# 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, contact Novell, Inc.
-#
+#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#++
@@ -28,9 +28,9 @@ class MailsettingController < ApplicationController
def show
authorize! :read, Mailsetting
-
+
@mail = Mailsetting.find
- @mail.confirm_password = @mail.password
+ @mail.password_confirmation = @mail.password
@mail.test_mail_address = ""
@mail.test_mail_address = params["email"] if params.has_key? "email"
@mail.smtp_server = @mail.smtp_server.gsub(/^(\[)|(\])/, '') unless @mail.smtp_server.nil? #remove square brackets from smtp_server string
@@ -53,19 +53,35 @@ def show
}
end
end
-
+
def update
authorize! :write, Mailsetting
- @mail = Mailsetting.find
- @mail.load params["mailsetting"] || params["mail"] #keep mail for backwards compatibility with old REST API
+ mail_params = params[:mailsetting] || params[:mail] #keep mail for backwards compatibility with old REST API
+ @mail = Mailsetting.new mail_params
+
+ if params.has_key? :send_mail
+ if request.format.html?
+ if mail_params[:test_mail_address].to_s.match(/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/)
+ Mailsetting.send_test_mail mail_params[:test_mail_address]
+ flash[:notice] = _("A test message has been sent to email address %s") % mail_params[:test_mail_address]
+ redirect_to :action => "show", :email => mail_params[:test_mail_address].to_s
+ return
+ else
+ flash[:error] = _("Wrong format for email address")
+ render :show
+ return
+ end
+ end
+ end
- # FIXME: move the validation to the model
- # validate data also here, if javascript in view is off
- if @mail.password != @mail.confirm_password
- problem _("Passwords do not match.")
+ unless @mail.valid?
+ problem _(@mail.errors.full_messages.join(', '))
return
end
+ @mail = Mailsetting.find
+ @mail.load mail_params
+
begin
response = @mail.save
notice = _('Mail settings have been written.')
@@ -74,18 +90,18 @@ def update
end
flash[:notice] = notice
- rescue Exception => error
- problem _("Error while saving mail settings.")
+ rescue Exception => error
+ problem _("Error while saving mail settings.")
Rails.logger.error "ERROR: #{error.inspect}"
return
end
- smtp_server = params["mail"]["smtp_server"]
+ smtp_server = mail_params["smtp_server"]
# check if mail forwarning for root is configured
# during initial workflow, only warn if administrator configuration does not follow
if smtp_server.blank? && (!Basesystem.new.load_from_session(session).following_steps.any? { |h| h[:controller] == "administrator" })
- @administrator = Administrator.find
+ @administrator = Administrator.find
if @administrator && !@administrator.aliases.blank?
flash[:warning] = _("No outgoing mail server is set, but administrator has mail forwarders defined.
@@ -93,21 +109,13 @@ def update
end
end
- if params.has_key?("send_mail")
- if request.format.html?
- redirect_to :action => "show", :email => params["mail"]["test_mail_address"]
- return
- else
- params[:email] = params["mail"]["test_mail_address"]
- end
- end
- if request.format.html?
+ if request.format.html?
redirect_success # redirect to next step
else
show
end
end
-
+
def create
update
end
@@ -117,7 +125,7 @@ def create
def problem message
if request.format.html?
flash[:error] = message
- redirect_to :action => "show"
+ render :action => "show"
else #REST request
error = { "error" => { "type" => "ADMINISTRATOR_ERROR", "messsage" => message, "id" => "ADMINISTRATOR" }}
respond_to do |format|
View
37 plugins/mailsetting/app/models/mailsetting.rb
@@ -1,20 +1,20 @@
#--
# Copyright (c) 2009-2010 Novell, Inc.
-#
+#
# All Rights Reserved.
-#
+#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License
# as published by the Free Software Foundation.
-#
+#
# 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, contact Novell, Inc.
-#
+#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com
#++
@@ -32,11 +32,18 @@ class Mailsetting < BaseModel::Base
attr_accessor :smtp_server
attr_accessor :user
attr_accessor :password
- attr_accessor :confirm_password
+ attr_accessor :password_confirmation
attr_accessor :test_mail_address
attr_accessor :transport_layer_security
- TEST_MAIL_FILE = File.join(YaST::Paths::VAR,"mail","test_sent")
+
+ validates :smtp_server, :presence=>true
+ validates :user, :presence=>true
+ validates :password, :presence=>true, :confirmation=>true
+ validates :password_confirmation, :presence=>true
+ validates :transport_layer_security, :presence=>true
+
+ TEST_MAIL_FILE = File.join(YaST::Paths::VAR,"mailsetting","test_sent")
CACHE_ID = "webyast_mailsetting"
# read the settings from system
@@ -74,21 +81,23 @@ def self.send_test_mail(to)
Rails.logger.debug "sending test mail to #{to}..."
- message = "This is the test mail sent to you by webYaST. Go to the status page and confirm you've got it."
+ message = "This is the test mail sent to you by webYaST."
# remove potential problematic characters from email address
to.tr!("~'\"<>","")
`/bin/echo "#{message}" | /bin/mail -s "WebYaST Test Mail" '#{to}' -r root`
- unless File.directory? File.join(Paths::VAR,"mail")
- Rails.logger.debug "directory does not exists...."
+ mail_directory = File.join(YaST::Paths::VAR,"mailsetting")
+ unless File.directory? mail_directory
+ Rails.logger.debug "Directory #{mail_directory} does not exists"
return
end
begin
- f = File.new(TEST_MAIL_FILE, 'w')
- f.puts "#{to}"
- rescue
- Rails.logger.error "writing #{TEST_MAIL_FILE} file failed - wrong permissions?"
+ File.open TEST_MAIL_FILE, 'w' do |file|
+ file.puts to.to_s
+ end
+ rescue => error
+ Rails.logger.error e
end
end
end
View
17 plugins/mailsetting/app/views/mailsetting/show.html.erb
@@ -29,7 +29,6 @@
$("#mailForm").validate({
submitHandler: function(form) {
var message = <%= jss _("Please wait") -%>;
- //disableFormOnSubmit(message);
$.modalDialog.wait( {message: message});
form.submit();
}
@@ -53,7 +52,7 @@
$('#mailForm').valid();
});
- $("#mailsetting_confirm_password").validate({keyup : true});
+ $("#mailsetting_password_confirmation").validate({keyup : true});
});
</script>
<% end %>
@@ -63,7 +62,7 @@
<% disabled = cannot? :write, Mailsetting %>
<%= render :partial => 'shared/missing_write_permissions' if disabled %>
- <%= form_for(@mail, :url => { :action => "update" }, :html => { :method => :put, :id => "mailForm", :class=>"webyast_form", :autocomplete => :off, :onsubmit => "if ($('#mailForm').valid()); disable_forms ()" } ) do |f| %>
+ <%= form_for(@mail, :url => { :action => "update" }, :html => { :method => :put, :id => "mailForm", :class=>"webyast_form", :autocomplete => :off } ) do |f| %>
<div class="plugin-header">
<div class="left">
@@ -84,29 +83,29 @@
<div class="fieldset_body">
<div class="row">
- <label for="<%= :smtp_server %>"><%=_("Outgoing mail server")%></label>
+ <label style="float:left" for="<%= :smtp_server %>"><%=_("Outgoing mail server")%></label>
<%=f.text_field :smtp_server, :disabled => disabled, :class => "smtp_server tipsy_help", :title => _("URL of the outgoing mail server. You may also specify an alternate port number, e.g.
relay.example.com:26. Use square brackets around the host name to prevent from DNS MX lookups.") %>
@kobliha Owner
kobliha added a note

Just an idea. It could be useful if you've written an example of what is summarized here: square brackets around hostname (with/without port number).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
</div>
<div class="row">
- <label><%=_("Use secure connection (TLS)")%></label>
+ <label style="float:left"><%=_("Use secure connection (TLS)")%></label>
<%= f.select :transport_layer_security, [ [_("Never"), "no" ], [_("If available"), "yes"], [_("Always"), "must"]], :disabled => disabled %>
</div>
<div class="row">
- <label><%=_("User name")%></label>
+ <label style="float:left"><%=_("User name")%></label>
<%= f.text_field :user, :disabled => disabled %>
</div>
<div class="row">
- <label><%=_("Password")%></label>
+ <label style="float:left"><%=_("Password")%></label>
<%= f.password_field :password, :disabled => disabled %>
</div>
<div class="row lastrow">
- <label><%=_("Confirm password")%></label>
- <%= f.password_field :confirm_password, :disabled => disabled, :equalTo => "#mailsetting_password" %>
+ <label style="float:left"><%=_("Confirm password")%></label>
+ <%= f.password_field :password_confirmation, :disabled => disabled, :equalTo => "#mailsetting_password" %>
</div>
</div>
</fieldset>
Something went wrong with that request. Please try again.