Feature #33126

Support custom fields when exporting users to CSV

Added by Mizuki ISHIKAWA 6 months ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Accounts / authentication
Target version:4.2.0
Resolution:Fixed

Description

You can export the users list csv(#5957), but it does not include the value of UserCustomField.
The value of UserCustomField should also be output as csv.

feature-33126.patch Magnifier (2.53 KB) Mizuki ISHIKAWA, 2020-03-11 09:22

33126.patch Magnifier (954 Bytes) Marius BALTEANU, 2020-04-04 17:03


Related issues

Related to Redmine - Patch #5957: Export users list to CSV Closed 2010-07-25

Associated revisions

Revision 19642
Added by Go MAEDA 6 months ago

Support custom fields when exporting users to CSV (#33126).

Patch by Mizuki ISHIKAWA.

Revision 19643
Added by Go MAEDA 6 months ago

RuboCop: Add "EnforcedStyle: sprintf" (#33126).

Revision 19767
Added by Go MAEDA 4 months ago

Fix that custom fields in users CSV are not ordered by position value (#33126).

History

#1 Updated by Mizuki ISHIKAWA 6 months ago

I have attached a patch.

#2 Updated by Go MAEDA 6 months ago

  • Target version set to Candidate for next major release

#3 Updated by Go MAEDA 6 months ago

  • Target version changed from Candidate for next major release to 4.2.0

Setting the target version to 4.2.0.

#4 Updated by Go MAEDA 6 months ago

  • Subject changed from Add UserCustomField value to csv of users list to Support custom fields when exporting users to CSV
  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch. Thank you for improving Redmine.

#5 Updated by Go MAEDA 6 months ago

  • Related to Patch #5957: Export users list to CSV added

#6 Updated by Marius BALTEANU 6 months ago

  • Status changed from Closed to Reopened
 Offenses:
 app/helpers/users_helper.rb:99:15: C: Style/FormatString: Favor format over sprintf.
               sprintf('%.2f', v).gsub('.', l(:general_csv_decimal_separator))
               ^^^^^^^
 889 files inspected, 1 offense detected

#7 Updated by Go MAEDA 6 months ago

The following code fixes the Rubocop offence:

Index: app/helpers/users_helper.rb
===================================================================
--- app/helpers/users_helper.rb    (リビジョン 19642)
+++ app/helpers/users_helper.rb    (作業コピー)
@@ -96,7 +96,7 @@
           format_object(value, false) do |v|
             case v.class.name
             when 'Float'
-              sprintf('%.2f', v).gsub('.', l(:general_csv_decimal_separator))
+              format('%.2f', v).gsub('.', l(:general_csv_decimal_separator))
             else
               v
             end

#8 Updated by Marius BALTEANU 6 months ago

Go MAEDA wrote:

The following code fixes the Rubocop offence:

[...]

Yes, this is an option, but format is just an alias of sprintf and it's not used anywhere else in the code. I propose to stick to sprintf and fix this using the following code:

mariusbalteanu@Mariuss-MacBook-Pro redmine % git diff
diff --git a/.rubocop.yml b/.rubocop.yml
index 73f1d18f0..4b63e0b5f 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -83,6 +83,9 @@ Style/AsciiComments:
 Style/EmptyElse:
   EnforcedStyle: empty

+Style/FormatString:
+  EnforcedStyle: sprintf
+
 Style/FormatStringToken:
   Enabled: false

In another ticket, we should replace in the code the "percent" style used in some files with sprintf and remove the todo from rubocop.

#9 Updated by Marius BALTEANU 6 months ago

#10 Updated by Go MAEDA 6 months ago

  • Status changed from Reopened to Closed

Marius BALTEANU wrote:

Go MAEDA wrote:

The following code fixes the Rubocop offence:

[...]

Yes, this is an option, but format is just an alias of sprintf and it's not used anywhere else in the code. I propose to stick to sprintf and fix this using the following code:
[...]

Done in r19643. Thank you.

#11 Updated by Go MAEDA 5 months ago

  • Status changed from Closed to Reopened

I think it is better to sort columns for custom fields according to the position value, as issues CSV do.

diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index 2a72a5db4..264259d5b 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -82,7 +82,7 @@ module UsersHelper
         'last_login_on',
         'status'
       ]
-      user_custom_fields = UserCustomField.all
+      user_custom_fields = UserCustomField.sorted

       # csv header fields
       csv << columns.map {|column| l('field_' + column)} + user_custom_fields.pluck(:name)

#12 Updated by Go MAEDA 4 months ago

  • Status changed from Reopened to Closed

Go MAEDA wrote:

I think it is better to sort columns for custom fields according to the position value, as issues CSV do.

[...]

Committed the fix in r19767.

Also available in: Atom PDF