You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context_menus_controller.rb 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class ContextMenusController < ApplicationController
  19. helper :watchers
  20. helper :issues
  21. before_action :find_issues, :only => :issues
  22. def issues
  23. if @issues.size == 1
  24. @issue = @issues.first
  25. end
  26. @issue_ids = @issues.map(&:id).sort
  27. @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
  28. @can = {
  29. :edit => @issues.all?(&:attributes_editable?),
  30. :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
  31. :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
  32. :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
  33. :delete => @issues.all?(&:deletable?),
  34. :add_subtask => @issue && !@issue.closed? && User.current.allowed_to?(:manage_subtasks, @project)
  35. }
  36. @assignables = @issues.map(&:assignable_users).reduce(:&)
  37. @trackers = @projects.map {|p| Issue.allowed_target_trackers(p)}.reduce(:&)
  38. @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
  39. @priorities = IssuePriority.active.reverse
  40. @back = back_url
  41. @columns = params[:c]
  42. @options_by_custom_field = {}
  43. if @can[:edit]
  44. custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
  45. custom_fields.each do |field|
  46. values = field.possible_values_options(@projects)
  47. if values.present?
  48. @options_by_custom_field[field] = values
  49. end
  50. end
  51. end
  52. @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
  53. render :layout => false
  54. end
  55. def time_entries
  56. @time_entries = TimeEntry.where(:id => params[:ids]).
  57. preload(:project => :time_entry_activities).
  58. preload(:user).to_a
  59. (render_404; return) unless @time_entries.present?
  60. if @time_entries.size == 1
  61. @time_entry = @time_entries.first
  62. end
  63. @projects = @time_entries.collect(&:project).compact.uniq
  64. @project = @projects.first if @projects.size == 1
  65. @activities = @projects.map(&:activities).reduce(:&)
  66. edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)}
  67. @can = {:edit => edit_allowed, :delete => edit_allowed}
  68. @back = back_url
  69. @options_by_custom_field = {}
  70. if @can[:edit]
  71. custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
  72. custom_fields.each do |field|
  73. values = field.possible_values_options(@projects)
  74. if values.present?
  75. @options_by_custom_field[field] = values
  76. end
  77. end
  78. end
  79. render :layout => false
  80. end
  81. end