redmine_changeable_author_r21324.patch

Go MAEDA, 2021-12-25 09:16

Download (4.34 KB)

View differences:

app/helpers/issues_helper.rb
534 534
        old_value = format_date(detail.old_value.to_date) if detail.old_value
535 535

  
536 536
      when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
537
            'priority_id', 'category_id', 'fixed_version_id'
537
            'priority_id', 'category_id', 'fixed_version_id', 'author_id'
538 538
        value = find_name_by_reflection(field, detail.value)
539 539
        old_value = find_name_by_reflection(field, detail.old_value)
540 540

  
app/models/issue.rb
517 517
  safe_attributes(
518 518
    'deleted_attachment_ids',
519 519
    :if => lambda {|issue, user| issue.attachments_deletable?(user)})
520
  safe_attributes(
521
    'author_id',
522
    :if => lambda {|issue, user| user.allowed_to?(:change_issue_author, issue.project)})
520 523

  
521 524
  def safe_attribute_names(user=nil)
522 525
    names = super
app/views/issues/_attributes.html.erb
3 3
<div class="splitcontent">
4 4
<div class="splitcontentleft">
5 5
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %>
6
<% if User.current.allowed_to?(:change_issue_author, @project) %>
7
  <p><%= f.select :author_id, principals_options_for_select(@issue.assignable_users.select {|m| m.is_a?(User) && m.allowed_to?(:add_issues, @project)  }, @issue.author), :include_blank => false, :required => true %>
8
<% end %>
6 9
<p>
7 10
  <%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true},
8 11
                :onchange => "updateIssueFrom('#{escape_javascript(update_issue_form_path(@project, @issue))}', this)" %>
config/locales/en.yml
533 533
  permission_view_private_notes: View private notes
534 534
  permission_set_notes_private: Set notes as private
535 535
  permission_delete_issues: Delete issues
536
  permission_change_issue_author: Change issue author
536 537
  permission_manage_public_queries: Manage public queries
537 538
  permission_save_queries: Save queries
538 539
  permission_view_gantt: View gantt chart
lib/redmine/preparation.rb
71 71
          map.permission :view_private_notes, {}, :read => true, :require => :member
72 72
          map.permission :set_notes_private, {}, :require => :member
73 73
          map.permission :delete_issues, {:issues => :destroy}, :require => :member
74
          map.permission :change_issue_author, {:issues => [:edit, :update]}
74 75
          # Watchers
75 76
          map.permission :view_issue_watchers, {}, :read => true
76 77
          map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]}
test/unit/issue_test.rb
3427 3427
    r = Issue.like('issue today')
3428 3428
    assert_include Issue.find(7), r
3429 3429
  end
3430

  
3431
  def test_author_should_be_changed_when_user_with_permission_change_issue_author
3432
    Role.all.each do |r|
3433
      r.add_permission! :change_issue_author
3434
    end
3435
    User.current = User.find(2)
3436

  
3437
    issue = Issue.generate!(:author => User.find(3))
3438
    assert_equal 3, issue.author_id
3439

  
3440
    issue.safe_attributes = { 'author_id' => 4 }
3441
    assert_equal 4, issue.author_id
3442
    assert_not_equal 3, issue.author_id
3443
  end
3444

  
3445
  def test_author_should_not_be_changed_when_user_without_permission_change_issue_author
3446
    Role.all.each do |r|
3447
      r.remove_permission! :change_issue_author
3448
    end
3449
    User.current = User.find(2)
3450

  
3451
    issue = Issue.generate!(:author => User.find(3))
3452
    assert_equal 3, issue.author_id
3453

  
3454
    issue.safe_attributes = { 'author_id' => 4 }
3455
    assert_not_equal 4, issue.author_id
3456
    assert_equal 3, issue.author_id
3457
  end
3430 3458
end