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

Redirect tasks subcollection to request_tasks #15357

Merged
merged 2 commits into from
Jun 14, 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: 0 additions & 1 deletion app/controllers/api/automation_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Api
class AutomationRequestsController < BaseController
include Subcollections::RequestTasks
include Subcollections::Tasks

def create_resource(type, _id, data)
assert_id_not_specified(data, type)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/api/provision_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Api
class ProvisionRequestsController < BaseController
include Subcollections::RequestTasks
include Subcollections::Tasks

def create_resource(type, _id, data)
assert_id_not_specified(data, type)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/api/requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Api
class RequestsController < BaseController
include Subcollections::RequestTasks
include Subcollections::Tasks

def create_resource(type, _id, data)
assert_id_not_specified(data, type)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/api/service_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Api
class ServiceRequestsController < BaseController
include Subcollections::RequestTasks
include Subcollections::Tasks

def approve_resource(type, id, data)
raise "Must specify a reason for approving a service request" unless data["reason"].present?
Expand Down
10 changes: 0 additions & 10 deletions app/controllers/api/subcollections/tasks.rb

This file was deleted.

5 changes: 0 additions & 5 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@
:klass: AutomationRequest
:subcollections:
- :request_tasks
- :tasks
:collection_actions:
:post:
- :name: create
Expand Down Expand Up @@ -1380,7 +1379,6 @@
:klass: MiqProvisionRequest
:subcollections:
- :request_tasks
- :tasks
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1534,7 +1532,6 @@
:klass: MiqRequest
:subcollections:
- :request_tasks
- :tasks
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1852,7 +1849,6 @@
:klass: ServiceTemplateProvisionRequest
:subcollections:
- :request_tasks
- :tasks
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -2150,7 +2146,6 @@
:identifier: tasks
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: MiqTask
:collection_actions:
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
}.freeze
end

# Redirect of /tasks subcollections to /request_tasks
[:automation_requests, :provision_requests, :requests, :service_requests].each do |collection_name|
get "/#{collection_name}/:c_id/tasks", :to => redirect { |path_params, _req| "/api/#{collection_name}/#{path_params[:c_id]}/request_tasks" }
get "/#{collection_name}/:c_id/tasks/:s_id", :to => redirect { |path_params, _req| "/api/#{collection_name}/#{path_params[:c_id]}/request_tasks/#{path_params[:s_id]}" }
end

Api::ApiConfig.collections.each do |collection_name, collection|
# OPTIONS action for each collection
match collection_name.to_s, :controller => collection_name, :action => :options, :via => :options
Expand Down
24 changes: 24 additions & 0 deletions spec/requests/api/automation_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,28 @@
expect(response).to have_http_status(:ok)
end
end

context 'Tasks subcollection' do
let(:automation_request) { FactoryGirl.create(:automation_request) }

it 'redirects to request_tasks subcollection' do
FactoryGirl.create(:miq_request_task, :miq_request_id => automation_request.id)
api_basic_authorize

run_get("#{automation_requests_url(automation_request.id)}/tasks")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{automation_requests_url(automation_request.id)}/request_tasks")
end

it 'redirects to request_tasks subresources' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => automation_request.id)
api_basic_authorize

run_get("#{automation_requests_url(automation_request.id)}/tasks/#{task.id}")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{automation_requests_url(automation_request.id)}/request_tasks/#{task.id}")
end
end
end
24 changes: 24 additions & 0 deletions spec/requests/api/provision_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,28 @@
expect(response).to have_http_status(:ok)
end
end

context 'Tasks subcollection' do
let(:provision_request) { FactoryGirl.create(:miq_provision_request) }

it 'redirects to request_tasks subcollection' do
FactoryGirl.create(:miq_request_task, :miq_request_id => provision_request.id)
api_basic_authorize collection_action_identifier(:service_requests, :read, :get)

run_get("#{provision_requests_url(provision_request.id)}/tasks")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{provision_requests_url(provision_request.id)}/request_tasks")
end

it 'redirects to request_tasks subresources' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => provision_request.id)
api_basic_authorize action_identifier(:services, :read, :resource_actions, :get)

run_get("#{provision_requests_url(provision_request.id)}/tasks/#{task.id}")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{provision_requests_url(provision_request.id)}/request_tasks/#{task.id}")
end
end
end
29 changes: 29 additions & 0 deletions spec/requests/api/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,33 @@
expect(response.parsed_body['resources']).to match_array(expected)
end
end

context 'Tasks subcollection' do
let(:request) do
FactoryGirl.create(:service_template_provision_request,
:requester => @user,
:source_id => template.id,
:source_type => template.class.name)
end

it 'redirects to request_tasks subcollection' do
FactoryGirl.create(:miq_request_task, :miq_request_id => request.id)
api_basic_authorize collection_action_identifier(:service_requests, :read, :get)

run_get("#{requests_url(request.id)}/tasks")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{requests_url(request.id)}/request_tasks")
end

it 'redirects to request_tasks subresources' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => request.id)
api_basic_authorize action_identifier(:services, :read, :resource_actions, :get)

run_get("#{requests_url(request.id)}/tasks/#{task.id}")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{requests_url(request.id)}/request_tasks/#{task.id}")
end
end
end
22 changes: 22 additions & 0 deletions spec/requests/api/service_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,26 @@ def expect_result_to_have_user_email(email)
expect(response.parsed_body).to include(expected)
end
end

context 'Tasks subcollection' do
it 'redirects to request_tasks subcollection' do
FactoryGirl.create(:miq_request_task, :miq_request_id => service_request.id)
api_basic_authorize collection_action_identifier(:service_requests, :read, :get)

run_get("#{service_requests_url(service_request.id)}/tasks")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{service_requests_url(service_request.id)}/request_tasks")
end

it 'redirects to request_tasks subresources' do
task = FactoryGirl.create(:miq_request_task, :miq_request_id => service_request.id)
api_basic_authorize action_identifier(:services, :read, :resource_actions, :get)

run_get("#{service_requests_url(service_request.id)}/tasks/#{task.id}")

expect(response).to have_http_status(:moved_permanently)
expect(response.redirect_url).to include("#{service_requests_url(service_request.id)}/request_tasks/#{task.id}")
end
end
end