Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix/handle old uncrypted value #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/active_admin_versioning/active_admin/views/pages/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,38 @@ def filter_methods
end

def decrypt_field(method, value)
pp method
pp 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
Expand Down