fix: use getter method for bot protection level check#4297
Open
fix: use getter method for bot protection level check#4297
Conversation
settings[field] reads the raw DB column value, bypassing the custom getter that handles nil values. For accounts where admin_bot_protection_level was never set (e.g. master), the column is nil, causing `nil.to_sym` to raise NoMethodError. Using public_send(field) calls the proper getter which returns :none for nil values and normalizes :auto to :captcha. Co-Authored-By: Claude <noreply@anthropic.com>
akostadinov
previously approved these changes
May 8, 2026
Contributor
|
Good, but how about a small test for this one? Just to make sure we don't hit this regression again. |
Ensures the security settings page renders when admin_bot_protection_level is nil in the database, which is the scenario that caused a NoMethodError on master portal. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
Here: da7e27f |
❌ 1 blocking issue (1 total)
|
mayorova
reviewed
May 8, 2026
| test 'edit with nil admin_bot_protection_level' do | ||
| @provider.settings.update_column(:admin_bot_protection_level, nil) | ||
| get edit_provider_admin_security_path | ||
| assert_response :success |
Contributor
There was a problem hiding this comment.
Suggested change
| assert_response :success | |
| assert_response :success | |
| assert_xpath '//input[@type="radio"][@name="settings[admin_bot_protection_level]"][@value="none"][@checked]' |
We could potentially add this assertion, to make it clear, what's expected when the value is nil.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
In the Captcha radio button, the values we expect are either
noneorcaptcha. However, we got a lot of old records in SaaS which value in the column is empty orNULL.Instead of backfilling, I created a small migration code in the settings getter:
porta/app/models/settings.rb
Lines 97 to 100 in 35a2706
In the Permissions Policy PR (#4264) we migrated the form to Patternfly, and in the process we started to call
settings[field]directly, which bypasses the getter.Which issue(s) this PR fixes
No Jira issue
Verification steps
admin_bot_protection_levelcolumn toNULLin thesettingstable, for a provider, no need for it to be master.