Feature #34241 » feature-34241-v2.patch
| app/helpers/users_helper.rb | ||
|---|---|---|
|
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 = [
|
||
| ... | ... | |
|
'mail',
|
||
|
'admin',
|
||
|
'status',
|
||
|
'twofa_scheme',
|
||
|
'created_on',
|
||
|
'updated_on',
|
||
|
'last_login_on',
|
||
| ... | ... | |
|
# csv lines
|
||
|
users = users.preload(:custom_values)
|
||
|
users.each do |user|
|
||
|
values = columns.map {|c| c == 'status' ? l("status_#{User::LABEL_BY_STATUS[user.status]}") : user.send(c)} +
|
||
|
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|
|
||
| config/locales/en.yml | ||
|---|---|---|
|
field_password: Password
|
||
|
field_new_password: New password
|
||
|
field_password_confirmation: Confirmation
|
||
|
field_twofa_scheme: Two-factor authentication scheme
|
||
|
field_version: Version
|
||
|
field_type: Type
|
||
|
field_host: Host
|
||
| config/locales/ja.yml | ||
|---|---|---|
|
field_password: パスワード
|
||
|
field_new_password: 新しいパスワード
|
||
|
field_password_confirmation: パスワードの確認
|
||
|
field_twofa_scheme: 二要素認証方式
|
||
|
field_version: バージョン
|
||
|
field_type: タイプ
|
||
|
field_host: ホスト
|
||
| test/functional/users_controller_test.rb | ||
|---|---|---|
|
def test_index_csv
|
||
|
with_settings :default_language => 'en' do
|
||
|
user = User.logged.status(1).first
|
||
|
user.update(passwd_changed_on: Time.current.last_month)
|
||
|
get :index, :params => { :format => 'csv' }
|
||
|
user.update(passwd_changed_on: Time.current.last_month, twofa_scheme: 'totp')
|
||
|
get :index, params: {format: 'csv'}
|
||
|
assert_response :success
|
||
|
assert_equal User.logged.status(1).count, response.body.chomp.split("\n").size - 1
|
||
|
assert_include 'active', response.body
|
||
|
assert_not_include 'locked', response.body
|
||
|
assert_include format_time(user.updated_on), response.body
|
||
|
assert_include format_time(user.passwd_changed_on), response.body
|
||
|
assert_include format_time(user.updated_on), response.body.split("\n").second
|
||
|
assert_include format_time(user.passwd_changed_on), response.body.split("\n").second
|
||
|
# status
|
||
|
assert_include 'active', response.body.split("\n").second
|
||
|
assert_not_include 'locked', response.body.split("\n").second
|
||
|
# twofa_scheme
|
||
|
assert_include 'Authenticator app', response.body.split("\n").second
|
||
|
assert_include 'disabled', response.body.split("\n").third
|
||
|
assert_equal 'text/csv', @response.media_type
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- Next »