##// END OF EJS Templates
Use #find_issues as before filter for issues context menu....
Jean-Philippe Lang -
r11731:60d2a5e322cb
parent child
Show More
@@ -1,89 +1,87
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class ContextMenusController < ApplicationController
19 19 helper :watchers
20 20 helper :issues
21 21
22 before_filter :find_issues, :only => :issues
23
22 24 def issues
23 @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project)
24 (render_404; return) unless @issues.present?
25 25 if (@issues.size == 1)
26 26 @issue = @issues.first
27 27 end
28 28 @issue_ids = @issues.map(&:id).sort
29 29
30 30 @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
31 @projects = @issues.collect(&:project).compact.uniq
32 @project = @projects.first if @projects.size == 1
33 31
34 32 @can = {:edit => User.current.allowed_to?(:edit_issues, @projects),
35 33 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
36 34 :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)),
37 35 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
38 36 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
39 37 :delete => User.current.allowed_to?(:delete_issues, @projects)
40 38 }
41 39 if @project
42 40 if @issue
43 41 @assignables = @issue.assignable_users
44 42 else
45 43 @assignables = @project.assignable_users
46 44 end
47 45 @trackers = @project.trackers
48 46 else
49 47 #when multiple projects, we only keep the intersection of each set
50 48 @assignables = @projects.map(&:assignable_users).reduce(:&)
51 49 @trackers = @projects.map(&:trackers).reduce(:&)
52 50 end
53 51 @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
54 52
55 53 @priorities = IssuePriority.active.reverse
56 54 @back = back_url
57 55
58 56 @options_by_custom_field = {}
59 57 if @can[:edit]
60 58 custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f|
61 59 %w(bool list user version).include?(f.field_format) && !f.multiple?
62 60 end
63 61 custom_fields.each do |field|
64 62 values = field.possible_values_options(@projects)
65 63 if values.any?
66 64 @options_by_custom_field[field] = values
67 65 end
68 66 end
69 67 end
70 68
71 69 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
72 70 render :layout => false
73 71 end
74 72
75 73 def time_entries
76 74 @time_entries = TimeEntry.all(
77 75 :conditions => {:id => params[:ids]}, :include => :project)
78 76 (render_404; return) unless @time_entries.present?
79 77
80 78 @projects = @time_entries.collect(&:project).compact.uniq
81 79 @project = @projects.first if @projects.size == 1
82 80 @activities = TimeEntryActivity.shared.active
83 81 @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects),
84 82 :delete => User.current.allowed_to?(:edit_time_entries, @projects)
85 83 }
86 84 @back = back_url
87 85 render :layout => false
88 86 end
89 87 end
@@ -1,252 +1,250
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class ContextMenusControllerTest < ActionController::TestCase
21 21 fixtures :projects,
22 22 :trackers,
23 23 :projects_trackers,
24 24 :roles,
25 25 :member_roles,
26 26 :members,
27 27 :enabled_modules,
28 28 :workflows,
29 29 :journals, :journal_details,
30 30 :versions,
31 31 :issues, :issue_statuses, :issue_categories,
32 32 :users,
33 33 :enumerations,
34 34 :time_entries
35 35
36 36 def test_context_menu_one_issue
37 37 @request.session[:user_id] = 2
38 38 get :issues, :ids => [1]
39 39 assert_response :success
40 40 assert_template 'context_menu'
41 41
42 42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
43 43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
44 44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
45 45
46 46 # Statuses
47 47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
48 48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
49 49 # No inactive priorities
50 50 assert_select 'a', :text => /Inactive Priority/, :count => 0
51 51 # Versions
52 52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
53 53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
54 54 # Assignees
55 55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
56 56 end
57 57
58 58 def test_context_menu_one_issue_by_anonymous
59 59 get :issues, :ids => [1]
60 60 assert_response :success
61 61 assert_template 'context_menu'
62 62 assert_tag :tag => 'a', :content => 'Delete',
63 63 :attributes => { :href => '#',
64 64 :class => 'icon-del disabled' }
65 65 end
66 66
67 67 def test_context_menu_multiple_issues_of_same_project
68 68 @request.session[:user_id] = 2
69 69 get :issues, :ids => [1, 2]
70 70 assert_response :success
71 71 assert_template 'context_menu'
72 72 assert_not_nil assigns(:issues)
73 73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
74 74
75 75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
76 76
77 77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
78 78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
79 79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
80 80
81 81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
82 82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
83 83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
84 84 end
85 85
86 86 def test_context_menu_multiple_issues_of_different_projects
87 87 @request.session[:user_id] = 2
88 88 get :issues, :ids => [1, 2, 6]
89 89 assert_response :success
90 90 assert_template 'context_menu'
91 91 assert_not_nil assigns(:issues)
92 92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
93 93
94 94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
95 95
96 96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
97 97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
98 98
99 99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
100 100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
101 101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
102 102 end
103 103
104 104 def test_context_menu_should_include_list_custom_fields
105 105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
106 106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
107 107 @request.session[:user_id] = 2
108 108 get :issues, :ids => [1]
109 109
110 110 assert_select "li.cf_#{field.id}" do
111 111 assert_select 'a[href=#]', :text => 'List'
112 112 assert_select 'ul' do
113 113 assert_select 'a', 3
114 114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
115 115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
116 116 end
117 117 end
118 118 end
119 119
120 120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
121 121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
122 122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
123 123 @request.session[:user_id] = 2
124 124 get :issues, :ids => [1, 2]
125 125
126 126 assert_select "li.cf_#{field.id}" do
127 127 assert_select 'a[href=#]', :text => 'List'
128 128 assert_select 'ul' do
129 129 assert_select 'a', 2
130 130 assert_select 'a', :text => 'none', :count => 0
131 131 end
132 132 end
133 133 end
134 134
135 135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
136 136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
137 137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
138 138 issue = Issue.find(1)
139 139 issue.custom_field_values = {field.id => 'Bar'}
140 140 issue.save!
141 141 @request.session[:user_id] = 2
142 142 get :issues, :ids => [1]
143 143
144 144 assert_select "li.cf_#{field.id}" do
145 145 assert_select 'a[href=#]', :text => 'List'
146 146 assert_select 'ul' do
147 147 assert_select 'a', 3
148 148 assert_select 'a.icon-checked', :text => 'Bar'
149 149 end
150 150 end
151 151 end
152 152
153 153 def test_context_menu_should_include_bool_custom_fields
154 154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
155 155 :is_for_all => true, :tracker_ids => [1, 2, 3])
156 156 @request.session[:user_id] = 2
157 157 get :issues, :ids => [1]
158 158
159 159 assert_select "li.cf_#{field.id}" do
160 160 assert_select 'a[href=#]', :text => 'Bool'
161 161 assert_select 'ul' do
162 162 assert_select 'a', 3
163 163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
164 164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
165 165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
166 166 end
167 167 end
168 168 end
169 169
170 170 def test_context_menu_should_include_user_custom_fields
171 171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
172 172 :is_for_all => true, :tracker_ids => [1, 2, 3])
173 173 @request.session[:user_id] = 2
174 174 get :issues, :ids => [1]
175 175
176 176 assert_select "li.cf_#{field.id}" do
177 177 assert_select 'a[href=#]', :text => 'User'
178 178 assert_select 'ul' do
179 179 assert_select 'a', Project.find(1).members.count + 1
180 180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
181 181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
182 182 end
183 183 end
184 184 end
185 185
186 186 def test_context_menu_should_include_version_custom_fields
187 187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
188 188 @request.session[:user_id] = 2
189 189 get :issues, :ids => [1]
190 190
191 191 assert_select "li.cf_#{field.id}" do
192 192 assert_select 'a[href=#]', :text => 'Version'
193 193 assert_select 'ul' do
194 194 assert_select 'a', Project.find(1).shared_versions.count + 1
195 195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
196 196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
197 197 end
198 198 end
199 199 end
200 200
201 201 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
202 202 @request.session[:user_id] = 2
203 203 get :issues, :ids => [1]
204 204 assert_response :success
205 205 assert_template 'context_menu'
206 206
207 207 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
208 208 end
209 209
210 210 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
211 211 @request.session[:user_id] = 2
212 212 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
213 213
214 214 get :issues, :ids => [1, 4]
215 215 assert_response :success
216 216 assert_template 'context_menu'
217 217
218 218 assert_include version, assigns(:versions)
219 219 assert_select 'a', :text => 'eCookbook - Shared'
220 220 end
221 221
222 def test_context_menu_issue_visibility
223 get :issues, :ids => [1, 4]
224 assert_response :success
225 assert_template 'context_menu'
226 assert_equal [1], assigns(:issues).collect(&:id)
222 def test_context_menu_with_issue_that_is_not_visible_should_fail
223 get :issues, :ids => [1, 4] # issue 4 is not visible
224 assert_response 302
227 225 end
228 226
229 227 def test_should_respond_with_404_without_ids
230 228 get :issues
231 229 assert_response 404
232 230 end
233 231
234 232 def test_time_entries_context_menu
235 233 @request.session[:user_id] = 2
236 234 get :time_entries, :ids => [1, 2]
237 235 assert_response :success
238 236 assert_template 'time_entries'
239 237
240 238 assert_select 'a:not(.disabled)', :text => 'Edit'
241 239 end
242 240
243 241 def test_time_entries_context_menu_without_edit_permission
244 242 @request.session[:user_id] = 2
245 243 Role.find_by_name('Manager').remove_permission! :edit_time_entries
246 244
247 245 get :time_entries, :ids => [1, 2]
248 246 assert_response :success
249 247 assert_template 'time_entries'
250 248 assert_select 'a.disabled', :text => 'Edit'
251 249 end
252 250 end
General Comments 0
You need to be logged in to leave comments. Login now