Skip to content

Commit

Permalink
Merge pull request #211 from dmacvicar/dmacvicar_error_messages
Browse files Browse the repository at this point in the history
Better feedback on a wrongly configured (OBS auth) instance
  • Loading branch information
lnussel committed Feb 9, 2018
2 parents 96f83c8 + 2e6171a commit b8e0375
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
11 changes: 11 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class ApplicationController < ActionController::Base

before_action :validate_configuration
before_action :set_language
before_action :set_distributions
before_action :set_baseproject
Expand All @@ -32,6 +33,16 @@ class MissingParameterError < Exception; end
render :template => 'error', :formats => [:html], :layout => layout, :status => 400
end

def validate_configuration
config = Rails.configuration.x
layout = request.xhr? ? false : "application"

if config.api_username.blank? && config.opensuse_cookie.blank?
@message = _("The authentication to the OBS API has not been configured correctly.")
render :template => 'error', :formats => [:html], :layout => layout, :status => 503
end
end

def set_language
set_gettext_locale
requested_locale = FastGettext.locale
Expand Down
11 changes: 4 additions & 7 deletions app/views/error.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<% @page_title = "Error" -%>

<div class="box box-shadow">
<h2 class="box-header">
<span class="alignleft"><%= @page_title -%></span></h2>
<div>
<% @page_title = "Error" if @page_title.blank? -%>

<div class="container">
<h2Y<%= @page_title -%></h2>
<div class="alert alert-danger">
<p><%=h @message %></p>

</div>
</div>
10 changes: 3 additions & 7 deletions config/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ defaults: &defaults
api_host: https://api.opensuse.org
api_username: test
api_password: test
relative_url_root:

relative_url_root:
development:
<<: *defaults
api_username: wiki_hermes
api_password: w_h_p1

test:
<<: *defaults
# only for production use
#opensuse_cookie:
production:
<<: *defaults
relative_url_root:
relative_url_root:
api_username: <%= ENV['API_USERNAME'] %>
api_password: <%= ENV['API_PASSWORD'] %>
use_static: software.o.o
opensuse_cookie: <%= ENV['OPENSUSE_COOKIE'] %>
opensuse_cookie: <%= ENV['OPENSUSE_COOKIE'] %>
4 changes: 2 additions & 2 deletions test/integration/package_information_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PackageInformationTest < ActionDispatch::IntegrationTest
def test_package_information
# Check that package information is displayed
visit '/package/pidgin'
assert page.has_content? 'Multiprotocol Instant Messaging Client'
assert page.has_content? 'Pidgin is a chat program'
page.assert_text 'Multiprotocol Instant Messaging Client'
page.assert_text 'Pidgin is a chat program'
end
end
17 changes: 17 additions & 0 deletions test/integration/validate_configuration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require File.expand_path('../../test_helper', __FILE__)

class ValidateConfigurationTest < ActionDispatch::IntegrationTest
def test_validate_configuration
# Fake that authentication is not configured
x = Rails.configuration.x.clone
Rails.configuration.x.api_username = nil
Rails.configuration.x.opensuse_cookie = nil

visit '/'
page.assert_text 'The authentication to the OBS API has not been configured correctly.'
assert_equal 503, page.status_code

# Restore normal configuration values for other tests
Rails.configuration.x = x
end
end

0 comments on commit b8e0375

Please sign in to comment.