From 4019ba76ab3005ccc1f0495069861e4a8814be55 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 9 May 2016 17:16:55 +0000 Subject: [PATCH] Restores the "New issue" tab in the project menu and makes it optional (#6204). git-svn-id: http://svn.redmine.org/redmine/trunk@15407 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 10 +++++ app/views/settings/_display.html.erb | 2 + config/locales/en.yml | 1 + config/locales/fr.yml | 1 + config/settings.yml | 2 + lib/redmine.rb | 4 ++ test/functional/issues_controller_test.rb | 54 +++++++++++++++++++++-- 7 files changed, 70 insertions(+), 4 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 7c10769aa..cf402de22 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -350,6 +350,16 @@ class IssuesController < ApplicationController end end + # Overrides Redmine::MenuManager::MenuController::ClassMethods for + # when the "New issue" tab is enabled + def current_menu_item + if Setting.new_project_issue_tab_enabled? && [:new, :create].include?(action_name.to_sym) + :new_issue + else + super + end + end + private def retrieve_previous_and_next_issue_ids diff --git a/app/views/settings/_display.html.erb b/app/views/settings/_display.html.erb index 3497f9076..1185a7cae 100644 --- a/app/views/settings/_display.html.erb +++ b/app/views/settings/_display.html.erb @@ -24,6 +24,8 @@

<%= setting_check_box :thumbnails_enabled %>

<%= setting_text_field :thumbnails_size, :size => 6 %>

+ +

<%= setting_check_box :new_project_issue_tab_enabled %>

<%= submit_tag l(:button_save) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e1a8f2bd4..b3396c5de 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -443,6 +443,7 @@ en: setting_search_results_per_page: Search results per page setting_attachment_extensions_allowed: Allowed extensions setting_attachment_extensions_denied: Disallowed extensions + setting_new_project_issue_tab_enabled: Display the "New issue" tab permission_add_project: Create project permission_add_subprojects: Create subprojects diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 659a873ea..6a72024f6 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -455,6 +455,7 @@ fr: setting_attachment_extensions_denied: Extensions non autorisées setting_sys_api_key: Clé de protection de l'API setting_lost_password: Autoriser la réinitialisation par email de mot de passe perdu + setting_new_project_issue_tab_enabled: Afficher l'onglet "Nouvelle demande" permission_add_project: Créer un projet permission_add_subprojects: Créer des sous-projets diff --git a/config/settings.yml b/config/settings.yml index 20dfe5416..fd807c8a1 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -275,3 +275,5 @@ non_working_week_days: default: - '6' - '7' +new_project_issue_tab_enabled: + default: 0 diff --git a/lib/redmine.rb b/lib/redmine.rb index 540384071..1d37a523b 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -231,6 +231,10 @@ Redmine::MenuManager.map :project_menu do |menu| menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id, :if => Proc.new { |p| p.shared_versions.any? } menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural + menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new, + :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }, + :if => Proc.new { |p| Setting.new_project_issue_tab_enabled? && p.trackers.any? }, + :permission => :add_issues menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 0a021289a..8e04d7cf5 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1060,7 +1060,7 @@ class IssuesControllerTest < ActionController::TestCase def test_index_should_include_new_issue_link @request.session[:user_id] = 2 get :index, :project_id => 1 - assert_select 'a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue' + assert_select '#content a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue' end def test_index_should_not_include_new_issue_link_for_project_without_trackers @@ -1068,7 +1068,7 @@ class IssuesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 get :index, :project_id => 1 - assert_select 'a.new-issue', 0 + assert_select '#content a.new-issue', 0 end def test_index_should_not_include_new_issue_link_for_users_with_copy_issues_permission_only @@ -1078,13 +1078,59 @@ class IssuesControllerTest < ActionController::TestCase @request.session[:user_id] = 2 get :index, :project_id => 1 - assert_select 'a.new-issue', 0 + assert_select '#content a.new-issue', 0 end def test_index_without_project_should_include_new_issue_link @request.session[:user_id] = 2 get :index - assert_select 'a.new-issue[href="/issues/new"]', :text => 'New issue' + assert_select '#content a.new-issue[href="/issues/new"]', :text => 'New issue' + end + + def test_index_should_not_include_new_issue_tab_when_disabled + with_settings :new_project_issue_tab_enabled => '0' do + @request.session[:user_id] = 2 + get :index, :project_id => 1 + assert_select '#main-menu a.new-issue', 0 + end + end + + def test_index_should_include_new_issue_tab_when_enabled + with_settings :new_project_issue_tab_enabled => '1' do + @request.session[:user_id] = 2 + get :index, :project_id => 1 + assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue' + end + end + + def test_new_should_have_new_issue_tab_as_current_menu_item + with_settings :new_project_issue_tab_enabled => '1' do + @request.session[:user_id] = 2 + get :new, :project_id => 1 + assert_select '#main-menu a.new-issue.selected' + end + end + + def test_index_should_not_include_new_issue_tab_for_project_without_trackers + with_settings :new_project_issue_tab_enabled => '1' do + Project.find(1).trackers.clear + + @request.session[:user_id] = 2 + get :index, :project_id => 1 + assert_select '#main-menu a.new-issue', 0 + end + end + + def test_index_should_not_include_new_issue_tab_for_users_with_copy_issues_permission_only + with_settings :new_project_issue_tab_enabled => '1' do + role = Role.find(1) + role.remove_permission! :add_issues + role.add_permission! :copy_issues + + @request.session[:user_id] = 2 + get :index, :project_id => 1 + assert_select '#main-menu a.new-issue', 0 + end end def test_show_by_anonymous -- 2.39.5