annotate app/controllers/context_menus_controller.rb @ 1466:834828a14f2b bug_598

Close obsolete branch bug_598
author Chris Cannam
date Fri, 21 Jun 2013 14:51:55 +0100
parents 433d4f72a19b
children 622f24f53b42 261b3d9a4903
rev   line source
Chris@1115 1 # Redmine - project management software
Chris@1115 2 # Copyright (C) 2006-2012 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@14 22 def issues
Chris@119 23 @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
Chris@14 24 if (@issues.size == 1)
Chris@14 25 @issue = @issues.first
Chris@14 26 end
Chris@1115 27 @issue_ids = @issues.map(&:id).sort
Chris@1115 28
Chris@1115 29 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
chris@22 30 @projects = @issues.collect(&:project).compact.uniq
chris@22 31 @project = @projects.first if @projects.size == 1
Chris@14 32
chris@37 33 @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
Chris@14 34 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
chris@37 35 :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
Chris@14 36 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
Chris@14 37 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
chris@37 38 :delete => User.current.allowed_to?(:delete_issues, @projects)
Chris@14 39 }
Chris@14 40 if @project
Chris@909 41 if @issue
Chris@909 42 @assignables = @issue.assignable_users
Chris@909 43 else
Chris@909 44 @assignables = @project.assignable_users
Chris@909 45 end
Chris@14 46 @trackers = @project.trackers
chris@37 47 else
chris@37 48 #when multiple projects, we only keep the intersection of each set
Chris@1115 49 @assignables = @projects.map(&:assignable_users).reduce(:&)
Chris@1115 50 @trackers = @projects.map(&:trackers).reduce(:&)
Chris@1115 51 end
Chris@1115 52 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
Chris@1115 53
Chris@1115 54 @priorities = IssuePriority.active.reverse
Chris@1115 55 @back = back_url
Chris@1115 56
Chris@1115 57 @options_by_custom_field = {}
Chris@1115 58 if @can[:edit]
Chris@1115 59 custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
Chris@1115 60 %w(bool list user version).include?(f.field_format) && !f.multiple?
Chris@1115 61 end
Chris@1115 62 custom_fields.each do |field|
Chris@1115 63 values = field.possible_values_options(@projects)
Chris@1115 64 if values.any?
Chris@1115 65 @options_by_custom_field[field] = values
Chris@1115 66 end
Chris@1115 67 end
Chris@14 68 end
Chris@909 69
Chris@1115 70 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
Chris@14 71 render :layout => false
Chris@14 72 end
Chris@441 73
Chris@441 74 def time_entries
Chris@441 75 @time_entries = TimeEntry.all(
Chris@441 76 :conditions => {:id => params[:ids]}, :include => :project)
Chris@441 77 @projects = @time_entries.collect(&:project).compact.uniq
Chris@441 78 @project = @projects.first if @projects.size == 1
Chris@441 79 @activities = TimeEntryActivity.shared.active
Chris@909 80 @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
Chris@909 81 :delete => User.current.allowed_to?(:edit_time_entries, @projects)
Chris@441 82 }
Chris@441 83 @back = back_url
Chris@441 84 render :layout => false
Chris@909 85 end
Chris@14 86 end