mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-11-15 17:31:27 +00:00
77 lines
1.8 KiB
Ruby
77 lines
1.8 KiB
Ruby
class ChallengesController < ApplicationController
|
|
before_filter :get_challenge, only: [:show, :edit, :update, :destroy]
|
|
|
|
def index
|
|
@challenges = Challenge.all
|
|
end
|
|
|
|
def show
|
|
return_here
|
|
end
|
|
|
|
def refresh
|
|
Challenge.past.pending.each do |c|
|
|
c.destroy
|
|
end
|
|
|
|
render text: t(:challenges_cleared)
|
|
end
|
|
|
|
def new
|
|
#No new challenges for now.
|
|
raise AccessError
|
|
@challenge = Challenge.new
|
|
@challenge.user = cuser
|
|
@challenge.contester2 = Contester.active.find params[:id]
|
|
contest = @challenge.contester2.contest
|
|
@challenge.contester1 = @challenge.user.active_contesters.of_contest(contest).first
|
|
raise AccessError unless @challenge.can_create? cuser
|
|
end
|
|
|
|
def create
|
|
@challenge = Challenge.new params[:challenge]
|
|
@challenge.user = cuser
|
|
raise AccessError unless @challenge.can_create? cuser
|
|
|
|
if @challenge.valid? and @challenge.save
|
|
flash[:notice] = t(:challenges_create)
|
|
redirect_to @challenge
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def update
|
|
@challenge = Challenge.find params[:id]
|
|
raise AccessError unless @challenge.can_update? cuser
|
|
case params[:commit]
|
|
when "Accept"
|
|
@challenge.status = Challenge::STATUS_ACCEPTED
|
|
when "Default time"
|
|
@challenge.status = Challenge::STATUS_DEFAULT
|
|
when "Forfeit"
|
|
@challenge.status = Challenge::STATUS_FORFEIT
|
|
when "Decline"
|
|
@challenge.status = Challenge::STATUS_DECLINED
|
|
end
|
|
|
|
if @challenge.update_attributes params[:challenge]
|
|
flash[:notice] = t(:challenges_update)
|
|
end
|
|
|
|
render :show
|
|
end
|
|
|
|
def destroy
|
|
raise AccessError unless @challenge.can_destroy? cuser
|
|
@challenge.destroy
|
|
#return_to FIX ME from challenge side
|
|
render text: t(:challenges_cleared)
|
|
end
|
|
|
|
private
|
|
|
|
def get_challenge
|
|
@challenge = Challenge.find params[:id]
|
|
end
|
|
end
|