diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 6876bccd87..6e9d673152 100644 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -44,6 +44,7 @@ def auth_identity :role_href => "#{@req.api_prefix}/roles/#{group.miq_user_role.id}", :tenant => group.tenant.name, :groups => user.miq_groups.pluck(:description), + :miq_groups => normalize_array(user.miq_groups, :groups) } end diff --git a/app/controllers/api/base_controller/normalizer.rb b/app/controllers/api/base_controller/normalizer.rb index 0461ceb232..fc56838de1 100644 --- a/app/controllers/api/base_controller/normalizer.rb +++ b/app/controllers/api/base_controller/normalizer.rb @@ -111,8 +111,8 @@ def normalize_select_attributes(obj, opts) end end - def normalize_array(obj) - type = @req.subject + def normalize_array(obj, type = nil) + type ||= @req.subject obj.collect { |item| normalize_attr(get_reftype(type, type, item), item) } end diff --git a/spec/requests/authentication_spec.rb b/spec/requests/authentication_spec.rb index 4e7be629ce..09e26e2899 100644 --- a/spec/requests/authentication_spec.rb +++ b/spec/requests/authentication_spec.rb @@ -104,7 +104,11 @@ "group_href" => "/api/groups/#{group2.id}", "role" => @role.name, "role_href" => "/api/roles/#{group2.miq_user_role.id}", - "tenant" => @group.tenant.name + "tenant" => @group.tenant.name, + "groups" => @user.miq_groups.pluck(:description), + "miq_groups" => a_collection_including( + hash_including("href" => api_group_url(nil, @user.miq_groups.first)) + ) ) expect(response.parsed_body["identity"]["groups"]).to match_array(@user.miq_groups.pluck(:description)) end