From eae61994be1f50fd45cd6647fac27e226fe687af Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 15 Sep 2019 04:35:05 +0500 Subject: [PATCH] Only display alert to key owners and superusers --- app/policies/private_key_policy.rb | 9 ++-- app/views/private_keys/_alert.html.erb | 66 ++++++++++++++------------ 2 files changed, 41 insertions(+), 34 deletions(-) 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? %> - + <% end %> <% end %>