ankane / lockbox

Modern encryption for Ruby and Rails
MIT License
1.44k stars 68 forks source link

RailsAdmin and/or ActiveAdmin Use #116

Closed georgioskap closed 3 years ago

georgioskap commented 3 years ago

Hi, is there an easy way to get RailsAdmin and/or ActiveAdmin gems working wit lockbox? It looks like they are accessing the databse fields directly so I cannot do any admin as all I can see are the ciphertext fields. I'd rather avoid rebuilding the admin backend from scratch if there's an easier way.

ankane commented 3 years ago

Hey @georgioskap, you should be able to use virtual fields with RailsAdmin (and I imagine ActiveAdmin has something similar).

x9sim9 commented 3 years ago

I am using activeadmin with lockbox I think you just need to define the fields in each register method

example:

index do
  column :field_name
end

if you define the fields rather than leaving it blank it works fine for me

georgioskap commented 3 years ago

Thanks both. I worked out a solution for RailsAdmin. It used the suggested solution here https://github.com/sferik/rails_admin/issues/3241#issuecomment-607581466 along with this code in RailsAdmin config:

  required_models = ["Model1", "Model2"]  
  required_models.each do |act_model|
    config.model act_model do
      include_all_fields
      Object.const_get(act_model).column_names.each do |c|
          field c.gsub('_ciphertext','').to_sym if c.match("_ciphertext")  
      end
      exclude_fields :created_at, :updated_at
      exclude_fields_if do
        name =~ /_bidx|_ciphertext/
      end
    end
  end
ankane commented 3 years ago

Thank you both for sharing!