From b62cd32428ffa0c125d6f81e243cc9331196c2ad Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 22 Jul 2016 14:43:14 -0400 Subject: [PATCH] Fixes #370: Notify user when secret decryption fails --- netbox/project-static/js/secrets.js | 18 +++++++++++------- .../secrets/inc/private_key_modal.html | 5 ++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/netbox/project-static/js/secrets.js b/netbox/project-static/js/secrets.js index 21d8656e6..181984b71 100644 --- a/netbox/project-static/js/secrets.js +++ b/netbox/project-static/js/secrets.js @@ -10,15 +10,16 @@ $(document).ready(function() { $('#privkey_modal').modal('show'); } else { unlock_secret(secret_id, private_key); - $(this).hide(); - $(this).siblings('button.lock-secret').show(); } }); // Locking a secret $('button.lock-secret').click(function (event) { var secret_id = $(this).attr('secret-id'); - $('#secret_' + secret_id).html('********'); + var secret_div = $('#secret_' + secret_id); + + // Delete the plaintext + secret_div.html('********'); $(this).hide(); $(this).siblings('button.unlock-secret').show(); }); @@ -81,13 +82,16 @@ $(document).ready(function() { xhr.setRequestHeader("X-CSRFToken", csrf_token); }, success: function (response, status) { - var secret_plaintext = response.plaintext; - $('#secret_' + secret_id).html(secret_plaintext); - return true; + $('#secret_' + secret_id).html(response.plaintext); + $('button.unlock-secret').hide(); + $('button.lock-secret').show(); }, error: function (xhr, ajaxOptions, thrownError) { if (xhr.status == 403) { - alert("Decryption failed: " + xhr.statusText); + alert("Permission denied"); + } else { + var json = jQuery.parseJSON(xhr.responseText); + alert("Decryption failed: " + json['error']); } } }); diff --git a/netbox/templates/secrets/inc/private_key_modal.html b/netbox/templates/secrets/inc/private_key_modal.html index 5ab5400c3..0e1e6219a 100644 --- a/netbox/templates/secrets/inc/private_key_modal.html +++ b/netbox/templates/secrets/inc/private_key_modal.html @@ -17,7 +17,10 @@
- +