reidmorrison / symmetric-encryption

Symmetric Encryption for Ruby Projects using OpenSSL
https://logger.rocketjob.github.io/
Apache License 2.0
476 stars 92 forks source link

Replaced method name to avoid conflict with Rails 7 method name #156

Closed kaiserbrito closed 2 years ago

kaiserbrito commented 2 years ago

Issue # (if available)

Description of changes

Replaced method encrypted_attributes for symmetric_encrypted_attributes to avoid conflicts when upgrading Rails to version 7, which has an implementation of this method encrypted_attributes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

vineelvineel commented 2 years ago

@reidmorrison Can you merge this PR? This fixes the method name conflict with the newer version of rails.

vineelvineel commented 2 years ago

Hey @reidmorrison Any chance that you have sometime to merge this PR. This PR fixes the method name conflict with rails 7. Let me know if you need any help with this. Thanks.

reidmorrison commented 2 years ago

Unfortunately, this is a breaking change which means we need a new major release to implement it. I know it will break our applications that use this method.

reidmorrison commented 2 years ago

Ok, figured out a solution. With Rails 7, it now removes the old attributes_encrypted approach entirely.

    # Remove old way of defining attributes with Rails 7 since it conflicts with the method names.
    if ActiveRecord.version <= Gem::Version.new("7.0.0")
      ActiveRecord::Base.include(SymmetricEncryption::ActiveRecord::AttrEncrypted)
    end

So for Rails 7 and above we need to upgrade to the new Active Record Attributes API. See https://encryption.rocketjob.io/frameworks.html

This change is in v4.5.0. Let me know if this works for you?

reidmorrison commented 2 years ago

Please re-open if the change above does not address the issue.

vieenaysiingh commented 2 years ago

with v4.5.0, I am still getting method_missing': undefined methodattr_encrypted. I use Rails 7.0.1 with symmetric-encryption v4.5.0. Is there any workaround here? I have used it as below attr_encrypted :authentication_token in my User model.

reidmorrison commented 2 years ago

Correct, attr_encrypted is no longer available when using Rails 7. The newer approach is documented here: https://encryption.rocketjob.io/frameworks.html.