Add method to update contestants through admin UI
Some checks failed
CI / scan_ruby (push) Successful in 19s
CI / scan_js (push) Successful in 14s
CI / lint (push) Successful in 13s
CI / test (push) Failing after 35s

This commit is contained in:
sto
2025-11-18 11:15:23 +01:00
parent ecb36e19ed
commit 63a88ea113
5 changed files with 35 additions and 2 deletions

View File

@@ -1,4 +1,6 @@
class UsersController < ApplicationController
include CompletionsConcern
before_action :set_user, only: %i[ destroy edit show update ]
def index
@@ -51,6 +53,26 @@ class UsersController < ApplicationController
authorize @user
end
def update_contestants
authorize :user
total = 0
updated = 0
Contestant.all.each do |contestant|
if contestant.completions.length > 0
total += 1
contestant.completions.each do |completion|
completion.save
end
if extend_completions!(contestant)
updated += 1
end
end
end
redirect_to users_path, notice: "Updated contestants: #{updated}/#{total}"
end
private
def set_user

View File

@@ -68,7 +68,11 @@ class Completion < ApplicationRecord
self.time_seconds = arr[0].to_i
end
else
if self.contest.duration_seconds.present?
self.time_seconds = self.contest.duration_seconds
else
self.time_seconds = 2 * 3600
end
self.display_time_from_start = display_time(self.time_seconds)
end
end

View File

@@ -26,4 +26,8 @@ class UserPolicy < ApplicationPolicy
def destroy?
user.admin?
end
def update_contestants?
user.admin?
end
end

View File

@@ -25,3 +25,4 @@ table.table.table-striped.table-hover
.col
a.btn.btn-primary href=new_user_path
| New user
= button_to "Update contestants", "/update_contestants", method: :post, class: "mt-3 btn btn-success"

View File

@@ -36,6 +36,8 @@ Rails.application.routes.draw do
post "connect", to: "messages#connect"
post "message", to: "messages#create"
post "update_contestants", to: "users#update_contestants"
get "public/:id", to: "contests#scoreboard"
get "public/:id/offline", to: "contests#offline_new"
post "public/:id/offline", to: "contests#offline_create"