debian-mirror-gitlab/app/controllers/projects/triggers_controller.rb

77 lines
2 KiB
Ruby
Raw Normal View History

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]
before_action :trigger, only: [:take_ownership, :edit, :update, :destroy]
2015-10-24 18:46:33 +05:30
layout 'project_settings'
def index
2017-08-17 22:00:37 +05:30
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
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?
2017-08-17 22:00:37 +05:30
flash[:notice] = 'Trigger was created successfully.'
2015-10-24 18:46:33 +05:30
else
2017-08-17 22:00:37 +05:30
flash[:alert] = 'You could not create a new trigger.'
end
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
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
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
end
def edit
end
def update
if trigger.update(trigger_params)
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project), notice: 'Trigger was successfully updated.'
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
flash[:notice] = "Trigger removed."
else
flash[:alert] = "Could not remove the trigger."
end
2015-10-24 18:46:33 +05:30
2017-08-17 22:00:37 +05:30
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
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
2017-08-17 22:00:37 +05:30
@trigger ||= project.triggers.find(params[:id]) || render_404
end
def trigger_params
params.require(:trigger).permit(
:description,
trigger_schedule_attributes: [:id, :active, :cron, :cron_timezone, :ref]
)
2015-10-24 18:46:33 +05:30
end
end