Commit bb22989c authored by Shinya Maeda's avatar Shinya Maeda

Improve def pipeline_schedule with authrozation code

parent 362f2226
...@@ -31,8 +31,6 @@ module API ...@@ -31,8 +31,6 @@ module API
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end end
get ':id/pipeline_schedules/:pipeline_schedule_id' do get ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :read_pipeline_schedule, user_project
present pipeline_schedule, with: Entities::PipelineScheduleDetails present pipeline_schedule, with: Entities::PipelineScheduleDetails
end end
...@@ -72,7 +70,6 @@ module API ...@@ -72,7 +70,6 @@ module API
optional :active, type: Boolean, desc: 'The activation of pipeline schedule' optional :active, type: Boolean, desc: 'The activation of pipeline schedule'
end end
put ':id/pipeline_schedules/:pipeline_schedule_id' do put ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :read_pipeline_schedule, user_project
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.update(declared_params(include_missing: false)) if pipeline_schedule.update(declared_params(include_missing: false))
...@@ -89,7 +86,6 @@ module API ...@@ -89,7 +86,6 @@ module API
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end end
post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do post ':id/pipeline_schedules/:pipeline_schedule_id/take_ownership' do
authorize! :read_pipeline_schedule, user_project
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule.own!(current_user) if pipeline_schedule.own!(current_user)
...@@ -106,7 +102,6 @@ module API ...@@ -106,7 +102,6 @@ module API
requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id' requires :pipeline_schedule_id, type: Integer, desc: 'The pipeline schedule id'
end end
delete ':id/pipeline_schedules/:pipeline_schedule_id' do delete ':id/pipeline_schedules/:pipeline_schedule_id' do
authorize! :read_pipeline_schedule, user_project
authorize! :admin_pipeline_schedule, pipeline_schedule authorize! :admin_pipeline_schedule, pipeline_schedule
destroy_conditionally!(pipeline_schedule) destroy_conditionally!(pipeline_schedule)
...@@ -121,7 +116,6 @@ module API ...@@ -121,7 +116,6 @@ module API
requires :value, type: String, desc: 'The value of the variable' requires :value, type: String, desc: 'The value of the variable'
end end
post ':id/pipeline_schedules/:pipeline_schedule_id/variables' do post ':id/pipeline_schedules/:pipeline_schedule_id/variables' do
authorize! :read_pipeline_schedule, user_project
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
variable_params = declared_params(include_missing: false) variable_params = declared_params(include_missing: false)
...@@ -142,7 +136,6 @@ module API ...@@ -142,7 +136,6 @@ module API
optional :value, type: String, desc: 'The value of the variable' optional :value, type: String, desc: 'The value of the variable'
end end
put ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do put ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do
authorize! :read_pipeline_schedule, user_project
authorize! :update_pipeline_schedule, pipeline_schedule authorize! :update_pipeline_schedule, pipeline_schedule
if pipeline_schedule_variable.update(declared_params(include_missing: false)) if pipeline_schedule_variable.update(declared_params(include_missing: false))
...@@ -160,7 +153,6 @@ module API ...@@ -160,7 +153,6 @@ module API
requires :key, type: String, desc: 'The key of the variable' requires :key, type: String, desc: 'The key of the variable'
end end
delete ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do delete ':id/pipeline_schedules/:pipeline_schedule_id/variables/:key' do
authorize! :read_pipeline_schedule, user_project
authorize! :admin_pipeline_schedule, pipeline_schedule authorize! :admin_pipeline_schedule, pipeline_schedule
status :accepted status :accepted
...@@ -171,18 +163,23 @@ module API ...@@ -171,18 +163,23 @@ module API
helpers do helpers do
def pipeline_schedule def pipeline_schedule
@pipeline_schedule ||= @pipeline_schedule ||=
user_project.pipeline_schedules user_project
.preload(:owner, :last_pipeline) .pipeline_schedules
.find_by(id: params.delete(:pipeline_schedule_id)) .preload(:owner, :last_pipeline)
.find_by(id: params.delete(:pipeline_schedule_id)).tap do |pipeline_schedule|
@pipeline_schedule || not_found!('Pipeline Schedule') unless pipeline_schedule || can?(current_user, :read_pipeline_schedule, pipeline_schedule)
not_found!('Pipeline Schedule')
end
end
end end
def pipeline_schedule_variable def pipeline_schedule_variable
@pipeline_schedule_variable ||= @pipeline_schedule_variable ||=
pipeline_schedule.variables.find_by(key: params[:key]) pipeline_schedule.variables.find_by(key: params[:key]).tap do |pipeline_schedule_variable|
unless pipeline_schedule_variable
@pipeline_schedule_variable || not_found!('Pipeline Schedule Variable') not_found!('Pipeline Schedule Variable')
end
end
end end
end end
end end
......
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