Feature #35616 » 0002-Show-the-Delete-item-in-the-context-menu-only-when-o.patch
app/controllers/context_menus_controller.rb | ||
---|---|---|
46 | 46 | |
47 | 47 |
@priorities = IssuePriority.active.reverse |
48 | 48 |
@back = back_url |
49 |
begin |
|
50 |
# Recognize the controller and action from the back_url to determine |
|
51 |
# which view triggered the context menu. |
|
52 |
route = Rails.application.routes.recognize_path(@back) |
|
53 |
@include_delete = |
|
54 |
[ |
|
55 |
{controller: 'issues', action: 'index'}, |
|
56 |
{controller: 'gantts', action: 'show'}, |
|
57 |
{controller: 'calendars', action: 'show'} |
|
58 |
].any?(route.slice(:controller, :action)) |
|
59 |
rescue ActionController::RoutingError |
|
60 |
@include_delete = false |
|
61 |
end |
|
49 | 62 | |
50 | 63 |
@columns = params[:c] |
51 | 64 |
app/views/context_menus/issues.html.erb | ||
---|---|---|
173 | 173 |
<li><%= context_menu_link sprite_icon('copy', l(:button_copy)), bulk_edit_issues_path(:ids => @issue_ids, :copy => '1'), |
174 | 174 |
:class => 'icon icon-copy', :disabled => !@can[:copy] %></li> |
175 | 175 |
<% end %> |
176 |
<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), |
|
177 |
:method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon icon-del', :disabled => !@can[:delete] %></li> |
|
176 |
<% if @include_delete %> |
|
177 |
<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), |
|
178 |
:method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon icon-del', :disabled => !@can[:delete] %></li> |
|
179 |
<% end %> |
|
178 | 180 | |
179 | 181 |
<%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %> |
180 | 182 |
</ul> |
test/functional/context_menus_controller_test.rb | ||
---|---|---|
459 | 459 | |
460 | 460 |
assert_select 'a.disabled', :text => 'Bulk edit' |
461 | 461 |
end |
462 | ||
463 |
def test_context_menu_should_include_delete_for_allowed_back_urls |
|
464 |
@request.session[:user_id] = 2 |
|
465 |
%w[ |
|
466 |
/issues |
|
467 |
/projects/ecookbook/issues/gantt |
|
468 |
/projects/ecookbook/issues/calendar |
|
469 |
].each do |back_url| |
|
470 |
get :issues, :params => { :ids => [1], :back_url => back_url } |
|
471 |
assert_response :success |
|
472 |
assert_select 'a.icon-del', :text => /Delete/ |
|
473 |
end |
|
474 |
end |
|
475 | ||
476 |
def test_context_menu_should_not_include_delete_for_disallowed_back_urls |
|
477 |
@request.session[:user_id] = 2 |
|
478 |
%w[ |
|
479 |
/issues/1 |
|
480 |
/projects/ecookbook/roadmap |
|
481 |
/not/a/real/path |
|
482 |
].each do |back_url| |
|
483 |
get :issues, :params => { :ids => [1], :back_url => back_url } |
|
484 |
assert_response :success |
|
485 |
assert_select 'a.icon-del', :count => 0 |
|
486 |
end |
|
487 |
end |
|
462 | 488 |
end |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »