Skip to content

Add MongoMapper.filter_attributes#709

Merged
a2ikm merged 8 commits into
mongomapper:masterfrom
mopp:add_filter_attributes
Jul 5, 2022
Merged

Add MongoMapper.filter_attributes#709
a2ikm merged 8 commits into
mongomapper:masterfrom
mopp:add_filter_attributes

Conversation

@mopp

@mopp mopp commented Jul 4, 2022

Copy link
Copy Markdown
Contributor

Background

The ActiveRecord has filter_attributes option in order to conceal private information such as user email address.
See also rails/rails#33756
So we would like to do the same thing on the mongomapper.

What we did

We added filter_attributes option and made #inspect filter the value based on the given keywords.

Comment thread lib/mongo_mapper/utils.rb
Comment on lines +13 to +15
if ActiveSupport.version >= Gem::Version.new("6.0")
@filter ||= begin
require "active_support/parameter_filter"

@mopp mopp Jul 4, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

parameter_filter exists in ActionPack in Rails 5.x.
Then, we have to check the version and add branches to support it.

Rails 5.x was already EOL.
So we suggest dropping the support for Rails 5.x to keep the implementation simple.

Rails 5.2.Z is included in the list of supported series until June 1st 2022.

https://guides.rubyonrails.org/maintenance_policy.html#severe-security-issues

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great feature!

I think we should leave in the 5.x support for now since it was so recently removed and since the conditional code is already there. I suspect there are also a lot of people running rails 5.2. (looks like ~ 17% are on 5.2 - https://rails-hosting.com/2022/#what-versions-of-rails-are-you-using-in-your-applications).

With that said, I think in the next few months we should drop rails 5.2 support, but only do it with a major version upgrade.

Also, I suspect that once the rails team stops providing security updates to rails 5.2 it will encourage a majority of users to upgrade.

So let's leave in the conditional code for now but plan to remove it in the next few months with mongomapper v16

@mopp mopp Jul 5, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, thanks for your comment based on the evidence 👍
Let's keep the conditional code!

remove it in the next few months with mongomapper v16

👍 👍 👍

@a2ikm a2ikm Jul 5, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good 👍
I will add a deprecation warning for v16 with another PR.

@a2ikm a2ikm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution!
This feature improves the security and the compatibility with ActiveRecord.
I think it's ok to merge this PR now.

On the other hand, as @mopp commented, the incompatibility between Rails 5.x and 6.0+ makes the code complex. I think we should drop Rails 5.x support.
(Of course, we need some deprecation warning before that)

@smtlaissezfaire How do you think?

@a2ikm a2ikm requested a review from smtlaissezfaire July 4, 2022 09:10
@mopp

mopp commented Jul 5, 2022

Copy link
Copy Markdown
Contributor Author

Please merge this PR if you are ready ✨

@a2ikm a2ikm merged commit 6b9694a into mongomapper:master Jul 5, 2022
@mopp mopp deleted the add_filter_attributes branch July 5, 2022 23:58
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.

4 participants