##// END OF EJS Templates
Adds watchers selection on new issue form (#398). Permission 'add issue watchers' required....
Jean-Philippe Lang -
r2162:1f89dad23aab
parent child
Show More
@@ -121,7 +121,10 class IssuesController < ApplicationController
121 render :nothing => true, :layout => true
121 render :nothing => true, :layout => true
122 return
122 return
123 end
123 end
124 @issue.attributes = params[:issue]
124 if params[:issue].is_a?(Hash)
125 @issue.attributes = params[:issue]
126 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
127 end
125 @issue.author = User.current
128 @issue.author = User.current
126
129
127 default_status = IssueStatus.default
130 default_status = IssueStatus.default
@@ -28,6 +28,7 class Mailer < ActionMailer::Base
28 'Issue-Author' => issue.author.login
28 'Issue-Author' => issue.author.login
29 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
29 redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
30 recipients issue.recipients
30 recipients issue.recipients
31 cc(issue.watcher_recipients - @recipients)
31 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
32 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
32 body :issue => issue,
33 body :issue => issue,
33 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
34 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
@@ -48,6 +48,14
48 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
48 <p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
49 <% end %>
49 <% end %>
50
50
51 <% if @issue.new_record? && User.current.allowed_to?(:add_issue_watchers, @project) -%>
52 <p><label>Watchers</label>
53 <% @issue.project.users.sort.each do |user| -%>
54 <label class="floating"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watcher_user_ids.include?(user.id) %> <%=h user %></label>
55 <% end -%>
56 </p>
57 <% end %>
58
51 <%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %>
59 <%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %>
52
60
53 <%= wikitoolbar_for 'issue_description' %>
61 <%= wikitoolbar_for 'issue_description' %>
@@ -322,6 +322,30 class IssuesControllerTest < Test::Unit::TestCase
322 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
322 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
323 end
323 end
324
324
325 def test_post_new_with_watchers
326 @request.session[:user_id] = 2
327 ActionMailer::Base.deliveries.clear
328
329 assert_difference 'Watcher.count', 2 do
330 post :new, :project_id => 1,
331 :issue => {:tracker_id => 1,
332 :subject => 'This is a new issue with watchers',
333 :description => 'This is the description',
334 :priority_id => 5,
335 :watcher_user_ids => ['2', '3']}
336 end
337 assert_redirected_to 'issues/show'
338
339 issue = Issue.find_by_subject('This is a new issue with watchers')
340 # Watchers added
341 assert_equal [2, 3], issue.watcher_user_ids.sort
342 assert issue.watched_by?(User.find(3))
343 # Watchers notified
344 mail = ActionMailer::Base.deliveries.last
345 assert_kind_of TMail::Mail, mail
346 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
347 end
348
325 def test_post_should_preserve_fields_values_on_validation_failure
349 def test_post_should_preserve_fields_values_on_validation_failure
326 @request.session[:user_id] = 2
350 @request.session[:user_id] = 2
327 post :new, :project_id => 1,
351 post :new, :project_id => 1,
@@ -14,6 +14,8 module Redmine
14 class_eval do
14 class_eval do
15 has_many :watchers, :as => :watchable, :dependent => :delete_all
15 has_many :watchers, :as => :watchable, :dependent => :delete_all
16 has_many :watcher_users, :through => :watchers, :source => :user
16 has_many :watcher_users, :through => :watchers, :source => :user
17
18 attr_protected :watcher_ids, :watcher_user_ids
17 end
19 end
18 end
20 end
19 end
21 end
General Comments 0
You need to be logged in to leave comments. Login now