Skip to content

Commit

Permalink
Merge pull request ManageIQ#424 from CharlleDaniel/add_event_stream_s…
Browse files Browse the repository at this point in the history
…ubcollection

Add event_streams as subcollection of the physical resources
  • Loading branch information
abellotti authored Jul 25, 2018
2 parents 2e2fbad + bffaf3c commit c22dca5
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/physical_chassis_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Api
class PhysicalChassisController < BaseController
include Subcollections::EventStreams

def refresh_resource(type, id, _data = nil)
raise BadRequestError, "Must specify an id for refreshing a #{type} resource" if id.blank?

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/physical_servers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Api
class PhysicalServersController < BaseController
include Subcollections::EventStreams

def blink_loc_led_resource(type, id, _data)
change_resource_state(:blink_loc_led, type, id)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/physical_switches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Api
class PhysicalSwitchesController < BaseController
include Api::Mixins::Operations
include Subcollections::EventStreams

def refresh_resource(type, id, _data = nil)
perform_action(:refresh_ems, type, id)
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/event_streams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module EventStreams
def event_streams_query_resource(object)
object.respond_to?(:event_where_clause) ? EventStream.where(object.event_where_clause) : []
end
end
end
end
12 changes: 12 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@
:description: Event Streams
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: EventStream
:collection_actions:
Expand All @@ -1090,6 +1091,14 @@
:get:
- :name: read
:identifier: event_streams_show
:subcollection_actions:
:get:
- :name: read
:identifier: event_streams_show_list
:subresource_actions:
:get:
- :name: read
:identifier: event_streams_show
:events:
:description: Events
:identifier: event
Expand Down Expand Up @@ -1762,6 +1771,7 @@
:verbs: *gp
:klass: PhysicalChassis
:subcollections:
- :event_streams
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1808,6 +1818,7 @@
:verbs: *gp
:klass: PhysicalServer
:subcollections:
- :event_streams
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1898,6 +1909,7 @@
:verbs: *gp
:klass: PhysicalSwitch
:subcollections:
- :event_streams
:collection_actions:
:get:
- :name: read
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/physical_chassis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,53 @@
end
end
end

describe "Subcollections" do
let(:physical_chassis) { FactoryGirl.create(:physical_chassis) }
let(:event_stream) { FactoryGirl.create(:event_stream, :physical_chassis_id => physical_chassis.id, :event_type => "Some Event") }

context 'Events subcollection' do
context 'GET /api/physical_chassis/:id/event_streams' do
it 'returns the event_streams with an appropriate role' do
api_basic_authorize(collection_action_identifier(:event_streams, :read, :get))

expected = {
'resources' => [
{ 'href' => api_one_physical_chassis_event_stream_url(nil, physical_chassis, event_stream) }
]
}
get(api_one_physical_chassis_event_streams_url(nil, physical_chassis))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the event_streams without an appropriate role' do
api_basic_authorize
get(api_one_physical_chassis_event_streams_url(nil, physical_chassis))

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

context 'GET /api/physical_chassis/:id/event_streams/:id' do
it 'returns the event_stream with an appropriate role' do
api_basic_authorize(action_identifier(:event_streams, :read, :resource_actions, :get))
url = api_one_physical_chassis_event_stream_url(nil, physical_chassis, event_stream)
expected = { 'href' => url }
get(url)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the event_stream without an appropriate role' do
api_basic_authorize
get(api_one_physical_chassis_event_stream_url(nil, physical_chassis, event_stream))

expect(response).to have_http_status(:forbidden)
end
end
end
end
end
48 changes: 48 additions & 0 deletions spec/requests/physical_servers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,52 @@
end
end
end
describe "Subcollections" do
let(:physical_server) { FactoryGirl.create(:physical_server) }
let(:event_stream) { FactoryGirl.create(:event_stream, :physical_server_id => physical_server.id, :event_type => "Some Event") }

context 'Events subcollection' do
context 'GET /api/physical_servers/:id/event_streams' do
it 'returns the event_streams with an appropriate role' do
api_basic_authorize(collection_action_identifier(:event_streams, :read, :get))

expected = {
'resources' => [
{ 'href' => api_physical_server_event_stream_url(nil, physical_server, event_stream) }
]
}
get(api_physical_server_event_streams_url(nil, physical_server))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the event_streams without an appropriate role' do
api_basic_authorize
get(api_physical_server_event_streams_url(nil, physical_server))

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

context 'GET /api/physical_servers/:id/event_streams/:id' do
it 'returns the event_stream with an appropriate role' do
api_basic_authorize(action_identifier(:event_streams, :read, :resource_actions, :get))
url = api_physical_server_event_stream_url(nil, physical_server, event_stream)
expected = { 'href' => url }
get(url)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the event_stream without an appropriate role' do
api_basic_authorize
get(api_physical_server_event_stream_url(nil, physical_server, event_stream))

expect(response).to have_http_status(:forbidden)
end
end
end
end
end
49 changes: 49 additions & 0 deletions spec/requests/physical_switches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,53 @@
end
end
end

describe "Subcollections" do
let(:physical_switch) { FactoryGirl.create(:physical_switch) }
let(:event_stream) { FactoryGirl.create(:event_stream, :physical_switch_id => physical_switch.id, :event_type => "Some Event") }

context 'Events subcollection' do
context 'GET /api/physical_switches/:id/event_streams' do
it 'returns the event_streams with an appropriate role' do
api_basic_authorize(collection_action_identifier(:event_streams, :read, :get))

expected = {
'resources' => [
{ 'href' => api_physical_switch_event_stream_url(nil, physical_switch, event_stream) }
]
}
get(api_physical_switch_event_streams_url(nil, physical_switch))

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the event_streams without an appropriate role' do
api_basic_authorize
get(api_physical_switch_event_streams_url(nil, physical_switch))

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

context 'GET /api/physical_switches/:id/event_streams/:id' do
it 'returns the event_stream with an appropriate role' do
api_basic_authorize(action_identifier(:event_streams, :read, :resource_actions, :get))
url = api_physical_switch_event_stream_url(nil, physical_switch, event_stream)
expected = { 'href' => url }
get(url)

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'does not return the event_stream without an appropriate role' do
api_basic_authorize
get(api_physical_switch_event_stream_url(nil, physical_switch, event_stream))

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

0 comments on commit c22dca5

Please sign in to comment.