summaryrefslogtreecommitdiff
path: root/app/controllers/projects
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/projects')
-rw-r--r--app/controllers/projects/pipeline_schedules_controller.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/app/controllers/projects/pipeline_schedules_controller.rb b/app/controllers/projects/pipeline_schedules_controller.rb
new file mode 100644
index 00000000000..fd03eab7340
--- /dev/null
+++ b/app/controllers/projects/pipeline_schedules_controller.rb
@@ -0,0 +1,63 @@
+class Projects::PipelineSchedulesController < Projects::ApplicationController
+ before_action :authorize_create_pipeline!, only: [:new, :create, :edit]
+ before_action :authorize_update_pipeline!, only: [:retry, :cancel] # TODO set this right, its own authorize method
+ before_action :pipeline_schedule, only: [:edit, :update, :destroy]
+
+ # TODO test for N+1 queries
+ def index
+ @all_schedules = @project.pipeline_schedules.order('created_at DESC')
+
+ @scope = params[:scope]
+ @schedules =
+ case @scope
+ when 'active'
+ @all_schedules.active
+ when 'inactive'
+ @all_schedules.inactive
+ else
+ @all_schedules
+ end
+ end
+
+ def new
+ @pipeline_schedule = project.pipeline_schedules.new
+ end
+
+ def create
+ @pipeline_schedule = Ci::CreatePipelineScheduleService.
+ new(@project, current_user, pipeline_schedule_params).
+ execute
+
+ if @pipeline_schedule.persisted?
+ redirect_to project_pipeline_schedules_path(@project)
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @pipeline_schedule.update_attributes(pipeline_schedule_params).valid?
+ redirect_to project_pipeline_schedules_path(@project)
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ end
+
+ private
+
+ def pipeline_schedule
+ @pipeline_schedule = project.pipeline_schedules.find(params[:id])
+ end
+
+ def pipeline_schedule_params
+ params.require(:pipeline_schedule).
+ permit(:description, :cron, :cron_timezone, :ref).
+ reverse_merge(active: true, cron_timezone: 'UTC')
+ end
+end