2014-03-23 00:22:25 +00:00
|
|
|
class BracketsController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_bracket, only: [:show, :edit, :update, :destroy]
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @bracket.can_update? cuser
|
2014-04-26 02:42:16 +00:00
|
|
|
render layout: 'full'
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-18 03:38:17 +00:00
|
|
|
@bracket = Bracket.new Bracket.params(params, cuser)
|
2014-03-23 00:22:25 +00:00
|
|
|
raise AccessError unless @bracket.can_create? cuser
|
|
|
|
|
|
|
|
if @bracket.save
|
|
|
|
flash[:notice] = t(:brackets_create)
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to edit_contest_path(@bracket.contest)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @bracket.can_update? cuser
|
|
|
|
|
2020-03-28 20:39:41 +00:00
|
|
|
if @bracket.update_attributes(Bracket.params(params, cuser)) and @bracket.update_cells(params.permit(:cell))
|
2014-03-23 00:22:25 +00:00
|
|
|
flash[:notice] = t(:brackets_update)
|
|
|
|
end
|
|
|
|
|
2020-03-28 20:39:41 +00:00
|
|
|
render :edit, layout: 'full'
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @bracket.can_destroy? cuser
|
|
|
|
@bracket.destroy
|
|
|
|
redirect_to edit_contest_path(@bracket.contest)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_bracket
|
|
|
|
@bracket = Bracket.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|