patch_user-auth-source-filter_RM3.1.1.patch

patch based on Redmine 3.1.1_stable code - Olivier Houdas, 2015-10-23 12:36

Download (2.62 KB)

View differences:

app/controllers/users_controller.rb Fri Oct 23 12:28:55 2015 +0200
46 46
    scope = User.logged.status(@status).preload(:email_address)
47 47
    scope = scope.like(params[:name]) if params[:name].present?
48 48
    scope = scope.in_group(params[:group_id]) if params[:group_id].present?
49
    scope = scope.auth_source(params[:auth_source]) if (params[:auth_source].present? && !params[:auth_source].blank?)
49 50

  
50 51
    @user_count = scope.count
51 52
    @user_pages = Paginator.new @user_count, @limit, params['page']
app/helpers/users_helper.rb Fri Oct 23 12:28:44 2015 +0200
26 26
                        ["#{l(:status_locked)} (#{user_count_by_status[3].to_i})", '3']], selected.to_s)
27 27
  end
28 28

  
29
  def users_auth_sources_options_for_select(selected)
30
    options = [[l(:label_all), ''],
31
               [l(:label_internal), 'NULL']]
32
    AuthSource.all.each do |as|
33
      options << [as.name, as.id]
34
    end
35
    options_for_select(options, selected.to_s)
36
  end
37

  
29 38
  def user_mail_notification_options(user)
30 39
    user.valid_notification_options.collect {|o| [l(o.last), o.first]}
31 40
  end
app/models/user.rb Fri Oct 23 12:29:06 2015 +0200
135 135
      none
136 136
    end
137 137
  }
138
  scope :auth_source, lambda {|auth_source_id|
139
    if (auth_source_id == 'NULL') 
140
      where("#{User.table_name}.auth_source_id IS NULL", auth_source_id)
141
    else
142
      where("#{User.table_name}.auth_source_id = ?", auth_source_id)
143
    end
144
  }
138 145

  
139 146
  def set_mail_notification
140 147
    self.mail_notification = Setting.default_notification_option if self.mail_notification.blank?
app/views/users/index.html.erb Fri Oct 23 12:29:20 2015 +0200
16 16

  
17 17
<label for='name'><%= l(:label_user) %>:</label>
18 18
<%= text_field_tag 'name', params[:name], :size => 30 %>
19
<label for='auth_source'><%= l(:label_auth_source) %>:</label>
20
<%= select_tag 'auth_source', users_auth_sources_options_for_select(params[:auth_source]), :onchange => "this.form.submit(); return false;"  %>
21

  
22

  
19 23
<%= submit_tag l(:button_apply), :class => "small", :name => nil %>
20 24
<%= link_to l(:button_clear), users_path, :class => 'icon icon-reload' %>
21 25
</fieldset>