Project

General

Profile

Revision bfc065ce

Added by Thomas McKay over 8 years ago

roles-test - wip

roles-test - users now get roles, orgs, and locations

View differences:

lib/hammer_cli_csv/roles.rb
100 100
    def create_roles_from_csv(line)
101 101
      line[COUNT].to_i.times do |number|
102 102
        name = namify(line[NAME], number)
103
        filter = namify(line[FILTER], number)
103
        filter = namify(line[FILTER], number) if line[FILTER]
104 104

  
105 105
        if !@existing_roles[name]
106 106
          print "Creating role '#{name}'..." if option_verbose?
107
          role = @f_role_api.create({
108
                                      'name' => name
109
                                    })[0]
110
          @existing_roles[name] = role['id']
107 111
        else
108 112
          print "Updating role '#{name}'..." if option_verbose?
109 113
          @f_role_api.update({
......
113 117

  
114 118
        permissions = CSV.parse_line(line[PERMISSIONS], {:skip_blanks => true}).collect do |permission|
115 119
          foreman_permission(:name => permission)
116
        end
117
        puts permissions
120
        end if line[PERMISSIONS]
118 121
        organizations = CSV.parse_line(line[ORGANIZATIONS], {:skip_blanks => true}).collect do |organization|
119 122
          foreman_organization(:name => organization)
120
        end
123
        end if line[ORGANIZATIONS]
121 124
        locations = CSV.parse_line(line[LOCATIONS], {:skip_blanks => true}).collect do |location|
122 125
          foreman_location(:name => location)
123
        end
126
        end if line[LOCATIONS]
124 127

  
125
        filter_id = foreman_filter(name, :name => filter)
126
        if !filter_id
127
          @f_filter_api.create({
128
                                 'role_id' => @existing_roles[name],
129
                                 'search' => filter,
130
                                 'organization_ids' => organizations,
131
                                 'location_ids' => locations
132
                               })
133
        else
134
          @f_filter_api.update({
135
                                 'id' => filter_id,
136
                                 'search' => filter,
137
                                 'organization_ids' => organizations,
138
                                 'location_ids' => locations,
139
                                 'permission_ids' => permissions
140
                               })
128
        if filter
129
          filter_id = foreman_filter(name, :name => filter)
130
          if !filter_id
131
            @f_filter_api.create({
132
                                   'role_id' => @existing_roles[name],
133
                                   'search' => filter,
134
                                   'organization_ids' => organizations || [],
135
                                   'location_ids' => locations || [],
136
                                   'permission_ids' => permissions || []
137
                                 })
138
          else
139
            @f_filter_api.update({
140
                                   'id' => filter_id,
141
                                   'search' => filter,
142
                                   'organization_ids' => organizations || [],
143
                                   'location_ids' => locations || [],
144
                                   'permission_ids' => permissions || []
145
                                 })
146
          end
141 147
        end
142 148

  
143 149
        puts "done" if option_verbose?

Also available in: Unified diff