Commit acc33668 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'configure-home-page' into 'master'

Allow to specify home page for non logged-in users

See merge request !1404
parents ada6c608 f2eb234c
...@@ -26,6 +26,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -26,6 +26,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:signin_enabled, :signin_enabled,
:gravatar_enabled, :gravatar_enabled,
:sign_in_text, :sign_in_text,
:home_page_url
) )
end end
end end
...@@ -48,6 +48,17 @@ class ApplicationController < ActionController::Base ...@@ -48,6 +48,17 @@ class ApplicationController < ActionController::Base
end end
end end
def authenticate_user!(*args)
# If user is not signe-in and tries to access root_path - redirect him to landing page
if current_application_settings.home_page_url.present?
if current_user.nil? && controller_name == 'dashboard' && action_name == 'show'
redirect_to current_application_settings.home_page_url and return
end
end
super(*args)
end
def log_exception(exception) def log_exception(exception)
application_trace = ActionDispatch::ExceptionWrapper.new(env, exception).application_trace application_trace = ActionDispatch::ExceptionWrapper.new(env, exception).application_trace
application_trace.map!{ |t| " #{t}\n" } application_trace.map!{ |t| " #{t}\n" }
......
...@@ -292,9 +292,4 @@ module ApplicationHelper ...@@ -292,9 +292,4 @@ module ApplicationHelper
profile_key_path(key) profile_key_path(key)
end end
end end
def redirect_from_root?
request.env['rack.session']['user_return_to'] ==
'/'
end
end end
class ApplicationSetting < ActiveRecord::Base class ApplicationSetting < ActiveRecord::Base
validates :home_page_url, allow_blank: true,
format: { with: URI::regexp(%w(http https)), message: "should be a valid url" },
if: :home_page_url_column_exist
def self.current def self.current
ApplicationSetting.last ApplicationSetting.last
end end
...@@ -12,4 +16,8 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -12,4 +16,8 @@ class ApplicationSetting < ActiveRecord::Base
sign_in_text: Settings.extra['sign_in_text'], sign_in_text: Settings.extra['sign_in_text'],
) )
end end
def home_page_url_column_exist
ActiveRecord::Base.connection.column_exists?(:application_settings, :home_page_url)
end
end end
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
= f.label :default_projects_limit, class: 'control-label' = f.label :default_projects_limit, class: 'control-label'
.col-sm-10 .col-sm-10
= f.number_field :default_projects_limit, class: 'form-control' = f.number_field :default_projects_limit, class: 'form-control'
.form-group
= f.label :home_page_url, class: 'control-label'
.col-sm-10
= f.text_field :home_page_url, class: 'form-control', placeholder: 'http://company.example.com'
%span.help-block We will redirect non-logged in users to this page
.form-group .form-group
= f.label :sign_in_text, class: 'control-label' = f.label :sign_in_text, class: 'control-label'
.col-sm-10 .col-sm-10
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
= render "layouts/public_head_panel", title: '' = render "layouts/public_head_panel", title: ''
.container.navless-container .container.navless-container
.content .content
- unless redirect_from_root?
= render "layouts/flash" = render "layouts/flash"
.row.prepend-top-20 .row.prepend-top-20
.col-sm-5.pull-right .col-sm-5.pull-right
......
class AddHomePageUrlForApplicationSettings < ActiveRecord::Migration
def change
add_column :application_settings, :home_page_url, :string
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150108073740) do ActiveRecord::Schema.define(version: 20150116234544) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -24,6 +24,7 @@ ActiveRecord::Schema.define(version: 20150108073740) do ...@@ -24,6 +24,7 @@ ActiveRecord::Schema.define(version: 20150108073740) do
t.text "sign_in_text" t.text "sign_in_text"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "home_page_url"
end end
create_table "broadcast_messages", force: true do |t| create_table "broadcast_messages", force: true do |t|
......
...@@ -5,5 +5,5 @@ Feature: Admin Settings ...@@ -5,5 +5,5 @@ Feature: Admin Settings
And I visit admin settings page And I visit admin settings page
Scenario: Change application settings Scenario: Change application settings
When I disable gravatars and save form When I modify settings and save form
Then I should be see gravatar disabled Then I should see application settings saved
...@@ -4,13 +4,15 @@ class Spinach::Features::AdminSettings < Spinach::FeatureSteps ...@@ -4,13 +4,15 @@ class Spinach::Features::AdminSettings < Spinach::FeatureSteps
include SharedAdmin include SharedAdmin
include Gitlab::CurrentSettings include Gitlab::CurrentSettings
step 'I disable gravatars and save form' do step 'I modify settings and save form' do
uncheck 'Gravatar enabled' uncheck 'Gravatar enabled'
fill_in 'Home page url', with: 'https://about.gitlab.com/'
click_button 'Save' click_button 'Save'
end end
step 'I should be see gravatar disabled' do step 'I should see application settings saved' do
current_application_settings.gravatar_enabled.should be_false current_application_settings.gravatar_enabled.should be_false
current_application_settings.home_page_url.should == 'https://about.gitlab.com/'
page.should have_content 'Application settings saved successfully' page.should have_content 'Application settings saved successfully'
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment