From 7c20478eda9d21492b487b5140771430fdbdc38d Mon Sep 17 00:00:00 2001 From: SebastienLauret Date: Wed, 10 May 2023 17:21:03 +0200 Subject: [PATCH 1/2] feat(encrypted): handle old encrypted value --- .../active_admin/views/pages/show.rb | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/active_admin_versioning/active_admin/views/pages/show.rb b/lib/active_admin_versioning/active_admin/views/pages/show.rb index 2f002b7..3bbe040 100644 --- a/lib/active_admin_versioning/active_admin/views/pages/show.rb +++ b/lib/active_admin_versioning/active_admin/views/pages/show.rb @@ -55,13 +55,35 @@ def filter_methods def decrypt_field(method, value) if method.end_with? "_ciphertext" - resource.class.send("decrypt_#{method}", value) + decrypte_value(method, value) else value end rescue Lockbox::DecryptionError value end + + def decrypte_value(method, value) + klass = resource.class + + return klass.send(decrypted_method(method), value) if klass.respond_to? decrypted_method(method) + + klass.encrypt_and_blind_index(base_method(method) => { type: :string }) + + value = klass.send(decrypted_method(method), value) + + klass.reset_column_information + + value + end + + def base_method(method) + method.match(/(.*)_ciphertext/)[1] + end + + def decrypted_method(method) + "decrypt_#{method}" + end end end end From cbad59ef3660d45ac38e488b326ae58e09235ee7 Mon Sep 17 00:00:00 2001 From: SebastienLauret Date: Tue, 6 Jun 2023 13:41:58 +0200 Subject: [PATCH 2/2] fix(show): encrypted feild --- lib/active_admin_versioning/active_admin/views/pages/show.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_admin_versioning/active_admin/views/pages/show.rb b/lib/active_admin_versioning/active_admin/views/pages/show.rb index 3bbe040..ea9a892 100644 --- a/lib/active_admin_versioning/active_admin/views/pages/show.rb +++ b/lib/active_admin_versioning/active_admin/views/pages/show.rb @@ -54,6 +54,8 @@ def filter_methods end def decrypt_field(method, value) + pp method + pp value if method.end_with? "_ciphertext" decrypte_value(method, value) else