diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-12-22 19:21:02 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-12-22 19:21:02 +0000 |
commit | 1f89dad23aab9a4736e05d66ae468c0253ab9255 (patch) | |
tree | 0ceb6e0568d883ebcb21b78d1df62a053a3137bc | |
parent | 3de4a1d788e3ad9f1fd888725449634fb9333dd2 (diff) | |
download | redmine-1f89dad23aab9a4736e05d66ae468c0253ab9255.tar.gz redmine-1f89dad23aab9a4736e05d66ae468c0253ab9255.zip |
Adds watchers selection on new issue form (#398). Permission 'add issue watchers' required.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2164 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/issues_controller.rb | 5 | ||||
-rw-r--r-- | app/models/mailer.rb | 1 | ||||
-rw-r--r-- | app/views/issues/_form.rhtml | 8 | ||||
-rw-r--r-- | test/functional/issues_controller_test.rb | 24 | ||||
-rw-r--r-- | vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb | 2 |
5 files changed, 39 insertions, 1 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index b5009ce3f..e13658241 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -121,7 +121,10 @@ class IssuesController < ApplicationController render :nothing => true, :layout => true return end - @issue.attributes = params[:issue] + if params[:issue].is_a?(Hash) + @issue.attributes = params[:issue] + @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project) + end @issue.author = User.current default_status = IssueStatus.default diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 969fcd9ac..d9207cd92 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -28,6 +28,7 @@ class Mailer < ActionMailer::Base 'Issue-Author' => issue.author.login redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to recipients issue.recipients + cc(issue.watcher_recipients - @recipients) subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" body :issue => issue, :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml index 419536fee..dcc554101 100644 --- a/app/views/issues/_form.rhtml +++ b/app/views/issues/_form.rhtml @@ -48,6 +48,14 @@ <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p> <% end %> +<% if @issue.new_record? && User.current.allowed_to?(:add_issue_watchers, @project) -%> +<p><label>Watchers</label> +<% @issue.project.users.sort.each do |user| -%> +<label class="floating"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watcher_user_ids.include?(user.id) %> <%=h user %></label> +<% end -%> +</p> +<% end %> + <%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %> <%= wikitoolbar_for 'issue_description' %> diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 86340ba63..49dddf91c 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -322,6 +322,30 @@ class IssuesControllerTest < Test::Unit::TestCase assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values) end + def test_post_new_with_watchers + @request.session[:user_id] = 2 + ActionMailer::Base.deliveries.clear + + assert_difference 'Watcher.count', 2 do + post :new, :project_id => 1, + :issue => {:tracker_id => 1, + :subject => 'This is a new issue with watchers', + :description => 'This is the description', + :priority_id => 5, + :watcher_user_ids => ['2', '3']} + end + assert_redirected_to 'issues/show' + + issue = Issue.find_by_subject('This is a new issue with watchers') + # Watchers added + assert_equal [2, 3], issue.watcher_user_ids.sort + assert issue.watched_by?(User.find(3)) + # Watchers notified + mail = ActionMailer::Base.deliveries.last + assert_kind_of TMail::Mail, mail + assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) + end + def test_post_should_preserve_fields_values_on_validation_failure @request.session[:user_id] = 2 post :new, :project_id => 1, diff --git a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb index 2cb122795..3d0de0dca 100644 --- a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb +++ b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -14,6 +14,8 @@ module Redmine class_eval do has_many :watchers, :as => :watchable, :dependent => :delete_all has_many :watcher_users, :through => :watchers, :source => :user + + attr_protected :watcher_ids, :watcher_user_ids end end end |