Fix register last name
What does this MR do and why?
What
The previous MR was reverted after being merged, and now it is the second submission.
- Previous MR: !102637 (merged)
- Revert MR: !104545 (merged)
The reason for revert is: When feature flag arkose_labs_signup_challenge
is enabled, there will be serious errors in registration.
On the basis of the previous MR, I only added one change (as shown below) to solve the error caused by params[resource_name]
being equal to nil
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index 753bed2953a..2be7b72159e 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -174,10 +174,16 @@ def check_captcha
end
def ensure_first_name_and_last_name_not_empty
- return if params[resource_name][:first_name].present? && params[resource_name][:last_name].present?
+ # The key here will be affected by feature flag 'arkose_labs_signup_challenge'
+ # When flag is disabled, the key will be 'user' because #check_captcha will remove 'new_' prefix
+ # When flag is enabled, #check_captcha will be skipped, so the key will have 'new_' prefix
+ first_name = params.dig(resource_name, :first_name) || params.dig("new_#{resource_name}", :first_name)
+ last_name = params.dig(resource_name, :last_name) || params.dig("new_#{resource_name}", :last_name)
- resource.errors.add(_('First name'), _("cannot be blank")) if params[resource_name][:first_name].blank?
- resource.errors.add(_('Last name'), _("cannot be blank")) if params[resource_name][:last_name].blank?
+ return if first_name.present? && last_name.present?
+
+ resource.errors.add(_('First name'), _("cannot be blank")) if first_name.blank?
+ resource.errors.add(_('Last name'), _("cannot be blank")) if last_name.blank?
render action: 'new'
end
Why
Why does feature flag arkose_labs_signup_challenge
affect the key in registration params?
Edited by Zhiyuan Lu