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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 = {:edit => @issues.all?(&:attributes_editable?),
  29. :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
  30. :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
  31. :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
  32. :delete => @issues.all?(&:deletable?)
  33. }
  34. @assignables = @issues.map(&:assignable_users).reduce(:&)
  35. @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
  36. @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
  37. @priorities = IssuePriority.active.reverse
  38. @back = back_url
  39. @columns = params[:c]
  40. @options_by_custom_field = {}
  41. if @can[:edit]
  42. custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
  43. custom_fields.each do |field|
  44. values = field.possible_values_options(@projects)
  45. if values.present?
  46. @options_by_custom_field[field] = values
  47. end
  48. end
  49. end
  50. @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
  51. render :layout => false
  52. end
  53. def time_entries
  54. @time_entries = TimeEntry.where(:id => params[:ids]).
  55. preload(:project => :time_entry_activities).
  56. preload(:user).to_a
  57. (render_404; return) unless @time_entries.present?
  58. if (@time_entries.size == 1)
  59. @time_entry = @time_entries.first
  60. end
  61. @projects = @time_entries.collect(&:project).compact.uniq
  62. @project = @projects.first if @projects.size == 1
  63. @activities = @projects.map(&:activities).reduce(:&)
  64. edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)}
  65. @can = {:edit => edit_allowed, :delete => edit_allowed}
  66. @back = back_url
  67. @options_by_custom_field = {}
  68. if @can[:edit]
  69. custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
  70. custom_fields.each do |field|
  71. values = field.possible_values_options(@projects)
  72. if values.present?
  73. @options_by_custom_field[field] = values
  74. end
  75. end
  76. end
  77. render :layout => false
  78. end
  79. end