Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-08-24 15:51:46 +0300
committerShinya Maeda <shinya@gitlab.com>2017-09-04 15:10:34 +0300
commit362f2226a5febb7a3a82e86f4a83e87a870d67b3 (patch)
tree618071ce63102842b8e1fc1f6af187fe4cf2b67b /lib/api/pipeline_schedules.rb
parentfb8f32a92cdfe4cca24cb80a91e8fe48d6b0df25 (diff)
Improve by zj nice catches
Diffstat (limited to 'lib/api/pipeline_schedules.rb')
-rw-r--r--lib/api/pipeline_schedules.rb37
1 files changed, 13 insertions, 24 deletions
diff --git a/lib/api/pipeline_schedules.rb b/lib/api/pipeline_schedules.rb
index 7a3f74006c6..a6414bfe3f4 100644
--- a/lib/api/pipeline_schedules.rb
+++ b/lib/api/pipeline_schedules.rb
@@ -33,8 +33,6 @@ module API
get ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :read_pipeline_schedule, user_project
- not_found!('PipelineSchedule') unless pipeline_schedule
-
present pipeline_schedule, with: Entities::PipelineScheduleDetails
end
@@ -75,8 +73,6 @@ module API
end
put ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :read_pipeline_schedule, user_project
-
- not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.update(declared_params(include_missing: false))
@@ -94,8 +90,6 @@ module API
end
post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do
authorize! :read_pipeline_schedule, user_project
-
- not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.own!(current_user)
@@ -113,8 +107,6 @@ module API
end
delete ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :read_pipeline_schedule, user_project
-
- not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :admin_pipeline_schedule, pipeline_schedule
destroy_conditionally!(pipeline_schedule)
@@ -130,8 +122,6 @@ module API
end
post ':id/pipeline_schedules/:pipeline_schedule_id/variables' do
authorize! :read_pipeline_schedule, user_project
-
- not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :update_pipeline_schedule, pipeline_schedule
variable_params = declared_params(include_missing: false)
@@ -153,17 +143,12 @@ module API
end
put ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do
authorize! :read_pipeline_schedule, user_project
-
- not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :update_pipeline_schedule, pipeline_schedule
- variable = pipeline_schedule.variables.find_by(key: params[:key])
- not_found!('Variable') unless variable
-
- if variable.update(declared_params(include_missing: false))
- present variable, with: Entities::Variable
+ if pipeline_schedule_variable.update(declared_params(include_missing: false))
+ present pipeline_schedule_variable, with: Entities::Variable
else
- render_validation_error!(variable)
+ render_validation_error!(pipeline_schedule_variable)
end
end
@@ -176,15 +161,10 @@ module API
end
delete ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do
authorize! :read_pipeline_schedule, user_project
-
- not_found!('PipelineSchedule') unless pipeline_schedule
authorize! :admin_pipeline_schedule, pipeline_schedule
- variable = pipeline_schedule.variables.find_by(key: params[:key])
- not_found!('Variable') unless variable
-
status :accepted
- present variable.destroy, with: Entities::Variable
+ present pipeline_schedule_variable.destroy, with: Entities::Variable
end
end
@@ -194,6 +174,15 @@ module API
user_project.pipeline_schedules
.preload(:owner, :last_pipeline)
.find_by(id: params.delete(:pipeline_schedule_id))
+
+ @pipeline_schedule || not_found!('Pipeline Schedule')
+ end
+
+ def pipeline_schedule_variable
+ @pipeline_schedule_variable ||=
+ pipeline_schedule.variables.find_by(key: params[:key])
+
+ @pipeline_schedule_variable || not_found!('Pipeline Schedule Variable')
end
end
end