Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return miq_groups on api entrypoint #84

Merged
merged 1 commit into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid to ask: why was this needed, what is @req.subject in the case of entrypoint, who calls it with that second argument ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abellotti I used this for rendering the miq_groups properly, and since the /api endpoint doesn't have the groups subject, I pass in the :groups parameter

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