summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-08-03 09:14:43 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-08-03 09:14:43 +0000
commita332e0a4febeb36aac41f8d5762d18f4cbbf115c (patch)
tree8e0883bbdbfd7bfca332880da6f1739362b8c579 /app
parent6034067d8623e87ef1391962b882fcc93196bf4b (diff)
downloadredmine-a332e0a4febeb36aac41f8d5762d18f4cbbf115c.tar.gz
redmine-a332e0a4febeb36aac41f8d5762d18f4cbbf115c.zip
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/watchers_controller.rb52
-rw-r--r--app/helpers/watchers_helper.rb7
-rw-r--r--app/models/watcher.rb7
-rw-r--r--app/views/issues/show.rhtml8
-rw-r--r--app/views/watchers/_watchers.rhtml25
5 files changed, 81 insertions, 18 deletions
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb
index 014779b7f..a44686d3f 100644
--- a/app/controllers/watchers_controller.rb
+++ b/app/controllers/watchers_controller.rb
@@ -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)
- 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 added.', :layout => true
+ 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 remove
- user = User.current
- @watched.remove_watcher(user)
+ 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
- render :text => 'Watcher removed.', :layout => true
+ rescue ::ActionController::RedirectBackError
+ render :text => 'Watcher added.', :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
diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb
index c83c785fc..f4767ebed 100644
--- a/app/helpers/watchers_helper.rb
+++ b/app/helpers/watchers_helper.rb
@@ -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
diff --git a/app/models/watcher.rb b/app/models/watcher.rb
index cb6ff52ea..38110c584 100644
--- a/app/models/watcher.rb
+++ b/app/models/watcher.rb
@@ -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
diff --git a/app/views/issues/show.rhtml b/app/views/issues/show.rhtml
index b71a02ee7..df8fc372a 100644
--- a/app/views/issues/show.rhtml
+++ b/app/views/issues/show.rhtml
@@ -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) %>
diff --git a/app/views/watchers/_watchers.rhtml b/app/views/watchers/_watchers.rhtml
new file mode 100644
index 000000000..14bb5fc6b
--- /dev/null
+++ b/app/views/watchers/_watchers.rhtml
@@ -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 %>