mirror of
https://github.com/meineerde/redmine.git
synced 2026-02-10 12:45:24 +00:00
Show the "Delete" item in the context menu only when opened from Issues#index, Gantts#show, or Calendars#show. (#35616).
Patch by Go MAEDA (user:maeda). git-svn-id: https://svn.redmine.org/redmine/trunk@23938 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
43ef62c0d3
commit
9b4f905c78
@ -46,6 +46,19 @@ class ContextMenusController < ApplicationController
|
||||
|
||||
@priorities = IssuePriority.active.reverse
|
||||
@back = back_url
|
||||
begin
|
||||
# Recognize the controller and action from the back_url to determine
|
||||
# which view triggered the context menu.
|
||||
route = Rails.application.routes.recognize_path(@back)
|
||||
@include_delete =
|
||||
[
|
||||
{controller: 'issues', action: 'index'},
|
||||
{controller: 'gantts', action: 'show'},
|
||||
{controller: 'calendars', action: 'show'}
|
||||
].any?(route.slice(:controller, :action))
|
||||
rescue ActionController::RoutingError
|
||||
@include_delete = false
|
||||
end
|
||||
|
||||
@columns = params[:c]
|
||||
|
||||
|
||||
@ -173,8 +173,10 @@
|
||||
<li><%= context_menu_link sprite_icon('copy', l(:button_copy)), bulk_edit_issues_path(:ids => @issue_ids, :copy => '1'),
|
||||
:class => 'icon icon-copy', :disabled => !@can[:copy] %></li>
|
||||
<% end %>
|
||||
<li><%= context_menu_link sprite_icon('del', l(:button_delete_object, object_name: (@issue_ids.size > 1 ? l(:label_issue_plural) : l(:label_issue))).capitalize), issues_path(:ids => @issue_ids, :back_url => @back),
|
||||
:method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon icon-del', :disabled => !@can[:delete] %></li>
|
||||
<% if @include_delete %>
|
||||
<li><%= context_menu_link sprite_icon('del', l(:button_delete_object, object_name: (@issue_ids.size > 1 ? l(:label_issue_plural) : l(:label_issue))).capitalize), issues_path(:ids => @issue_ids, :back_url => @back),
|
||||
:method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon icon-del', :disabled => !@can[:delete] %></li>
|
||||
<% end %>
|
||||
|
||||
<%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
|
||||
</ul>
|
||||
|
||||
@ -459,4 +459,30 @@ class ContextMenusControllerTest < Redmine::ControllerTest
|
||||
|
||||
assert_select 'a.disabled', :text => 'Bulk edit'
|
||||
end
|
||||
|
||||
def test_context_menu_should_include_delete_for_allowed_back_urls
|
||||
@request.session[:user_id] = 2
|
||||
%w[
|
||||
/issues
|
||||
/projects/ecookbook/issues/gantt
|
||||
/projects/ecookbook/issues/calendar
|
||||
].each do |back_url|
|
||||
get :issues, :params => { :ids => [1], :back_url => back_url }
|
||||
assert_response :success
|
||||
assert_select 'a.icon-del', :text => /Delete/
|
||||
end
|
||||
end
|
||||
|
||||
def test_context_menu_should_not_include_delete_for_disallowed_back_urls
|
||||
@request.session[:user_id] = 2
|
||||
%w[
|
||||
/issues/1
|
||||
/projects/ecookbook/roadmap
|
||||
/not/a/real/path
|
||||
].each do |back_url|
|
||||
get :issues, :params => { :ids => [1], :back_url => back_url }
|
||||
assert_response :success
|
||||
assert_select 'a.icon-del', :count => 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user