Project

General

Profile

Defect #8560 ยป context_menus_controller.rb

Nicolas Connault, 2011-06-11 01:15

 
1
class ContextMenusController < ApplicationController
2
      helper :watchers
3
      helper :issues
4
    
5
      def issues
6
        @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
7
    
8
        if (@issues.size == 1)
9
          @issue = @issues.first
10
          @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
11
        else
12
          @allowed_statuses = @issues.map do |i|
13
            i.new_statuses_allowed_to(User.current)
14
          end.inject do |memo,s|
15
            memo & s
16
          end
17
        end
18
        @projects = @issues.collect(&:project).compact.uniq
19
        @project = @projects.first if @projects.size == 1
20
    
21
        @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
22
                :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
23
                :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
24
                :move => (@project && User.current.allowed_to?(:move_issues, @project)),
25
                :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
26
                :delete => User.current.allowed_to?(:delete_issues, @projects)
27
                }
28
        
29
        if @project
30
          @assignables = @project.assignable_users
31
          @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
32
          @trackers = @project.trackers
33
        else
34
          #when multiple projects, we only keep the intersection of each set
35
          @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
36
          @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
37
        end 
38
	  
39
        @priorities = IssuePriority.all.reverse
40
        @statuses = IssueStatus.find(:all, :order => 'position')
41
        @back = back_url
42
    
43
        render :layout => false
44
      end
45
    
46
      def time_entries
47
        @time_entries = TimeEntry.all(
48
           :conditions => {:id => params[:ids]}, :include => :project)
49
        @projects = @time_entries.collect(&:project).compact.uniq
50
        @project = @projects.first if @projects.size == 1
51
        @activities = TimeEntryActivity.shared.active
52
        @can = {:edit   => User.current.allowed_to?(:log_time, @projects),
53
                :update => User.current.allowed_to?(:log_time, @projects),
54
                :delete => User.current.allowed_to?(:log_time, @projects)
55
                }
56
        @back = back_url
57
        render :layout => false
58
      end
59
    end
    (1-1/1)