Skip to content

Commit

Permalink
Merge pull request #84 from jntullo/enhancement/return_miq_groups
Browse files Browse the repository at this point in the history
Return miq_groups on api entrypoint
  • Loading branch information
abellotti authored Sep 27, 2017
2 parents 975a53f + 5b5cad8 commit 4231990
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/base_controller/normalizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4231990

Please sign in to comment.