Project

General

Profile

Feature #1739 » redmine_changeable_author_v4.2.1.patch

Takenori TAKAKI, 2021-06-21 08:10

View differences:

app/helpers/issues_helper.rb
521 521
        old_value = format_date(detail.old_value.to_date) if detail.old_value
522 522

  
523 523
      when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
524
            'priority_id', 'category_id', 'fixed_version_id'
524
            'priority_id', 'category_id', 'fixed_version_id', 'author_id'
525 525
        value = find_name_by_reflection(field, detail.value)
526 526
        old_value = find_name_by_reflection(field, detail.old_value)
527 527

  
app/models/issue.rb
513 513
  safe_attributes(
514 514
    'deleted_attachment_ids',
515 515
    :if => lambda {|issue, user| issue.attachments_deletable?(user)})
516
  safe_attributes(
517
    'author_id',
518
    :if => lambda {|issue, user| user.allowed_to?(:change_issue_author, issue.project)})
516 519

  
517 520
  def safe_attribute_names(user=nil)
518 521
    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
532 532
  permission_view_private_notes: View private notes
533 533
  permission_set_notes_private: Set notes as private
534 534
  permission_delete_issues: Delete issues
535
  permission_change_issue_author: Change issue author
535 536
  permission_manage_public_queries: Manage public queries
536 537
  permission_save_queries: Save queries
537 538
  permission_view_gantt: View gantt chart
lib/redmine.rb
118 118
    map.permission :view_private_notes, {}, :read => true, :require => :member
119 119
    map.permission :set_notes_private, {}, :require => :member
120 120
    map.permission :delete_issues, {:issues => :destroy}, :require => :member
121
    map.permission :change_issue_author, {:issues => [:edit, :update]}
121 122
    # Watchers
122 123
    map.permission :view_issue_watchers, {}, :read => true
123 124
    map.permission :add_issue_watchers, {:watchers => [:new, :create, :append, :autocomplete_for_user]}
test/unit/issue_test.rb
3406 3406

  
3407 3407
    assert_equal [5], issue2.filter_projects_scope('').ids.sort
3408 3408
  end
3409

  
3410
  def test_author_should_be_changed_when_user_with_permission_change_issue_author
3411
    Role.all.each do |r|
3412
      r.add_permission! :change_issue_author
3413
    end
3414
    User.current = User.find(2)
3415

  
3416
    issue = Issue.generate!(:author => User.find(3))
3417
    assert_equal 3, issue.author_id
3418

  
3419
    issue.safe_attributes = { 'author_id' => 4 }
3420
    assert_equal 4, issue.author_id
3421
    assert_not_equal 3, issue.author_id
3422
  end
3423

  
3424
  def test_author_should_not_be_changed_when_user_without_permission_change_issue_author
3425
    Role.all.each do |r|
3426
      r.remove_permission! :change_issue_author
3427
    end
3428
    User.current = User.find(2)
3429

  
3430
    issue = Issue.generate!(:author => User.find(3))
3431
    assert_equal 3, issue.author_id
3432

  
3433
    issue.safe_attributes = { 'author_id' => 4 }
3434
    assert_not_equal 4, issue.author_id
3435
    assert_equal 3, issue.author_id
3436
  end
3409 3437
end
(9-9/12)