Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Creating a custom field for "EncryptedField": value parsed twice #2755

Closed
Rodrigora opened this issue Nov 3, 2016 · 0 comments
Closed

Creating a custom field for "EncryptedField": value parsed twice #2755

Rodrigora opened this issue Nov 3, 2016 · 0 comments
Milestone

Comments

@Rodrigora
Copy link

Hi there,

I'm struggling to create a custom field for fields encrypted by the symmetric-encryption gem.

For what I learned from your documentation and your source code, I just need to implement a new type and implement the method parse_value(value) which is called prior to the query build.

So, that's is my code:

module RailsAdmin
  module Config
    module Fields
      module Types
        class EncryptedField < RailsAdmin::Config::Fields::Types::String
          RailsAdmin::Config::Fields::Types::register(self)

          def parse_value(value)
            SymmetricEncryption.encrypt(value)
          end
        end
      end
    end
  end
end

RailsAdmin.config do |config|
  config.model 'User' do
    list do
      field :email, :encrypted_field do
        searchable ['encrypted_email'] 
        queryable true
      end
    end
end

Ok, the problem is on the ActiveRecord adapter, which calls the method parse_value twice before building the query:
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/adapters/active_record.rb#L102
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/adapters/active_record.rb#L127

Before forking and removing one call for the parse_value method, I would like to know if there's a reason for this (will it break something else?). If no, I can submit a PR.

Thanks!

@mshibuya mshibuya added this to the 2.0.0 milestone May 28, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants