From e6a6a7488235ed3e94612f2b8873c1bbfb2ab7c7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 27 Aug 2025 11:31:54 -0400 Subject: [PATCH 1/4] Use partial for rule translation loop during registration --- app/controllers/auth/registrations_controller.rb | 5 ++++- app/views/auth/registrations/rules.html.haml | 7 +------ .../auth/rule_translations/_rule_translation.html.haml | 4 ++++ 3 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 app/views/auth/rule_translations/_rule_translation.html.haml diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index fc430544fbe..1a8d8a46510 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -135,7 +135,10 @@ class Auth::RegistrationsController < Devise::RegistrationsController @accept_token = session[:accept_token] = SecureRandom.hex @invite_code = invite_code - set_locale { render :rules } + set_locale do + @rule_translations = @rules.map { |rule| rule.translation_for(I18n.locale) } + render :rules + end end def is_flashing_format? # rubocop:disable Naming/PredicatePrefix diff --git a/app/views/auth/registrations/rules.html.haml b/app/views/auth/registrations/rules.html.haml index 59e7c9072fb..06fd87259a3 100644 --- a/app/views/auth/registrations/rules.html.haml +++ b/app/views/auth/registrations/rules.html.haml @@ -17,12 +17,7 @@ %p.lead= t('auth.rules.preamble', domain: site_hostname) %ol.rules-list - - @rules.each do |rule| - - translation = rule.translation_for(I18n.locale.to_s) - %li - %button{ type: 'button', aria: { expanded: 'false' } } - .rules-list__text= translation.text - .rules-list__hint= translation.hint + = render @rule_translations .stacked-actions - accept_path = @invite_code.present? ? public_invite_url(invite_code: @invite_code, accept: @accept_token) : new_user_registration_path(accept: @accept_token) diff --git a/app/views/auth/rule_translations/_rule_translation.html.haml b/app/views/auth/rule_translations/_rule_translation.html.haml new file mode 100644 index 00000000000..32b9cc28af1 --- /dev/null +++ b/app/views/auth/rule_translations/_rule_translation.html.haml @@ -0,0 +1,4 @@ +%li + %button{ type: 'button', aria: { expanded: 'false' } } + .rules-list__text= rule_translation.text + .rules-list__hint= rule_translation.hint From 84f5bb5ac01e972c4e28a298a5b7e516495c51a4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 27 Aug 2025 14:15:39 -0400 Subject: [PATCH 2/4] Remove double call to `set_locale` --- app/controllers/auth/registrations_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 1a8d8a46510..898d204d2d9 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -135,10 +135,8 @@ class Auth::RegistrationsController < Devise::RegistrationsController @accept_token = session[:accept_token] = SecureRandom.hex @invite_code = invite_code - set_locale do - @rule_translations = @rules.map { |rule| rule.translation_for(I18n.locale) } - render :rules - end + @rule_translations = @rules.map { |rule| rule.translation_for(I18n.locale) } + render :rules end def is_flashing_format? # rubocop:disable Naming/PredicatePrefix From 0d5a72aef5d5ce53e7a9ea59b7c1c464985406ec Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 27 Aug 2025 14:20:43 -0400 Subject: [PATCH 3/4] Method to check accept token value --- app/controllers/auth/registrations_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 898d204d2d9..6390773b4b7 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -130,7 +130,7 @@ class Auth::RegistrationsController < Devise::RegistrationsController end def require_rules_acceptance! - return if @rules.empty? || (session[:accept_token].present? && params[:accept] == session[:accept_token]) + return if @rules.empty? || validated_accept_token? @accept_token = session[:accept_token] = SecureRandom.hex @invite_code = invite_code @@ -139,6 +139,10 @@ class Auth::RegistrationsController < Devise::RegistrationsController render :rules end + def validated_accept_token? + session[:accept_token].present? && params[:accept] == session[:accept_token] + end + def is_flashing_format? # rubocop:disable Naming/PredicatePrefix if params[:action] == 'create' false # Disable flash messages for sign-up From a2241da91afaf92d9942d00441c616b29275550c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 27 Aug 2025 14:21:16 -0400 Subject: [PATCH 4/4] i-var group together --- app/controllers/auth/registrations_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index 6390773b4b7..c6c96b9acdf 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -133,9 +133,9 @@ class Auth::RegistrationsController < Devise::RegistrationsController return if @rules.empty? || validated_accept_token? @accept_token = session[:accept_token] = SecureRandom.hex - @invite_code = invite_code - + @invite_code = invite_code @rule_translations = @rules.map { |rule| rule.translation_for(I18n.locale) } + render :rules end