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

Folders subcollection on providers #338

Merged
merged 1 commit into from
Mar 7, 2018
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/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ProvidersController < BaseController
include Subcollections::Vms
include Subcollections::Flavors
include Subcollections::CloudTemplates
include Subcollections::Folders
include Subcollections::Networks

before_action :validate_provider_class
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/folders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module Folders
def folders_query_resource(object)
object.respond_to?(:folders) ? object.folders : []
end
end
end
end
19 changes: 19 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,12 @@
:get:
- :name: read
:identifier: floating_ip_show
:folders:
:description: Folders
:options:
- :subcollection
:verbs: *g
:klass: EmsFolder
:generic_object_definitions:
:description: Generic Object Definitions
:options:
Expand Down Expand Up @@ -1863,6 +1869,7 @@
- :vms
- :flavors
- :cloud_templates
- :folders
- :networks
:collection_actions:
:get:
Expand Down Expand Up @@ -1937,6 +1944,18 @@
:identifier: ems_infra_protect
- :name: unassign
:identifier: ems_infra_protect
:folders_subcollection_actions:
:get:
- :name: read
:identifier:
- ems_infra_show_list
- ems_block_storage_show_list
:folders_subresource_actions:
:get:
- :name: read
:identifier:
- ems_infra_show
- ems_block_storage_show
:networks_subcollection_actions:
:get:
- :name: read
Expand Down
50 changes: 50 additions & 0 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,56 @@ def gen_import_request
end
end

context 'Folders subcollection' do
let(:folder) { FactoryGirl.create(:ems_folder) }
let(:ems) { FactoryGirl.create(:ext_management_system) }

before do
ems.add_folder(folder)
end

context 'GET /api/providers/:id/folders' do
it 'returns the folders with an appropriate role' do
api_basic_authorize(collection_action_identifier(:providers, :read, :get))

get(api_provider_folders_url(nil, ems))

expected = {
'resources' => [{'href' => api_provider_folder_url(nil, ems, folder)}]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the folders without an appropriate role' do
api_basic_authorize

get(api_provider_folders_url(nil, ems))

expect(response).to have_http_status(:forbidden)
end
end

context 'GET /api/providers/:id/folders/:s_id' do
it 'returns the folder with an appropriate role' do
api_basic_authorize action_identifier(:providers, :read, :resource_actions, :get)

get(api_provider_folder_url(nil, ems, folder))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include('id' => folder.id.to_s)
end

it 'does not return the folder without an appropriate role' do
api_basic_authorize

get(api_provider_folder_url(nil, ems, folder))

expect(response).to have_http_status(:forbidden)
end
end
end

context 'Networks subcollection' do
let(:hardware) { FactoryGirl.create(:hardware) }
let(:network) { FactoryGirl.create(:network, :hardware => hardware) }
Expand Down