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]
|
2019-06-28 12:27:07 -04:00
|
|
|
before_action :trigger, only: [: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?
|
2019-03-27 12:52:52 -04:00
|
|
|
flash[:notice] = _('Trigger was created successfully.')
|
2015-09-29 04:37:31 -04:00
|
|
|
else
|
2019-03-27 12:52:52 -04:00
|
|
|
flash[:alert] = _('You could not create a new trigger.')
|
2017-03-07 08:02:56 -05:00
|
|
|
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)
|
2019-03-27 12:52:52 -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
|
2019-03-27 12:52:52 -04:00
|
|
|
flash[:notice] = _("Trigger removed.")
|
2017-03-07 08:02:56 -05:00
|
|
|
else
|
2019-03-27 12:52:52 -04:00
|
|
|
flash[:alert] = _("Could not remove the trigger.")
|
2017-03-07 08:02:56 -05:00
|
|
|
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
|
2018-12-19 08:15:58 -05:00
|
|
|
@trigger ||= project.triggers.find(params[:id])
|
|
|
|
.present(current_user: current_user)
|
2017-03-07 08:02:56 -05:00
|
|
|
end
|
|
|
|
|
2017-04-07 06:28:04 -04:00
|
|
|
def trigger_params
|
2018-12-19 08:15:58 -05:00
|
|
|
params.require(:trigger).permit(:description)
|
2015-09-29 04:37:31 -04:00
|
|
|
end
|
|
|
|
end
|