annotate app/controllers/context_menus_controller.rb @ 1613:90bed4e10cc8 deploy

Download file link
author Chris Cannam
date Wed, 30 Aug 2017 17:24:37 +0100
parents dffacf8a6908
children
rev   line source
Chris@1115 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1115 3 #
Chris@1115 4 # This program is free software; you can redistribute it and/or
Chris@1115 5 # modify it under the terms of the GNU General Public License
Chris@1115 6 # as published by the Free Software Foundation; either version 2
Chris@1115 7 # of the License, or (at your option) any later version.
Chris@1115 8 #
Chris@1115 9 # This program is distributed in the hope that it will be useful,
Chris@1115 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1115 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1115 12 # GNU General Public License for more details.
Chris@1115 13 #
Chris@1115 14 # You should have received a copy of the GNU General Public License
Chris@1115 15 # along with this program; if not, write to the Free Software
Chris@1115 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1115 17
Chris@14 18 class ContextMenusController < ApplicationController
Chris@14 19 helper :watchers
Chris@441 20 helper :issues
Chris@909 21
Chris@1464 22 before_filter :find_issues, :only => :issues
Chris@1464 23
Chris@14 24 def issues
Chris@14 25 if (@issues.size == 1)
Chris@14 26 @issue = @issues.first
Chris@14 27 end
Chris@1115 28 @issue_ids = @issues.map(&:id).sort
Chris@1115 29
Chris@1115 30 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
Chris@14 31
chris@37 32 @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
Chris@14 33 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
chris@37 34 :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
Chris@14 35 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
Chris@14 36 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
chris@37 37 :delete => User.current.allowed_to?(:delete_issues, @projects)
Chris@14 38 }
Chris@14 39 if @project
Chris@909 40 if @issue
Chris@909 41 @assignables = @issue.assignable_users
Chris@909 42 else
Chris@909 43 @assignables = @project.assignable_users
Chris@909 44 end
Chris@14 45 @trackers = @project.trackers
chris@37 46 else
chris@37 47 #when multiple projects, we only keep the intersection of each set
Chris@1115 48 @assignables = @projects.map(&:assignable_users).reduce(:&)
Chris@1115 49 @trackers = @projects.map(&:trackers).reduce(:&)
Chris@1115 50 end
Chris@1115 51 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
Chris@1115 52
Chris@1115 53 @priorities = IssuePriority.active.reverse
Chris@1115 54 @back = back_url
Chris@1115 55
Chris@1115 56 @options_by_custom_field = {}
Chris@1115 57 if @can[:edit]
Chris@1517 58 custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?)
Chris@1115 59 custom_fields.each do |field|
Chris@1115 60 values = field.possible_values_options(@projects)
Chris@1517 61 if values.present?
Chris@1115 62 @options_by_custom_field[field] = values
Chris@1115 63 end
Chris@1115 64 end
Chris@14 65 end
Chris@909 66
Chris@1115 67 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
Chris@14 68 render :layout => false
Chris@14 69 end
Chris@441 70
Chris@441 71 def time_entries
Chris@1464 72 @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a
Chris@1464 73 (render_404; return) unless @time_entries.present?
Chris@1464 74
Chris@441 75 @projects = @time_entries.collect(&:project).compact.uniq
Chris@441 76 @project = @projects.first if @projects.size == 1
Chris@441 77 @activities = TimeEntryActivity.shared.active
Chris@909 78 @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
Chris@909 79 :delete => User.current.allowed_to?(:edit_time_entries, @projects)
Chris@441 80 }
Chris@441 81 @back = back_url
Chris@441 82 render :layout => false
Chris@909 83 end
Chris@14 84 end