Feature #34241 » feature-34241-v2.patch
| app/helpers/users_helper.rb | ||
|---|---|---|
| 78 | 78 |
tabs |
| 79 | 79 |
end |
| 80 | 80 | |
| 81 |
def csv_content(column_name, user) |
|
| 82 |
case column_name |
|
| 83 |
when 'status' |
|
| 84 |
l("status_#{User::LABEL_BY_STATUS[user.status]}")
|
|
| 85 |
when 'twofa_scheme' |
|
| 86 |
if user.twofa_active? |
|
| 87 |
l("twofa__#{user.twofa_scheme}__name")
|
|
| 88 |
else |
|
| 89 |
l(:label_disabled) |
|
| 90 |
end |
|
| 91 |
else |
|
| 92 |
user.send(column_name) |
|
| 93 |
end |
|
| 94 |
end |
|
| 95 | ||
| 81 | 96 |
def users_to_csv(users) |
| 82 | 97 |
Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv| |
| 83 | 98 |
columns = [ |
| ... | ... | |
| 87 | 102 |
'mail', |
| 88 | 103 |
'admin', |
| 89 | 104 |
'status', |
| 105 |
'twofa_scheme', |
|
| 90 | 106 |
'created_on', |
| 91 | 107 |
'updated_on', |
| 92 | 108 |
'last_login_on', |
| ... | ... | |
| 99 | 115 |
# csv lines |
| 100 | 116 |
users = users.preload(:custom_values) |
| 101 | 117 |
users.each do |user| |
| 102 |
values = columns.map {|c| c == 'status' ? l("status_#{User::LABEL_BY_STATUS[user.status]}") : user.send(c)} +
|
|
| 118 |
values = columns.map {|c| csv_content(c, user)} +
|
|
| 103 | 119 |
user_custom_fields.map {|custom_field| user.custom_value_for(custom_field)}
|
| 104 | 120 | |
| 105 | 121 |
csv << values.map do |value| |
| config/locales/en.yml | ||
|---|---|---|
| 320 | 320 |
field_password: Password |
| 321 | 321 |
field_new_password: New password |
| 322 | 322 |
field_password_confirmation: Confirmation |
| 323 |
field_twofa_scheme: Two-factor authentication scheme |
|
| 323 | 324 |
field_version: Version |
| 324 | 325 |
field_type: Type |
| 325 | 326 |
field_host: Host |
| config/locales/ja.yml | ||
|---|---|---|
| 289 | 289 |
field_password: パスワード |
| 290 | 290 |
field_new_password: 新しいパスワード |
| 291 | 291 |
field_password_confirmation: パスワードの確認 |
| 292 |
field_twofa_scheme: 二要素認証方式 |
|
| 292 | 293 |
field_version: バージョン |
| 293 | 294 |
field_type: タイプ |
| 294 | 295 |
field_host: ホスト |
| test/functional/users_controller_test.rb | ||
|---|---|---|
| 69 | 69 |
def test_index_csv |
| 70 | 70 |
with_settings :default_language => 'en' do |
| 71 | 71 |
user = User.logged.status(1).first |
| 72 |
user.update(passwd_changed_on: Time.current.last_month) |
|
| 73 |
get :index, :params => { :format => 'csv' }
|
|
| 72 |
user.update(passwd_changed_on: Time.current.last_month, twofa_scheme: 'totp')
|
|
| 73 |
get :index, params: {format: 'csv'}
|
|
| 74 | 74 |
assert_response :success |
| 75 | 75 | |
| 76 | 76 |
assert_equal User.logged.status(1).count, response.body.chomp.split("\n").size - 1
|
| 77 |
assert_include 'active', response.body |
|
| 78 |
assert_not_include 'locked', response.body |
|
| 79 |
assert_include format_time(user.updated_on), response.body |
|
| 80 |
assert_include format_time(user.passwd_changed_on), response.body |
|
| 77 |
assert_include format_time(user.updated_on), response.body.split("\n").second
|
|
| 78 |
assert_include format_time(user.passwd_changed_on), response.body.split("\n").second
|
|
| 79 | ||
| 80 |
# status |
|
| 81 |
assert_include 'active', response.body.split("\n").second
|
|
| 82 |
assert_not_include 'locked', response.body.split("\n").second
|
|
| 83 | ||
| 84 |
# twofa_scheme |
|
| 85 |
assert_include 'Authenticator app', response.body.split("\n").second
|
|
| 86 |
assert_include 'disabled', response.body.split("\n").third
|
|
| 87 | ||
| 81 | 88 |
assert_equal 'text/csv', @response.media_type |
| 82 | 89 |
end |
| 83 | 90 |
end |
- « Previous
- 1
- 2
- Next »