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/16 20:23:16 UTC

airavata-php-gateway git commit: Changed flow of Gateway Request to create tenant first and then add oauth credentials

Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop dd2b78a55 -> 120a842ed


Changed flow of Gateway Request to create tenant first and then add oauth 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/120a842e
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/120a842e
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/120a842e

Branch: refs/heads/develop
Commit: 120a842ed9fa6ca1487f7402490bb236a8a2d991
Parents: dd2b78a
Author: Nipurn Doshi <ni...@gmail.com>
Authored: Tue Aug 16 13:22:39 2016 -0700
Committer: Nipurn Doshi <ni...@gmail.com>
Committed: Tue Aug 16 13:22:39 2016 -0700

----------------------------------------------------------------------
 app/controllers/AdminController.php      | 20 +++++---
 app/libraries/AdminUtilities.php         | 66 +++++++++++++++------------
 app/views/account/dashboard.blade.php    |  4 +-
 app/views/admin/manage-gateway.blade.php | 27 +++++++++--
 4 files changed, 76 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/120a842e/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php
index 63a8082..e5396f9 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -153,6 +153,7 @@ class AdminController extends BaseController {
 	}
 
 	public function updateGatewayRequest(){
+
 		$status = Input::get("status");
 		$oauthData = array();
 
@@ -169,12 +170,19 @@ class AdminController extends BaseController {
 		if( Input::has("comments"))
 			$comments = Input::get("comments");
 
-
-		AdminUtilities::update_gateway_status( Input::get("gateway_id"), $status, $oauthData, $comments);
-		if( Session::has("super-admin"))
-			return Redirect::to("admin/dashboard/gateway");
-		else
-			return Redirect::to("admin/dashboard");
+		if( Request::ajax()){
+			//first step of adding tenant and changing gateway request status to Approved.
+			AdminUtilities::update_gateway_status( Input::get("gateway_id"), $status, $oauthData, $comments, true);
+			return 1;
+		}
+		else{
+			//second step of changing gateway request status to active if tenant has been created and oauth credentials are entered.
+			AdminUtilities::update_gateway_status( Input::get("gateway_id"), $status, $oauthData, $comments, false);
+			if( Session::has("super-admin"))
+				return Redirect::to("admin/dashboard/gateway");
+			else
+				return Redirect::to("admin/dashboard");
+		}
 	}
 
 	public function rolesView(){

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/120a842e/app/libraries/AdminUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/AdminUtilities.php b/app/libraries/AdminUtilities.php
index 5d27f2a..a7d06bf 100644
--- a/app/libraries/AdminUtilities.php
+++ b/app/libraries/AdminUtilities.php
@@ -53,7 +53,7 @@ class AdminUtilities
         return $gatewayApprovalStatusObject::$__names;
     }
 
-    public static function update_gateway_status( $gatewayId, $status, $oauthData, $comments = null){
+    public static function update_gateway_status( $gatewayId, $status, $oauthData, $comments = null, $tenantAdd = null){
         $gateway = Airavata::getGateway( Session::get('authz-token'), $gatewayId);
         $gateway->gatewayApprovalStatus = intval( $status);
         if( count( $oauthData) != 0)
@@ -64,41 +64,51 @@ class AdminUtilities
         if( $comments != null)
             $gateway->declinedReason = $comments;
 
-        if( Airavata::updateGateway( Session::get('authz-token'), $gateway->gatewayId, $gateway) ){
+        if( Airavata::updateGateway( Session::get('authz-token'), $gateway->gatewayId, $gateway)  &&
+                                                                                            $tenantAdd == true){
+
             $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;
-                    }
-                }
-                if( !$tenantExists){
-                    if( AdminUtilities::add_tenant( $gateway) ){
-                            Adminutilities::update_gateway_status( Input::get("gateway_id"), GatewayApprovalStatus::ACTIVE);
-                    }
-                }
-                else
-                    echo "Tenant Name is already in use";
+            
+            if( AdminUtilities::add_tenant( $gateway) ){
+                Adminutilities::update_gateway_status( Input::get("gateway_id"), GatewayApprovalStatus::ACTIVE, $oauthData);
+            }
+            else{
+                //Need to find a better way for this.
+                echo "Tenant Name is already in use";
             }
-
         }
     }
 
     public static function add_tenant( $gateway){
-        $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, "//"));
+        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;
+                }
+            }
+            if( !$tenantExists){
+                $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);
+                //finally create tenant
+                return WSIS::createTenant(1, $gateway->identityServerUserName . "@" . $gatewayDomain, $gateway->identityServerPasswordToken, $gateway->emailAddress,$gateway->gatewayAdminFirstName, $gateway->gatewayAdminLastName, $gatewayURL);
+            }
+            else
+                return false;
+        }
+        else
+            return false;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/120a842e/app/views/account/dashboard.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/dashboard.blade.php b/app/views/account/dashboard.blade.php
index cac5391..ea520f3 100644
--- a/app/views/account/dashboard.blade.php
+++ b/app/views/account/dashboard.blade.php
@@ -89,12 +89,12 @@
                         </div>
                         <div class="form-group required">
                             <label class="control-label">Domain</label>
