##// END OF EJS Templates
Bulk watch/unwatch issues from the context menu (#7159)....
Jean-Philippe Lang -
r11109:856ef810b485
parent child
Show More
@@ -0,0 +1,69
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../../test_helper', __FILE__)
19
20 class WatchersHelperTest < ActionView::TestCase
21 include WatchersHelper
22 include Redmine::I18n
23
24 fixtures :users, :issues
25
26 def setup
27 super
28 set_language_if_valid('en')
29 User.current = nil
30 end
31
32 test '#watcher_link with a non-watched object' do
33 expected = link_to(
34 "Watch",
35 "/watchers/watch?object_id=1&object_type=issue",
36 :remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
37 )
38 assert_equal expected, watcher_link(Issue.find(1), User.find(1))
39 end
40
41 test '#watcher_link with a single objet array' do
42 expected = link_to(
43 "Watch",
44 "/watchers/watch?object_id=1&object_type=issue",
45 :remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
46 )
47 assert_equal expected, watcher_link([Issue.find(1)], User.find(1))
48 end
49
50 test '#watcher_link with a multiple objets array' do
51 expected = link_to(
52 "Watch",
53 "/watchers/watch?object_id%5B%5D=1&object_id%5B%5D=3&object_type=issue",
54 :remote => true, :method => 'post', :class => "issue-bulk-watcher icon icon-fav-off"
55 )
56 assert_equal expected, watcher_link([Issue.find(1), Issue.find(3)], User.find(1))
57 end
58
59 test '#watcher_link with a watched object' do
60 Watcher.create!(:watchable => Issue.find(1), :user => User.find(1))
61
62 expected = link_to(
63 "Unwatch",
64 "/watchers/unwatch?object_id=1&object_type=issue",
65 :remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav"
66 )
67 assert_equal expected, watcher_link(Issue.find(1), User.find(1))
68 end
69 end
@@ -1,101 +1,109
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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 WatchersController < ApplicationController
18 class WatchersController < ApplicationController
19 before_filter :find_project
19 before_filter :require_login, :find_watchables, :only => [:watch, :unwatch]
20 before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
21 before_filter :authorize, :only => [:new, :destroy]
22 accept_api_auth :create, :destroy
23
20
24 def watch
21 def watch
25 if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
22 set_watcher(@watchables, User.current, true)
26 render_403
27 else
28 set_watcher(User.current, true)
29 end
30 end
23 end
31
24
32 def unwatch
25 def unwatch
33 set_watcher(User.current, false)
26 set_watcher(@watchables, User.current, false)
34 end
27 end
35
28
29 before_filter :find_project, :authorize, :only => [:new, :create, :append, :destroy, :autocomplete_for_user]
30 accept_api_auth :create, :destroy
31
36 def new
32 def new
37 end
33 end
38
34
39 def create
35 def create
40 user_ids = []
36 user_ids = []
41 if params[:watcher].is_a?(Hash)
37 if params[:watcher].is_a?(Hash)
42 user_ids << (params[:watcher][:user_ids] || params[:watcher][:user_id])
38 user_ids << (params[:watcher][:user_ids] || params[:watcher][:user_id])
43 else
39 else
44 user_ids << params[:user_id]
40 user_ids << params[:user_id]
45 end
41 end
46 user_ids.flatten.compact.uniq.each do |user_id|
42 user_ids.flatten.compact.uniq.each do |user_id|
47 Watcher.create(:watchable => @watched, :user_id => user_id)
43 Watcher.create(:watchable => @watched, :user_id => user_id)
48 end
44 end
49 respond_to do |format|
45 respond_to do |format|
50 format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
46 format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
51 format.js
47 format.js
52 format.api { render_api_ok }
48 format.api { render_api_ok }
53 end
49 end
54 end
50 end
55
51
56 def append
52 def append
57 if params[:watcher].is_a?(Hash)
53 if params[:watcher].is_a?(Hash)
58 user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
54 user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
59 @users = User.active.find_all_by_id(user_ids)
55 @users = User.active.find_all_by_id(user_ids)
60 end
56 end
61 end
57 end
62
58
63 def destroy
59 def destroy
64 @watched.set_watcher(User.find(params[:user_id]), false)
60 @watched.set_watcher(User.find(params[:user_id]), false)
65 respond_to do |format|
61 respond_to do |format|
66 format.html { redirect_to :back }
62 format.html { redirect_to :back }
67 format.js
63 format.js
68 format.api { render_api_ok }
64 format.api { render_api_ok }
69 end
65 end
70 end
66 end
71
67
72 def autocomplete_for_user
68 def autocomplete_for_user
73 @users = User.active.sorted.like(params[:q]).limit(100).all
69 @users = User.active.sorted.like(params[:q]).limit(100).all
74 if @watched
70 if @watched
75 @users -= @watched.watcher_users
71 @users -= @watched.watcher_users
76 end
72 end
77 render :layout => false
73 render :layout => false
78 end
74 end
79
75
80 private
76 private
77
81 def find_project
78 def find_project
82 if params[:object_type] && params[:object_id]
79 if params[:object_type] && params[:object_id]
83 klass = Object.const_get(params[:object_type].camelcase)
80 klass = Object.const_get(params[:object_type].camelcase)
84 return false unless klass.respond_to?('watched_by')
81 return false unless klass.respond_to?('watched_by')
85 @watched = klass.find(params[:object_id])
82 @watched = klass.find(params[:object_id])
86 @project = @watched.project
83 @project = @watched.project
87 elsif params[:project_id]
84 elsif params[:project_id]
88 @project = Project.visible.find_by_param(params[:project_id])
85 @project = Project.visible.find_by_param(params[:project_id])
89 end
86 end
90 rescue
87 rescue
91 render_404
88 render_404
92 end
89 end
93
90
94 def set_watcher(user, watching)
91 def find_watchables
95 @watched.set_watcher(user, watching)
92 klass = Object.const_get(params[:object_type].camelcase) rescue nil
93 if klass && klass.respond_to?('watched_by')
94 @watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
95 raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
96 end
97 render_404 unless @watchables.present?
98 end
99
100 def set_watcher(watchables, user, watching)
101 watchables.each do |watchable|
102 watchable.set_watcher(user, watching)
103 end
96 respond_to do |format|
104 respond_to do |format|
97 format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
105 format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
98 format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => @watched} }
106 format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
99 end
107 end
100 end
108 end
101 end
109 end
@@ -1,76 +1,83
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2013 Jean-Philippe Lang
4 # Copyright (C) 2006-2013 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module WatchersHelper
20 module WatchersHelper
21
21
22 def watcher_tag(object, user, options={})
22 def watcher_tag(object, user, options={})
23 ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead."
23 ActiveSupport::Deprecation.warn "#watcher_tag is deprecated and will be removed in Redmine 3.0. Use #watcher_link instead."
24 watcher_link(object, user)
24 watcher_link(object, user)
25 end
25 end
26
26
27 def watcher_link(object, user)
27 def watcher_link(objects, user)
28 return '' unless user && user.logged? && object.respond_to?('watched_by?')
28 return '' unless user && user.logged?
29 watched = object.watched_by?(user)
29 objects = Array.wrap(objects)
30 css = [watcher_css(object), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
30
31 url = {:controller => 'watchers',
31 watched = objects.any? {|object| object.watched_by?(user)}
32 :action => (watched ? 'unwatch' : 'watch'),
32 css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
33 :object_type => object.class.to_s.underscore,
33 text = watched ? l(:button_unwatch) : l(:button_watch)
34 :object_id => object.id}
34 url = {
35 link_to((watched ? l(:button_unwatch) : l(:button_watch)), url,
35 :controller => 'watchers',
36 :remote => true, :method => 'post', :class => css)
36 :action => (watched ? 'unwatch' : 'watch'),
37 :object_type => objects.first.class.to_s.underscore,
38 :object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
39 }
40
41 link_to text, url, :remote => true, :method => 'post', :class => css
37 end
42 end
38
43
39 # Returns the css class used to identify watch links for a given +object+
44 # Returns the css class used to identify watch links for a given +object+
40 def watcher_css(object)
45 def watcher_css(objects)
41 "#{object.class.to_s.underscore}-#{object.id}-watcher"
46 objects = Array.wrap(objects)
47 id = (objects.size == 1 ? objects.first.id : 'bulk')
48 "#{objects.first.class.to_s.underscore}-#{id}-watcher"
42 end
49 end
43
50
44 # Returns a comma separated list of users watching the given object
51 # Returns a comma separated list of users watching the given object
45 def watchers_list(object)
52 def watchers_list(object)
46 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
53 remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
47 content = ''.html_safe
54 content = ''.html_safe
48 lis = object.watcher_users.collect do |user|
55 lis = object.watcher_users.collect do |user|
49 s = ''.html_safe
56 s = ''.html_safe
50 s << avatar(user, :size => "16").to_s
57 s << avatar(user, :size => "16").to_s
51 s << link_to_user(user, :class => 'user')
58 s << link_to_user(user, :class => 'user')
52 if remove_allowed
59 if remove_allowed
53 url = {:controller => 'watchers',
60 url = {:controller => 'watchers',
54 :action => 'destroy',
61 :action => 'destroy',
55 :object_type => object.class.to_s.underscore,
62 :object_type => object.class.to_s.underscore,
56 :object_id => object.id,
63 :object_id => object.id,
57 :user_id => user}
64 :user_id => user}
58 s << ' '
65 s << ' '
59 s << link_to(image_tag('delete.png'), url,
66 s << link_to(image_tag('delete.png'), url,
60 :remote => true, :method => 'post', :style => "vertical-align: middle", :class => "delete")
67 :remote => true, :method => 'post', :style => "vertical-align: middle", :class => "delete")
61 end
68 end
62 content << content_tag('li', s)
69 content << content_tag('li', s)
63 end
70 end
64 content.present? ? content_tag('ul', content) : content
71 content.present? ? content_tag('ul', content) : content
65 end
72 end
66
73
67 def watchers_checkboxes(object, users, checked=nil)
74 def watchers_checkboxes(object, users, checked=nil)
68 users.map do |user|
75 users.map do |user|
69 c = checked.nil? ? object.watched_by?(user) : checked
76 c = checked.nil? ? object.watched_by?(user) : checked
70 tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
77 tag = check_box_tag 'issue[watcher_user_ids][]', user.id, c, :id => nil
71 content_tag 'label', "#{tag} #{h(user)}".html_safe,
78 content_tag 'label', "#{tag} #{h(user)}".html_safe,
72 :id => "issue_watcher_user_ids_#{user.id}",
79 :id => "issue_watcher_user_ids_#{user.id}",
73 :class => "floating"
80 :class => "floating"
74 end.join.html_safe
81 end.join.html_safe
75 end
82 end
76 end
83 end
@@ -1,138 +1,139
1 <ul>
1 <ul>
2 <%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>
2 <%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>
3
3
4 <% if @issue -%>
4 <% if @issue -%>
5 <li><%= context_menu_link l(:button_edit), edit_issue_path(@issue),
5 <li><%= context_menu_link l(:button_edit), edit_issue_path(@issue),
6 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
6 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
7 <% else %>
7 <% else %>
8 <li><%= context_menu_link l(:button_edit), bulk_edit_issues_path(:ids => @issue_ids),
8 <li><%= context_menu_link l(:button_edit), bulk_edit_issues_path(:ids => @issue_ids),
9 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
9 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
10 <% end %>
10 <% end %>
11
11
12 <% if @allowed_statuses.present? %>
12 <% if @allowed_statuses.present? %>
13 <li class="folder">
13 <li class="folder">
14 <a href="#" class="submenu"><%= l(:field_status) %></a>
14 <a href="#" class="submenu"><%= l(:field_status) %></a>
15 <ul>
15 <ul>
16 <% @allowed_statuses.each do |s| -%>
16 <% @allowed_statuses.each do |s| -%>
17 <li><%= context_menu_link h(s.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {:status_id => s}, :back_url => @back), :method => :post,
17 <li><%= context_menu_link h(s.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {:status_id => s}, :back_url => @back), :method => :post,
18 :selected => (@issue && s == @issue.status), :disabled => !@can[:update] %></li>
18 :selected => (@issue && s == @issue.status), :disabled => !@can[:update] %></li>
19 <% end -%>
19 <% end -%>
20 </ul>
20 </ul>
21 </li>
21 </li>
22 <% end %>
22 <% end %>
23
23
24 <% if @trackers.present? %>
24 <% if @trackers.present? %>
25 <li class="folder">
25 <li class="folder">
26 <a href="#" class="submenu"><%= l(:field_tracker) %></a>
26 <a href="#" class="submenu"><%= l(:field_tracker) %></a>
27 <ul>
27 <ul>
28 <% @trackers.each do |t| -%>
28 <% @trackers.each do |t| -%>
29 <li><%= context_menu_link h(t.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'tracker_id' => t}, :back_url => @back), :method => :post,
29 <li><%= context_menu_link h(t.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'tracker_id' => t}, :back_url => @back), :method => :post,
30 :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
30 :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
31 <% end -%>
31 <% end -%>
32 </ul>
32 </ul>
33 </li>
33 </li>
34 <% end %>
34 <% end %>
35
35
36 <% if @safe_attributes.include?('priority_id') && @priorities.present? -%>
36 <% if @safe_attributes.include?('priority_id') && @priorities.present? -%>
37 <li class="folder">
37 <li class="folder">
38 <a href="#" class="submenu"><%= l(:field_priority) %></a>
38 <a href="#" class="submenu"><%= l(:field_priority) %></a>
39 <ul>
39 <ul>
40 <% @priorities.each do |p| -%>
40 <% @priorities.each do |p| -%>
41 <li><%= context_menu_link h(p.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'priority_id' => p}, :back_url => @back), :method => :post,
41 <li><%= context_menu_link h(p.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'priority_id' => p}, :back_url => @back), :method => :post,
42 :selected => (@issue && p == @issue.priority), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
42 :selected => (@issue && p == @issue.priority), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
43 <% end -%>
43 <% end -%>
44 </ul>
44 </ul>
45 </li>
45 </li>
46 <% end %>
46 <% end %>
47
47
48 <% if @safe_attributes.include?('fixed_version_id') && @versions.present? -%>
48 <% if @safe_attributes.include?('fixed_version_id') && @versions.present? -%>
49 <li class="folder">
49 <li class="folder">
50 <a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
50 <a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
51 <ul>
51 <ul>
52 <% @versions.sort.each do |v| -%>
52 <% @versions.sort.each do |v| -%>
53 <li><%= context_menu_link format_version_name(v), bulk_update_issues_path(:ids => @issue_ids, :issue => {'fixed_version_id' => v}, :back_url => @back), :method => :post,
53 <li><%= context_menu_link format_version_name(v), bulk_update_issues_path(:ids => @issue_ids, :issue => {'fixed_version_id' => v}, :back_url => @back), :method => :post,
54 :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
54 :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
55 <% end -%>
55 <% end -%>
56 <li><%= context_menu_link l(:label_none), bulk_update_issues_path(:ids => @issue_ids, :issue => {'fixed_version_id' => 'none'}, :back_url => @back), :method => :post,
56 <li><%= context_menu_link l(:label_none), bulk_update_issues_path(:ids => @issue_ids, :issue => {'fixed_version_id' => 'none'}, :back_url => @back), :method => :post,
57 :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
57 :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
58 </ul>
58 </ul>
59 </li>
59 </li>
60 <% end %>
60 <% end %>
61
61
62 <% if @safe_attributes.include?('assigned_to_id') && @assignables.present? -%>
62 <% if @safe_attributes.include?('assigned_to_id') && @assignables.present? -%>
63 <li class="folder">
63 <li class="folder">
64 <a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
64 <a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
65 <ul>
65 <ul>
66 <% if @assignables.include?(User.current) %>
66 <% if @assignables.include?(User.current) %>
67 <li><%= context_menu_link "<< #{l(:label_me)} >>", bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => User.current}, :back_url => @back), :method => :post,
67 <li><%= context_menu_link "<< #{l(:label_me)} >>", bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => User.current}, :back_url => @back), :method => :post,
68 :disabled => !@can[:update] %></li>
68 :disabled => !@can[:update] %></li>
69 <% end %>
69 <% end %>
70 <% @assignables.each do |u| -%>
70 <% @assignables.each do |u| -%>
71 <li><%= context_menu_link h(u.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => u}, :back_url => @back), :method => :post,
71 <li><%= context_menu_link h(u.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => u}, :back_url => @back), :method => :post,
72 :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
72 :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
73 <% end -%>
73 <% end -%>
74 <li><%= context_menu_link l(:label_nobody), bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => 'none'}, :back_url => @back), :method => :post,
74 <li><%= context_menu_link l(:label_nobody), bulk_update_issues_path(:ids => @issue_ids, :issue => {'assigned_to_id' => 'none'}, :back_url => @back), :method => :post,
75 :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
75 :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
76 </ul>
76 </ul>
77 </li>
77 </li>
78 <% end %>
78 <% end %>
79
79
80 <% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%>
80 <% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%>
81 <li class="folder">
81 <li class="folder">
82 <a href="#" class="submenu"><%= l(:field_category) %></a>
82 <a href="#" class="submenu"><%= l(:field_category) %></a>
83 <ul>
83 <ul>
84 <% @project.issue_categories.each do |u| -%>
84 <% @project.issue_categories.each do |u| -%>
85 <li><%= context_menu_link h(u.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'category_id' => u}, :back_url => @back), :method => :post,
85 <li><%= context_menu_link h(u.name), bulk_update_issues_path(:ids => @issue_ids, :issue => {'category_id' => u}, :back_url => @back), :method => :post,
86 :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li>
86 :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li>
87 <% end -%>
87 <% end -%>
88 <li><%= context_menu_link l(:label_none), bulk_update_issues_path(:ids => @issue_ids, :issue => {'category_id' => 'none'}, :back_url => @back), :method => :post,
88 <li><%= context_menu_link l(:label_none), bulk_update_issues_path(:ids => @issue_ids, :issue => {'category_id' => 'none'}, :back_url => @back), :method => :post,
89 :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
89 :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
90 </ul>
90 </ul>
91 </li>
91 </li>
92 <% end -%>
92 <% end -%>
93
93
94 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
94 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
95 <li class="folder">
95 <li class="folder">
96 <a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
96 <a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
97 <ul>
97 <ul>
98 <% (0..10).map{|x|x*10}.each do |p| -%>
98 <% (0..10).map{|x|x*10}.each do |p| -%>
99 <li><%= context_menu_link "#{p}%", bulk_update_issues_path(:ids => @issue_ids, :issue => {'done_ratio' => p}, :back_url => @back), :method => :post,
99 <li><%= context_menu_link "#{p}%", bulk_update_issues_path(:ids => @issue_ids, :issue => {'done_ratio' => p}, :back_url => @back), :method => :post,
100 :selected => (@issue && p == @issue.done_ratio), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
100 :selected => (@issue && p == @issue.done_ratio), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
101 <% end -%>
101 <% end -%>
102 </ul>
102 </ul>
103 </li>
103 </li>
104 <% end %>
104 <% end %>
105
105
106 <% @options_by_custom_field.each do |field, options| %>
106 <% @options_by_custom_field.each do |field, options| %>
107 <li class="folder cf_<%= field.id %>">
107 <li class="folder cf_<%= field.id %>">
108 <a href="#" class="submenu"><%= h(field.name) %></a>
108 <a href="#" class="submenu"><%= h(field.name) %></a>
109 <ul>
109 <ul>
110 <% options.each do |text, value| %>
110 <% options.each do |text, value| %>
111 <li><%= bulk_update_custom_field_context_menu_link(field, text, value || text) %></li>
111 <li><%= bulk_update_custom_field_context_menu_link(field, text, value || text) %></li>
112 <% end %>
112 <% end %>
113 <% unless field.is_required? %>
113 <% unless field.is_required? %>
114 <li><%= bulk_update_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li>
114 <li><%= bulk_update_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li>
115 <% end %>
115 <% end %>
116 </ul>
116 </ul>
117 </li>
117 </li>
118 <% end %>
118 <% end %>
119
119
120 <% if User.current.logged? %>
121 <li><%= watcher_link(@issues, User.current) %></li>
122 <% end %>
123
120 <% if @issue.present? %>
124 <% if @issue.present? %>
121 <% if User.current.logged? %>
122 <li><%= watcher_link(@issue, User.current) %></li>
123 <% end %>
124 <% if @can[:log_time] -%>
125 <% if @can[:log_time] -%>
125 <li><%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue),
126 <li><%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue),
126 :class => 'icon-time-add' %></li>
127 :class => 'icon-time-add' %></li>
127 <% end %>
128 <% end %>
128 <li><%= context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue),
129 <li><%= context_menu_link l(:button_copy), project_copy_issue_path(@project, @issue),
129 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
130 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
130 <% else %>
131 <% else %>
131 <li><%= context_menu_link l(:button_copy), bulk_edit_issues_path(:ids => @issue_ids, :copy => '1'),
132 <li><%= context_menu_link l(:button_copy), bulk_edit_issues_path(:ids => @issue_ids, :copy => '1'),
132 :class => 'icon-copy', :disabled => !@can[:move] %></li>
133 :class => 'icon-copy', :disabled => !@can[:move] %></li>
133 <% end %>
134 <% end %>
134 <li><%= context_menu_link l(:button_delete), issues_path(:ids => @issue_ids, :back_url => @back),
135 <li><%= context_menu_link l(:button_delete), issues_path(:ids => @issue_ids, :back_url => @back),
135 :method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon-del', :disabled => !@can[:delete] %></li>
136 :method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon-del', :disabled => !@can[:delete] %></li>
136
137
137 <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
138 <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
138 </ul>
139 </ul>
@@ -1,25 +1,27
1 <h3 class="title"><%= l(:permission_add_issue_watchers) %></h3>
1 <h3 class="title"><%= l(:permission_add_issue_watchers) %></h3>
2
2
3 <%= form_tag({:controller => 'watchers',
3 <%= form_tag({:controller => 'watchers',
4 :action => (watched ? 'create' : 'append'),
4 :action => (watched ? 'create' : 'append'),
5 :object_type => watched.class.name.underscore,
5 :object_type => (watched && watched.class.name.underscore),
6 :object_id => watched},
6 :object_id => watched,
7 :project_id => @project},
7 :remote => true,
8 :remote => true,
8 :method => :post,
9 :method => :post,
9 :id => 'new-watcher-form') do %>
10 :id => 'new-watcher-form') do %>
10
11
11 <p><%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
12 <p><%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
12 <%= javascript_tag "observeSearchfield('user_search', 'users_for_watcher', '#{ escape_javascript url_for(:controller => 'watchers',
13 <%= javascript_tag "observeSearchfield('user_search', 'users_for_watcher', '#{ escape_javascript url_for(:controller => 'watchers',
13 :action => 'autocomplete_for_user',
14 :action => 'autocomplete_for_user',
14 :object_type => watched.class.name.underscore,
15 :object_type => (watched && watched.class.name.underscore),
15 :object_id => watched) }')" %>
16 :object_id => watched,
17 :project_id => @project) }')" %>
16
18
17 <div id="users_for_watcher">
19 <div id="users_for_watcher">
18 <%= principals_check_box_tags 'watcher[user_ids][]', (watched ? watched.addable_watcher_users : User.active.all(:limit => 100)) %>
20 <%= principals_check_box_tags 'watcher[user_ids][]', (watched ? watched.addable_watcher_users : User.active.all(:limit => 100)) %>
19 </div>
21 </div>
20
22
21 <p class="buttons">
23 <p class="buttons">
22 <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %>
24 <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %>
23 <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
25 <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
24 </p>
26 </p>
25 <% end %>
27 <% end %>
@@ -1,284 +1,284
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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 require 'redmine/core_ext'
18 require 'redmine/core_ext'
19
19
20 begin
20 begin
21 require 'RMagick' unless Object.const_defined?(:Magick)
21 require 'RMagick' unless Object.const_defined?(:Magick)
22 rescue LoadError
22 rescue LoadError
23 # RMagick is not available
23 # RMagick is not available
24 end
24 end
25
25
26 require 'redmine/scm/base'
26 require 'redmine/scm/base'
27 require 'redmine/access_control'
27 require 'redmine/access_control'
28 require 'redmine/access_keys'
28 require 'redmine/access_keys'
29 require 'redmine/activity'
29 require 'redmine/activity'
30 require 'redmine/activity/fetcher'
30 require 'redmine/activity/fetcher'
31 require 'redmine/ciphering'
31 require 'redmine/ciphering'
32 require 'redmine/codeset_util'
32 require 'redmine/codeset_util'
33 require 'redmine/custom_field_format'
33 require 'redmine/custom_field_format'
34 require 'redmine/i18n'
34 require 'redmine/i18n'
35 require 'redmine/menu_manager'
35 require 'redmine/menu_manager'
36 require 'redmine/notifiable'
36 require 'redmine/notifiable'
37 require 'redmine/platform'
37 require 'redmine/platform'
38 require 'redmine/mime_type'
38 require 'redmine/mime_type'
39 require 'redmine/notifiable'
39 require 'redmine/notifiable'
40 require 'redmine/search'
40 require 'redmine/search'
41 require 'redmine/syntax_highlighting'
41 require 'redmine/syntax_highlighting'
42 require 'redmine/thumbnail'
42 require 'redmine/thumbnail'
43 require 'redmine/unified_diff'
43 require 'redmine/unified_diff'
44 require 'redmine/utils'
44 require 'redmine/utils'
45 require 'redmine/version'
45 require 'redmine/version'
46 require 'redmine/wiki_formatting'
46 require 'redmine/wiki_formatting'
47
47
48 require 'redmine/default_data/loader'
48 require 'redmine/default_data/loader'
49 require 'redmine/helpers/calendar'
49 require 'redmine/helpers/calendar'
50 require 'redmine/helpers/diff'
50 require 'redmine/helpers/diff'
51 require 'redmine/helpers/gantt'
51 require 'redmine/helpers/gantt'
52 require 'redmine/helpers/time_report'
52 require 'redmine/helpers/time_report'
53 require 'redmine/views/other_formats_builder'
53 require 'redmine/views/other_formats_builder'
54 require 'redmine/views/labelled_form_builder'
54 require 'redmine/views/labelled_form_builder'
55 require 'redmine/views/builders'
55 require 'redmine/views/builders'
56
56
57 require 'redmine/themes'
57 require 'redmine/themes'
58 require 'redmine/hook'
58 require 'redmine/hook'
59 require 'redmine/plugin'
59 require 'redmine/plugin'
60
60
61 if RUBY_VERSION < '1.9'
61 if RUBY_VERSION < '1.9'
62 require 'fastercsv'
62 require 'fastercsv'
63 else
63 else
64 require 'csv'
64 require 'csv'
65 FCSV = CSV
65 FCSV = CSV
66 end
66 end
67
67
68 Redmine::Scm::Base.add "Subversion"
68 Redmine::Scm::Base.add "Subversion"
69 Redmine::Scm::Base.add "Darcs"
69 Redmine::Scm::Base.add "Darcs"
70 Redmine::Scm::Base.add "Mercurial"
70 Redmine::Scm::Base.add "Mercurial"
71 Redmine::Scm::Base.add "Cvs"
71 Redmine::Scm::Base.add "Cvs"
72 Redmine::Scm::Base.add "Bazaar"
72 Redmine::Scm::Base.add "Bazaar"
73 Redmine::Scm::Base.add "Git"
73 Redmine::Scm::Base.add "Git"
74 Redmine::Scm::Base.add "Filesystem"
74 Redmine::Scm::Base.add "Filesystem"
75
75
76 Redmine::CustomFieldFormat.map do |fields|
76 Redmine::CustomFieldFormat.map do |fields|
77 fields.register 'string'
77 fields.register 'string'
78 fields.register 'text'
78 fields.register 'text'
79 fields.register 'int', :label => :label_integer
79 fields.register 'int', :label => :label_integer
80 fields.register 'float'
80 fields.register 'float'
81 fields.register 'list'
81 fields.register 'list'
82 fields.register 'date'
82 fields.register 'date'
83 fields.register 'bool', :label => :label_boolean
83 fields.register 'bool', :label => :label_boolean
84 fields.register 'user', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
84 fields.register 'user', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
85 fields.register 'version', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
85 fields.register 'version', :only => %w(Issue TimeEntry Version Project), :edit_as => 'list'
86 end
86 end
87
87
88 # Permissions
88 # Permissions
89 Redmine::AccessControl.map do |map|
89 Redmine::AccessControl.map do |map|
90 map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true
90 map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true
91 map.permission :search_project, {:search => :index}, :public => true, :read => true
91 map.permission :search_project, {:search => :index}, :public => true, :read => true
92 map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
92 map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
93 map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
93 map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
94 map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
94 map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
95 map.permission :select_project_modules, {:projects => :modules}, :require => :member
95 map.permission :select_project_modules, {:projects => :modules}, :require => :member
96 map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :create, :update, :destroy, :autocomplete]}, :require => :member
96 map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :create, :update, :destroy, :autocomplete]}, :require => :member
97 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
97 map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
98 map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
98 map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
99
99
100 map.project_module :issue_tracking do |map|
100 map.project_module :issue_tracking do |map|
101 # Issue categories
101 # Issue categories
102 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member
102 map.permission :manage_categories, {:projects => :settings, :issue_categories => [:index, :show, :new, :create, :edit, :update, :destroy]}, :require => :member
103 # Issues
103 # Issues
104 map.permission :view_issues, {:issues => [:index, :show],
104 map.permission :view_issues, {:issues => [:index, :show],
105 :auto_complete => [:issues],
105 :auto_complete => [:issues],
106 :context_menus => [:issues],
106 :context_menus => [:issues],
107 :versions => [:index, :show, :status_by],
107 :versions => [:index, :show, :status_by],
108 :journals => [:index, :diff],
108 :journals => [:index, :diff],
109 :queries => :index,
109 :queries => :index,
110 :reports => [:issue_report, :issue_report_details]},
110 :reports => [:issue_report, :issue_report_details]},
111 :read => true
111 :read => true
112 map.permission :add_issues, {:issues => [:new, :create, :update_form], :attachments => :upload}
112 map.permission :add_issues, {:issues => [:new, :create, :update_form], :attachments => :upload}
113 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new], :attachments => :upload}
113 map.permission :edit_issues, {:issues => [:edit, :update, :bulk_edit, :bulk_update, :update_form], :journals => [:new], :attachments => :upload}
114 map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]}
114 map.permission :manage_issue_relations, {:issue_relations => [:index, :show, :create, :destroy]}
115 map.permission :manage_subtasks, {}
115 map.permission :manage_subtasks, {}
116 map.permission :set_issues_private, {}
116 map.permission :set_issues_private, {}
117 map.permission :set_own_issues_private, {}, :require => :loggedin
117 map.permission :set_own_issues_private, {}, :require => :loggedin
118 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
118 map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
119 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
119 map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
120 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
120 map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
121 map.permission :view_private_notes, {}, :read => true, :require => :member
121 map.permission :view_private_notes, {}, :read => true, :require => :member
122 map.permission :set_notes_private, {}, :require => :member
122 map.permission :set_notes_private, {}, :require => :member
123 map.permission :move_issues, {:issues => [:bulk_edit, :bulk_update]}, :require => :loggedin
123 map.permission :move_issues, {:issues => [:bulk_edit, :bulk_update]}, :require => :loggedin
124 map.permission :delete_issues, {:issues => :destroy}, :require => :member
124 map.permission :delete_issues, {:issues => :destroy}, :require => :member
125 # Queries
125 # Queries
126 map.permission :manage_public_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :member
126 map.permission :manage_public_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :member
127 map.permission :save_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
127 map.permission :save_queries, {:queries => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
128 # Watchers
128 # Watchers
129 map.permission :view_issue_watchers, {}, :read => true
129 map.permission :view_issue_watchers, {}, :read => true
130 map.permission :add_issue_watchers, {:watchers => :new}
130 map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]}
131 map.permission :delete_issue_watchers, {:watchers => :destroy}
131 map.permission :delete_issue_watchers, {:watchers => :destroy}
132 end
132 end
133
133
134 map.project_module :time_tracking do |map|
134 map.project_module :time_tracking do |map|
135 map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin
135 map.permission :log_time, {:timelog => [:new, :create]}, :require => :loggedin
136 map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true
136 map.permission :view_time_entries, {:timelog => [:index, :report, :show]}, :read => true
137 map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
137 map.permission :edit_time_entries, {:timelog => [:edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
138 map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
138 map.permission :edit_own_time_entries, {:timelog => [:edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
139 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
139 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
140 end
140 end
141
141
142 map.project_module :news do |map|
142 map.project_module :news do |map|
143 map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
143 map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
144 map.permission :view_news, {:news => [:index, :show]}, :public => true, :read => true
144 map.permission :view_news, {:news => [:index, :show]}, :public => true, :read => true
145 map.permission :comment_news, {:comments => :create}
145 map.permission :comment_news, {:comments => :create}
146 end
146 end
147
147
148 map.project_module :documents do |map|
148 map.project_module :documents do |map|
149 map.permission :add_documents, {:documents => [:new, :create, :add_attachment]}, :require => :loggedin
149 map.permission :add_documents, {:documents => [:new, :create, :add_attachment]}, :require => :loggedin
150 map.permission :edit_documents, {:documents => [:edit, :update, :add_attachment]}, :require => :loggedin
150 map.permission :edit_documents, {:documents => [:edit, :update, :add_attachment]}, :require => :loggedin
151 map.permission :delete_documents, {:documents => [:destroy]}, :require => :loggedin
151 map.permission :delete_documents, {:documents => [:destroy]}, :require => :loggedin
152 map.permission :view_documents, {:documents => [:index, :show, :download]}, :read => true
152 map.permission :view_documents, {:documents => [:index, :show, :download]}, :read => true
153 end
153 end
154
154
155 map.project_module :files do |map|
155 map.project_module :files do |map|
156 map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
156 map.permission :manage_files, {:files => [:new, :create]}, :require => :loggedin
157 map.permission :view_files, {:files => :index, :versions => :download}, :read => true
157 map.permission :view_files, {:files => :index, :versions => :download}, :read => true
158 end
158 end
159
159
160 map.project_module :wiki do |map|
160 map.project_module :wiki do |map|
161 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
161 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
162 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
162 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
163 map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member
163 map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member
164 map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true
164 map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true
165 map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true
165 map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true
166 map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true
166 map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true
167 map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment]
167 map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment]
168 map.permission :delete_wiki_pages_attachments, {}
168 map.permission :delete_wiki_pages_attachments, {}
169 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
169 map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member
170 end
170 end
171
171
172 map.project_module :repository do |map|
172 map.project_module :repository do |map|
173 map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
173 map.permission :manage_repository, {:repositories => [:new, :create, :edit, :update, :committers, :destroy]}, :require => :member
174 map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true
174 map.permission :browse_repository, {:repositories => [:show, :browse, :entry, :raw, :annotate, :changes, :diff, :stats, :graph]}, :read => true
175 map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true
175 map.permission :view_changesets, {:repositories => [:show, :revisions, :revision]}, :read => true
176 map.permission :commit_access, {}
176 map.permission :commit_access, {}
177 map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
177 map.permission :manage_related_issues, {:repositories => [:add_related_issue, :remove_related_issue]}
178 end
178 end
179
179
180 map.project_module :boards do |map|
180 map.project_module :boards do |map|
181 map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
181 map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
182 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true
182 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true, :read => true
183 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
183 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
184 map.permission :edit_messages, {:messages => :edit}, :require => :member
184 map.permission :edit_messages, {:messages => :edit}, :require => :member
185 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
185 map.permission :edit_own_messages, {:messages => :edit}, :require => :loggedin
186 map.permission :delete_messages, {:messages => :destroy}, :require => :member
186 map.permission :delete_messages, {:messages => :destroy}, :require => :member
187 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
187 map.permission :delete_own_messages, {:messages => :destroy}, :require => :loggedin
188 end
188 end
189
189
190 map.project_module :calendar do |map|
190 map.project_module :calendar do |map|
191 map.permission :view_calendar, {:calendars => [:show, :update]}, :read => true
191 map.permission :view_calendar, {:calendars => [:show, :update]}, :read => true
192 end
192 end
193
193
194 map.project_module :gantt do |map|
194 map.project_module :gantt do |map|
195 map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true
195 map.permission :view_gantt, {:gantts => [:show, :update]}, :read => true
196 end
196 end
197 end
197 end
198
198
199 Redmine::MenuManager.map :top_menu do |menu|
199 Redmine::MenuManager.map :top_menu do |menu|
200 menu.push :home, :home_path
200 menu.push :home, :home_path
201 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
201 menu.push :my_page, { :controller => 'my', :action => 'page' }, :if => Proc.new { User.current.logged? }
202 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
202 menu.push :projects, { :controller => 'projects', :action => 'index' }, :caption => :label_project_plural
203 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
203 menu.push :administration, { :controller => 'admin', :action => 'index' }, :if => Proc.new { User.current.admin? }, :last => true
204 menu.push :help, Redmine::Info.help_url, :last => true
204 menu.push :help, Redmine::Info.help_url, :last => true
205 end
205 end
206
206
207 Redmine::MenuManager.map :account_menu do |menu|
207 Redmine::MenuManager.map :account_menu do |menu|
208 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
208 menu.push :login, :signin_path, :if => Proc.new { !User.current.logged? }
209 menu.push :register, :register_path, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
209 menu.push :register, :register_path, :if => Proc.new { !User.current.logged? && Setting.self_registration? }
210 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
210 menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
211 menu.push :logout, :signout_path, :html => {:method => 'post'}, :if => Proc.new { User.current.logged? }
211 menu.push :logout, :signout_path, :html => {:method => 'post'}, :if => Proc.new { User.current.logged? }
212 end
212 end
213
213
214 Redmine::MenuManager.map :application_menu do |menu|
214 Redmine::MenuManager.map :application_menu do |menu|
215 # Empty
215 # Empty
216 end
216 end
217
217
218 Redmine::MenuManager.map :admin_menu do |menu|
218 Redmine::MenuManager.map :admin_menu do |menu|
219 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
219 menu.push :projects, {:controller => 'admin', :action => 'projects'}, :caption => :label_project_plural
220 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
220 menu.push :users, {:controller => 'users'}, :caption => :label_user_plural
221 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
221 menu.push :groups, {:controller => 'groups'}, :caption => :label_group_plural
222 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
222 menu.push :roles, {:controller => 'roles'}, :caption => :label_role_and_permissions
223 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
223 menu.push :trackers, {:controller => 'trackers'}, :caption => :label_tracker_plural
224 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
224 menu.push :issue_statuses, {:controller => 'issue_statuses'}, :caption => :label_issue_status_plural,
225 :html => {:class => 'issue_statuses'}
225 :html => {:class => 'issue_statuses'}
226 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
226 menu.push :workflows, {:controller => 'workflows', :action => 'edit'}, :caption => :label_workflow
227 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
227 menu.push :custom_fields, {:controller => 'custom_fields'}, :caption => :label_custom_field_plural,
228 :html => {:class => 'custom_fields'}
228 :html => {:class => 'custom_fields'}
229 menu.push :enumerations, {:controller => 'enumerations'}
229 menu.push :enumerations, {:controller => 'enumerations'}
230 menu.push :settings, {:controller => 'settings'}
230 menu.push :settings, {:controller => 'settings'}
231 menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'},
231 menu.push :ldap_authentication, {:controller => 'auth_sources', :action => 'index'},
232 :html => {:class => 'server_authentication'}
232 :html => {:class => 'server_authentication'}
233 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
233 menu.push :plugins, {:controller => 'admin', :action => 'plugins'}, :last => true
234 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
234 menu.push :info, {:controller => 'admin', :action => 'info'}, :caption => :label_information_plural, :last => true
235 end
235 end
236
236
237 Redmine::MenuManager.map :project_menu do |menu|
237 Redmine::MenuManager.map :project_menu do |menu|
238 menu.push :overview, { :controller => 'projects', :action => 'show' }
238 menu.push :overview, { :controller => 'projects', :action => 'show' }
239 menu.push :activity, { :controller => 'activities', :action => 'index' }
239 menu.push :activity, { :controller => 'activities', :action => 'index' }
240 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
240 menu.push :roadmap, { :controller => 'versions', :action => 'index' }, :param => :project_id,
241 :if => Proc.new { |p| p.shared_versions.any? }
241 :if => Proc.new { |p| p.shared_versions.any? }
242 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
242 menu.push :issues, { :controller => 'issues', :action => 'index' }, :param => :project_id, :caption => :label_issue_plural
243 menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new,
243 menu.push :new_issue, { :controller => 'issues', :action => 'new', :copy_from => nil }, :param => :project_id, :caption => :label_issue_new,
244 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
244 :html => { :accesskey => Redmine::AccessKeys.key_for(:new_issue) }
245 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
245 menu.push :gantt, { :controller => 'gantts', :action => 'show' }, :param => :project_id, :caption => :label_gantt
246 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
246 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
247 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
247 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
248 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
248 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
249 menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id,
249 menu.push :wiki, { :controller => 'wiki', :action => 'show', :id => nil }, :param => :project_id,
250 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
250 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
251 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
251 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
252 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
252 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
253 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
253 menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id
254 menu.push :repository, { :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil },
254 menu.push :repository, { :controller => 'repositories', :action => 'show', :repository_id => nil, :path => nil, :rev => nil },
255 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
255 :if => Proc.new { |p| p.repository && !p.repository.new_record? }
256 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
256 menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true
257 end
257 end
258
258
259 Redmine::Activity.map do |activity|
259 Redmine::Activity.map do |activity|
260 activity.register :issues, :class_name => %w(Issue Journal)
260 activity.register :issues, :class_name => %w(Issue Journal)
261 activity.register :changesets
261 activity.register :changesets
262 activity.register :news
262 activity.register :news
263 activity.register :documents, :class_name => %w(Document Attachment)
263 activity.register :documents, :class_name => %w(Document Attachment)
264 activity.register :files, :class_name => 'Attachment'
264 activity.register :files, :class_name => 'Attachment'
265 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
265 activity.register :wiki_edits, :class_name => 'WikiContent::Version', :default => false
266 activity.register :messages, :default => false
266 activity.register :messages, :default => false
267 activity.register :time_entries, :default => false
267 activity.register :time_entries, :default => false
268 end
268 end
269
269
270 Redmine::Search.map do |search|
270 Redmine::Search.map do |search|
271 search.register :issues
271 search.register :issues
272 search.register :news
272 search.register :news
273 search.register :documents
273 search.register :documents
274 search.register :changesets
274 search.register :changesets
275 search.register :wiki_pages
275 search.register :wiki_pages
276 search.register :messages
276 search.register :messages
277 search.register :projects
277 search.register :projects
278 end
278 end
279
279
280 Redmine::WikiFormatting.map do |format|
280 Redmine::WikiFormatting.map do |format|
281 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
281 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
282 end
282 end
283
283
284 ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler
284 ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler
@@ -1,158 +1,195
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class WatchersControllerTest < ActionController::TestCase
20 class WatchersControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
22 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
22 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
23
23
24 def setup
24 def setup
25 User.current = nil
25 User.current = nil
26 end
26 end
27
27
28 def test_watch
28 def test_watch_a_single_object
29 @request.session[:user_id] = 3
29 @request.session[:user_id] = 3
30 assert_difference('Watcher.count') do
30 assert_difference('Watcher.count') do
31 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
31 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
32 assert_response :success
32 assert_response :success
33 assert_include '$(".issue-1-watcher")', response.body
33 assert_include '$(".issue-1-watcher")', response.body
34 end
34 end
35 assert Issue.find(1).watched_by?(User.find(3))
35 assert Issue.find(1).watched_by?(User.find(3))
36 end
36 end
37
37
38 def test_watch_a_collection_with_a_single_object
39 @request.session[:user_id] = 3
40 assert_difference('Watcher.count') do
41 xhr :post, :watch, :object_type => 'issue', :object_id => ['1']
42 assert_response :success
43 assert_include '$(".issue-1-watcher")', response.body
44 end
45 assert Issue.find(1).watched_by?(User.find(3))
46 end
47
48 def test_watch_a_collection_with_multiple_objects
49 @request.session[:user_id] = 3
50 assert_difference('Watcher.count', 2) do
51 xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3']
52 assert_response :success
53 assert_include '$(".issue-bulk-watcher")', response.body
54 end
55 assert Issue.find(1).watched_by?(User.find(3))
56 assert Issue.find(3).watched_by?(User.find(3))
57 end
58
38 def test_watch_should_be_denied_without_permission
59 def test_watch_should_be_denied_without_permission
39 Role.find(2).remove_permission! :view_issues
60 Role.find(2).remove_permission! :view_issues
40 @request.session[:user_id] = 3
61 @request.session[:user_id] = 3
41 assert_no_difference('Watcher.count') do
62 assert_no_difference('Watcher.count') do
42 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
63 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
43 assert_response 403
64 assert_response 403
44 end
65 end
45 end
66 end
46
67
47 def test_watch_invalid_class_should_respond_with_404
68 def test_watch_invalid_class_should_respond_with_404
48 @request.session[:user_id] = 3
69 @request.session[:user_id] = 3
49 assert_no_difference('Watcher.count') do
70 assert_no_difference('Watcher.count') do
50 xhr :post, :watch, :object_type => 'foo', :object_id => '1'
71 xhr :post, :watch, :object_type => 'foo', :object_id => '1'
51 assert_response 404
72 assert_response 404
52 end
73 end
53 end
74 end
54
75
55 def test_watch_invalid_object_should_respond_with_404
76 def test_watch_invalid_object_should_respond_with_404
56 @request.session[:user_id] = 3
77 @request.session[:user_id] = 3
57 assert_no_difference('Watcher.count') do
78 assert_no_difference('Watcher.count') do
58 xhr :post, :watch, :object_type => 'issue', :object_id => '999'
79 xhr :post, :watch, :object_type => 'issue', :object_id => '999'
59 assert_response 404
80 assert_response 404
60 end
81 end
61 end
82 end
62
83
63 def test_unwatch
84 def test_unwatch
64 @request.session[:user_id] = 3
85 @request.session[:user_id] = 3
65 assert_difference('Watcher.count', -1) do
86 assert_difference('Watcher.count', -1) do
66 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
87 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
67 assert_response :success
88 assert_response :success
68 assert_include '$(".issue-2-watcher")', response.body
89 assert_include '$(".issue-2-watcher")', response.body
69 end
90 end
70 assert !Issue.find(1).watched_by?(User.find(3))
91 assert !Issue.find(1).watched_by?(User.find(3))
71 end
92 end
72
93
94 def test_unwatch_a_collection_with_multiple_objects
95 @request.session[:user_id] = 3
96 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
97 Watcher.create!(:user_id => 3, :watchable => Issue.find(3))
98
99 assert_difference('Watcher.count', -2) do
100 xhr :post, :unwatch, :object_type => 'issue', :object_id => ['1', '3']
101 assert_response :success
102 assert_include '$(".issue-bulk-watcher")', response.body
103 end
104 assert !Issue.find(1).watched_by?(User.find(3))
105 assert !Issue.find(3).watched_by?(User.find(3))
106 end
107
73 def test_new
108 def test_new
74 @request.session[:user_id] = 2
109 @request.session[:user_id] = 2
75 xhr :get, :new, :object_type => 'issue', :object_id => '2'
110 xhr :get, :new, :object_type => 'issue', :object_id => '2'
76 assert_response :success
111 assert_response :success
77 assert_match /ajax-modal/, response.body
112 assert_match /ajax-modal/, response.body
78 end
113 end
79
114
80 def test_new_for_new_record_with_id
115 def test_new_for_new_record_with_project_id
81 @request.session[:user_id] = 2
116 @request.session[:user_id] = 2
82 xhr :get, :new, :project_id => 1
117 xhr :get, :new, :project_id => 1
83 assert_response :success
118 assert_response :success
84 assert_equal Project.find(1), assigns(:project)
119 assert_equal Project.find(1), assigns(:project)
85 assert_match /ajax-modal/, response.body
120 assert_match /ajax-modal/, response.body
86 end
121 end
87
122
88 def test_new_for_new_record_with_identifier
123 def test_new_for_new_record_with_project_identifier
89 @request.session[:user_id] = 2
124 @request.session[:user_id] = 2
90 xhr :get, :new, :project_id => 'ecookbook'
125 xhr :get, :new, :project_id => 'ecookbook'
91 assert_response :success
126 assert_response :success
92 assert_equal Project.find(1), assigns(:project)
127 assert_equal Project.find(1), assigns(:project)
93 assert_match /ajax-modal/, response.body
128 assert_match /ajax-modal/, response.body
94 end
129 end
95
130
96 def test_create
131 def test_create
97 @request.session[:user_id] = 2
132 @request.session[:user_id] = 2
98 assert_difference('Watcher.count') do
133 assert_difference('Watcher.count') do
99 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
134 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
100 assert_response :success
135 assert_response :success
101 assert_match /watchers/, response.body
136 assert_match /watchers/, response.body
102 assert_match /ajax-modal/, response.body
137 assert_match /ajax-modal/, response.body
103 end
138 end
104 assert Issue.find(2).watched_by?(User.find(4))
139 assert Issue.find(2).watched_by?(User.find(4))
105 end
140 end
106
141
107 def test_create_multiple
142 def test_create_multiple
108 @request.session[:user_id] = 2
143 @request.session[:user_id] = 2
109 assert_difference('Watcher.count', 2) do
144 assert_difference('Watcher.count', 2) do
110 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
145 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
111 assert_response :success
146 assert_response :success
112 assert_match /watchers/, response.body
147 assert_match /watchers/, response.body
113 assert_match /ajax-modal/, response.body
148 assert_match /ajax-modal/, response.body
114 end
149 end
115 assert Issue.find(2).watched_by?(User.find(4))
150 assert Issue.find(2).watched_by?(User.find(4))
116 assert Issue.find(2).watched_by?(User.find(7))
151 assert Issue.find(2).watched_by?(User.find(7))
117 end
152 end
118
153
119 def test_autocomplete_on_watchable_creation
154 def test_autocomplete_on_watchable_creation
120 xhr :get, :autocomplete_for_user, :q => 'mi'
155 @request.session[:user_id] = 2
156 xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook'
121 assert_response :success
157 assert_response :success
122 assert_select 'input', :count => 4
158 assert_select 'input', :count => 4
123 assert_select 'input[name=?][value=1]', 'watcher[user_ids][]'
159 assert_select 'input[name=?][value=1]', 'watcher[user_ids][]'
124 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
160 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
125 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
161 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
126 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
162 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
127 end
163 end
128
164
129 def test_autocomplete_on_watchable_update
165 def test_autocomplete_on_watchable_update
130 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue'
166 @request.session[:user_id] = 2
167 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue', :project_id => 'ecookbook'
131 assert_response :success
168 assert_response :success
132 assert_select 'input', :count => 3
169 assert_select 'input', :count => 3
133 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
170 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
134 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
171 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
135 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
172 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
136
173
137 end
174 end
138
175
139 def test_append
176 def test_append
140 @request.session[:user_id] = 2
177 @request.session[:user_id] = 2
141 assert_no_difference 'Watcher.count' do
178 assert_no_difference 'Watcher.count' do
142 xhr :post, :append, :watcher => {:user_ids => ['4', '7']}
179 xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook'
143 assert_response :success
180 assert_response :success
144 assert_include 'watchers_inputs', response.body
181 assert_include 'watchers_inputs', response.body
145 assert_include 'issue[watcher_user_ids][]', response.body
182 assert_include 'issue[watcher_user_ids][]', response.body
146 end
183 end
147 end
184 end
148
185
149 def test_remove_watcher
186 def test_remove_watcher
150 @request.session[:user_id] = 2
187 @request.session[:user_id] = 2
151 assert_difference('Watcher.count', -1) do
188 assert_difference('Watcher.count', -1) do
152 xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
189 xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
153 assert_response :success
190 assert_response :success
154 assert_match /watchers/, response.body
191 assert_match /watchers/, response.body
155 end
192 end
156 assert !Issue.find(2).watched_by?(User.find(3))
193 assert !Issue.find(2).watched_by?(User.find(3))
157 end
194 end
158 end
195 end
General Comments 0
You need to be logged in to leave comments. Login now