Add method to update contestants through admin UI
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -26,4 +26,8 @@ class UserPolicy < ApplicationPolicy
|
||||
def destroy?
|
||||
user.admin?
|
||||
end
|
||||
|
||||
def update_contestants?
|
||||
user.admin?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user