0001-Allow-issues-to-be-assigned-to-a-Group.-2964.patch

Patch against r3254 - Eric Davis, 2009-12-29 00:09

Download (9.22 KB)

View differences:

app/controllers/issues_controller.rb
237 237
      tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id])
238 238
      status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
239 239
      priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
240
      assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
240
      assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : Principal.find_by_id(params[:assigned_to_id])
241 241
      category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
242 242
      fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.versions.find_by_id(params[:fixed_version_id])
243 243
      custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
app/helpers/issues_helper.rb
82 82
        t = Tracker.find_by_id(detail.value) and value = t.name if detail.value
83 83
        t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value
84 84
      when 'assigned_to_id'
85
        u = User.find_by_id(detail.value) and value = u.name if detail.value
86
        u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
85
        u = Principal.find_by_id(detail.value) and value = u.name if detail.value
86
        u = Principal.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
87 87
      when 'priority_id'
88 88
        e = IssuePriority.find_by_id(detail.value) and value = e.name if detail.value
89 89
        e = IssuePriority.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
app/models/group.rb
28 28
  def to_s
29 29
    lastname.to_s
30 30
  end
31

  
32
  alias :name :to_s
31 33
  
32 34
  def user_added(user)
33 35
    members.each do |member|
app/models/issue.rb
20 20
  belongs_to :tracker
21 21
  belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
22 22
  belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
23
  belongs_to :assigned_to, :class_name => 'User', :foreign_key => 'assigned_to_id'
23
  belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id'
24 24
  belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
25 25
  belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
26 26
  belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
......
255 255
    notified = project.notified_users
256 256
    # Author and assignee are always notified unless they have been locked
257 257
    notified << author if author && author.active?
258
    notified << assigned_to if assigned_to && assigned_to.active?
258
    if assigned_to.is_a? Group
259
      notified += assigned_to.users
260
    else
261
      notified << assigned_to if assigned_to && assigned_to.active?
262
    end
259 263
    notified.uniq!
260 264
    # Remove users that can not view the issue
261 265
    notified.reject! {|user| !visible?(user)}
app/models/project.rb
344 344
  
345 345
  # Users issues can be assigned to
346 346
  def assignable_users
347
    members.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.user}.sort
347
    member_principals.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.principal }.sort
348 348
  end
349 349
  
350 350
  # Returns the mail adresses of users that should be always notified on project events
test/exemplars/group_exemplar.rb
1
class Group < Principal
2
  generator_for :lastname, :method => :next_lastname
3

  
4
  def self.next_lastname
5
    @last_lastname ||= 'AGroup'
6
    @last_lastname.succ!
7
    @last_lastname
8
  end
9
end
test/functional/issues_controller_test.rb
532 532
    assert_not_nil v
533 533
    assert_equal 'Value for field 2', v.value
534 534
  end
535
  
535

  
536
  def test_post_new_with_group_assignment
537
    @group = Group.find(11)
538
    @project = Project.find(1)
539
    @project.members << Member.new(:principal => @group, :roles => [Role.first])
540

  
541
    @request.session[:user_id] = 2
542
    assert_difference 'Issue.count' do
543
      post :new, :project_id => @project.id, 
544
                 :issue => {:tracker_id => 3,
545
                            :subject => 'This is the test_new_with_group_assignment issue',
546
                            :assigned_to_id => @group.id}
547
      end
548
    assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
549
    
550
    issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
551
    assert_not_nil issue
552
    assert_equal @group.id, issue.assigned_to_id
553
  end
554

  
536 555
  def test_post_new_and_continue
537 556
    @request.session[:user_id] = 2
538 557
    post :new, :project_id => 1, 
......
933 952
  end
934 953

  
935 954
  def test_bulk_edit
955
    @group = Group.find(11)
956
    @project = Project.find(1)
957
    @project.members << Member.new(:principal => @group, :roles => [Role.first])
936 958
    @request.session[:user_id] = 2
937 959
    # update issues priority
938 960
    post :bulk_edit, :ids => [1, 2], :priority_id => 7,
939
                                     :assigned_to_id => '',
961
                                     :assigned_to_id => @group.id,
940 962
                                     :custom_field_values => {'2' => ''},
941 963
                                     :notes => 'Bulk editing'
942 964
    assert_response 302
943 965
    # check that the issues were updated
944 966
    assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
967
    assert_equal [@group.id, @group.id], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to.id}
945 968
    
946 969
    issue = Issue.find(1)
947 970
    journal = issue.journals.find(:first, :order => 'created_on DESC')
948 971
    assert_equal '125', issue.custom_value_for(2).value
949 972
    assert_equal 'Bulk editing', journal.notes
950
    assert_equal 1, journal.details.size
973
    assert_equal 2, journal.details.size
951 974
  end
952 975

  
953 976
  def test_bullk_edit_should_send_a_notification
test/unit/issue_test.rb
27 27
           :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
28 28
           :time_entries
29 29

  
30
  should_belong_to :assigned_to
31
  
30 32
  def test_create
31 33
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :status_id => 1, :priority => IssuePriority.all.first, :subject => 'test_create', :description => 'IssueTest#test_create', :estimated_hours => '1:30')
32 34
    assert issue.save
......
362 364
    assert !copy.recipients.include?(copy.author.mail)
363 365
  end
364 366

  
367
  test '#recipients should include the assigned group members' do
368
    group_member = User.generate_with_protected!
369
    group = Group.generate!
370
    group.users << group_member
371
    
372
    issue = Issue.find(12)
373
    issue.assigned_to = group
374
    assert issue.recipients.include?(group_member.mail)
375
  end
376

  
365 377
  def test_watcher_recipients_should_not_include_users_that_cannot_view_the_issue
366 378
    user = User.find(3)
367 379
    issue = Issue.find(9)
368
-