rosa-build/app/controllers/projects/hooks_controller.rb

53 lines
1.3 KiB
Ruby

class Projects::HooksController < Projects::BaseController
before_action :authenticate_user!
before_action -> { authorize @project, :update? }
before_action :load_hook, except: %i(index new create)
def index
@name = params[:name]
@hooks = @project.hooks.for_name(@name).order('name asc, created_at desc')
render(:show) if @name.present?
end
def new
@hook = @project.hooks.build
end
def edit
end
def create
authorize @hook = @project.hooks.build(params[:hook])
if @hook.save
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.created')
else
flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ')
render :new
end
end
def update
if @hook.update_attributes(params[:hook])
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.updated')
else
flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ')
render :edit
end
end
def destroy
@hook.destroy
redirect_to project_hooks_path(@project, name: @hook.name)
end
private
# Private: before_action hook which loads Hook.
def load_hook
authorize @hook = @project.hooks.find(params[:id])
end
end