Project

General

Profile

Revision 561a8ac9

Added by Thomas McKay over 8 years ago

update roles use of api with test and docs

Note: The roles test does not work completely since changing user is not working. Unsure how to accomplish this. Tests run as admin do work.

View differences:

lib/hammer_cli_csv/roles.rb
59 59
      end
60 60

  
61 61
      def create_roles_from_csv(line)
62

  
63
        permissions = collect_column(line[PERMISSIONS]) do |permission|
64
          foreman_permission(:name => permission)
65
        end
66
        organizations = collect_column(line[ORGANIZATIONS]) do |organization|
67
          foreman_organization(:name => organization)
68
        end
69
        locations = collect_column(line[LOCATIONS]) do |location|
70
          foreman_location(:name => location)
71
        end
72

  
62 73
        line[COUNT].to_i.times do |number|
63 74
          name = namify(line[NAME], number)
64 75
          search = namify(line[SEARCH], number) if line[SEARCH]
......
76 87
                                       })
77 88
          end
78 89

  
79
          permissions = collect_column(line[PERMISSIONS]) do |permission|
80
            foreman_permission(:name => permission)
81
          end
82
          organizations = collect_column(line[ORGANIZATIONS]) do |organization|
83
            foreman_organization(:name => organization)
84
          end
85
          locations = collect_column(line[LOCATIONS]) do |location|
86
            foreman_location(:name => location)
87
          end
88

  
89 90
          filter_id = foreman_filter(name, line[RESOURCE], search)
90 91
          if !filter_id
91 92
            print " creating filter #{line[RESOURCE]}..."
92
            @api.resource(:filters).call(:create, {
93
            @api.resource(:filters).call(:create, { 'filter' => {
93 94
                                           'role_id' => @existing_roles[name],
94 95
                                           'search' => search,
95 96
                                           'organization_ids' => organizations,
96 97
                                           'location_ids' => locations,
97 98
                                           'permission_ids' => permissions
98
                                         })
99
                                         }})
99 100
          else
100 101
            print " updating filter #{line[RESOURCE]}..."
101 102
            @api.resource(:filters).call(:update, {

Also available in: Unified diff