diff --git a/app/policies/private_key_policy.rb b/app/policies/private_key_policy.rb index 6f08910..e7df983 100644 --- a/app/policies/private_key_policy.rb +++ b/app/policies/private_key_policy.rb @@ -2,10 +2,13 @@ class PrivateKeyPolicy < ApplicationPolicy def show? + show_alert? && record.exist? + end + + def show_alert? return false if account.nil? - (account.superuser? || account == record.account) && - record.exist? && - params[:private_key_pem_secret].present? + params[:private_key_pem_secret].present? && + (account.superuser? || account == record.account) end end diff --git a/app/views/private_keys/_alert.html.erb b/app/views/private_keys/_alert.html.erb index 91ba6d5..d7ab38e 100644 --- a/app/views/private_keys/_alert.html.erb +++ b/app/views/private_keys/_alert.html.erb @@ -1,36 +1,40 @@ -<% if policy(PrivateKey.new(asymmetric_key)).show? %> -
- <%= translate( - '.primary_text', - delay: distance_of_time_in_words(AsymmetricKey::PRIVATE_KEY_CLEAR_DELAY), +
+ <%= translate( + '.primary_text', + delay: distance_of_time_in_words( + AsymmetricKey::PRIVATE_KEY_CLEAR_DELAY, + ), + ) %> +
+ + <%= link_to( + translate('.link'), + asymmetric_key_private_key_path( + asymmetric_key, + format: :key, + private_key_pem_secret: params[:private_key_pem_secret], + ), + class: 'btn btn-primary', ) %> - +- <%= translate '.secondary_text' %> -
-+ <%= translate '.secondary_text' %> +
+