##// END OF EJS Templates
Time Entries context menu shows activities not available for the time entry's project (#23922)....
Jean-Philippe Lang -
r15570:88ab6dd946f0
parent child
Show More
@@ -1,89 +1,92
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class ContextMenusController < ApplicationController
18 class ContextMenusController < ApplicationController
19 helper :watchers
19 helper :watchers
20 helper :issues
20 helper :issues
21
21
22 before_action :find_issues, :only => :issues
22 before_action :find_issues, :only => :issues
23
23
24 def issues
24 def issues
25 if (@issues.size == 1)
25 if (@issues.size == 1)
26 @issue = @issues.first
26 @issue = @issues.first
27 end
27 end
28 @issue_ids = @issues.map(&:id).sort
28 @issue_ids = @issues.map(&:id).sort
29
29
30 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
30 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
31
31
32 @can = {:edit => @issues.all?(&:attributes_editable?),
32 @can = {:edit => @issues.all?(&:attributes_editable?),
33 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
33 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
34 :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
34 :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
35 :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
35 :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
36 :delete => @issues.all?(&:deletable?)
36 :delete => @issues.all?(&:deletable?)
37 }
37 }
38
38
39 @assignables = @issues.map(&:assignable_users).reduce(:&)
39 @assignables = @issues.map(&:assignable_users).reduce(:&)
40 @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
40 @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
41 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
41 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
42
42
43 @priorities = IssuePriority.active.reverse
43 @priorities = IssuePriority.active.reverse
44 @back = back_url
44 @back = back_url
45
45
46 @options_by_custom_field = {}
46 @options_by_custom_field = {}
47 if @can[:edit]
47 if @can[:edit]
48 custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
48 custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
49 custom_fields.each do |field|
49 custom_fields.each do |field|
50 values = field.possible_values_options(@projects)
50 values = field.possible_values_options(@projects)
51 if values.present?
51 if values.present?
52 @options_by_custom_field[field] = values
52 @options_by_custom_field[field] = values
53 end
53 end
54 end
54 end
55 end
55 end
56
56
57 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
57 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
58 render :layout => false
58 render :layout => false
59 end
59 end
60
60
61 def time_entries
61 def time_entries
62 @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project, :user).to_a
62 @time_entries = TimeEntry.where(:id => params[:ids]).
63 preload(:project => :time_entry_activities).
64 preload(:user).to_a
65
63 (render_404; return) unless @time_entries.present?
66 (render_404; return) unless @time_entries.present?
64 if (@time_entries.size == 1)
67 if (@time_entries.size == 1)
65 @time_entry = @time_entries.first
68 @time_entry = @time_entries.first
66 end
69 end
67
70
68 @projects = @time_entries.collect(&:project).compact.uniq
71 @projects = @time_entries.collect(&:project).compact.uniq
69 @project = @projects.first if @projects.size == 1
72 @project = @projects.first if @projects.size == 1
70 @activities = TimeEntryActivity.shared.active
73 @activities = @projects.map(&:activities).reduce(:&)
71
74
72 edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)}
75 edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)}
73 @can = {:edit => edit_allowed, :delete => edit_allowed}
76 @can = {:edit => edit_allowed, :delete => edit_allowed}
74 @back = back_url
77 @back = back_url
75
78
76 @options_by_custom_field = {}
79 @options_by_custom_field = {}
77 if @can[:edit]
80 if @can[:edit]
78 custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
81 custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
79 custom_fields.each do |field|
82 custom_fields.each do |field|
80 values = field.possible_values_options(@projects)
83 values = field.possible_values_options(@projects)
81 if values.present?
84 if values.present?
82 @options_by_custom_field[field] = values
85 @options_by_custom_field[field] = values
83 end
86 end
84 end
87 end
85 end
88 end
86
89
87 render :layout => false
90 render :layout => false
88 end
91 end
89 end
92 end
General Comments 0
You need to be logged in to leave comments. Login now