@@ -18,7 +18,7 | |||
|
18 | 18 | class WatchersController < ApplicationController |
|
19 | 19 | before_filter :find_project |
|
20 | 20 | before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch] |
|
21 | before_filter :authorize, :only => :new | |
|
21 | before_filter :authorize, :only => [:new, :destroy] | |
|
22 | 22 | |
|
23 | 23 | verify :method => :post, |
|
24 | 24 | :only => [ :watch, :unwatch ], |
@@ -48,6 +48,18 class WatchersController < ApplicationController | |||
|
48 | 48 | render :text => 'Watcher added.', :layout => true |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | def destroy | |
|
52 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? | |
|
53 | respond_to do |format| | |
|
54 | format.html { redirect_to :back } | |
|
55 | format.js do | |
|
56 | render :update do |page| | |
|
57 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} | |
|
58 | end | |
|
59 | end | |
|
60 | end | |
|
61 | end | |
|
62 | ||
|
51 | 63 | private |
|
52 | 64 | def find_project |
|
53 | 65 | klass = Object.const_get(params[:object_type].camelcase) |
@@ -36,6 +36,21 module WatchersHelper | |||
|
36 | 36 | |
|
37 | 37 | # Returns a comma separated list of users watching the given object |
|
38 | 38 | def watchers_list(object) |
|
39 | object.watcher_users.collect {|u| content_tag('span', link_to_user(u), :class => 'user') }.join(",\n") | |
|
39 | remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) | |
|
40 | object.watcher_users.collect do |user| | |
|
41 | s = content_tag('span', link_to_user(user), :class => 'user') | |
|
42 | if remove_allowed | |
|
43 | url = {:controller => 'watchers', | |
|
44 | :action => 'destroy', | |
|
45 | :object_type => object.class.to_s.underscore, | |
|
46 | :object_id => object.id, | |
|
47 | :user_id => user} | |
|
48 | s += ' ' + link_to_remote(image_tag('delete.png'), | |
|
49 | {:url => url}, | |
|
50 | :href => url_for(url), | |
|
51 | :style => "vertical-align: middle") | |
|
52 | end | |
|
53 | s | |
|
54 | end.join(",\n") | |
|
40 | 55 | end |
|
41 | 56 | end |
@@ -52,6 +52,7 Redmine::AccessControl.map do |map| | |||
|
52 | 52 | # Watchers |
|
53 | 53 | map.permission :view_issue_watchers, {} |
|
54 | 54 | map.permission :add_issue_watchers, {:watchers => :new} |
|
55 | map.permission :delete_issue_watchers, {:watchers => :destroy} | |
|
55 | 56 | end |
|
56 | 57 | |
|
57 | 58 | map.project_module :time_tracking do |map| |
@@ -18,6 +18,7 roles_001: | |||
|
18 | 18 | - :delete_issues |
|
19 | 19 | - :view_issue_watchers |
|
20 | 20 | - :add_issue_watchers |
|
21 | - :delete_issue_watchers | |
|
21 | 22 | - :manage_public_queries |
|
22 | 23 | - :save_queries |
|
23 | 24 | - :view_gantt |
@@ -67,4 +67,14 class WatchersControllerTest < ActionController::TestCase | |||
|
67 | 67 | end |
|
68 | 68 | assert Issue.find(2).watched_by?(User.find(4)) |
|
69 | 69 | end |
|
70 | ||
|
71 | def test_remove_watcher | |
|
72 | @request.session[:user_id] = 2 | |
|
73 | assert_difference('Watcher.count', -1) do | |
|
74 | xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |
|
75 | assert_response :success | |
|
76 | assert_select_rjs :replace_html, 'watchers' | |
|
77 | end | |
|
78 | assert !Issue.find(2).watched_by?(User.find(3)) | |
|
79 | end | |
|
70 | 80 | end |
General Comments 0
You need to be logged in to leave comments.
Login now