2017-05-07 18:35:56 -04:00
|
|
|
class Projects::PipelineSchedulesController < Projects::ApplicationController
|
2017-06-28 08:42:13 -04:00
|
|
|
before_action :schedule, except: [:index, :new, :create]
|
2017-06-27 03:23:16 -04:00
|
|
|
|
2017-05-07 18:35:56 -04:00
|
|
|
before_action :authorize_read_pipeline_schedule!
|
2017-06-01 10:30:12 -04:00
|
|
|
before_action :authorize_create_pipeline_schedule!, only: [:new, :create]
|
2017-06-28 08:42:13 -04:00
|
|
|
before_action :authorize_update_pipeline_schedule!, except: [:index, :new, :create]
|
2017-05-07 18:35:56 -04:00
|
|
|
before_action :authorize_admin_pipeline_schedule!, only: [:destroy]
|
|
|
|
|
|
|
|
def index
|
|
|
|
@scope = params[:scope]
|
|
|
|
@all_schedules = PipelineSchedulesFinder.new(@project).execute
|
|
|
|
@schedules = PipelineSchedulesFinder.new(@project).execute(scope: params[:scope])
|
|
|
|
.includes(:last_pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@schedule = project.pipeline_schedules.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@schedule = Ci::CreatePipelineScheduleService
|
|
|
|
.new(@project, current_user, schedule_params)
|
|
|
|
.execute
|
|
|
|
|
|
|
|
if @schedule.persisted?
|
|
|
|
redirect_to pipeline_schedules_path(@project)
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-07-05 11:23:28 -04:00
|
|
|
if schedule.update(schedule_params)
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_pipeline_schedules_path(@project)
|
2017-05-07 18:35:56 -04:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def take_ownership
|
|
|
|
if schedule.update(owner: current_user)
|
|
|
|
redirect_to pipeline_schedules_path(@project)
|
|
|
|
else
|
2017-06-07 09:46:10 -04:00
|
|
|
redirect_to pipeline_schedules_path(@project), alert: _("Failed to change the owner")
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
if schedule.destroy
|
2017-06-06 18:45:16 -04:00
|
|
|
redirect_to pipeline_schedules_path(@project), status: 302
|
2017-05-07 18:35:56 -04:00
|
|
|
else
|
2017-06-06 18:45:16 -04:00
|
|
|
redirect_to pipeline_schedules_path(@project),
|
2017-07-04 04:45:07 -04:00
|
|
|
status: :forbidden,
|
2017-06-07 09:46:10 -04:00
|
|
|
alert: _("Failed to remove the pipeline schedule")
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def schedule
|
|
|
|
@schedule ||= project.pipeline_schedules.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def schedule_params
|
|
|
|
params.require(:schedule)
|
2017-06-22 14:57:13 -04:00
|
|
|
.permit(:description, :cron, :cron_timezone, :ref, :active,
|
2017-06-25 13:59:27 -04:00
|
|
|
variables_attributes: [:id, :key, :value, :_destroy] )
|
2017-06-27 03:23:16 -04:00
|
|
|
end
|
2017-06-27 03:23:16 -04:00
|
|
|
|
|
|
|
def authorize_update_pipeline_schedule!
|
|
|
|
return access_denied! unless can?(current_user, :update_pipeline_schedule, schedule)
|
|
|
|
end
|
2017-07-07 06:09:35 -04:00
|
|
|
|
|
|
|
def authorize_admin_pipeline_schedule!
|
|
|
|
return access_denied! unless can?(current_user, :admin_pipeline_schedule, schedule)
|
|
|
|
end
|
2017-05-07 18:35:56 -04:00
|
|
|
end
|