[08/12] airavata-php-gateway git commit: AIRAVATA-2500 Prevent deleting in-use user credentials

2017-09-26 Thread machristie
AIRAVATA-2500 Prevent deleting in-use user credentials


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/277f3468
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/277f3468
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/277f3468

Branch: refs/heads/develop
Commit: 277f34685da4273b1ee2f030b02c2830f6ca55e9
Parents: 2782a49
Author: Marcus Christie 
Authored: Thu Sep 7 16:31:28 2017 -0400
Committer: Marcus Christie 
Committed: Thu Sep 7 16:31:28 2017 -0400

--
 app/controllers/UserSettingsController.php   | 22 +-
 app/views/account/credential-store.blade.php | 11 +--
 2 files changed, 26 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/277f3468/app/controllers/UserSettingsController.php
--
diff --git a/app/controllers/UserSettingsController.php 
b/app/controllers/UserSettingsController.php
index d73e874..7f449a6 100644
--- a/app/controllers/UserSettingsController.php
+++ b/app/controllers/UserSettingsController.php
@@ -17,7 +17,7 @@ class UserSettingsController extends BaseController
 $userCredentialSummaries = 
URPUtilities::get_all_ssh_pub_keys_summary_for_user();
 $defaultCredentialToken = $userResourceProfile->credentialStoreToken;
 foreach ($userCredentialSummaries as $credentialSummary) {
-$credentialSummary->canDelete = ($credentialSummary->token != 
$defaultCredentialToken);
+$credentialSummary->canDelete = 
$this->canDeleteCredential($credentialSummary->token, $userResourceProfile);
 }
 
 return View::make("account/credential-store", array(
@@ -27,6 +27,26 @@ class UserSettingsController extends BaseController
 ));
 }
 
+// Don't allow deleting credential if default credential or in use by a
+// userComputeResourcePreference or a userStoragePreference
+private function canDeleteCredential($token, $userResourceProfile) {
+if ($token == $userResourceProfile->credentialStoreToken) {
+return false;
+} else {
+foreach ($userResourceProfile->userComputeResourcePreferences as 
$userCompResPref) {
+if ($userCompResPref->resourceSpecificCredentialStoreToken == 
$token) {
+return false;
+}
+}
+foreach ($userResourceProfile->userStoragePreferences as 
$userStoragePreference) {
+if 
($userStoragePreference->resourceSpecificCredentialStoreToken == $token) {
+return false;
+}
+}
+}
+return true;
+}
+
 public function setDefaultCredential() {
 
 $defaultToken = Input::get("defaultToken");

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/277f3468/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 a6b0b33..32e0f0d 100644
--- a/app/views/account/credential-store.blade.php
+++ b/app/views/account/credential-store.blade.php
@@ -57,15 +57,14 @@
 @if ($credentialSummary->token != $defaultCredentialToken)
 
 
-Make 
Default
+Make Default
 
-@else
-This is the default SSH public key that the gateway 
will use to authenticate to your compute and storage accounts.
-@endif
-@if ($credentialSummary->canDelete)
 Delete
+class="btn btn-danger delete-credential"
+@if(!$credentialSummary->canDelete) disabled 
@endif>Delete
+@else
+This is the default SSH public key that the gateway 
will use to authenticate to your compute and storage accounts.
 @endif
 
 



[08/12] airavata-php-gateway git commit: AIRAVATA-2500 Prevent deleting in-use user credentials

2017-09-25 Thread machristie
AIRAVATA-2500 Prevent deleting in-use user credentials


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/277f3468
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/277f3468
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/277f3468

Branch: refs/heads/AIRAVATA-2500
Commit: 277f34685da4273b1ee2f030b02c2830f6ca55e9
Parents: 2782a49
Author: Marcus Christie 
Authored: Thu Sep 7 16:31:28 2017 -0400
Committer: Marcus Christie 
Committed: Thu Sep 7 16:31:28 2017 -0400

--
 app/controllers/UserSettingsController.php   | 22 +-
 app/views/account/credential-store.blade.php | 11 +--
 2 files changed, 26 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/277f3468/app/controllers/UserSettingsController.php
--
diff --git a/app/controllers/UserSettingsController.php 
b/app/controllers/UserSettingsController.php
index d73e874..7f449a6 100644
--- a/app/controllers/UserSettingsController.php
+++ b/app/controllers/UserSettingsController.php
@@ -17,7 +17,7 @@ class UserSettingsController extends BaseController
 $userCredentialSummaries = 
URPUtilities::get_all_ssh_pub_keys_summary_for_user();
 $defaultCredentialToken = $userResourceProfile->credentialStoreToken;
 foreach ($userCredentialSummaries as $credentialSummary) {
-$credentialSummary->canDelete = ($credentialSummary->token != 
$defaultCredentialToken);
+$credentialSummary->canDelete = 
$this->canDeleteCredential($credentialSummary->token, $userResourceProfile);
 }
 
 return View::make("account/credential-store", array(
@@ -27,6 +27,26 @@ class UserSettingsController extends BaseController
 ));
 }
 
+// Don't allow deleting credential if default credential or in use by a
+// userComputeResourcePreference or a userStoragePreference
+private function canDeleteCredential($token, $userResourceProfile) {
+if ($token == $userResourceProfile->credentialStoreToken) {
+return false;
+} else {
+foreach ($userResourceProfile->userComputeResourcePreferences as 
$userCompResPref) {
+if ($userCompResPref->resourceSpecificCredentialStoreToken == 
$token) {
+return false;
+}
+}
+foreach ($userResourceProfile->userStoragePreferences as 
$userStoragePreference) {
+if 
($userStoragePreference->resourceSpecificCredentialStoreToken == $token) {
+return false;
+}
+}
+}
+return true;
+}
+
 public function setDefaultCredential() {
 
 $defaultToken = Input::get("defaultToken");

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/277f3468/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 a6b0b33..32e0f0d 100644
--- a/app/views/account/credential-store.blade.php
+++ b/app/views/account/credential-store.blade.php
@@ -57,15 +57,14 @@
 @if ($credentialSummary->token != $defaultCredentialToken)
 
 
-Make 
Default
+Make Default
 
-@else
-This is the default SSH public key that the gateway 
will use to authenticate to your compute and storage accounts.
-@endif
-@if ($credentialSummary->canDelete)
 Delete
+class="btn btn-danger delete-credential"
+@if(!$credentialSummary->canDelete) disabled 
@endif>Delete
+@else
+This is the default SSH public key that the gateway 
will use to authenticate to your compute and storage accounts.
 @endif