-
Notifications
You must be signed in to change notification settings - Fork 72
[WIP] [PoC] Migrate from protected attributes to strong parameters #4238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4ca06ef
Migrate protected attrs to strong params for User-related controllers
mayorova f30629d
Update test for User-related controllers
mayorova cbe7b54
Fix tests related to user model
mayorova 97be0c3
Fix rspecs broken by duplicate field definitions creation
mayorova 305efc5
Fix more tests and refactor invitation signup flow
mayorova 60f881c
Remove TODO comments
mayorova a4a6540
Migrate to strong parameters for usage limits
mayorova dc62875
Remove attr_accessible for application_key
mayorova 563faf7
Remove attr_accessible for referrer_filter
mayorova b4c8211
Migrate access tokens controller to strong params
mayorova 30d5255
Remove attr_accessible for line_item
mayorova 24a509b
Migrate invoice to strong parameters
mayorova 0ddc0c5
Migrate signup flow to strong parameters
mayorova 269a25e
Fix invoice controller
mayorova 81f7063
Further fixes for account create/update
mayorova ca63300
Fix CMS groups update and add a test
mayorova 17c7232
Small fixes
mayorova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic was actually problematic.
There are some fields under User model that are "standard", but not required:
When they are added in FieldsDefinitions, the fields appear in the Edit form and can be updated. Here is what the
params.require(:user)looks like in this case:However, the further
permitfilters them out in a way, that only the ones listed inDEFAULT_PARAMSare kept, along with theextra_fields, however, theextra_fieldsonly contain the actually custom fields, so theuser_paramsresults in:Hence, title, first_name, last_name and job_role can never be updated through the UI - I think it's a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, these special fields ('title', 'first_name', 'last_name' and 'job_role'), if defined as extra fields, need to be accepted at the lower level, not under
extra_fields.This looks like a bug in either UI or in the way params are permitted.
I would probably rather fix how UI pass them down but also checking for them and permitting them on the lower level is also good. I assume on the API side they already have to be passed udder extra fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it depends on whether it's a UI controller or API.
In the API, all parameters (standard and custom) are accepted at the same level (as
userattributes). In the UI, they are nested underextra_fields.The comment is not about that, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the comment about then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the issue is not about where the parameters appear - at the "root" user level, or under
extra_fields. As I explained, in the UI forms only truly custom (created by user) fields appear underextra_fields, others are at the "root" level along withusernameandpassword(they are actually normal attributes, that have a corresponding column in the DB).The problem is that this
DEFAULT_PARAMSdoesn't include the "optional" fields -:title, :first_name, :last_name, :job_role. So, even if they are defined through the fields definitions, they can not be updated through the UI, because they are removed from the list of permitteduser_params.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hang on, once I fix the tests and push the latest updates, I'll explain the new implementation. It has some drawbacks too, but hopefully it can work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this explanation still sounds the same. And basically the fix is to either:
extra_fieldswhere they will be permitted due to them being defined as extra fieldsuserlevel paramsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this comment will clarify things 🙏 https://github.com/3scale/porta/pull/4238/changes#r2895692403