2019-03-16 09:37:35 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2012-05-05 12:56:53 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2012-05-05 12:56:53 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
2010-08-19 18:16:54 +00:00
|
|
|
class ContextMenusController < ApplicationController
|
|
|
|
|
helper :watchers
|
2011-04-17 15:17:18 +00:00
|
|
|
helper :issues
|
2011-08-30 13:03:57 +00:00
|
|
|
|
2016-07-14 07:27:31 +00:00
|
|
|
before_action :find_issues, :only => :issues
|
2013-06-11 18:33:06 +00:00
|
|
|
|
2010-08-19 18:16:54 +00:00
|
|
|
def issues
|
2019-10-19 13:32:37 +00:00
|
|
|
if @issues.size == 1
|
2010-08-19 18:16:54 +00:00
|
|
|
@issue = @issues.first
|
|
|
|
|
end
|
2012-07-08 13:31:22 +00:00
|
|
|
@issue_ids = @issues.map(&:id).sort
|
2012-02-09 19:51:38 +00:00
|
|
|
|
2012-02-09 20:06:36 +00:00
|
|
|
@allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
|
2010-08-19 18:16:54 +00:00
|
|
|
|
2020-10-27 15:18:17 +00:00
|
|
|
@can = {
|
|
|
|
|
:edit => @issues.all?(&:attributes_editable?),
|
2025-03-30 07:48:53 +00:00
|
|
|
:log_time => @issue&.time_loggable?,
|
2020-10-27 15:18:17 +00:00
|
|
|
:copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
|
|
|
|
|
:add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
|
2020-12-10 15:18:49 +00:00
|
|
|
:delete => @issues.all?(&:deletable?),
|
|
|
|
|
:add_subtask => @issue && !@issue.closed? && User.current.allowed_to?(:manage_subtasks, @project)
|
2020-10-27 15:18:17 +00:00
|
|
|
}
|
2016-06-28 20:31:08 +00:00
|
|
|
|
|
|
|
|
@assignables = @issues.map(&:assignable_users).reduce(:&)
|
2020-08-07 12:42:34 +00:00
|
|
|
@trackers = @projects.map {|p| Issue.allowed_target_trackers(p)}.reduce(:&)
|
2012-07-08 13:19:46 +00:00
|
|
|
@versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
|
2011-08-30 13:03:57 +00:00
|
|
|
|
2011-06-13 19:43:40 +00:00
|
|
|
@priorities = IssuePriority.active.reverse
|
2010-08-19 18:16:54 +00:00
|
|
|
@back = back_url
|
2025-09-04 05:31:22 +00:00
|
|
|
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
|
2011-08-30 13:03:57 +00:00
|
|
|
|
2019-03-15 07:52:21 +00:00
|
|
|
@columns = params[:c]
|
2019-03-15 07:50:50 +00:00
|
|
|
|
2012-02-09 18:22:11 +00:00
|
|
|
@options_by_custom_field = {}
|
|
|
|
|
if @can[:edit]
|
2016-10-23 11:48:52 +00:00
|
|
|
custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
|
2012-02-09 18:22:11 +00:00
|
|
|
custom_fields.each do |field|
|
|
|
|
|
values = field.possible_values_options(@projects)
|
2013-12-14 08:57:30 +00:00
|
|
|
if values.present?
|
2012-02-09 18:22:11 +00:00
|
|
|
@options_by_custom_field[field] = values
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-07-05 12:20:07 +00:00
|
|
|
@safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
|
2010-08-19 18:16:54 +00:00
|
|
|
render :layout => false
|
|
|
|
|
end
|
2011-04-04 11:53:03 +00:00
|
|
|
|
|
|
|
|
def time_entries
|
2016-11-18 08:19:11 +00:00
|
|
|
@time_entries = TimeEntry.where(:id => params[:ids]).
|
|
|
|
|
preload(:project => :time_entry_activities).
|
|
|
|
|
preload(:user).to_a
|
|
|
|
|
|
2013-01-20 16:04:25 +00:00
|
|
|
(render_404; return) unless @time_entries.present?
|
2019-10-19 13:32:37 +00:00
|
|
|
if @time_entries.size == 1
|
2014-07-29 17:52:27 +00:00
|
|
|
@time_entry = @time_entries.first
|
|
|
|
|
end
|
2013-01-20 16:04:25 +00:00
|
|
|
|
2023-01-17 01:38:27 +00:00
|
|
|
@projects = @time_entries.filter_map(&:project).uniq
|
2011-04-04 11:53:03 +00:00
|
|
|
@project = @projects.first if @projects.size == 1
|
2016-11-18 08:19:11 +00:00
|
|
|
@activities = @projects.map(&:activities).reduce(:&)
|
2015-05-09 10:10:28 +00:00
|
|
|
|
|
|
|
|
edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)}
|
|
|
|
|
@can = {:edit => edit_allowed, :delete => edit_allowed}
|
2011-04-04 11:53:03 +00:00
|
|
|
@back = back_url
|
2014-07-29 17:52:27 +00:00
|
|
|
|
|
|
|
|
@options_by_custom_field = {}
|
|
|
|
|
if @can[:edit]
|
2016-10-23 11:51:26 +00:00
|
|
|
custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
|
2014-07-29 17:52:27 +00:00
|
|
|
custom_fields.each do |field|
|
|
|
|
|
values = field.possible_values_options(@projects)
|
|
|
|
|
if values.present?
|
|
|
|
|
@options_by_custom_field[field] = values
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-04-04 11:53:03 +00:00
|
|
|
render :layout => false
|
2011-08-30 13:03:57 +00:00
|
|
|
end
|
2022-04-01 15:09:28 +00:00
|
|
|
|
|
|
|
|
def projects
|
|
|
|
|
@projects = Project.where(id: params[:ids]).to_a
|
|
|
|
|
if @projects.empty?
|
|
|
|
|
render_404
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if @projects.size == 1
|
|
|
|
|
@project = @projects.first
|
|
|
|
|
end
|
|
|
|
|
render layout: false
|
|
|
|
|
end
|
2022-09-20 03:16:05 +00:00
|
|
|
|
|
|
|
|
def users
|
|
|
|
|
@users = User.where(id: params[:ids]).to_a
|
|
|
|
|
|
|
|
|
|
(render_404; return) unless @users.present?
|
|
|
|
|
if @users.size == 1
|
|
|
|
|
@user = @users.first
|
|
|
|
|
end
|
|
|
|
|
render layout: false
|
|
|
|
|
end
|
2010-08-19 18:16:54 +00:00
|
|
|
end
|