diff options
-rw-r--r-- | app/controllers/context_menus_controller.rb | 3 | ||||
-rw-r--r-- | app/helpers/issues_helper.rb | 8 | ||||
-rw-r--r-- | app/views/context_menus/issues.html.erb | 4 | ||||
-rw-r--r-- | config/locales/en.yml | 1 | ||||
-rw-r--r-- | test/functional/context_menus_controller_test.rb | 39 | ||||
-rw-r--r-- | 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 @@ <li><%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue), :class => 'icon icon-time-add' %></li> <% end %> + <% if @can[:add_subtask] -%> + <li><%= context_menu_link l(:button_add_subtask), url_for_new_subtask(@issue), + :class => 'icon icon-add' %></li> + <% end %> <li><%= context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue), :class => 'icon icon-copy', :disabled => !@can[:copy] %></li> <% 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 |