diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e2eebfa41..b70fa1b6a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1879,4 +1879,15 @@ module ApplicationHelper wiki_pages: auto_complete_wiki_pages_path(project_id: project, q: ''), } end + + def render_top_banner(id: nil, mobile: false) + return if Setting.login_required? && !User.current.logged? + + parsed_banner_text = textilizable(Setting.banner_text) + return if parsed_banner_text.blank? + + tag.div(id: id, class: "wiki top-banner #{mobile ? 'mobile-show' : 'mobile-hide'}") do + parsed_banner_text + end + end end diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index 8114ff9e0..a312c9cd1 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -58,6 +58,7 @@ +<%= render_top_banner(id: 'top-banner') %>
@@ -108,6 +109,7 @@
+ <%= render_top_banner(id: 'top-banner-in-content', mobile: true) %> <%= render_flash_messages %> <%= yield %> <%= call_hook :view_layouts_base_content %> diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 043067f18..0d729f3c1 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -6,6 +6,8 @@

<%= setting_text_area :welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %>

<%= wikitoolbar_for 'settings_welcome_text' %> +

<%= setting_text_area :banner_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %>

+<%= wikitoolbar_for 'settings_banner_text' %>

<%= setting_text_field :per_page_options, :size => 20 %> <%= l(:text_comma_separated) %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 5fee1e225..1a35c22c2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -417,6 +417,7 @@ en: setting_app_title: Application title setting_welcome_text: Welcome text + setting_banner_text: Banner text setting_default_language: Default language setting_login_required: Authentication required setting_self_registration: Self-registration diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 3a250c6c3..eda6f3dce 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -346,6 +346,7 @@ ja: setting_app_title: アプリケーションのタイトル setting_welcome_text: ウェルカムメッセージ + setting_banner_text: バナーメッセージ setting_default_language: デフォルトの言語 setting_login_required: 認証が必要 setting_self_registration: ユーザーによるアカウント登録 diff --git a/config/settings.yml b/config/settings.yml index 0c41b7eda..30c1594db 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -23,6 +23,8 @@ app_title: default: Redmine welcome_text: default: +banner_text: + default: login_required: default: 0 security_notifications: 1 diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 6d7402f66..815019f91 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1151,6 +1151,16 @@ img.ui-datepicker-trigger { margin-bottom: 15px; } +/***** Banner *****/ + +div.top-banner { + padding: 0px 20px; + margin: 0px; + background-color: #dfffdf; + border: 1px solid #9fcf9f; + color: #005f00; +} + /***** Progress bar *****/ table.progress { border-collapse: collapse; diff --git a/public/stylesheets/responsive.css b/public/stylesheets/responsive.css index 3d3a41fff..61cc3afb3 100644 --- a/public/stylesheets/responsive.css +++ b/public/stylesheets/responsive.css @@ -584,6 +584,8 @@ .mobile-hide {display:none;} .mobile-show {display:initial;} + .top-banner.mobile-show { display: block; } + /* Contextual Buttons */ #content>.contextual { diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 93a434e40..69bf42477 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -64,6 +64,22 @@ class AccountControllerTest < Redmine::ControllerTest assert_equal 2, @request.session[:user_id] end + def test_login_should_not_view_banner_if_required_login + with_settings :banner_text => 'h1. banner text' do + with_settings :login_required => '0' do + get :login + assert_response :success + assert_select '#top-banner h1', text: /banner text/ + end + + with_settings :login_required => '1' do + get :login + assert_response :success + assert_select '#top-banner', count: 0 + end + end + end + def test_login_should_redirect_to_back_url_param # request.uri is "test.host" in test environment back_urls = [