You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by nd...@apache.org on 2016/08/10 08:22:05 UTC

airavata-php-gateway git commit: Adding ability for super admin to manually input oauth details

Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop d016990d8 -> eed3374e4


Adding ability for super admin to manually input oauth details


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

Branch: refs/heads/develop
Commit: eed3374e4ca12fd86a97905d8f654d3c768ffdcb
Parents: d016990
Author: Nipurn Doshi <ni...@gmail.com>
Authored: Wed Aug 10 01:21:18 2016 -0700
Committer: Nipurn Doshi <ni...@gmail.com>
Committed: Wed Aug 10 01:21:18 2016 -0700

----------------------------------------------------------------------
 app/controllers/AdminController.php      |  30 ++++----
 app/libraries/AdminUtilities.php         |  34 ++++++++-
 app/libraries/CRUtilities.php            |  16 +++--
 app/views/account/dashboard.blade.php    |  19 +++--
 app/views/admin/manage-gateway.blade.php | 100 ++++++++++++++++++++++----
 5 files changed, 157 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eed3374e/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php
index abf6e85..cfd6c0f 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -18,24 +18,17 @@ class AdminController extends BaseController {
             Session::put("super-admin", true);
             $gatewaysInfo = CRUtilities::getAllGateways();
             $requestedGateways = array();
+            $gatewayApprovalStatuses = AdminUtilities::get_gateway_approval_statuses();
+
             foreach ($gatewaysInfo as $index => $gateway) {
                 if ($gateway->identityServerUserName == $userProfile["username"]) {
                     $gatewayOfUser = $gateway->gatewayId;
                     Session::forget("super-admin");
                     Session::put("new-gateway-provider", true);
                     Session::put("existing-gateway-provider", true);
+
                     $requestedGateways[ $gateway->gatewayId]["gatewayInfo"] = $gateway;
-                    $requestedGateways[ $gateway->gatewayId]["approvalStatus"] = "Approved";
-                    if( $gateway->gatewayApprovalStatus == 0){
-                    	$requestedGateways[ $gateway->gatewayId]["approvalStatus"] = "Requested";
-                    }
-                    if( $gateway->gatewayApprovalStatus == 1){
-                    	$requestedGateways[ $gateway->gatewayId]["approvalStatus"] = "Approved";
-		            	Session::put("gateway_id", $gateway->gatewayId);
-                    }
-                    elseif( $gateway->gatewayApprovalStatus == 3){
-                    	$requestedGateways[ $gateway->gatewayId]["approvalStatus"] = "Denied";
-                    }
+                    $requestedGateways[ $gateway->gatewayId]["approvalStatus"] = $gatewayApprovalStatuses[ $gateway->gatewayApprovalStatus];
                     //seeing if admin wants to start managing one of the gateways
 		            if( Input::has("gatewayId")){
 		            	if( Input::get("gatewayId") == $gateway->gatewayId)
@@ -46,6 +39,7 @@ class AdminController extends BaseController {
                 }
             }
             $data["requestedGateways"] = $requestedGateways;
+            $data["gatewayApprovalStatuses"] = $gatewayApprovalStatuses;
             //to make it accessible to navbar
             Session::put("requestedGateways", $requestedGateways);
 
@@ -136,7 +130,8 @@ class AdminController extends BaseController {
 								"tokens" => $tokens,
 								"pwdTokens" => $pwdTokens,
 								"unselectedCRs" => $unselectedCRs,
-								"unselectedSRs" => $unselectedSRs
+								"unselectedSRs" => $unselectedSRs,
+								"gatewayApprovalStatuses" => AdminUtilities::get_gateway_approval_statuses()
 							);
 		$view = "admin/manage-gateway";
 
@@ -159,8 +154,14 @@ class AdminController extends BaseController {
 
 	public function updateGatewayRequest(){
 		$status = Input::get("status");
-		if( $status == "Approve")
+		$oauthData = array();
+
+		if( $status == "Approve"){			
 			$status = 1;
+
+			$oauthData["oauthClientId"] = Input::get("oauth-client-id");
+			$oauthData["oauthClientSecret"] = Input::get("oauth-client-secret");
+		}
 		if( $status == "Deny")
 			$status = 5;
 
@@ -168,7 +169,8 @@ class AdminController extends BaseController {
 		if( Input::has("comments"))
 			$comments = Input::get("comments");
 
-		AdminUtilities::update_gateway_status( Input::get("gateway_id"), $status, $comments);
+
+		AdminUtilities::update_gateway_status( Input::get("gateway_id"), $status, $oauthData, $comments);
 		if( Session::has("super-admin"))
 			return Redirect::to("admin/dashboard/gateway");
 		else

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eed3374e/app/libraries/AdminUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/AdminUtilities.php b/app/libraries/AdminUtilities.php
index 7ba6b9b..79aa7e6 100644
--- a/app/libraries/AdminUtilities.php
+++ b/app/libraries/AdminUtilities.php
@@ -28,10 +28,14 @@ class AdminUtilities
         $gateway = new Gateway( $inputs);
         $gateway->gatewayId = $inputs["gateway-name"];
         $gateway->gatewayApprovalStatus = GatewayApprovalStatus::REQUESTED;
+        if( strpos($input["domain"], "//") != false)
+            $input["domain"] = substr( $input["domain"], 1 + strpos($input["domain"], "//"));
         $gateway->domain = $inputs["domain"];
         $gateway->gatewayName = $inputs["gateway-name"];
         $gateway->emailAddress = $inputs["email-address"];
         $gateway->gatewayAcronym = $inputs["gateway-acronym"];
+        if( strpos($input["gateway-url"], "//") != false)
+            $input["gateway-url"] = substr( $input["gateway-url"], 1 + strpos($input["gateway-url"], "//"));
         $gateway->gatewayURL = $inputs["gateway-url"];
         $gateway->gatewayAdminFirstName = $inputs["admin-firstname"];
         $gateway->gatewayAdminLastName = $inputs["admin-lastname"];
@@ -43,18 +47,32 @@ class AdminUtilities
         return Airavata::addGateway(Session::get('authz-token'), $gateway);
     }
 
-    public static function update_gateway_status( $gatewayId, $status, $comments = null){
+    public static function get_gateway_approval_statuses()
+    {
+        $gatewayApprovalStatusObject = new GatewayApprovalStatus();
+        return $gatewayApprovalStatusObject::$__names;
+    }
+
+    public static function update_gateway_status( $gatewayId, $status, $oauthData, $comments = null){
         $gateway = Airavata::getGateway( Session::get('authz-token'), $gatewayId);
         $gateway->gatewayApprovalStatus = intval( $status);
+        if( count( $oauthData) != 0)
+        {
+            $gateway->oauthClientId = $oauthData["oauthClientId"];
+            $gateway->oauthClientSecret = $oauthData["oauthClientSecret"];
+        }
         if( $comments != null)
             $gateway->declinedReason = $comments;
 
         if( Airavata::updateGateway( Session::get('authz-token'), $gateway->gatewayId, $gateway) ){
-        $gateway = Airavata::getGateway( Session::get('authz-token'), $gatewayId);
+            $gateway = Airavata::getGateway( Session::get('authz-token'), $gatewayId);
             if( $gateway->gatewayApprovalStatus == GatewayApprovalStatus::APPROVED){
                 $tenants = WSIS::getTenants();
                 $tenantExists = false;
                 foreach( $tenants as $tenant){
+                    $gatewayURL = $gateway->gatewayURL;
+                    if( strpos($gateway->gatewayURL, "//") != false)
+                        $gatewayURL = substr( $gateway->gatewayURL, 2 + strpos($gateway->gatewayURL, "//"));
                     if( $tenant->tenantDomain == $gateway->gatewayURL){
                         $tenantExists = true;
                     }
@@ -64,13 +82,23 @@ class AdminUtilities
                             Adminutilities::update_gateway_status( Input::get("gateway_id"), GatewayApprovalStatus::ACTIVE);
                     }
                 }
+                else
+                    echo "Tenant Name is already in use";
             }
 
         }
     }
 
     public static function add_tenant( $gateway){
-        return WSIS::createTenant(1, $gateway->identityServerUserName . "@" . $gateway->domain, $gateway->identityServerPasswordToken, $gateway->emailAddress,$gateway->gatewayAdminFirstName, $gateway->gatewayAdminLastName, $gateway->domain);
+        $gatewayURL = $gateway->gatewayURL;
+        $gatewayDomain = $gateway->domain;
+        if( strpos($gateway->gatewayURL, "//") != false)
+            $gatewayURL = substr( $gateway->gatewayURL, 2 + strpos($gateway->gatewayURL, "//"));
+
+        if( strpos($gateway->domain, "//") != false)
+            $gatewayDomain = substr( $gateway->domain, 2 + strpos( $gateway->domain, "//"));
+
+        return WSIS::createTenant(1, $gateway->identityServerUserName . "@" . $gatewayDomain, $gateway->identityServerPasswordToken, $gateway->emailAddress,$gateway->gatewayAdminFirstName, $gateway->gatewayAdminLastName, $gatewayURL);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eed3374e/app/libraries/CRUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/CRUtilities.php b/app/libraries/CRUtilities.php
index 171965a..bf36256 100755
--- a/app/libraries/CRUtilities.php
+++ b/app/libraries/CRUtilities.php
@@ -447,19 +447,20 @@ class CRUtilities
 
     public static function getAllGatewayProfilesData()
     {
+        $selectedCRs = array();
+        $selectedSRs = array();
+        $allCRs = CRUtilities::getAllCRObjects();
+        $allSRs = SRUtilities::getAllSRObjects();
+        $allCRArray = array();
+        $allSRArray = array();
 
         if (Session::has("super-admin"))
+
             $gateways = Airavata::getAllGateways(Session::get('authz-token'));
         else {
             $gateways[0] = Airavata::getGateway(Session::get('authz-token'), Session::get("gateway_id"));
         }
 
-        $selectedCRs = array();
-        $selectedSRs = array();
-        $allCRs = CRUtilities::getAllCRObjects();
-        $allSRs = SRUtilities::getAllSRObjects();
-        $allCRArray = array();
-        $allSRArray = array();
         foreach( $allCRs as $index => $crObject)
         {
             $allCRArray[$crObject->computeResourceId] = $crObject;
@@ -500,7 +501,8 @@ class CRUtilities
                                 "selectedCRs" => $selectedCRs, 
                                 "selectedSRs" => $selectedSRs, 
                                 "allCRs" => $allCRs,
-                                "allSRs" => $allSRs
+                                "allSRs" => $allSRs,
+                                "gatewayApprovalStatuses" => AdminUtilities::get_gateway_approval_statuses()
                             );
         return $gatewaysInfo;
     }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eed3374e/app/views/account/dashboard.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/dashboard.blade.php b/app/views/account/dashboard.blade.php
index e062449..cac5391 100644
--- a/app/views/account/dashboard.blade.php
+++ b/app/views/account/dashboard.blade.php
@@ -38,7 +38,7 @@
                             <td>{{ $gateway["gatewayInfo"]->gatewayName }}</td>
                             <td>{{ $gateway["approvalStatus"] }}</td>
                             <td>
-                                @if( $gateway["approvalStatus"] == "Approved")
+                                @if( $gateway["approvalStatus"] == "APPROVED")
                                     <div class="btn-group" role="group" aria-label="...">
                                         <button type="button" class="btn btn-default view-credentials" data-gatewayobject="{{ htmlentities( json_encode( $gateway['gatewayInfo'])) }}">View Credentials</button>
                                         <!--
@@ -47,8 +47,10 @@
                                         <button type="button" class="btn btn-danger deactivateGateway-button" data-toggle="modal" data-target="#deactivateGateway" data-gatewayid="{{$gatewayId}}">Deactivate Gateway</button>
                                         -->
                                     </div>
-                                @elseif( $gateway["approvalStatus"] == "Requested")
-                                    <button type="button" class="btn btn-danger"><a href="{{URL::to('/')}}/admin/update-gateway-request?gateway_id={{$gatewayId}}&status=4">Cancel Request</a></button>
+                                @elseif( $gateway["approvalStatus"] == "REQUESTED")
+                                    <a href="{{URL::to('/')}}/admin/update-gateway-request?gateway_id={{$gatewayId}}&status=4">
+                                        <button type="button" class="btn btn-danger">Cancel Request</button>
+                                    </a>
                                 @endif
                             </td>
                             <td>
@@ -87,12 +89,12 @@
                         </div>
                         <div class="form-group required">
                             <label class="control-label">Domain</label>
-                            <input type="text" name="domain" class="form-control" value="{{Input::old('domain') }}"/>
+                            <input type="url" name="domain" id="domain" class="form-control" value="{{Input::old('domain') }}"  data-container="body" data-toggle="popover" data-placement="left" data-content="Domain's main URL. eg:domain.org"/>
                         </div>
 
                         <div class="form-group required">
                             <label class="control-label">Gateway URL</label>
-                            <input type="text" name="gateway-url" id="gateway-url" class="form-control" value="{{Input::old('gateway-url') }}" data-container="body" data-toggle="popover" data-placement="left" data-content="URL to Portal home page or Download URL (for desktop applications). This is required if the gateway is Production Ready above."/>
+                            <input type="url" name="gateway-url" id="gateway-url" class="form-control" value="{{Input::old('gateway-url') }}" data-container="body" data-toggle="popover" data-placement="left" data-content="URL to Portal home page or Download URL (for desktop applications) where gateway has been deployed. eg:portal.domain.org"/>
                         </div>
                         <div class="form-group required">
                             <label class="control-label">Gateway Admin Username</label>
@@ -437,6 +439,10 @@
         'trigger':'focus'
     });
 
+    $("#domain").popover({
+        'trigger':'focus'
+    });
+
     $("#gateway-url").popover({
         'trigger':'focus'
     });
@@ -456,10 +462,11 @@
 
     $(".view-credentials").click( function(){
         var gatewayObject = $(this).data("gatewayobject");
-        console.log( gatewayObject);
         $(".admin-username").html( gatewayObject["identityServerUserName"]);
         $(".admin-password").html( gatewayObject["identityServerPasswordToken"]);
         $(".gateway-id").html( gatewayObject["gatewayId"]);
+        $(".oauth-client-key").html( gatewayObject["oauthClientId"]);
+        $(".oauth-client-secret").html( gatewayObject["oauthClientSecret"]);
         $("#viewCredentials").modal("show");
     });
 </script>

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eed3374e/app/views/admin/manage-gateway.blade.php
----------------------------------------------------------------------
diff --git a/app/views/admin/manage-gateway.blade.php b/app/views/admin/manage-gateway.blade.php
index a2c4ac9..609026c 100644
--- a/app/views/admin/manage-gateway.blade.php
+++ b/app/views/admin/manage-gateway.blade.php
@@ -97,20 +97,15 @@
                                         <td>{{ $gp->gatewayURL }}</td>
                                         <td>{{ $gp->reviewProposalDescription}}</td>
                                         <td>{{ $gp->gatewayPublicAbstract}}</td>
-                                        @if( $gp->gatewayApprovalStatus == 0)
+                                        @if( $gatewayApprovalStatuses[$gp->gatewayApprovalStatus] == "REQUESTED")
                                             <td>
-                                                <form action="{{URL::to('/')}}/admin/update-gateway-request" method="GET">
-                                                    <input type="hidden" name="gateway_id" value="{{$gp->gatewayId}}">
-                                                    <textarea style="width:100%; height:80px" width="100%" name="comments" placeholder="Comments"></textarea>
-                                                    <br/>
-                                                    <input type="submit" name="status" class="btn btn-primary" value="Approve"/>
-                                                    <input type="submit" name="status" class="btn btn-danger" value="Deny"/>
-                                                </form>
+                                                    <input type="button" class="btn btn-primary start-approval" data-gatewayid="{{$gp->gatewayId}}" value="Approve"/>
+                                                    <input type="button" class="btn btn-danger deny-approval" data-gatewayid="{{$gp->gatewayId}}" value="Deny"/>
+                                            </td>
+                                        @else
+                                            <td>{{$gatewayApprovalStatuses[$gp->gatewayApprovalStatus]}}
+                                                @if( $gp->declinedReason != "")<br/><br/>Comment: {{$gp->declinedReason}} @endif
                                             </td>
-                                        @elseif( $gp->gatewayApprovalStatus == 1)
-                                            <td>Approved @if( $gp->declinedReason != "")<br/><br/>Comment: {{$gp->declinedReason}} @endif</td>
-                                        @elseif( $gp->gatewayApprovalStatus == 5)
-                                            <td>Denied @if( $gp->declinedReason != "")<br/><br/>Comment: {{$gp->declinedReason}} @endif</td>
                                         @endif
                                     </tr>
                                 @endforeach
@@ -191,6 +186,77 @@
     </div>
 </div>
 
+@if( Session::has("super-admin"))
+<!-- Approve a Gateway request -->
+<div class="modal fade" id="approve-gateway" tabindex="-1" role="dialog" aria-labelledby="add-modal"
+     aria-hidden="true">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <form action="{{URL::to('/')}}/admin/update-gateway-request" method="GET">
+            
+                <div class="modal-header">
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
+                                aria-hidden="true">&times;</span></button>
+                    <h3>Approve Gateway Request</h3>
+                </div>
+                <div class="modal-body">
+                    <div class="form-group">
+                        <h4>GatewayId: <span class="gatewayid-for-approval"></span></h4>
+                    </div>
+                    <div class="form-group">
+                        <label>Oauth Client Id</label>
+                        <input type="text" name="oauth-client-id" class="form-control" required="required"/>
+                    </div>
+                    <div class="form-group">
+                        <label>Oauth Client Secret</label>
+                        <input type="text" name="oauth-client-secret" class="form-control" required="required" >
+                    </div>
+                    <div class="form-group">
+                        <label>Comments</label>
+                        <textarea style="width:100%; height:80px" width="100%" name="comments"></textarea>
+                    </div>
+                    <input type="hidden" class="gatewayid-for-approval" name="gateway_id">
+                </div>
+                <div class="modal-footer">
+                    <input type="submit" name="status" class="btn btn-primary" value="Approve"/>
+                    <input type="cancel"  data-dismiss="modal"  class="btn btn-default" value="Cancel"/>
+                </div>
+            </form>
+
+        </div>
+    </div>
+</div>
+
+<!-- Deny a Gateway request -->
+<div class="modal fade" id="deny-gateway" tabindex="-1" role="dialog" aria-labelledby="add-modal"
+     aria-hidden="true">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <form action="{{URL::to('/')}}/admin/update-gateway-request" method="GET">
+            
+                <div class="modal-header">
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
+                                aria-hidden="true">&times;</span></button>
+                    <h3>Deny Gateway Request</h3>
+                </div>
+                <div class="modal-body">
+                    <div class="form-group">
+                        <label>Comments</label>
+                        <textarea style="width:100%; height:80px" width="100%" name="comments"></textarea>
+                    </div>
+                </div>
+                <input type="hidden" class="gatewayid-for-approval" name="gateway_id">
+                <div class="modal-footer">
+                    <input type="submit" name="status" class="btn btn-danger" value="Deny"/>
+                    <input type="cancel"  data-dismiss="modal"  class="btn btn-default" value="Cancel"/>
+                </div>
+            </form>
+
+        </div>
+    </div>
+</div>
+@endif
+
 <!-- Remove a Compute Resource from a Gateway -->
 <div class="modal fade" id="remove-compute-resource-block" tabindex="-1" role="dialog" aria-labelledby="add-modal"
      aria-hidden="true">
@@ -409,5 +475,15 @@
         elem.find(".glyphicon").hide();
     }
 
+    $(".start-approval").click( function(){
+        $(".gatewayid-for-approval").val( $(this).data("gatewayid")).html(  $(this).data("gatewayid"));
+        $("#approve-gateway").modal("show");
+    });
+
+    $(".deny-approval").click( function(){
+        $(".gatewayid-for-approval").val( $(this).data("gatewayid")).html(  $(this).data("gatewayid"));
+        $("#deny-gateway").modal("show");
+    });
+
 </script>
 @stop
\ No newline at end of file