-                            <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"/>
+                            <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:http://domain.org"/>
                         </div>
 
                         <div class="form-group required">
                             <label class="control-label">Gateway URL</label>
-                            <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"/>
+                            <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:http://portal.domain.org"/>
                         </div>
                         <div class="form-group required">
                             <label class="control-label">Gateway Admin Username</label>

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/120a842e/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 127cc90..b01b896 100644
--- a/app/views/admin/manage-gateway.blade.php
+++ b/app/views/admin/manage-gateway.blade.php
@@ -63,7 +63,7 @@
                 <div class="tab-pane" id="tab-requestedGateways">
 
                     <div class="row">
-                        <form id="add-tenant-form" action="{{ URL::to("/") }}/admin/add-gateway">
+                        <form id="add-tenant-form" action="{{ URL::to('/') }}/admin/add-gateway">
                             <div class="col-md-12">
                                 <button type="button" class="btn btn-default toggle-add-tenant"><span
                                         class="glyphicon glyphicon-plus"></span>Add a new gateway
@@ -186,7 +186,7 @@
 @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">
+     aria-hidden="true" data-backdrop="static" >
     <div class="modal-dialog">
         <div class="modal-content">
             <form action="{{URL::to('/')}}/admin/update-gateway-request" method="GET">
@@ -196,7 +196,11 @@
                                 aria-hidden="true">&times;</span></button>
                     <h3>Approve Gateway Request</h3>
                 </div>
-                <div class="modal-body">
+                <div class="modal-body onTenantLoad">
+                    Adding tenant for GatewayId: <span class="gatewayid-for-approval"></span>. Please do not refresh or close this page!
+                </div>
+                <div class="modal-body onTenantComplete hide">
+                    <h3>Gateway Tenant has been added. Please fill in rest of the required details.</h3>
                     <div class="form-group">
                         <h4>GatewayId: <span class="gatewayid-for-approval"></span></h4>
                     </div>
@@ -214,7 +218,7 @@
                     </div>
                     <input type="hidden" class="gatewayid-for-approval" name="gateway_id">
                 </div>
-                <div class="modal-footer">
+                <div class="modal-footer onTenantComplete hide">
                     <input type="submit" name="status" class="btn btn-primary" value="Approve"/>
                     <input type="cancel"  data-dismiss="modal"  class="btn btn-default" value="Cancel"/>
                 </div>
@@ -476,8 +480,21 @@
     }
 
     $(".start-approval").click( function(){
-        $(".gatewayid-for-approval").val( $(this).data("gatewayid")).html(  $(this).data("gatewayid"));
+        var gatewayId = $(this).data("gatewayid");
+        $(".onTenantLoad").removeClass("hide");
+        $(".gatewayid-for-approval").val( gatewayId).html(  $(this).data("gatewayid"));
+        $(".onTenantComplete").addClass("hide");
         $("#approve-gateway").modal("show");
+
+        $.ajax({
+            url: "{{URL::to('/')}}/admin/update-gateway-request",
+            method: "GET",
+            data: { gateway_id : gatewayId, status: 1}
+        }).done( function( data){
+            $(".onTenantComplete").removeClass("hide");
+            $(".onTenantLoad").addClass("hide");
+            $(".onTenantComplete").removeClass("hide");
+        });
     });
 
     $(".deny-approval").click( function(){