Offline participation: implement completed puzzle methods
Some checks failed
CI / scan_ruby (push) Successful in 20s
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
sto
2025-10-31 11:55:28 +01:00
parent 37a65526e4
commit ff5f387a87
13 changed files with 110 additions and 17 deletions

View File

@@ -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