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

Added support for collection specific hide_resources option. #78

Merged
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
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def collection_to_jbuilder(type, reftype, resources, opts = {})

json.set! 'pages', link_builder.pages if link_builder.links?

unless @req.hide?("resources")
unless @req.hide?("resources") || collection_option?(:hide_resources)
json.resources resources.collect do |resource|
if opts[:expand_resources]
add_hash json, resource_to_jbuilder(type, reftype, resource, opts).attributes!
Expand Down
1 change: 1 addition & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
:description: Automate Workspaces
:options:
- :collection
- :hide_resources
:verbs: *gp
:klass: AutomateWorkspace
:collection_actions:
Expand Down
10 changes: 10 additions & 0 deletions spec/requests/automate_workspaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
describe 'GET' do
let(:user) { FactoryGirl.create(:user_with_group, :userid => "admin") }
let(:aw) { FactoryGirl.create(:automate_workspace, :user => user, :tenant => user.current_tenant) }

it 'should not return resources when fetching the collection' do
api_basic_authorize collection_action_identifier(:automate_workspaces, :read, :get)
aw
get(api_automate_workspaces_url)

expect(response.parsed_body).not_to include("resources")
expect(response).to have_http_status(:ok)
end

it 'should not allow fetching using id' do
api_basic_authorize action_identifier(:automate_workspaces, :read, :resource_actions, :get)
get(api_automate_workspace_url(nil, aw.id))
Expand Down