Commit dcd4ea47 authored by Robert Schilling's avatar Robert Schilling

Update remaining endpoints

parent f0f3f385
...@@ -88,8 +88,7 @@ module API ...@@ -88,8 +88,7 @@ module API
variable = user_group.variables.find_by(key: params[:key]) variable = user_group.variables.find_by(key: params[:key])
not_found!('GroupVariable') unless variable not_found!('GroupVariable') unless variable
status 204 destroy_conditionally!(variable)
variable.destroy
end end
end end
end end
......
...@@ -14,7 +14,7 @@ module API ...@@ -14,7 +14,7 @@ module API
def check_unmodified_since!(last_modified) def check_unmodified_since!(last_modified)
if_unmodified_since = Time.parse(headers['If-Unmodified-Since']) rescue nil if_unmodified_since = Time.parse(headers['If-Unmodified-Since']) rescue nil
if if_unmodified_since && last_modified > if_unmodified_since if if_unmodified_since && last_modified && last_modified > if_unmodified_since
render_api_error!('412 Precondition Failed', 412) render_api_error!('412 Precondition Failed', 412)
end end
end end
......
...@@ -117,8 +117,7 @@ module API ...@@ -117,8 +117,7 @@ module API
not_found!('PipelineSchedule') unless pipeline_schedule not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :admin_pipeline_schedule, pipeline_schedule authorize! :admin_pipeline_schedule, pipeline_schedule
status :accepted destroy_conditionally!(pipeline_schedule)
present pipeline_schedule.destroy, with: Entities::PipelineScheduleDetails
end end
end end
......
require_dependency 'declarative_policy' require_dependency 'declarative_policy'
module API module API
# Projects API
class Projects < Grape::API class Projects < Grape::API
include PaginationParams include PaginationParams
......
...@@ -76,9 +76,7 @@ module API ...@@ -76,9 +76,7 @@ module API
delete ':id/protected_branches/:name', requirements: BRANCH_ENDPOINT_REQUIREMENTS do delete ':id/protected_branches/:name', requirements: BRANCH_ENDPOINT_REQUIREMENTS do
protected_branch = user_project.protected_branches.find_by!(name: params[:name]) protected_branch = user_project.protected_branches.find_by!(name: params[:name])
protected_branch.destroy destroy_conditionally!(protected_branch)
status 204
end end
end end
end end
......
...@@ -655,15 +655,15 @@ module API ...@@ -655,15 +655,15 @@ module API
end end
delete ":id/services/:service_slug" do delete ":id/services/:service_slug" do
service = user_project.find_or_initialize_service(params[:service_slug].underscore) service = user_project.find_or_initialize_service(params[:service_slug].underscore)
# Todo: Check if this done the right way
check_unmodified_since!(service.updated_at)
attrs = service_attributes(service).inject({}) do |hash, key| destroy_conditionally!(service) do
hash.merge!(key => nil) attrs = service_attributes(service).inject({}) do |hash, key|
end hash.merge!(key => nil)
end
unless service.update_attributes(attrs.merge(active: false)) unless service.update_attributes(attrs.merge(active: false))
render_api_error!('400 Bad Request', 400) render_api_error!('400 Bad Request', 400)
end
end end
end end
......
...@@ -408,8 +408,11 @@ module API ...@@ -408,8 +408,11 @@ module API
requires :impersonation_token_id, type: Integer, desc: 'The ID of the impersonation token' requires :impersonation_token_id, type: Integer, desc: 'The ID of the impersonation token'
end end
delete ':impersonation_token_id' do delete ':impersonation_token_id' do
status 204 token = find_impersonation_token
find_impersonation_token.revoke!
destroy_conditionally!(token) do
token.revoke!
end
end end
end end
end end
......
...@@ -88,6 +88,7 @@ module API ...@@ -88,6 +88,7 @@ module API
variable = user_project.variables.find_by(key: params[:key]) variable = user_project.variables.find_by(key: params[:key])
not_found!('Variable') unless variable not_found!('Variable') unless variable
# Variables don't have any timestamp. Therfore, destroy unconditionally.
status 204 status 204
variable.destroy variable.destroy
end end
......
...@@ -267,8 +267,7 @@ describe API::PipelineSchedules do ...@@ -267,8 +267,7 @@ describe API::PipelineSchedules do
delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", master) delete api("/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}", master)
end.to change { project.pipeline_schedules.count }.by(-1) end.to change { project.pipeline_schedules.count }.by(-1)
expect(response).to have_http_status(:accepted) expect(response).to have_http_status(204)
expect(response).to match_response_schema('pipeline_schedule')
end end
it 'responds with 404 Not Found if requesting non-existing pipeline_schedule' do it 'responds with 404 Not Found if requesting non-existing pipeline_schedule' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment