From 2b1a2c92964679be7da709e7ac3ebab9bdd3f388 Mon Sep 17 00:00:00 2001 From: sto Date: Wed, 25 Jun 2025 10:07:27 +0200 Subject: [PATCH] Add "public" setting to contests --- app/controllers/contests_controller.rb | 4 ++-- app/models/contest.rb | 1 + app/views/contests/_form.html.slim | 5 +++++ app/views/contests/show.html.slim | 8 ++++++-- config/locales/en.yml | 2 ++ config/locales/fr.yml | 2 ++ db/migrate/20250625075513_add_public_to_contest.rb | 5 +++++ db/schema.rb | 3 ++- spec/factories/contests.rb | 1 + 9 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20250625075513_add_public_to_contest.rb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index f5bf010..ed10354 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -67,7 +67,7 @@ class ContestsController < ApplicationController def scoreboard @contest = Contest.find_by(slug: params[:id]) - unless @contest + unless @contest && @contest.public skip_authorization not_found and return end @@ -94,6 +94,6 @@ class ContestsController < ApplicationController end def contest_params - params.expect(contest: [ :lang, :name, :team, :allow_registration ]) + params.expect(contest: [ :lang, :name, :public, :team, :allow_registration ]) end end diff --git a/app/models/contest.rb b/app/models/contest.rb index 1b46a46..0a094b0 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -6,6 +6,7 @@ # allow_registration :boolean default(FALSE) # lang :string default("en") # name :string +# public :boolean default(FALSE) # slug :string # team :boolean default(FALSE) # created_at :datetime not null diff --git a/app/views/contests/_form.html.slim b/app/views/contests/_form.html.slim index fad3110..c242aec 100644 --- a/app/views/contests/_form.html.slim +++ b/app/views/contests/_form.html.slim @@ -9,6 +9,11 @@ .form-floating = form.select :lang, Languages::AVAILABLE_LANGUAGES.map { |lang| [ lang[:name], lang[:id] ] }, {}, class: "form-select" = 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 .col .form-check.form-switch diff --git a/app/views/contests/show.html.slim b/app/views/contests/show.html.slim index b4c1398..51fc07d 100644 --- a/app/views/contests/show.html.slim +++ b/app/views/contests/show.html.slim @@ -14,8 +14,12 @@ javascript: .row.mb-5 .col - a.btn.btn-success href="/public/#{@contest.slug}" - = t("contests.show.open_public_scoreboard") + - if @contest.public + 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()" css: button > svg { diff --git a/config/locales/en.yml b/config/locales/en.yml index 3fc63ed..cc3d534 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -47,6 +47,7 @@ en: contest: lang: Language for the public scoreboard name: Name + public: Enable the public scoreboard team: Team contest team_description: For UI display purposes mainly allow_registration: Allow registration @@ -141,6 +142,7 @@ en: add_puzzle: Add puzzle copy_extension_url: Copy the URL for connecting from the browser extension open_public_scoreboard: Open public scoreboard + public_scoreboard_disabled: The public scoreboard is disabled url_copied: URL copied to the clipboard contestants: convert_csv: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2f4a3c2..8b3b335 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -18,6 +18,7 @@ fr: contest: lang: Langue pour le classement public name: Nom + public: Activer le classement public team: Concours par équipes team_description: Principalement pour des raisons d'affichage allow_registration: Autoriser l'inscription via l'interface @@ -112,6 +113,7 @@ fr: add_puzzle: Ajouter un puzzle copy_extension_url: Copier l'URL pour la connexion depuis l'extension web open_public_scoreboard: Ouvrir le classement public + public_scoreboard_disabled: Le classement public n'est pas activé url_copied: L’URL a été copiée dans le presse-papier contestants: convert_csv: diff --git a/db/migrate/20250625075513_add_public_to_contest.rb b/db/migrate/20250625075513_add_public_to_contest.rb new file mode 100644 index 0000000..5b64811 --- /dev/null +++ b/db/migrate/20250625075513_add_public_to_contest.rb @@ -0,0 +1,5 @@ +class AddPublicToContest < ActiveRecord::Migration[8.0] + def change + add_column :contests, :public, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 82b4f11..49268c3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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| t.string "name", 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.string "slug" t.string "lang", default: "en" + t.boolean "public", default: false t.index ["slug"], name: "index_contests_on_slug", unique: true t.index ["user_id"], name: "index_contests_on_user_id" end diff --git a/spec/factories/contests.rb b/spec/factories/contests.rb index 043a1a3..f9be5d0 100644 --- a/spec/factories/contests.rb +++ b/spec/factories/contests.rb @@ -6,6 +6,7 @@ # allow_registration :boolean default(FALSE) # lang :string default("en") # name :string +# public :boolean default(FALSE) # slug :string # team :boolean default(FALSE) # created_at :datetime not null