Adds permissions for viewing the watcher list and adding new watchers on the issue detail view (#398).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1712 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -17,30 +17,38 @@
|
||||
|
||||
class WatchersController < ApplicationController
|
||||
layout 'base'
|
||||
before_filter :require_login, :find_project, :check_project_privacy
|
||||
before_filter :find_project
|
||||
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
|
||||
before_filter :authorize, :only => :new
|
||||
|
||||
def add
|
||||
user = User.current
|
||||
@watched.add_watcher(user)
|
||||
verify :method => :post,
|
||||
:only => [ :watch, :unwatch ],
|
||||
:render => { :nothing => true, :status => :method_not_allowed }
|
||||
|
||||
def watch
|
||||
set_watcher(User.current, true)
|
||||
end
|
||||
|
||||
def unwatch
|
||||
set_watcher(User.current, false)
|
||||
end
|
||||
|
||||
def new
|
||||
@watcher = Watcher.new(params[:watcher])
|
||||
@watcher.watchable = @watched
|
||||
@watcher.save if request.post?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue RedirectBackError
|
||||
rescue ::ActionController::RedirectBackError
|
||||
render :text => 'Watcher added.', :layout => true
|
||||
end
|
||||
|
||||
def remove
|
||||
user = User.current
|
||||
@watched.remove_watcher(user)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||
end
|
||||
rescue RedirectBackError
|
||||
render :text => 'Watcher removed.', :layout => true
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
@@ -50,4 +58,14 @@ private
|
||||
rescue
|
||||
render_404
|
||||
end
|
||||
|
||||
def set_watcher(user, watching)
|
||||
@watched.set_watcher(user, watching)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} }
|
||||
end
|
||||
rescue ::ActionController::RedirectBackError
|
||||
render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,7 +24,7 @@ module WatchersHelper
|
||||
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
||||
watched = object.watched_by?(user)
|
||||
url = {:controller => 'watchers',
|
||||
:action => (watched ? 'remove' : 'add'),
|
||||
:action => (watched ? 'unwatch' : 'watch'),
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id}
|
||||
link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)),
|
||||
@@ -33,4 +33,9 @@ module WatchersHelper
|
||||
:class => (watched ? 'icon icon-fav' : 'icon icon-fav-off'))
|
||||
|
||||
end
|
||||
|
||||
# Returns a comma separated list of users watching the given object
|
||||
def watchers_list(object)
|
||||
object.watcher_users.collect {|u| content_tag('span', link_to_user(u), :class => 'user') }.join(",\n")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,5 +19,12 @@ class Watcher < ActiveRecord::Base
|
||||
belongs_to :watchable, :polymorphic => true
|
||||
belongs_to :user
|
||||
|
||||
validates_presence_of :user
|
||||
validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id]
|
||||
|
||||
protected
|
||||
|
||||
def validate
|
||||
errors.add :user_id, :activerecord_error_invalid unless user.nil? || user.active?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,6 +78,14 @@ end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if User.current.allowed_to?(:add_issue_watchers, @project) ||
|
||||
(@issue.watchers.any? && User.current.allowed_to?(:view_issue_watchers, @project)) %>
|
||||
<hr />
|
||||
<div id="watchers">
|
||||
<%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<% if @issue.changesets.any? && User.current.allowed_to?(:view_changesets, @project) %>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<div class="contextual">
|
||||
<%= link_to_remote l(:button_add),
|
||||
:url => {:controller => 'watchers',
|
||||
:action => 'new',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched} if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
||||
</div>
|
||||
|
||||
<p><strong><%= l(:label_issue_watchers) %></strong></p>
|
||||
<%= watchers_list(watched) %>
|
||||
|
||||
<% unless @watcher.nil? %>
|
||||
<% remote_form_for(:watcher, @watcher,
|
||||
:url => {:controller => 'watchers',
|
||||
:action => 'new',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched},
|
||||
:method => :post,
|
||||
:html => {:id => 'new-watcher-form'}) do |f| %>
|
||||
<p><%= f.select :user_id, (watched.addable_watcher_users.collect {|m| [m.name, m.id]}), :prompt => true %>
|
||||
|
||||
<%= submit_tag l(:button_add) %>
|
||||
<%= toggle_link l(:button_cancel), 'new-watcher-form'%></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
Reference in New Issue
Block a user