gitlab-org--gitlab-foss/app/controllers/projects/triggers_controller.rb

67 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Projects::TriggersController < Projects::ApplicationController
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: [:edit, :update, :destroy]
layout 'project_settings'
def index
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers')
end
def create
@trigger = project.triggers.create(trigger_params.merge(owner: current_user))
if @trigger.valid?
flash[:notice] = _('Trigger was created successfully.')
else
flash[:alert] = _('You could not create a new trigger.')
2017-03-07 08:02:56 -05:00
end
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
if trigger.update(trigger_params)
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"
end
end
def destroy
2017-03-07 08:02:56 -05:00
if trigger.destroy
flash[:notice] = _("Trigger removed.")
2017-03-07 08:02:56 -05:00
else
flash[:alert] = _("Could not remove the trigger.")
2017-03-07 08:02:56 -05:00
end
redirect_to project_settings_ci_cd_path(@project, anchor: 'js-pipeline-triggers'), status: :found
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
def trigger
@trigger ||= project.triggers.find(params[:id])
.present(current_user: current_user)
2017-03-07 08:02:56 -05:00
end
def trigger_params
params.require(:trigger).permit(:description)
end
end