You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2016/10/28 16:46:04 UTC

[15/20] airavata-php-gateway git commit: AIRAVATA-2156 Prevent deleting default SSH key

AIRAVATA-2156 Prevent deleting default SSH key

Also fixes for the client-side description field validation


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/a90dfedb
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/a90dfedb
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/a90dfedb

Branch: refs/heads/develop
Commit: a90dfedb1b51ce8de956ccc2b450a6269dc30b99
Parents: 9bc02d0
Author: Marcus Christie <ma...@iu.edu>
Authored: Thu Oct 27 10:37:56 2016 -0400
Committer: Marcus Christie <ma...@iu.edu>
Committed: Thu Oct 27 10:37:56 2016 -0400

----------------------------------------------------------------------
 app/controllers/AccountController.php        |  8 ++++++++
 app/views/account/credential-store.blade.php | 18 +++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a90dfedb/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index bd8091d..b5361b5 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -473,6 +473,9 @@ class AccountController extends BaseController
         $userCredentialSummaries = URPUtilities::get_all_ssh_pub_keys_summary_for_user();
         $credentialSummaryMap = $this->create_credential_summary_map(URPUtilities::get_all_ssh_pub_keys_summary_for_user());
         $defaultCredentialSummary = $credentialSummaryMap[$userResourceProfile->credentialStoreToken];
+        foreach ($userCredentialSummaries as $credentialSummary) {
+            $credentialSummary->canDelete = ($credentialSummary->token != $defaultCredentialSummary->token);
+        }
 
         return View::make("account/credential-store", array(
             "userResourceProfile" => $userResourceProfile,
@@ -519,7 +522,12 @@ class AccountController extends BaseController
 
     public function deleteCredential() {
 
+        $userResourceProfile = URPUtilities::get_user_resource_profile();
         $credentialStoreToken = Input::get("credentialStoreToken");
+        if ($credentialStoreToken == $userResourceProfile->credentialStoreToken) {
+            return Redirect::to("account/credential-store")->with("error-message", "You are not allowed to delete the default SSH key.");
+        }
+
         $credentialSummaryMap = $this->create_credential_summary_map(URPUtilities::get_all_ssh_pub_keys_summary_for_user());
         $description = $credentialSummaryMap[$credentialStoreToken]->description;
 

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/a90dfedb/app/views/account/credential-store.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/credential-store.blade.php b/app/views/account/credential-store.blade.php
index 6908844..3f4fee6 100644
--- a/app/views/account/credential-store.blade.php
+++ b/app/views/account/credential-store.blade.php
@@ -14,6 +14,16 @@
     </div>
     {{ Session::forget("message") }}
     @endif
+
+    @if( Session::has("error-message"))
+    <div class="alert alert-danger alert-dismissible" role="alert">
+        <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span
+                class="sr-only">Close</span></button>
+        {{{ Session::get("error-message") }}}
+    </div>
+    {{ Session::forget("error-message") }}
+    @endif
+
     <h1>SSH Keys</h1>
     <h3>Default SSH Key</h3>
     <form class="form-inline" action="{{ URL::to('/') }}/account/set-default-credential" method="post">
@@ -66,9 +76,11 @@
                     {{ $credentialSummary->publicKey }}
                 </td>
                 <td>
+                    @if ($credentialSummary->canDelete)
                     <span data-token="{{$credentialSummary->token}}"
                         data-description="{{$credentialSummary->description}}"
                         class="glyphicon glyphicon-trash delete-credential"></span>
+                    @endif
                 </td>
             </tr>
             @endforeach
@@ -117,12 +129,16 @@ $('.delete-credential').on('click', function(){
 });
 
 $('#credential-description').on('invalid', function(event){
+    this.setCustomValidity("Please provide a description");
     $('#credential-description-form-group').addClass('has-error');
 });
 $('#credential-description').on('keyup input change', function(event){
     if (this.checkValidity) {
+        // Reset custom error message. If it isn't empty string it is considered invalid.
+        this.setCustomValidity("");
+        // checkValidity will cause invalid event to be dispatched. See invalid
+        // event handler above which will set the custom error message.
         var valid = this.checkValidity();
-        this.setCustomValidity("Please provide a description");
         $('#credential-description-form-group').toggleClass('has-error', !valid);
     }
 });