1
0
Fork 0

Only display alert to key owners and superusers

This commit is contained in:
Alex Kotov 2019-09-15 04:35:05 +05:00
parent be9156a5da
commit eae61994be
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 41 additions and 34 deletions

View file

@ -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

View file

@ -1,36 +1,40 @@
<% if policy(PrivateKey.new(asymmetric_key)).show? %>
<div class="alert alert-primary" role="alert">
<h4 class="alert-heading">
<%= translate '.primary_header' %>
</h4>
<% if policy(PrivateKey.new(asymmetric_key)).show_alert? %>
<% if policy(PrivateKey.new(asymmetric_key)).show? %>
<div class="alert alert-primary" role="alert">
<h4 class="alert-heading">
<%= translate '.primary_header' %>
</h4>
<hr/>
<hr/>
<p>
<%= translate(
'.primary_text',
delay: distance_of_time_in_words(AsymmetricKey::PRIVATE_KEY_CLEAR_DELAY),
<p>
<%= translate(
'.primary_text',
delay: distance_of_time_in_words(
AsymmetricKey::PRIVATE_KEY_CLEAR_DELAY,
),
) %>
</p>
<%= 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',
) %>
</p>
</div>
<% else %>
<div class="alert alert-secondary" role="alert">
<h4 class="alert-heading">
<%= translate '.secondary_header' %>
</h4>
<%= 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',
) %>
</div>
<% else %>
<div class="alert alert-secondary" role="alert">
<h4 class="alert-heading">
<%= translate '.secondary_header' %>
</h4>
<p>
<%= translate '.secondary_text' %>
</p>
</div>
<p>
<%= translate '.secondary_text' %>
</p>
</div>
<% end %>
<% end %>