scope = scope.like(params[:name]) if params[:name].present?
scope = scope.in_group(params[:group_id]) if params[:group_id].present?
+ if params[:twofa].present?
+ case params[:twofa].to_i
+ when 1
+ scope = scope.where.not(twofa_scheme: nil)
+ when 0
+ scope = scope.where(twofa_scheme: nil)
+ end
+ end
+
@user_count = scope.count
@user_pages = Paginator.new @user_count, @limit, params['page']
@offset ||= @user_pages.offset
<%= select_tag 'group_id', content_tag('option') + options_from_collection_for_select(@groups, :id, :name, params[:group_id].to_i), :onchange => "this.form.submit(); return false;" %>
<% end %>
+<% if Setting.twofa_required? || Setting.twofa_optional? %>
+ <label for='twofa'><%= l(:setting_twofa) %>:</label>
+ <%= select_tag 'twofa', options_for_select([[l(:general_text_yes), "1"], [l(:general_text_no), "0"]], params[:twofa]), :onchange => "this.form.submit(); return false;", :include_blank => true %>
+<% end %>
+
<label for='name'><%= l(:label_user) %>:</label>
<%= text_field_tag 'name', params[:name], :size => 30 %>
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
<%= sort_header_tag('lastname', :caption => l(:field_lastname)) %>
<th><%= l(:field_mail) %></th>
<%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %>
+ <% if Setting.twofa_required? || Setting.twofa_optional? %>
+ <th><%= l(:setting_twofa) %></th>
+ <% end %>
<%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %>
<%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %>
<th></th>
<td class="lastname"><%= user.lastname %></td>
<td class="email"><%= mail_to(user.mail) %></td>
<td class="tick"><%= checked_image user.admin? %></td>
+ <% if Setting.twofa_required? || Setting.twofa_optional? %>
+ <td class="twofa tick"><%= checked_image user.twofa_active? %></td>
+ <% end %>
<td class="created_on"><%= format_time(user.created_on) %></td>
<td class="last_login_on"><%= format_time(user.last_login_on) unless user.last_login_on.nil? %></td>
<td class="buttons">
end
end
+ def test_index_should_not_show_2fa_filter_and_column_if_disabled
+ with_settings twofa: "0" do
+ get :index
+ assert_response :success
+
+ assert_select "select#twofa", 0
+ assert_select 'td.twofa', 0
+ end
+ end
+
+ def test_index_filter_by_twofa_yes
+ with_settings twofa: "1" do
+ user = User.find(1)
+ user.twofa_totp_key = "AVYA3RARZ3GY3VWT7MIEJ72I5TTJRO3X"
+ user.twofa_scheme = "totp"
+ user.save
+
+ get :index, :params => {:twofa => '1'}
+ assert_response :success
+
+ assert_select "select#twofa", 1
+
+ assert_select 'tr.user', 1
+ assert_select 'td.twofa.tick .icon-checked'
+ end
+ end
+
+ def test_index_filter_by_twofa_no
+ with_settings twofa: "1" do
+ user = User.find(1)
+ user.twofa_totp_key = "AVYA3RARZ3GY3VWT7MIEJ72I5TTJRO3X"
+ user.twofa_scheme = "totp"
+ user.save
+
+ get :index, :params => {:twofa => '0'}
+ assert_response :success
+
+ assert_select "select#twofa", 1
+ assert_select "td.twofa.tick" do
+ assert_select "span.icon-checked", 0
+ end
+ end
+ end
+
def test_index_csv
with_settings :default_language => 'en' do
user = User.logged.status(1).first