module UsersHelper
include ApplicationHelper
- def users_status_options_for_select(selected)
- user_count_by_status = User.group('status').count.to_hash
- options_for_select([[l(:label_all), '']] + (User.valid_statuses.map {|c| ["#{l('status_' + User::LABEL_BY_STATUS[c])} (#{user_count_by_status[c].to_i})", c]}), selected.to_s)
- end
-
def user_mail_notification_options(user)
user.valid_notification_options.collect {|o| [l(o.last), o.first]}
end
end
tabs
end
-
- def csv_content(column_name, user)
- case column_name
- when 'status'
- l("status_#{User::LABEL_BY_STATUS[user.status]}")
- when 'twofa_scheme'
- if user.twofa_active?
- l("twofa__#{user.twofa_scheme}__name")
- else
- l(:label_disabled)
- end
- else
- user.send(column_name)
- end
- end
-
- def users_to_csv(users)
- Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
- columns = [
- 'login',
- 'firstname',
- 'lastname',
- 'mail',
- 'admin',
- 'status',
- 'twofa_scheme',
- 'created_on',
- 'updated_on',
- 'last_login_on',
- 'passwd_changed_on'
- ]
- user_custom_fields = UserCustomField.sorted
-
- # csv header fields
- csv << columns.map {|column| l('field_' + column)} + user_custom_fields.pluck(:name)
- # csv lines
- users = users.preload(:custom_values)
- users.each do |user|
- values = columns.map {|c| csv_content(c, user)} +
- user_custom_fields.map {|custom_field| user.custom_value_for(custom_field)}
-
- csv << values.map do |value|
- format_object(value, false) do |v|
- case v.class.name
- when 'Float'
- sprintf('%.2f', v).gsub('.', l(:general_csv_decimal_separator))
- else
- v
- end
- end
- end
- end
- end
- end
end