From f8bf009cd61ef78da92732390cc1def5c7b4c18b Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Thu, 10 Dec 2020 15:18:49 +0000 Subject: [PATCH] Allow to add subtask from context menu (#34303). Patch by Go MAEDA and Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@20617 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/context_menus_controller.rb | 3 +- app/helpers/issues_helper.rb | 8 +++- app/views/context_menus/issues.html.erb | 4 ++ config/locales/en.yml | 1 + .../context_menus_controller_test.rb | 39 +++++++++++++++++++ test/helpers/issues_helper_test.rb | 7 ++++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb index e9ff824f5..af3bda41d 100644 --- a/app/controllers/context_menus_controller.rb +++ b/app/controllers/context_menus_controller.rb @@ -36,7 +36,8 @@ class ContextMenusController < ApplicationController :log_time => (@project && User.current.allowed_to?(:log_time, @project)), :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?, :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects), - :delete => @issues.all?(&:deletable?) + :delete => @issues.all?(&:deletable?), + :add_subtask => @issue && !@issue.closed? && User.current.allowed_to?(:manage_subtasks, @project) } @assignables = @issues.map(&:assignable_users).reduce(:&) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 0bcb90ad0..808842325 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -235,11 +235,17 @@ module IssuesHelper # Returns a link for adding a new subtask to the given issue def link_to_new_subtask(issue) + link_to(l(:button_add), url_for_new_subtask(issue)) + end + + def url_for_new_subtask(issue) attrs = { :parent_issue_id => issue } attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id') - link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs, :back_url => issue_path(issue))) + params = {:issue => attrs} + params[:back_url] = issue_path(issue) if controller_name == 'issues' && action_name == 'show' + new_project_issue_path(issue.project, params) end def trackers_options_for_select(issue) diff --git a/app/views/context_menus/issues.html.erb b/app/views/context_menus/issues.html.erb index eef2bdea2..3a8e19cdd 100644 --- a/app/views/context_menus/issues.html.erb +++ b/app/views/context_menus/issues.html.erb @@ -151,6 +151,10 @@
  • <%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue), :class => 'icon icon-time-add' %>
  • <% end %> + <% if @can[:add_subtask] -%> +
  • <%= context_menu_link l(:button_add_subtask), url_for_new_subtask(@issue), + :class => 'icon icon-add' %>
  • + <% end %>
  • <%= context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue), :class => 'icon icon-copy', :disabled => !@can[:copy] %>
  • <% else %> diff --git a/config/locales/en.yml b/config/locales/en.yml index b62305b9d..55bb52505 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1160,6 +1160,7 @@ en: button_project_bookmark_delete: Remove bookmark button_filter: Filter button_actions: Actions + button_add_subtask: Add subtask status_active: active status_registered: registered diff --git a/test/functional/context_menus_controller_test.rb b/test/functional/context_menus_controller_test.rb index 5309e7ba6..b1a819422 100644 --- a/test/functional/context_menus_controller_test.rb +++ b/test/functional/context_menus_controller_test.rb @@ -290,6 +290,45 @@ class ContextMenusControllerTest < Redmine::ControllerTest assert_select 'a', :text => 'eCookbook - Shared' end + def test_context_menu_should_include_add_subtask_link + @request.session[:user_id] = 2 + get( + :issues, + :params => { + :ids => [1] + } + ) + assert_response :success + + assert_select 'a.icon-add[href=?]', '/projects/ecookbook/issues/new?issue%5Bparent_issue_id%5D=1&issue%5Btracker_id%5D=1', :text => 'Add subtask' + end + + def test_context_menu_with_closed_issue_should_not_include_add_subtask_link + @request.session[:user_id] = 2 + get( + :issues, + :params => { + :ids => [8] + } + ) + assert_response :success + + assert_select 'a.icon-add', :text => 'Add subtask', :count => 0 + end + + def test_context_menu_multiple_issues_should_not_include_add_subtask_link + @request.session[:user_id] = 2 + get( + :issues, + :params => { + :ids => [1, 2] + } + ) + assert_response :success + + assert_select 'a.icon-add', :text => 'Add subtask', :count => 0 + end + def test_context_menu_with_issue_that_is_not_visible_should_fail get( :issues, diff --git a/test/helpers/issues_helper_test.rb b/test/helpers/issues_helper_test.rb index 4fe603454..fdd5f3598 100644 --- a/test/helpers/issues_helper_test.rb +++ b/test/helpers/issues_helper_test.rb @@ -360,4 +360,11 @@ class IssuesHelperTest < Redmine::HelperTest assert_equal '06/06/2019', issue_due_date_details(issue) end end + + def test_url_for_new_subtask + issue = Issue.find(1) + params = {:issue => {:parent_issue_id => issue.id, :tracker_id => issue.tracker.id}} + assert_equal new_project_issue_path(issue.project, params), + url_for_new_subtask(issue) + end end -- 2.39.5