2013-04-12 14:26:18 +01:00
|
|
|
class Projects::HooksController < Projects::BaseController
|
|
|
|
before_filter :authenticate_user!
|
2013-04-15 11:30:48 +01:00
|
|
|
load_and_authorize_resource :project
|
2014-01-21 04:51:49 +00:00
|
|
|
load_and_authorize_resource :hook, through: :project
|
2013-04-15 12:47:53 +01:00
|
|
|
|
2013-04-12 14:26:18 +01:00
|
|
|
|
|
|
|
def index
|
2013-05-16 10:52:55 +01:00
|
|
|
authorize! :edit, @project
|
2013-04-14 16:46:56 +01:00
|
|
|
@name = params[:name]
|
2013-04-15 10:40:41 +01:00
|
|
|
@hooks = @project.hooks.for_name(@name).order('name asc, created_at desc')
|
2013-05-16 12:36:29 +01:00
|
|
|
render(:show) if @name.present?
|
2013-05-16 10:52:55 +01:00
|
|
|
end
|
|
|
|
|
2013-04-12 14:26:18 +01:00
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-04-14 16:46:56 +01:00
|
|
|
if @hook.save
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.created')
|
2013-04-14 16:46:56 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.hook.save_error')
|
|
|
|
flash[:warning] = @hook.errors.full_messages.join('. ')
|
|
|
|
render :new
|
2013-04-12 14:26:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-04-14 16:46:56 +01:00
|
|
|
if @hook.update_attributes(params[:hook])
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.updated')
|
2013-04-14 16:46:56 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.hook.save_error')
|
|
|
|
flash[:warning] = @hook.errors.full_messages.join('. ')
|
|
|
|
render :edit
|
2013-04-12 14:26:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@hook.destroy
|
2014-01-21 04:51:49 +00:00
|
|
|
redirect_to project_hooks_path(@project, name: @hook.name)
|
2013-04-12 14:26:18 +01:00
|
|
|
end
|
2013-04-15 12:47:53 +01:00
|
|
|
|
2013-04-12 14:26:18 +01:00
|
|
|
end
|