From 85b788576f8fdff39b0423fcc5f25d6240641ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Delmaire=20Lo=C3=AFc?= Date: Tue, 7 Jul 2026 12:03:01 +0200 Subject: [PATCH] Reset blacklisted_at when regenerating a banned token When banning a token with regeneration, the Ban organizer runs BanToken (which sets blacklisted_at on the original token) then RegenerateToken, which builds the replacement via token.dup. dup copies every attribute including the freshly-set blacklisted_at, so the regenerated token was born banned and would expire at the exact same moment as the token it was meant to replace, defeating the purpose of regeneration. Explicitly clear blacklisted_at on the duplicate so the new token is actually active. --- site/app/interactors/admin/tokens/regenerate_token.rb | 1 + site/spec/organizers/admin/tokens/ban_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/site/app/interactors/admin/tokens/regenerate_token.rb b/site/app/interactors/admin/tokens/regenerate_token.rb index 8f5a9a3ad0..e422a7fff6 100644 --- a/site/app/interactors/admin/tokens/regenerate_token.rb +++ b/site/app/interactors/admin/tokens/regenerate_token.rb @@ -13,6 +13,7 @@ def generate_new_token? def create_new_token copy = token.dup + copy.blacklisted_at = nil copy.iat = Time.zone.now.to_i copy.save copy diff --git a/site/spec/organizers/admin/tokens/ban_spec.rb b/site/spec/organizers/admin/tokens/ban_spec.rb index 6b604b517d..050a50cb1b 100644 --- a/site/spec/organizers/admin/tokens/ban_spec.rb +++ b/site/spec/organizers/admin/tokens/ban_spec.rb @@ -27,6 +27,12 @@ expect(new_token.iat).to be_within(5).of(Time.zone.now.to_i) end + it 'does not blacklist the newly generated token' do + subject + new_token = Token.where.not(id: token.id).order(created_at: :desc).first + expect(new_token.blacklisted_at).to be_nil + end + it 'sends emails to demandeur and contact technique' do expect { subject }.to have_enqueued_job(ActionMailer::MailDeliveryJob).at_least(2).times end