Skip to content

THREESCALE-12434: Migrate from protected attributes to strong parameters - Part 2#4249

Draft
mayorova wants to merge 43 commits intostrong-params-part1from
strong-params-part2
Draft

THREESCALE-12434: Migrate from protected attributes to strong parameters - Part 2#4249
mayorova wants to merge 43 commits intostrong-params-part1from
strong-params-part2

Conversation

@mayorova
Copy link
Contributor

@mayorova mayorova commented Mar 11, 2026

What this PR does / why we need it:

This is part 2 of the migration from protected attributes to strong parameters. See the first part in #4248

Protected attributes is an old Rails feature which was deprecated a long time ago. We were using protected_attributes_continued gem to keep it working, but now it's also discontinued and does not support Rails 7+, so it's a blocker for upgrading to Rails 7.2 for us.

This Part 2 handles the models that can have custom attributes through FieldsDefinitions - Account, User, Cinstance.

Which issue(s) this PR fixes

https://redhat.atlassian.net/browse/THREESCALE-12434

Verification steps

All tests should pass, and all features should work as before.

Special notes for your reviewer:

Copy link
Contributor

@jlledom jlledom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments come from the other PR. Also, I still see a lot of

def update_resource(user, attributes)
attributes.each do |attrs|
user.attributes = filter_readonly_params(attrs, User)
user.attributes = filter_readonly_params(attrs, User).permit!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All permitted here? is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not good 😅 I guess it was some temporary thing, I'll need to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d8e75bc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should list permitted attributes here instead of permitting everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... this didn't break after removing the attr_accessible, so I missed it, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed implementation: fe5852b

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I removed the update_resource method from that controller anyway!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, great, it was just an example of which parameters were supposed to be permitted.

class CreateInvitedUser < Procedure

def call
user = invitation.make_user(user_data.to_hash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is user_data permitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, honestly, I didn't dig too deep into the OAuth flows, but in general user_data is some data that is returned from the OAuth server, when authenticated via a third-party, see https://github.com/3scale/porta/blob/master/app/lib/three_scale/oauth2/user_data.rb#L8-L20 for its possible fields.

In this case specifically, .to_hash is applied, so the data is reduced to a hash with two fields - :username and :email. As it's a plain hash (not ActionController::Params), there is no need to permit.

@mayorova mayorova force-pushed the strong-params-part2 branch 2 times, most recently from 38e277c to db25ecf Compare March 13, 2026 00:03
@account_params ||= begin
defined_fields_names = buyer_account.defined_fields_names
allowed_attrs = defined_fields_names - %w(billing_address) + %w(name)
nested_params = { extra_fields: buyer_account.defined_extra_fields_names }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is different from other API controller, which have only plain parameters, i.e. not nested under extra_fields.
I only did this because there was an existing test in test/integration/admin/api/accounts_controller_test.rb which was passing extra params in this way:

params: update_params.merge(extra_fields: { my_field: 4 })

I also added a check that plain parameters would also work.

Now I'm not sure if other API controllers need to accept both ways too 🤔

@mayorova mayorova force-pushed the strong-params-part2 branch 4 times, most recently from 070a9e0 to d8e75bc Compare March 13, 2026 18:40
jlledom and others added 2 commits March 16, 2026 09:31
Co-authored-by: Daria Mayorova <mayorova@users.noreply.github.com>
@mayorova mayorova force-pushed the strong-params-part2 branch from 6887355 to c7bf8ef Compare March 16, 2026 12:57
@mayorova mayorova force-pushed the strong-params-part2 branch from a676b21 to 8b5a6de Compare March 17, 2026 15:36
@mayorova mayorova changed the base branch from master to strong-params-part1 March 17, 2026 17:19
@mayorova mayorova changed the title Strong params part2 THREESCALE-12434: Migrate from protected attributes to strong parameters - Part 2 Mar 17, 2026
@mayorova mayorova force-pushed the strong-params-part1 branch from 0b8ead4 to 6c69623 Compare March 18, 2026 15:35
@mayorova mayorova force-pushed the strong-params-part2 branch 2 times, most recently from df4ba51 to 498f50b Compare March 18, 2026 17:34
@mayorova mayorova force-pushed the strong-params-part2 branch from 498f50b to 706cacb Compare March 18, 2026 17:47
@mayorova mayorova force-pushed the strong-params-part1 branch 2 times, most recently from bf3524b to a08b299 Compare March 18, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants