Project

General

Profile

Feature #37674 » 0004-adds-column-and-filter-for-authentication-mode-to-ad.patch

Jens Krämer, 2022-09-14 04:37

View differences:

app/models/user_query.rb
29 29
    QueryColumn.new(:updated_on, :sortable => "#{User.table_name}.updated_on"),
30 30
    QueryColumn.new(:last_login_on, :sortable => "#{User.table_name}.last_login_on"),
31 31
    QueryColumn.new(:passwd_changed_on, :sortable => "#{User.table_name}.passwd_changed_on"),
32
    QueryColumn.new(:status, sortable: "#{User.table_name}.status")
32
    QueryColumn.new(:status, sortable: "#{User.table_name}.status"),
33
    QueryAssociationColumn.new(:auth_source, :name, caption: :field_auth_source, sortable: "#{AuthSource.table_name}.name")
33 34
  ]
34 35

  
35 36
  def initialize(attributes=nil, *args)
......
40 41
  def initialize_available_filters
41 42
    add_available_filter "status",
42 43
      type: :list, values: ->{ user_statuses_values }
44
    add_available_filter "auth_source_id",
45
      type: :list_optional, values: ->{ auth_sources_values }
43 46
    add_available_filter "is_member_of_group",
44 47
      type: :list_optional,
45 48
      values: ->{ Group.givable.visible.map {|g| [g.name, g.id.to_s] } }
......
57 60
    add_custom_fields_filters(user_custom_fields)
58 61
  end
59 62

  
63
  def auth_sources_values
64
    AuthSource.order(name: :asc).to_a.map do |auth_source|
65
      [auth_source.name, auth_source.id]
66
    end
67
  end
68

  
60 69
  def user_statuses_values
61 70
    [
62 71
      [l(:status_active), User::STATUS_ACTIVE.to_s],
test/functional/users_controller_test.rb
134 134
    end
135 135
  end
136 136

  
137
  def test_index_filter_by_auth_source_none
138
    user = User.find(1)
139
    user.update_column :auth_source_id, 1
140

  
141
    get :index, params: {
142
      set_filter: 1,
143
      f: ['auth_source_id'], op: {auth_source_id: '!*'}
144
    }
145
    assert_response :success
146

  
147
    assert_select 'tr.user'
148
    assert_select 'tr#user-1', 0
149
  end
150

  
151
  def test_index_filter_by_auth_source
152
    user = User.find(1)
153
    user.update_column :auth_source_id, 1
154

  
155
    get :index, params: {
156
      set_filter: 1,
157
      f: ['auth_source_id'], op: {auth_source_id: '='}, v: {auth_source_id: ['1']}
158
    }
159
    assert_response :success
160

  
161
    assert_select 'tr#user-1', 1
162

  
163
    assert_select "select#add_filter_select" do
164
      assert_select "option[value=auth_source_id]"
165
    end
166
    assert_select "select#available_c" do
167
      assert_select "option[value='auth_source.name']"
168
    end
169
  end
170

  
137 171
  def test_index_csv
138 172
    with_settings :default_language => 'en' do
139 173
      user = User.logged.status(1).first
(4-4/11)