Add "public" setting to contests
All checks were successful
CI / scan_ruby (push) Successful in 16s
CI / scan_js (push) Successful in 13s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 35s

This commit is contained in:
sto 2025-06-25 10:07:27 +02:00
parent 1a8ea0afee
commit 2b1a2c9296
9 changed files with 26 additions and 5 deletions

View File

@ -67,7 +67,7 @@ class ContestsController < ApplicationController
def scoreboard def scoreboard
@contest = Contest.find_by(slug: params[:id]) @contest = Contest.find_by(slug: params[:id])
unless @contest unless @contest && @contest.public
skip_authorization skip_authorization
not_found and return not_found and return
end end
@ -94,6 +94,6 @@ class ContestsController < ApplicationController
end end
def contest_params def contest_params
params.expect(contest: [ :lang, :name, :team, :allow_registration ]) params.expect(contest: [ :lang, :name, :public, :team, :allow_registration ])
end end
end end

View File

@ -6,6 +6,7 @@
# allow_registration :boolean default(FALSE) # allow_registration :boolean default(FALSE)
# lang :string default("en") # lang :string default("en")
# name :string # name :string
# public :boolean default(FALSE)
# slug :string # slug :string
# team :boolean default(FALSE) # team :boolean default(FALSE)
# created_at :datetime not null # created_at :datetime not null

View File

@ -9,6 +9,11 @@
.form-floating .form-floating
= form.select :lang, Languages::AVAILABLE_LANGUAGES.map { |lang| [ lang[:name], lang[:id] ] }, {}, class: "form-select" = form.select :lang, Languages::AVAILABLE_LANGUAGES.map { |lang| [ lang[:name], lang[:id] ] }, {}, class: "form-select"
= form.label :lang = form.label :lang
.row.mb-3
.col
.form-check.form-switch
= form.check_box :public, class: "form-check-input"
= form.label :public
.row.mb-3 .row.mb-3
.col .col
.form-check.form-switch .form-check.form-switch

View File

@ -14,8 +14,12 @@ javascript:
.row.mb-5 .row.mb-5
.col .col
a.btn.btn-success href="/public/#{@contest.slug}" - if @contest.public
= t("contests.show.open_public_scoreboard") a.btn.btn-success href="/public/#{@contest.slug}"
= t("contests.show.open_public_scoreboard")
- else
a.btn.btn-success.disabled
= t("contests.show.public_scoreboard_disabled")
button.btn.btn-success.ms-3 onclick="copyExtensionUrlToClipboard()" button.btn.btn-success.ms-3 onclick="copyExtensionUrlToClipboard()"
css: css:
button > svg { button > svg {

View File

@ -47,6 +47,7 @@ en:
contest: contest:
lang: Language for the public scoreboard lang: Language for the public scoreboard
name: Name name: Name
public: Enable the public scoreboard
team: Team contest team: Team contest
team_description: For UI display purposes mainly team_description: For UI display purposes mainly
allow_registration: Allow registration allow_registration: Allow registration
@ -141,6 +142,7 @@ en:
add_puzzle: Add puzzle add_puzzle: Add puzzle
copy_extension_url: Copy the URL for connecting from the browser extension copy_extension_url: Copy the URL for connecting from the browser extension
open_public_scoreboard: Open public scoreboard open_public_scoreboard: Open public scoreboard
public_scoreboard_disabled: The public scoreboard is disabled
url_copied: URL copied to the clipboard url_copied: URL copied to the clipboard
contestants: contestants:
convert_csv: convert_csv:

View File

@ -18,6 +18,7 @@ fr:
contest: contest:
lang: Langue pour le classement public lang: Langue pour le classement public
name: Nom name: Nom
public: Activer le classement public
team: Concours par équipes team: Concours par équipes
team_description: Principalement pour des raisons d'affichage team_description: Principalement pour des raisons d'affichage
allow_registration: Autoriser l'inscription via l'interface allow_registration: Autoriser l'inscription via l'interface
@ -112,6 +113,7 @@ fr:
add_puzzle: Ajouter un puzzle add_puzzle: Ajouter un puzzle
copy_extension_url: Copier l'URL pour la connexion depuis l'extension web copy_extension_url: Copier l'URL pour la connexion depuis l'extension web
open_public_scoreboard: Ouvrir le classement public open_public_scoreboard: Ouvrir le classement public
public_scoreboard_disabled: Le classement public n'est pas activé
url_copied: LURL a été copiée dans le presse-papier url_copied: LURL a été copiée dans le presse-papier
contestants: contestants:
convert_csv: convert_csv:

View File

@ -0,0 +1,5 @@
class AddPublicToContest < ActiveRecord::Migration[8.0]
def change
add_column :contests, :public, :boolean, default: false
end
end

3
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_06_20_051905) do ActiveRecord::Schema[8.0].define(version: 2025_06_25_075513) do
create_table "active_storage_attachments", force: :cascade do |t| create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
@ -75,6 +75,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_20_051905) do
t.boolean "allow_registration", default: false t.boolean "allow_registration", default: false
t.string "slug" t.string "slug"
t.string "lang", default: "en" t.string "lang", default: "en"
t.boolean "public", default: false
t.index ["slug"], name: "index_contests_on_slug", unique: true t.index ["slug"], name: "index_contests_on_slug", unique: true
t.index ["user_id"], name: "index_contests_on_user_id" t.index ["user_id"], name: "index_contests_on_user_id"
end end

View File

@ -6,6 +6,7 @@
# allow_registration :boolean default(FALSE) # allow_registration :boolean default(FALSE)
# lang :string default("en") # lang :string default("en")
# name :string # name :string
# public :boolean default(FALSE)
# slug :string # slug :string
# team :boolean default(FALSE) # team :boolean default(FALSE)
# created_at :datetime not null # created_at :datetime not null