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

46 lines
1.1 KiB
Ruby
Raw Normal View History

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
def index
authorize! :edit, @project
@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?
end
def new
end
def edit
end
def create
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')
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])
2014-01-21 04:51:49 +00:00
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
2014-01-21 04:51:49 +00:00
redirect_to project_hooks_path(@project, name: @hook.name)
end
2013-04-15 12:47:53 +01:00
end