Project

General

Profile

Revision c06f1783

Added by Thomas McKay over 6 years ago

fixes #15743 - import and export of subscriptions one-per-line

View differences:

lib/hammer_cli_csv/users.rb
12 12
      ADMIN = 'Administrator'
13 13
      ROLES = 'Roles'
14 14

  
15
      def export
16
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
17
          csv << [NAME, FIRSTNAME, LASTNAME, EMAIL, ORGANIZATIONS, LOCATIONS, ADMIN, ROLES]
18
          @api.resource(:users).call(:index, {:per_page => 999999})['results'].each do |user|
19
            if user['organizations']
20
              organizations = CSV.generate do |column|
21
                column << user['organizations'].collect do |organization|
22
                  organization['name']
23
                end
15
      def export(csv)
16
        csv << [NAME, FIRSTNAME, LASTNAME, EMAIL, ORGANIZATIONS, LOCATIONS, ADMIN, ROLES]
17
        @api.resource(:users).call(:index, {:per_page => 999999})['results'].each do |user|
18
          if user['organizations']
19
            organizations = CSV.generate do |column|
20
              column << user['organizations'].collect do |organization|
21
                organization['name']
24 22
              end
25
              organizations.delete!("\n")
26 23
            end
27
            if user['locations']
28
              locations = CSV.generate do |column|
29
                column << user['locations'].collect do |location|
30
                  location['name']
31
                end
24
            organizations.delete!("\n")
25
          end
26
          if user['locations']
27
            locations = CSV.generate do |column|
28
              column << user['locations'].collect do |location|
29
                location['name']
32 30
              end
33
              locations.delete!("\n")
34 31
            end
35
            if user['roles']
36
              roles = CSV.generate do |column|
37
                column << user['roles'].collect do |role|
38
                  role['name']
39
                end
32
            locations.delete!("\n")
33
          end
34
          if user['roles']
35
            roles = CSV.generate do |column|
36
              column << user['roles'].collect do |role|
37
                role['name']
40 38
              end
41
              roles.delete!("\n")
42
            end
43
            admin = user['admin'] ? 'Yes' : 'No'
44
            if user['login'] != 'admin' && !user['login'].start_with?('hidden-')
45
              csv << [user['login'], user['firstname'], user['lastname'], user['mail'],
46
                      organizations, locations, admin, roles]
47 39
            end
40
            roles.delete!("\n")
41
          end
42
          admin = user['admin'] ? 'Yes' : 'No'
43
          if user['login'] != 'admin' && !user['login'].start_with?('hidden-')
44
            csv << [user['login'], user['firstname'], user['lastname'], user['mail'],
45
                    organizations, locations, admin, roles]
48 46
          end
49 47
        end
50 48
      end

Also available in: Unified diff