summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2020-11-13 01:08:15 +0000
committerGo MAEDA <maeda@farend.jp>2020-11-13 01:08:15 +0000
commit167637730dbf2e45ac33f6808517c8138050470d (patch)
tree61e8eac5341d3e54be67158358bf39a87de50bb5
parenta20eb9b7647d71f0ee5751fdee4113a0de1fc2e9 (diff)
downloadredmine-167637730dbf2e45ac33f6808517c8138050470d.tar.gz
redmine-167637730dbf2e45ac33f6808517c8138050470d.zip
Include twofa_scheme (two-factor scheme) column when exporting users to CSV (#34241).
Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@20350 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/users_helper.rb18
-rw-r--r--config/locales/en.yml1
-rw-r--r--config/locales/ja.yml1
-rw-r--r--test/functional/users_controller_test.rb19
4 files changed, 32 insertions, 7 deletions
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 1f5841199..32890ded3 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -78,6 +78,21 @@ module UsersHelper
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 = [
@@ -87,6 +102,7 @@ module UsersHelper
'mail',
'admin',
'status',
+ 'twofa_scheme',
'created_on',
'updated_on',
'last_login_on',
@@ -99,7 +115,7 @@ module UsersHelper
# 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|
diff --git a/config/locales/en.yml b/config/locales/en.yml
index b5245a7df..dce5bda76 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -320,6 +320,7 @@ en:
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
diff --git a/config/locales/ja.yml b/config/locales/ja.yml
index 281972862..68a8f2297 100644
--- a/config/locales/ja.yml
+++ b/config/locales/ja.yml
@@ -289,6 +289,7 @@ ja:
field_password: パスワード
field_new_password: 新しいパスワード
field_password_confirmation: パスワードの確認
+ field_twofa_scheme: 二要素認証方式
field_version: バージョン
field_type: タイプ
field_host: ホスト
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb
index 5b9c51dd9..feb75ccff 100644
--- a/test/functional/users_controller_test.rb
+++ b/test/functional/users_controller_test.rb
@@ -69,15 +69,22 @@ class UsersControllerTest < Redmine::ControllerTest
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