2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-09-29 04:37:31 -04:00
|
|
|
class Projects::TriggersController < Projects::ApplicationController
|
2016-02-01 17:58:04 -05:00
|
|
|
before_action :authorize_admin_build!
|
2017-03-07 08:02:56 -05:00
|
|
|
before_action :authorize_manage_trigger!, except: [:index, :create]
|
|
|
|
before_action :authorize_admin_trigger!, only: [:edit, :update]
|
|
|
|
before_action :trigger, only: [:take_ownership, :edit, :update, :destroy]
|
2015-09-29 04:37:31 -04:00
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2017-01-30 10:36:49 -05:00
|
|
|
def index
|
2018-08-07 17:16:04 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers')
|
2017-01-30 10:36:49 -05:00
|
|
|
end
|
|
|
|
|
2015-09-29 04:37:31 -04:00
|
|
|
def create
|
2017-04-07 06:28:04 -04:00
|
|
|
@trigger = project.triggers.create(trigger_params.merge(owner: current_user))
|
2015-09-29 04:37:31 -04:00
|
|
|
|
|
|
|
if @trigger.valid?
|
2017-03-07 08:02:56 -05:00
|
|
|
flash[:notice] = 'Trigger was created successfully.'
|
2015-09-29 04:37:31 -04:00
|
|
|
else
|
2017-03-07 08:02:56 -05:00
|
|
|
flash[:alert] = 'You could not create a new trigger.'
|
|
|
|
end
|
|
|
|
|
2018-08-07 17:16:04 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers')
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def take_ownership
|
|
|
|
if trigger.update(owner: current_user)
|
|
|
|
flash[:notice] = 'Trigger was re-assigned.'
|
|
|
|
else
|
|
|
|
flash[:alert] = 'You could not take ownership of trigger.'
|
|
|
|
end
|
|
|
|
|
2018-08-07 17:16:04 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers')
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-04-07 06:28:04 -04:00
|
|
|
if trigger.update(trigger_params)
|
2018-08-07 17:16:04 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers'), notice: 'Trigger was successfully updated.'
|
2017-03-07 08:02:56 -05:00
|
|
|
else
|
|
|
|
render action: "edit"
|
2015-09-29 04:37:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2017-03-07 08:02:56 -05:00
|
|
|
if trigger.destroy
|
|
|
|
flash[:notice] = "Trigger removed."
|
|
|
|
else
|
|
|
|
flash[:alert] = "Could not remove the trigger."
|
|
|
|
end
|
2015-09-29 04:37:31 -04:00
|
|
|
|
2018-08-07 17:16:04 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers'), status: :found
|
2015-09-29 04:37:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-03-07 08:02:56 -05:00
|
|
|
def authorize_manage_trigger!
|
|
|
|
access_denied! unless can?(current_user, :manage_trigger, trigger)
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_trigger!
|
|
|
|
access_denied! unless can?(current_user, :admin_trigger, trigger)
|
|
|
|
end
|
|
|
|
|
2015-09-29 04:37:31 -04:00
|
|
|
def trigger
|
2017-03-07 08:02:56 -05:00
|
|
|
@trigger ||= project.triggers.find(params[:id]) || render_404
|
|
|
|
end
|
|
|
|
|
2017-04-07 06:28:04 -04:00
|
|
|
def trigger_params
|
2017-04-06 15:02:19 -04:00
|
|
|
params.require(:trigger).permit(
|
2017-07-13 08:17:47 -04:00
|
|
|
:description
|
2017-04-06 15:02:19 -04:00
|
|
|
)
|
2015-09-29 04:37:31 -04:00
|
|
|
end
|
|
|
|
end
|