@@ -1,84 +1,85 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 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 | 24 | if (@issues.size == 1) |
|
25 | 25 | @issue = @issues.first |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) |
|
29 | 29 | @projects = @issues.collect(&:project).compact.uniq |
|
30 | 30 | @project = @projects.first if @projects.size == 1 |
|
31 | 31 | |
|
32 | 32 | @can = {:edit => User.current.allowed_to?(:edit_issues, @projects), |
|
33 | 33 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), |
|
34 | 34 | :update => (User.current.allowed_to?(:edit_issues, @projects) || (User.current.allowed_to?(:change_status, @projects) && !@allowed_statuses.blank?)), |
|
35 | 35 | :move => (@project && User.current.allowed_to?(:move_issues, @project)), |
|
36 | 36 | :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)), |
|
37 | 37 | :delete => User.current.allowed_to?(:delete_issues, @projects) |
|
38 | 38 | } |
|
39 | 39 | if @project |
|
40 | 40 | if @issue |
|
41 | 41 | @assignables = @issue.assignable_users |
|
42 | 42 | else |
|
43 | 43 | @assignables = @project.assignable_users |
|
44 | 44 | end |
|
45 | 45 | @trackers = @project.trackers |
|
46 | 46 | else |
|
47 | 47 | #when multiple projects, we only keep the intersection of each set |
|
48 | 48 | @assignables = @projects.map(&:assignable_users).reduce(:&) |
|
49 | 49 | @trackers = @projects.map(&:trackers).reduce(:&) |
|
50 | 50 | end |
|
51 | @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&) | |
|
51 | 52 | |
|
52 | 53 | @priorities = IssuePriority.active.reverse |
|
53 | 54 | @back = back_url |
|
54 | 55 | |
|
55 | 56 | @options_by_custom_field = {} |
|
56 | 57 | if @can[:edit] |
|
57 | 58 | custom_fields = @issues.map(&:available_custom_fields).reduce(:&).select do |f| |
|
58 | 59 | %w(bool list user version).include?(f.field_format) && !f.multiple? |
|
59 | 60 | end |
|
60 | 61 | custom_fields.each do |field| |
|
61 | 62 | values = field.possible_values_options(@projects) |
|
62 | 63 | if values.any? |
|
63 | 64 | @options_by_custom_field[field] = values |
|
64 | 65 | end |
|
65 | 66 | end |
|
66 | 67 | end |
|
67 | 68 | |
|
68 | 69 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) |
|
69 | 70 | render :layout => false |
|
70 | 71 | end |
|
71 | 72 | |
|
72 | 73 | def time_entries |
|
73 | 74 | @time_entries = TimeEntry.all( |
|
74 | 75 | :conditions => {:id => params[:ids]}, :include => :project) |
|
75 | 76 | @projects = @time_entries.collect(&:project).compact.uniq |
|
76 | 77 | @project = @projects.first if @projects.size == 1 |
|
77 | 78 | @activities = TimeEntryActivity.shared.active |
|
78 | 79 | @can = {:edit => User.current.allowed_to?(:edit_time_entries, @projects), |
|
79 | 80 | :delete => User.current.allowed_to?(:edit_time_entries, @projects) |
|
80 | 81 | } |
|
81 | 82 | @back = back_url |
|
82 | 83 | render :layout => false |
|
83 | 84 | end |
|
84 | 85 | end |
@@ -1,142 +1,141 | |||
|
1 | 1 | <ul> |
|
2 | 2 | <%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %> |
|
3 | 3 | |
|
4 | 4 | <% if !@issue.nil? -%> |
|
5 | 5 | <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue}, |
|
6 | 6 | :class => 'icon-edit', :disabled => !@can[:edit] %></li> |
|
7 | 7 | <% else %> |
|
8 | 8 | <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id)}, |
|
9 | 9 | :class => 'icon-edit', :disabled => !@can[:edit] %></li> |
|
10 | 10 | <% end %> |
|
11 | 11 | |
|
12 | 12 | <% if @allowed_statuses.present? %> |
|
13 | 13 | <li class="folder"> |
|
14 | 14 | <a href="#" class="submenu"><%= l(:field_status) %></a> |
|
15 | 15 | <ul> |
|
16 | 16 | <% @allowed_statuses.each do |s| -%> |
|
17 | 17 | <li><%= context_menu_link h(s.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {:status_id => s}, :back_url => @back}, :method => :post, |
|
18 | 18 | :selected => (@issue && s == @issue.status), :disabled => !@can[:update] %></li> |
|
19 | 19 | <% end -%> |
|
20 | 20 | </ul> |
|
21 | 21 | </li> |
|
22 | 22 | <% end %> |
|
23 | 23 | |
|
24 | 24 | <% unless @trackers.nil? %> |
|
25 | 25 | <li class="folder"> |
|
26 | 26 | <a href="#" class="submenu"><%= l(:field_tracker) %></a> |
|
27 | 27 | <ul> |
|
28 | 28 | <% @trackers.each do |t| -%> |
|
29 | 29 | <li><%= context_menu_link h(t.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'tracker_id' => t}, :back_url => @back}, :method => :post, |
|
30 | 30 | :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li> |
|
31 | 31 | <% end -%> |
|
32 | 32 | </ul> |
|
33 | 33 | </li> |
|
34 | 34 | <% end %> |
|
35 | 35 | |
|
36 | 36 | <% if @safe_attributes.include?('priority_id') -%> |
|
37 | 37 | <li class="folder"> |
|
38 | 38 | <a href="#" class="submenu"><%= l(:field_priority) %></a> |
|
39 | 39 | <ul> |
|
40 | 40 | <% @priorities.each do |p| -%> |
|
41 | 41 | <li><%= context_menu_link h(p.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'priority_id' => p}, :back_url => @back}, :method => :post, |
|
42 | 42 | :selected => (@issue && p == @issue.priority), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li> |
|
43 | 43 | <% end -%> |
|
44 | 44 | </ul> |
|
45 | 45 | </li> |
|
46 | 46 | <% end %> |
|
47 | 47 | |
|
48 | <% #TODO: allow editing versions when multiple projects %> | |
|
49 | <% if @safe_attributes.include?('fixed_version_id') && @project && @project.shared_versions.open.any? -%> | |
|
48 | <% if @safe_attributes.include?('fixed_version_id') && @versions.any? -%> | |
|
50 | 49 | <li class="folder"> |
|
51 | 50 | <a href="#" class="submenu"><%= l(:field_fixed_version) %></a> |
|
52 | 51 | <ul> |
|
53 |
<% @ |
|
|
52 | <% @versions.sort.each do |v| -%> | |
|
54 | 53 | <li><%= context_menu_link format_version_name(v), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'fixed_version_id' => v}, :back_url => @back}, :method => :post, |
|
55 | 54 | :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li> |
|
56 | 55 | <% end -%> |
|
57 | 56 | <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'fixed_version_id' => 'none'}, :back_url => @back}, :method => :post, |
|
58 | 57 | :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li> |
|
59 | 58 | </ul> |
|
60 | 59 | </li> |
|
61 | 60 | <% end %> |
|
62 | 61 | |
|
63 | 62 | <% if @safe_attributes.include?('assigned_to_id') && @assignables.present? -%> |
|
64 | 63 | <li class="folder"> |
|
65 | 64 | <a href="#" class="submenu"><%= l(:field_assigned_to) %></a> |
|
66 | 65 | <ul> |
|
67 | 66 | <% if @assignables.include?(User.current) %> |
|
68 | 67 | <li><%= context_menu_link "<< #{l(:label_me)} >>", {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'assigned_to_id' => User.current}, :back_url => @back}, :method => :post, |
|
69 | 68 | :disabled => !@can[:update] %></li> |
|
70 | 69 | <% end %> |
|
71 | 70 | <% @assignables.each do |u| -%> |
|
72 | 71 | <li><%= context_menu_link h(u.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'assigned_to_id' => u}, :back_url => @back}, :method => :post, |
|
73 | 72 | :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li> |
|
74 | 73 | <% end -%> |
|
75 | 74 | <li><%= context_menu_link l(:label_nobody), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'assigned_to_id' => 'none'}, :back_url => @back}, :method => :post, |
|
76 | 75 | :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li> |
|
77 | 76 | </ul> |
|
78 | 77 | </li> |
|
79 | 78 | <% end %> |
|
80 | 79 | |
|
81 | 80 | <% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%> |
|
82 | 81 | <li class="folder"> |
|
83 | 82 | <a href="#" class="submenu"><%= l(:field_category) %></a> |
|
84 | 83 | <ul> |
|
85 | 84 | <% @project.issue_categories.each do |u| -%> |
|
86 | 85 | <li><%= context_menu_link h(u.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'category_id' => u}, :back_url => @back}, :method => :post, |
|
87 | 86 | :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li> |
|
88 | 87 | <% end -%> |
|
89 | 88 | <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'category_id' => 'none'}, :back_url => @back}, :method => :post, |
|
90 | 89 | :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li> |
|
91 | 90 | </ul> |
|
92 | 91 | </li> |
|
93 | 92 | <% end -%> |
|
94 | 93 | |
|
95 | 94 | <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %> |
|
96 | 95 | <li class="folder"> |
|
97 | 96 | <a href="#" class="submenu"><%= l(:field_done_ratio) %></a> |
|
98 | 97 | <ul> |
|
99 | 98 | <% (0..10).map{|x|x*10}.each do |p| -%> |
|
100 | 99 | <li><%= context_menu_link "#{p}%", {:controller => 'issues', :action => 'bulk_update', :ids => @issues.collect(&:id), :issue => {'done_ratio' => p}, :back_url => @back}, :method => :post, |
|
101 | 100 | :selected => (@issue && p == @issue.done_ratio), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li> |
|
102 | 101 | <% end -%> |
|
103 | 102 | </ul> |
|
104 | 103 | </li> |
|
105 | 104 | <% end %> |
|
106 | 105 | |
|
107 | 106 | <% @options_by_custom_field.each do |field, options| %> |
|
108 | 107 | <li class="folder"> |
|
109 | 108 | <a href="#" class="submenu"><%= h(field.name) %></a> |
|
110 | 109 | <ul> |
|
111 | 110 | <% options.each do |text, value| %> |
|
112 | 111 | <li><%= bulk_update_custom_field_context_menu_link(field, text, value || text) %></li> |
|
113 | 112 | <% end %> |
|
114 | 113 | <% unless field.is_required? %> |
|
115 | 114 | <li><%= bulk_update_custom_field_context_menu_link(field, l(:label_none), '') %></li> |
|
116 | 115 | <% end %> |
|
117 | 116 | </ul> |
|
118 | 117 | </li> |
|
119 | 118 | <% end %> |
|
120 | 119 | |
|
121 | 120 | <% if !@issue.nil? %> |
|
122 | 121 | <% if @can[:log_time] -%> |
|
123 | 122 | <li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'new', :issue_id => @issue}, |
|
124 | 123 | :class => 'icon-time-add' %></li> |
|
125 | 124 | <% end %> |
|
126 | 125 | <% if User.current.logged? %> |
|
127 | 126 | <li><%= watcher_link(@issue, User.current) %></li> |
|
128 | 127 | <% end %> |
|
129 | 128 | <% end %> |
|
130 | 129 | |
|
131 | 130 | <% if @issue.present? %> |
|
132 | 131 | <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue}, |
|
133 | 132 | :class => 'icon-copy', :disabled => !@can[:copy] %></li> |
|
134 | 133 | <% else %> |
|
135 | 134 | <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), :copy => '1'}, |
|
136 | 135 | :class => 'icon-copy', :disabled => !@can[:move] %></li> |
|
137 | 136 | <% end %> |
|
138 | 137 | <li><%= context_menu_link l(:button_delete), issues_path(:ids => @issues.collect(&:id), :back_url => @back), |
|
139 | 138 | :method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon-del', :disabled => !@can[:delete] %></li> |
|
140 | 139 | |
|
141 | 140 | <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %> |
|
142 | 141 | </ul> |
@@ -1,251 +1,263 | |||
|
1 | 1 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 2 | |
|
3 | 3 | class ContextMenusControllerTest < ActionController::TestCase |
|
4 | 4 | fixtures :projects, |
|
5 | 5 | :trackers, |
|
6 | 6 | :projects_trackers, |
|
7 | 7 | :roles, |
|
8 | 8 | :member_roles, |
|
9 | 9 | :members, |
|
10 | 10 | :enabled_modules, |
|
11 | 11 | :workflows, |
|
12 | 12 | :journals, :journal_details, |
|
13 | 13 | :versions, |
|
14 | 14 | :issues, :issue_statuses, :issue_categories, |
|
15 | 15 | :users, |
|
16 | 16 | :enumerations, |
|
17 | 17 | :time_entries |
|
18 | 18 | |
|
19 | 19 | def test_context_menu_one_issue |
|
20 | 20 | @request.session[:user_id] = 2 |
|
21 | 21 | get :issues, :ids => [1] |
|
22 | 22 | assert_response :success |
|
23 | 23 | assert_template 'context_menu' |
|
24 | 24 | assert_tag :tag => 'a', :content => 'Edit', |
|
25 | 25 | :attributes => { :href => '/issues/1/edit', |
|
26 | 26 | :class => 'icon-edit' } |
|
27 | 27 | assert_tag :tag => 'a', :content => 'Closed', |
|
28 | 28 | :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bstatus_id%5D=5', |
|
29 | 29 | :class => '' } |
|
30 | 30 | assert_tag :tag => 'a', :content => 'Immediate', |
|
31 | 31 | :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bpriority_id%5D=8', |
|
32 | 32 | :class => '' } |
|
33 | 33 | assert_no_tag :tag => 'a', :content => 'Inactive Priority' |
|
34 | 34 | # Versions |
|
35 | 35 | assert_tag :tag => 'a', :content => '2.0', |
|
36 | 36 | :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=3', |
|
37 | 37 | :class => '' } |
|
38 | 38 | assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0', |
|
39 | 39 | :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4', |
|
40 | 40 | :class => '' } |
|
41 | 41 | |
|
42 | 42 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
43 | 43 | :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3', |
|
44 | 44 | :class => '' } |
|
45 | 45 | assert_tag :tag => 'a', :content => 'Copy', |
|
46 | 46 | :attributes => { :href => '/projects/ecookbook/issues/1/copy', |
|
47 | 47 | :class => 'icon-copy' } |
|
48 | 48 | assert_no_tag :tag => 'a', :content => 'Move' |
|
49 | 49 | assert_tag :tag => 'a', :content => 'Delete', |
|
50 | 50 | :attributes => { :href => '/issues?ids%5B%5D=1', |
|
51 | 51 | :class => 'icon-del' } |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_context_menu_one_issue_by_anonymous |
|
55 | 55 | get :issues, :ids => [1] |
|
56 | 56 | assert_response :success |
|
57 | 57 | assert_template 'context_menu' |
|
58 | 58 | assert_tag :tag => 'a', :content => 'Delete', |
|
59 | 59 | :attributes => { :href => '#', |
|
60 | 60 | :class => 'icon-del disabled' } |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | def test_context_menu_multiple_issues_of_same_project |
|
64 | 64 | @request.session[:user_id] = 2 |
|
65 | 65 | get :issues, :ids => [1, 2] |
|
66 | 66 | assert_response :success |
|
67 | 67 | assert_template 'context_menu' |
|
68 | 68 | assert_not_nil assigns(:issues) |
|
69 | 69 | assert_equal [1, 2], assigns(:issues).map(&:id).sort |
|
70 | 70 | |
|
71 | 71 | ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&') |
|
72 | 72 | assert_tag :tag => 'a', :content => 'Edit', |
|
73 | 73 | :attributes => { :href => "/issues/bulk_edit?#{ids}", |
|
74 | 74 | :class => 'icon-edit' } |
|
75 | 75 | assert_tag :tag => 'a', :content => 'Closed', |
|
76 | 76 | :attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bstatus_id%5D=5", |
|
77 | 77 | :class => '' } |
|
78 | 78 | assert_tag :tag => 'a', :content => 'Immediate', |
|
79 | 79 | :attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8", |
|
80 | 80 | :class => '' } |
|
81 | 81 | assert_tag :tag => 'a', :content => 'Dave Lopper', |
|
82 | 82 | :attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bassigned_to_id%5D=3", |
|
83 | 83 | :class => '' } |
|
84 | 84 | assert_tag :tag => 'a', :content => 'Copy', |
|
85 | 85 | :attributes => { :href => "/issues/bulk_edit?copy=1&#{ids}", |
|
86 | 86 | :class => 'icon-copy' } |
|
87 | 87 | assert_no_tag :tag => 'a', :content => 'Move' |
|
88 | 88 | assert_tag :tag => 'a', :content => 'Delete', |
|
89 | 89 | :attributes => { :href => "/issues?#{ids}", |
|
90 | 90 | :class => 'icon-del' } |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def test_context_menu_multiple_issues_of_different_projects |
|
94 | 94 | @request.session[:user_id] = 2 |
|
95 | 95 | get :issues, :ids => [1, 2, 6] |
|
96 | 96 | assert_response :success |
|
97 | 97 | assert_template 'context_menu' |
|
98 | 98 | assert_not_nil assigns(:issues) |
|
99 | 99 | assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort |
|
100 | 100 | |
|
101 | 101 | ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&') |
|
102 | 102 | assert_tag :tag => 'a', :content => 'Edit', |
|
103 | 103 | :attributes => { :href => "/issues/bulk_edit?#{ids}", |
|
104 | 104 | :class => 'icon-edit' } |
|
105 | 105 | assert_tag :tag => 'a', :content => 'Closed', |
|
106 | 106 | :attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bstatus_id%5D=5", |
|
107 | 107 | :class => '' } |
|
108 | 108 | assert_tag :tag => 'a', :content => 'Immediate', |
|
109 | 109 | :attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bpriority_id%5D=8", |
|
110 | 110 | :class => '' } |
|
111 | 111 | assert_tag :tag => 'a', :content => 'John Smith', |
|
112 | 112 | :attributes => { :href => "/issues/bulk_update?#{ids}&issue%5Bassigned_to_id%5D=2", |
|
113 | 113 | :class => '' } |
|
114 | 114 | assert_tag :tag => 'a', :content => 'Delete', |
|
115 | 115 | :attributes => { :href => "/issues?#{ids}", |
|
116 | 116 | :class => 'icon-del' } |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def test_context_menu_should_include_list_custom_fields |
|
120 | 120 | field = IssueCustomField.create!(:name => 'List', :field_format => 'list', |
|
121 | 121 | :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3]) |
|
122 | 122 | @request.session[:user_id] = 2 |
|
123 | 123 | get :issues, :ids => [1] |
|
124 | 124 | |
|
125 | 125 | assert_tag 'a', |
|
126 | 126 | :content => 'List', |
|
127 | 127 | :attributes => {:href => '#'}, |
|
128 | 128 | :sibling => {:tag => 'ul', :children => {:count => 3}} |
|
129 | 129 | |
|
130 | 130 | assert_tag 'a', |
|
131 | 131 | :content => 'Foo', |
|
132 | 132 | :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"} |
|
133 | 133 | assert_tag 'a', |
|
134 | 134 | :content => 'none', |
|
135 | 135 | :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D="} |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def test_context_menu_should_not_include_null_value_for_required_custom_fields |
|
139 | 139 | field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list', |
|
140 | 140 | :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3]) |
|
141 | 141 | @request.session[:user_id] = 2 |
|
142 | 142 | get :issues, :ids => [1, 2] |
|
143 | 143 | |
|
144 | 144 | assert_tag 'a', |
|
145 | 145 | :content => 'List', |
|
146 | 146 | :attributes => {:href => '#'}, |
|
147 | 147 | :sibling => {:tag => 'ul', :children => {:count => 2}} |
|
148 | 148 | end |
|
149 | 149 | |
|
150 | 150 | def test_context_menu_on_single_issue_should_select_current_custom_field_value |
|
151 | 151 | field = IssueCustomField.create!(:name => 'List', :field_format => 'list', |
|
152 | 152 | :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3]) |
|
153 | 153 | issue = Issue.find(1) |
|
154 | 154 | issue.custom_field_values = {field.id => 'Bar'} |
|
155 | 155 | issue.save! |
|
156 | 156 | @request.session[:user_id] = 2 |
|
157 | 157 | get :issues, :ids => [1] |
|
158 | 158 | |
|
159 | 159 | assert_tag 'a', |
|
160 | 160 | :content => 'List', |
|
161 | 161 | :attributes => {:href => '#'}, |
|
162 | 162 | :sibling => {:tag => 'ul', :children => {:count => 3}} |
|
163 | 163 | assert_tag 'a', |
|
164 | 164 | :content => 'Bar', |
|
165 | 165 | :attributes => {:class => /icon-checked/} |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | def test_context_menu_should_include_bool_custom_fields |
|
169 | 169 | field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool', |
|
170 | 170 | :is_for_all => true, :tracker_ids => [1, 2, 3]) |
|
171 | 171 | @request.session[:user_id] = 2 |
|
172 | 172 | get :issues, :ids => [1] |
|
173 | 173 | |
|
174 | 174 | assert_tag 'a', |
|
175 | 175 | :content => 'Bool', |
|
176 | 176 | :attributes => {:href => '#'}, |
|
177 | 177 | :sibling => {:tag => 'ul', :children => {:count => 3}} |
|
178 | 178 | |
|
179 | 179 | assert_tag 'a', |
|
180 | 180 | :content => 'Yes', |
|
181 | 181 | :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"} |
|
182 | 182 | end |
|
183 | 183 | |
|
184 | 184 | def test_context_menu_should_include_user_custom_fields |
|
185 | 185 | field = IssueCustomField.create!(:name => 'User', :field_format => 'user', |
|
186 | 186 | :is_for_all => true, :tracker_ids => [1, 2, 3]) |
|
187 | 187 | @request.session[:user_id] = 2 |
|
188 | 188 | get :issues, :ids => [1] |
|
189 | 189 | |
|
190 | 190 | assert_tag 'a', |
|
191 | 191 | :content => 'User', |
|
192 | 192 | :attributes => {:href => '#'}, |
|
193 | 193 | :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}} |
|
194 | 194 | |
|
195 | 195 | assert_tag 'a', |
|
196 | 196 | :content => 'John Smith', |
|
197 | 197 | :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"} |
|
198 | 198 | end |
|
199 | 199 | |
|
200 | 200 | def test_context_menu_should_include_version_custom_fields |
|
201 | 201 | field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3]) |
|
202 | 202 | @request.session[:user_id] = 2 |
|
203 | 203 | get :issues, :ids => [1] |
|
204 | 204 | |
|
205 | 205 | assert_tag 'a', |
|
206 | 206 | :content => 'Version', |
|
207 | 207 | :attributes => {:href => '#'}, |
|
208 | 208 | :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}} |
|
209 | 209 | |
|
210 | 210 | assert_tag 'a', |
|
211 | 211 | :content => '2.0', |
|
212 | 212 | :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"} |
|
213 | 213 | end |
|
214 | 214 | |
|
215 | 215 | def test_context_menu_by_assignable_user_should_include_assigned_to_me_link |
|
216 | 216 | @request.session[:user_id] = 2 |
|
217 | 217 | get :issues, :ids => [1] |
|
218 | 218 | assert_response :success |
|
219 | 219 | assert_template 'context_menu' |
|
220 | 220 | |
|
221 | 221 | assert_tag :tag => 'a', :content => / me /, |
|
222 | 222 | :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&issue%5Bassigned_to_id%5D=2', |
|
223 | 223 | :class => '' } |
|
224 | 224 | end |
|
225 | 225 | |
|
226 | def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects | |
|
227 | @request.session[:user_id] = 2 | |
|
228 | version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1) | |
|
229 | ||
|
230 | get :issues, :ids => [1, 4] | |
|
231 | assert_response :success | |
|
232 | assert_template 'context_menu' | |
|
233 | ||
|
234 | assert_include version, assigns(:versions) | |
|
235 | assert_tag :tag => 'a', :content => 'eCookbook - Shared' | |
|
236 | end | |
|
237 | ||
|
226 | 238 | def test_context_menu_issue_visibility |
|
227 | 239 | get :issues, :ids => [1, 4] |
|
228 | 240 | assert_response :success |
|
229 | 241 | assert_template 'context_menu' |
|
230 | 242 | assert_equal [1], assigns(:issues).collect(&:id) |
|
231 | 243 | end |
|
232 | 244 | |
|
233 | 245 | def test_time_entries_context_menu |
|
234 | 246 | @request.session[:user_id] = 2 |
|
235 | 247 | get :time_entries, :ids => [1, 2] |
|
236 | 248 | assert_response :success |
|
237 | 249 | assert_template 'time_entries' |
|
238 | 250 | assert_tag 'a', :content => 'Edit' |
|
239 | 251 | assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/} |
|
240 | 252 | end |
|
241 | 253 | |
|
242 | 254 | def test_time_entries_context_menu_without_edit_permission |
|
243 | 255 | @request.session[:user_id] = 2 |
|
244 | 256 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
245 | 257 | |
|
246 | 258 | get :time_entries, :ids => [1, 2] |
|
247 | 259 | assert_response :success |
|
248 | 260 | assert_template 'time_entries' |
|
249 | 261 | assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/} |
|
250 | 262 | end |
|
251 | 263 | end |
General Comments 0
You need to be logged in to leave comments.
Login now