Project

General

Profile

Feature #16045 » previous-assignee-v8.patch

Go MAEDA, 2024-09-14 09:42

View differences:

app/helpers/application_helper.rb
672 672
    if collection.include?(User.current)
673 673
      s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
674 674
    end
675
    groups = +''
675

  
676
    involved_principals_html = +''
677
    # This optgroup is displayed only when editing a single issue
678
    if @issue.present? && !@issue.new_record?
679
      involved_principals = [@issue.author, @issue.prior_assigned_to].uniq.compact
680
      involved_principals_html = involved_principals.map do |p|
681
        content_tag('option', p.name, value: p.id, disabled: !collection.include?(p))
682
      end.join
683
    end
684

  
685
    users_html = +''
686
    groups_html = +''
676 687
    collection.sort.each do |element|
677 688
      if option_value_selected?(element, selected) || element.id.to_s == selected
678 689
        selected_attribute = ' selected="selected"'
679 690
      end
680
      (element.is_a?(Group) ? groups : s) <<
691
      (element.is_a?(Group) ? groups_html : users_html) <<
681 692
        %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
682 693
    end
683
    unless groups.empty?
684
      s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
694
    if involved_principals_html.blank? && groups_html.blank?
695
      s << users_html
696
    else
697
      [
698
        [l(:label_involved_principals), involved_principals_html],
699
        [l(:label_user_plural), users_html],
700
        [l(:label_group_plural), groups_html]
701
      ].each do |label, options_html|
702
        s << %(<optgroup label="#{h(label)}">#{options_html}</optgroup>) if options_html.present?
703
      end
685 704
    end
686 705
    s.html_safe
687 706
  end
app/models/issue.rb
925 925
    result
926 926
  end
927 927

  
928
  # Returns the assignee immediately prior to the current one from the issue history
929
  def prior_assigned_to
930
    prior_assigned_to_id =
931
      journals.joins(:details)
932
              .where(details: {prop_key: 'assigned_to_id'})
933
              .where.not(details: {old_value: nil})
934
              .order(id: :desc)
935
              .pick(:old_value)
936

  
937
    prior_assigned_to_id && Principal.find_by(id: prior_assigned_to_id)
938
  end
939

  
928 940
  # Returns the initial status of the issue
929 941
  # Returns nil for a new issue
930 942
  def status_was
config/locales/en.yml
1145 1145
  label_default_query: Default query
1146 1146
  label_edited: Edited
1147 1147
  label_time_by_author: "%{time} by %{author}"
1148
  label_involved_principals: Author / Previous assignee
1148 1149

  
1149 1150
  button_login: Login
1150 1151
  button_submit: Submit
config/locales/ja.yml
1445 1445
  setting_issue_done_ratio_interval: 進捗率の選択肢の間隔
1446 1446
  setting_copy_attachments_on_issue_copy: チケットをコピーするとき添付ファイルもコピー
1447 1447
  field_thousands_delimiter: 3桁区切り表示
1448
  label_involved_principals: 作成者 / 直前担当者
test/helpers/application_helper_test.rb
2052 2052
    User.current = nil
2053 2053
    set_language_if_valid 'en'
2054 2054
    users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
2055
    assert_equal(
2056
      %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
2057
      %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
2058
      principals_options_for_select(users))
2055
    result = principals_options_for_select(users)
2056

  
2057
    assert_select_in result, 'optgroup[label="Users"]' do
2058
      assert_select 'option[value="2"]', text: 'John Smith'
2059
      assert_select 'option[value="4"]', text: 'Robert Hill'
2060
    end
2061
    assert_select_in result, 'optgroup[label="Groups"]' do
2062
      assert_select 'option[value="10"]', text: 'A Team'
2063
      assert_select 'option[value="11"]', text: 'B Team'
2064
    end
2059 2065
  end
2060 2066

  
2061 2067
  def test_principals_options_for_select_with_empty_collection
......
2070 2076
                   principals_options_for_select(users)
2071 2077
  end
2072 2078

  
2079
  def test_principals_options_for_select_should_include_author_and_prior_assignee
2080
    set_language_if_valid 'en'
2081
    users = [User.find(2), User.find(3), User.find(1)]
2082
    @issue = Issue.generate!(author_id: 1, assigned_to_id: 2)
2083
    @issue.init_journal(users.first, 'update')
2084
    @issue.assigned_to_id = 3
2085
    @issue.save
2086

  
2087
    result = principals_options_for_select(users)
2088
    assert_select_in result, 'optgroup[label="Author / Prior assignee"]' do
2089
      assert_select 'option:nth-of-type(1)', text: 'Redmine Admin'  # Author
2090
      assert_select 'option:nth-of-type(2)', text: 'John Smith'     # Prior assignee
2091
    end
2092
  end
2093

  
2073 2094
  def test_stylesheet_link_tag_should_pick_the_default_stylesheet
2074 2095
    assert_match 'href="/assets/styles.css"', stylesheet_link_tag("styles")
2075 2096
  end
test/unit/issue_test.rb
3257 3257
    assert_equal was_closed_on, issue.closed_on
3258 3258
  end
3259 3259

  
3260
  def test_prior_assigned_to
3261
    issue = Issue.generate!(assigned_to_id: 2)
3262
    issue.init_journal(User.find(2), 'update')
3263
    issue.assigned_to_id = 3
3264
    issue.save
3265

  
3266
    assert_equal User.find(2), issue.prior_assigned_to
3267
  end
3268

  
3260 3269
  def test_status_was_should_return_nil_for_new_issue
3261 3270
    issue = Issue.new
3262 3271
    assert_nil issue.status_was
(15-15/15)