From a4b4af3373fea3afb48a6a0a4ab47047c64752ba Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Wed, 27 Aug 2025 15:05:55 +0900 Subject: [PATCH 2/2] Show the 'Delete' item in the context menu only when opened from Issues#index, Gantts#show, or Calendars#show. --- app/controllers/context_menus_controller.rb | 13 +++++++++++++ app/views/context_menus/issues.html.erb | 6 ++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb index 1e37f623b..bb9e5d82f 100644 --- a/app/controllers/context_menus_controller.rb +++ b/app/controllers/context_menus_controller.rb @@ -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] diff --git a/app/views/context_menus/issues.html.erb b/app/views/context_menus/issues.html.erb index ee7eaa18c..23b7718f1 100644 --- a/app/views/context_menus/issues.html.erb +++ b/app/views/context_menus/issues.html.erb @@ -173,8 +173,10 @@
  • <%= 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] %>
  • <% end %> -
  • <%= 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] %>
  • + <% if @include_delete %> +
  • <%= 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] %>
  • + <% end %> <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %> -- 2.50.1