Offline participation: implement completed puzzle methods
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class ContestsController < ApplicationController
|
||||
before_action :set_contest, only: %i[ destroy edit show update ]
|
||||
before_action :offline_setup, only: %i[ offline_new offline_create ]
|
||||
skip_before_action :require_authentication, only: %i[ scoreboard offline_new offline_create ]
|
||||
before_action :offline_setup, only: %i[ offline_new offline_create offline_edit offline_update offline_completed ]
|
||||
skip_before_action :require_authentication, only: %i[ scoreboard offline_new offline_create offline_edit offline_update offline_completed ]
|
||||
|
||||
def index
|
||||
authorize :contest
|
||||
@@ -111,12 +111,47 @@ class ContestsController < ApplicationController
|
||||
@offline.contest = @contest
|
||||
@offline.start_time = Time.now()
|
||||
if @offline.save
|
||||
redirect_to "/public/#{@contest.friendly_id}/offline/test"
|
||||
redirect_to "/public/#{@contest.friendly_id}/offline/#{@offline.generate_token_for(:token)}"
|
||||
else
|
||||
render :offline_new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def offline_edit
|
||||
authorize @contest
|
||||
|
||||
@offline = Offline.find_by_token_for(:token, params[:token])
|
||||
if !@offline
|
||||
not_found and return
|
||||
end
|
||||
end
|
||||
|
||||
def offline_update
|
||||
authorize @contest
|
||||
|
||||
@offline = Offline.find_by_token_for(:token, params[:token])
|
||||
if !@offline
|
||||
not_found and return
|
||||
end
|
||||
|
||||
@offline.completed = true
|
||||
@offline.images.attach(params[:offline][:end_image])
|
||||
if @offline.save
|
||||
redirect_to "/public/#{@contest.friendly_id}/offline/#{@offline.generate_token_for(:token)}/completed"
|
||||
else
|
||||
render :offline_edit, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def offline_completed
|
||||
authorize @contest
|
||||
|
||||
@offline = Offline.find_by_token_for(:token, params[:token])
|
||||
if !@offline
|
||||
not_found and return
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def offline_setup
|
||||
@@ -150,6 +185,10 @@ class ContestsController < ApplicationController
|
||||
end
|
||||
|
||||
def offline_start_params
|
||||
params.expect(offline: [ :name, :start_image ])
|
||||
params.expect(offline: [ :name, :images ])
|
||||
end
|
||||
|
||||
def offline_end_params
|
||||
params.expect(offline: [ :completed, :end_image ])
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user