feature-33602.patch

Mizuki ISHIKAWA, 2020-07-16 07:06

Download (3.2 KB)

View differences:

app/helpers/activities_helper.rb
30 30
    end
31 31
    sorted_events
32 32
  end
33

  
34
  def activity_authors_options_for_select(project, selected)
35
    options = []
36
    options += [["<< #{l(:label_me)} >>", User.current.id]] if User.current.logged?
37
    options += Query.new(project: project).users.select{|user| user.active?}.map{|user| [user.name, user.id]}
38
    options_for_select(options, selected)
39
  end
33 40
end
app/views/activities/index.html.erb
36 36
  <%= t(:label_days_to_html, :days => @days, :date => date_field_tag('from', '', :value => (@date_to - 1), :size => 10)) %>
37 37
  <%= calendar_for('from') %>
38 38
</p>
39
<p>
40
  <%= l(:label_user) %>
41
  <%= select_tag('user_id', activity_authors_options_for_select(@project, params[:user_id]), include_blank: true) %>
42
</p>
39 43
<ul>
40 44
<% @activity.event_types.each do |t| %>
41 45
  <li>
......
51 55
    <%= hidden_field_tag 'with_subprojects', 0, :id => nil %>
52 56
    <p><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label></p>
53 57
<% end %>
54
<%= hidden_field_tag('user_id', params[:user_id]) unless params[:user_id].blank? %>
55 58
<p><%= submit_tag l(:button_apply), :class => 'button-small', :name => 'submit' %></p>
56 59
<% end %>
57 60
<% end %>
test/functional/activities_controller_test.rb
87 87
    assert_response :success
88 88

  
89 89
    assert_select 'h2 a[href="/users/2"]', :text => 'John Smith'
90
    assert_select '#sidebar select#user_id option[value="2"][selected=selected]'
90 91

  
91 92
    i1 = Issue.find(1)
92 93
    d1 = User.find(1).time_to_date(i1.created_on)
test/helpers/activities_helper_test.rb
109 109
      sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
110 110
   )
111 111
  end
112

  
113
  def test_activity_authors_options_for_select_if_current_user_is_admin
114
    User.current = User.find(1)
115
    project = Project.find(1)
116

  
117
    options = [["<< #{l(:label_me)} >>", 1], ['Dave Lopper', 3], ['John Smith', 2], ['Redmine Admin', 1], ['User Misc', 8]]
118
    assert_equal(
119
      options_for_select(options, nil),
120
      activity_authors_options_for_select(project, nil))
121
  end
122

  
123
  def test_activity_authors_options_for_select_if_current_user_is_anonymous
124
    User.current = nil
125
    project = Project.find(1)
126

  
127
    options = [['Dave Lopper', 3], ['John Smith', 2]]
128
    assert_equal(
129
      options_for_select(options, nil),
130
      activity_authors_options_for_select(project, nil))
131
  end
112 132
end