Events: add edit/update actions
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run

This commit is contained in:
sto
2026-07-28 13:45:27 +02:00
parent 17d99a92c0
commit b8a2e4b0b4
6 changed files with 49 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
class EventsController < ApplicationController class EventsController < ApplicationController
before_action :set_event, only: %i[ destroy show ] before_action :set_event, only: %i[ destroy show edit update ]
def index def index
authorize :event authorize :event
@@ -20,7 +20,7 @@ class EventsController < ApplicationController
def create def create
authorize :event authorize :event
@event = Event.new(new_event_params) @event = Event.new(event_params)
@event.lang = @current_user.lang @event.lang = @current_user.lang
@event.user_id = current_user.id @event.user_id = current_user.id
if @event.save if @event.save
@@ -39,6 +39,25 @@ class EventsController < ApplicationController
@title = @event.name @title = @event.name
end end
def edit
authorize @event
@title = I18n.t("events.edit.title")
@nonav = true
end
def update
authorize @event
if @event.update(event_params)
redirect_to event_path(@event), notice: t("events.edit.notice")
else
@title = I18n.t("events.edit.title")
@nonav = true
render :edit, status: :unprocessable_entity
end
end
def destroy def destroy
authorize @event authorize @event
@@ -50,7 +69,7 @@ class EventsController < ApplicationController
@event = Event.find(params[:id]) @event = Event.find(params[:id])
end end
def new_event_params def event_params
params.expect(event: [ :name, :shared_scoreboard ]) params.expect(event: [ :name, :shared_scoreboard ])
end end
end end

View File

@@ -22,4 +22,12 @@ class EventPolicy < ApplicationPolicy
def show? def show?
owner_or_admin owner_or_admin
end end
def edit?
owner_or_admin
end
def update?
owner_or_admin
end
end end

View File

@@ -0,0 +1 @@
= render "form", event: @event, submit_text: t("helpers.buttons.save"), method: :patch, url: event_path(@event)

View File

@@ -1,10 +1,12 @@
.row .row
.col .col
h4.mb-3 h4.mb-3 style="margin-top: -1rem;"
= t("events.index.manage_contests") = t("events.show.manage_contests")
a.ms-3.mt-3.btn.btn-primary.mb-4 href=edit_event_path(@event)
= t("events.show.modify")
.float-end .float-end
a.btn.btn-primary.mb-4 href=new_contest_path(event: @event.id) a.mt-3.btn.btn-primary.mb-4 href=new_contest_path(event: @event.id)
= t("events.index.new_contest") = t("events.show.new_contest")
.row.row-cols-1.row-cols-md-3.g-4 .row.row-cols-1.row-cols-md-3.g-4
- @contests.each do |contest| - @contests.each do |contest|

View File

@@ -289,16 +289,16 @@ en:
events: events:
destroy: destroy:
notice: Event deleted notice: Event deleted
edit:
notice: Event updated
form: form:
shared_scoreboard_message: As safety measure, for each tab, no information will be shown until the first finish, or if the stopwatch for that contest is started. shared_scoreboard_message: As safety measure, for each tab, no information will be shown until the first finish, or if the stopwatch for that contest is started.
index: index:
contest: contest contest: contest
contests: contests contests: contests
manage_contests: Contests in this event
message: New feature! Events offer to groupe multiple contests in one management space. This also offers, if activated, to have a single scoreboard link for all contests of an event. message: New feature! Events offer to groupe multiple contests in one management space. This also offers, if activated, to have a single scoreboard link for all contests of an event.
my_contests_outside_events: My contests not linked to any event my_contests_outside_events: My contests not linked to any event
new: Create a new event new: Create a new event
new_contest: Add a contest to this event
other_contest: contest other_contest: contest
other_contests: contests other_contests: contests
subtitle: My events subtitle: My events
@@ -306,6 +306,10 @@ en:
new: new:
notice: Event added notice: Event added
title: New event title: New event
show:
manage_contests: Contests in this event
modify: Settings
new_contest: Add a contest to this event
helpers: helpers:
badges: badges:
registration: "registration" registration: "registration"

View File

@@ -260,16 +260,16 @@ fr:
events: events:
destroy: destroy:
notice: Événement supprimé notice: Événement supprimé
edit:
notice: Événement modifié
form: form:
shared_scoreboard_message: Par mesure de sécurité, chaque onglet restera vide jusqu'à ce que soit il y a des premières complétions, soit le chronomètre de l'épreuve a été démarré. shared_scoreboard_message: Par mesure de sécurité, chaque onglet restera vide jusqu'à ce que soit il y a des premières complétions, soit le chronomètre de l'épreuve a été démarré.
index: index:
contest: épreuve contest: épreuve
contests: épreuves contests: épreuves
manage_contests: Épreuves de cet événement
message: Nouvelle fonctionalité ! Les événements permettent de regrouper plusieurs concours/épreuves en un seul espace de gestion. Cela permet aussi, si souhaité, d'avoir un lien de classement commun à toutes les épreuces d'un même événement. message: Nouvelle fonctionalité ! Les événements permettent de regrouper plusieurs concours/épreuves en un seul espace de gestion. Cela permet aussi, si souhaité, d'avoir un lien de classement commun à toutes les épreuces d'un même événement.
my_contests_outside_events: Mes concours non associés à un événement my_contests_outside_events: Mes concours non associés à un événement
new: Créer un nouvel événement new: Créer un nouvel événement
new_contest: Ajouter une épreuve à cet événement
other_contest: concours other_contest: concours
other_contests: concours other_contests: concours
subtitle: Mes événements subtitle: Mes événements
@@ -277,6 +277,10 @@ fr:
new: new:
notice: Événement ajouté notice: Événement ajouté
title: Nouvel événement title: Nouvel événement
show:
manage_contests: Épreuves de cet événement
modify: Paramètres
new_contest: Ajouter une épreuve à cet événement
helpers: helpers:
badges: badges:
registration: "auto-inscription" registration: "auto-inscription"