Project

General

Profile

« Previous | Next » 

Revision 2164

Adds watchers selection on new issue form (#398). Permission 'add issue watchers' required.

View differences:

trunk/app/controllers/issues_controller.rb
121 121
      render :nothing => true, :layout => true
122 122
      return
123 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 128
    @issue.author = User.current
126 129
    
127 130
    default_status = IssueStatus.default
trunk/app/models/mailer.rb
28 28
                    'Issue-Author' => issue.author.login
29 29
    redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
30 30
    recipients issue.recipients
31
    cc(issue.watcher_recipients - @recipients)
31 32
    subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}"
32 33
    body :issue => issue,
33 34
         :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
trunk/app/views/issues/_form.rhtml
48 48
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
49 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 59
<%= call_hook(:view_issues_form_details_bottom, { :issue => @issue, :form => f }) %>
52 60

  
53 61
<%= wikitoolbar_for 'issue_description' %>
trunk/test/functional/issues_controller_test.rb
322 322
    assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
323 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 349
  def test_post_should_preserve_fields_values_on_validation_failure
326 350
    @request.session[:user_id] = 2
327 351
    post :new, :project_id => 1, 
trunk/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb
14 14
          class_eval do
15 15
            has_many :watchers, :as => :watchable, :dependent => :delete_all
16 16
            has_many :watcher_users, :through => :watchers, :source => :user
17
            
18
            attr_protected :watcher_ids, :watcher_user_ids
17 19
          end
18 20
        end
19 21
      end

Also available in: Unified diff