Skip to content

Commit

Permalink
Add DELETE service_templates/X/schedules/X
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Jul 11, 2018
1 parent 325e0bf commit 1671344
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/api/service_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def schedules_query_resource(object)
object.miq_schedules
end

def schedules_delete_resource(_parent, type, id, data)
delete_resource(type, id, data)
end
alias delete_resource_schedules schedules_delete_resource

private

def set_additional_attributes
Expand Down
11 changes: 10 additions & 1 deletion config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2518,16 +2518,25 @@
:identifier: miq_report_reports
:options:
- :subcollection
:verbs: *gp
:verbs: *gpd
:klass: MiqSchedule
:subcollection_actions:
:get:
- :name: read
:identifier: miq_report_view
:post:
- :name: delete
:identifier: schedule_delete
:subresource_actions:
:delete:
- :name: delete
:identifier: schedule_delete
:get:
- :name: read
:identifier: miq_report_view
:post:
- :name: delete
:identifier: schedule_delete
:search_filters:
:description: Filters
:verbs: *gpd
Expand Down
54 changes: 54 additions & 0 deletions spec/requests/service_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,60 @@

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

it "DELETE service_templates/x/schedules/x" do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :delete, :delete))

delete(api_service_template_schedule_url(nil, service_template, schedule_1))

expect(response).to have_http_status(:no_content)
expect { schedule_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

describe "POST /api/service_templates/:id/schedules/:id with delete action" do
it "can delete a schedule" do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :delete))

expect do
post(api_service_template_schedule_url(nil, service_template, schedule_1), :params => { :action => "delete" })
end.to change(MiqSchedule, :count).by(-1)

expected = {
"message" => "schedules id: #{schedule_1.id} deleting",
"success" => true,
}
expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
end

it "will not delete a schedule unless authorized" do
api_basic_authorize

post(api_service_template_schedule_url(nil, service_template, schedule_1), :params => { :action => "delete" })

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

describe "POST /api/service_templates/:id/schedules/ with delete action" do
it "can delete multiple schedules" do
api_basic_authorize(subresource_action_identifier(:service_templates, :schedules, :delete))

expect do
post(api_service_template_schedules_url(nil, service_template), :params => {:action => "delete", :resources => [{:id => schedule_1.id}, {:id => schedule_2.id}]})
end.to change(MiqSchedule, :count).by(-2)

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

it "forbids multiple schedule deletion without an appropriate role" do
api_basic_authorize

post(api_service_template_schedules_url(nil, service_template), :params => {:action => "delete", :resources => [{:id => schedule_1.id}, {:id => schedule_2.id}]})

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

it "without any schedules" do
Expand Down

0 comments on commit 1671344

Please sign in to comment.