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