2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
class Projects::TriggersController < Projects::ApplicationController
|
2016-04-02 18:10:28 +05:30
|
|
|
before_action :authorize_admin_build!
|
2017-08-17 22:00:37 +05:30
|
|
|
before_action :authorize_manage_trigger!, except: [:index, :create]
|
|
|
|
before_action :authorize_admin_trigger!, only: [:edit, :update]
|
2019-07-31 22:56:46 +05:30
|
|
|
before_action :trigger, only: [:edit, :update, :destroy]
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
layout 'project_settings'
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :continuous_integration
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
def index
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers')
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-08-17 22:00:37 +05:30
|
|
|
@trigger = project.triggers.create(trigger_params.merge(owner: current_user))
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
if @trigger.valid?
|
2019-07-07 11:18:12 +05:30
|
|
|
flash[:notice] = _('Trigger was created successfully.')
|
2015-10-24 18:46:33 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
flash[:alert] = _('You could not create a new trigger.')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if trigger.update(trigger_params)
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers'), notice: _('Trigger was successfully updated.')
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
|
|
|
render action: "edit"
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2017-08-17 22:00:37 +05:30
|
|
|
if trigger.destroy
|
2019-07-07 11:18:12 +05:30
|
|
|
flash[:notice] = _("Trigger removed.")
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
2019-07-07 11:18:12 +05:30
|
|
|
flash[:alert] = _("Could not remove the trigger.")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers'), status: :found
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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-10-24 18:46:33 +05:30
|
|
|
def trigger
|
2019-02-02 18:00:53 +05:30
|
|
|
@trigger ||= project.triggers.find(params[:id])
|
|
|
|
.present(current_user: current_user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def trigger_params
|
2019-02-02 18:00:53 +05:30
|
|
|
params.require(:trigger).permit(:description)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|