@@ -1,86 +1,89 | |||
|
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 | 22 | def issues |
|
23 | 23 | @issues = Issue.visible.all(:conditions => {:id => params[:ids]}, :include => :project) |
|
24 | (render_404; return) unless @issues.present? | |
|
24 | 25 | if (@issues.size == 1) |
|
25 | 26 | @issue = @issues.first |
|
26 | 27 | end |
|
27 | 28 | @issue_ids = @issues.map(&:id).sort |
|
28 | 29 | |
|
29 | 30 | @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) |
|
30 | 31 | @projects = @issues.collect(&:project).compact.uniq |
|
31 | 32 | @project = @projects.first if @projects.size == 1 |
|
32 | 33 | |
|
33 | 34 | @can = {:edit => User.current.allowed_to?(:edit_issues, @projects), |
|
34 | 35 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
35 | 36 | :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)), |
|
36 | 37 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
37 | 38 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
38 | 39 | :delete => User.current.allowed_to?(:delete_issues, @projects) |
|
39 | 40 | } |
|
40 | 41 | if @project |
|
41 | 42 | if @issue |
|
42 | 43 | @assignables = @issue.assignable_users |
|
43 | 44 | else |
|
44 | 45 | @assignables = @project.assignable_users |
|
45 | 46 | end |
|
46 | 47 | @trackers = @project.trackers |
|
47 | 48 | else |
|
48 | 49 | #when multiple projects, we only keep the intersection of each set |
|
49 | 50 | @assignables = @projects.map(&:assignable_users).reduce(:&) |
|
50 | 51 | @trackers = @projects.map(&:trackers).reduce(:&) |
|
51 | 52 | end |
|
52 | 53 | @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
53 | 54 | |
|
54 | 55 | @priorities = IssuePriority.active.reverse |
|
55 | 56 | @back = back_url |
|
56 | 57 | |
|
57 | 58 | @options_by_custom_field = {} |
|
58 | 59 | if @can[:edit] |
|
59 | 60 | custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f| |
|
60 | 61 | %w(bool list user version).include?(f.field_format) && !f.multiple? |
|
61 | 62 | end |
|
62 | 63 | custom_fields.each do |field| |
|
63 | 64 | values = field.possible_values_options(@projects) |
|
64 | 65 | if values.any? |
|
65 | 66 | @options_by_custom_field[field] = values |
|
66 | 67 | end |
|
67 | 68 | end |
|
68 | 69 | end |
|
69 | 70 | |
|
70 | 71 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) |
|
71 | 72 | render :layout => false |
|
72 | 73 | end |
|
73 | 74 | |
|
74 | 75 | def time_entries |
|
75 | 76 | @time_entries = TimeEntry.all( |
|
76 | 77 | :conditions => {:id => params[:ids]}, :include => :project) |
|
78 | (render_404; return) unless @time_entries.present? | |
|
79 | ||
|
77 | 80 | @projects = @time_entries.collect(&:project).compact.uniq |
|
78 | 81 | @project = @projects.first if @projects.size == 1 |
|
79 | 82 | @activities = TimeEntryActivity.shared.active |
|
80 | 83 | @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects), |
|
81 | 84 | :delete => User.current.allowed_to?(:edit_time_entries, @projects) |
|
82 | 85 | } |
|
83 | 86 | @back = back_url |
|
84 | 87 | render :layout => false |
|
85 | 88 | end |
|
86 | 89 | end |
@@ -1,247 +1,252 | |||
|
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&issue%5Bstatus_id%5D=5', :text => 'Closed' |
|
48 | 48 | assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&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&issue%5Bfixed_version_id%5D=3', :text => '2.0' |
|
53 | 53 | assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&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&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('&') |
|
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&#{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}&issue%5Bstatus_id%5D=5", :text => 'Closed' |
|
82 | 82 | assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8", :text => 'Immediate' |
|
83 | 83 | assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&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('&') |
|
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}&issue%5Bstatus_id%5D=5", :text => 'Closed' |
|
100 | 100 | assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8", :text => 'Immediate' |
|
101 | 101 | assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&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&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&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :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&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&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&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :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&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&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :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&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&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :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&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 | 222 | def test_context_menu_issue_visibility |
|
223 | 223 | get :issues, :ids => [1, 4] |
|
224 | 224 | assert_response :success |
|
225 | 225 | assert_template 'context_menu' |
|
226 | 226 | assert_equal [1], assigns(:issues).collect(&:id) |
|
227 | 227 | end |
|
228 | 228 | |
|
229 | def test_should_respond_with_404_without_ids | |
|
230 | get :issues | |
|
231 | assert_response 404 | |
|
232 | end | |
|
233 | ||
|
229 | 234 | def test_time_entries_context_menu |
|
230 | 235 | @request.session[:user_id] = 2 |
|
231 | 236 | get :time_entries, :ids => [1, 2] |
|
232 | 237 | assert_response :success |
|
233 | 238 | assert_template 'time_entries' |
|
234 | 239 | |
|
235 | 240 | assert_select 'a:not(.disabled)', :text => 'Edit' |
|
236 | 241 | end |
|
237 | 242 | |
|
238 | 243 | def test_time_entries_context_menu_without_edit_permission |
|
239 | 244 | @request.session[:user_id] = 2 |
|
240 | 245 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
241 | 246 | |
|
242 | 247 | get :time_entries, :ids => [1, 2] |
|
243 | 248 | assert_response :success |
|
244 | 249 | assert_template 'time_entries' |
|
245 | 250 | assert_select 'a.disabled', :text => 'Edit' |
|
246 | 251 | end |
|
247 | 252 | end |
General Comments 0
You need to be logged in to leave comments.
Login now