11454: On /search & /sessions page, check if the current user is
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 2 Feb 2018 22:29:37 +0000 (19:29 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Fri, 2 Feb 2018 22:29:37 +0000 (19:29 -0300)
from a remote cluster, and if that's the case, redirect to the
proper home cluster workbench's page.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

apps/workbench/app/assets/javascripts/models/session_db.js
apps/workbench/app/views/search/index.html
apps/workbench/app/views/sessions/index.html

index 2d22a98958b2129025c83bd7521aaa6903e91ff2..0c3a081fd3e2deff0338c055e5dc616a484978dc 100644 (file)
@@ -244,9 +244,6 @@ window.SessionDB = function() {
             var activeSessions = db.loadActive()
             var doc = db.discoveryDoc(db.loadLocal())
             doc.map(function(d) {
-                // NOTE: the below line is to simulate that 9tee4 is included as a remote host
-                // the current test cluster
-                // d.remoteHosts = {"9tee4":"9tee4.arvadosapi.com"}
                 Object.keys(d.remoteHosts).map(function(uuidPrefix) {
                     if (!(uuidPrefix in Object.keys(activeSessions))) {
                         db.findAPI(d.remoteHosts[uuidPrefix]).then(function(baseURL) {
@@ -256,5 +253,34 @@ window.SessionDB = function() {
                 })
             })
         },
+        autoRedirectToHomeCluster: function(path = '/') {
+            var session = db.loadLocal()
+            var userUUIDPrefix = session.user.uuid.slice(0, 5)
+            // If the current user is local to the cluster, do nothing.
+            if (userUUIDPrefix == session.user.owner_uuid.slice(0, 5)) {
+                return
+            }
+            var doc = db.discoveryDoc(session)
+            doc.map(function(d) {
+                // Guess the remote host from the local discovery doc settings
+                var rHost = null
+                if (d.remoteHosts[userUUIDPrefix]) {
+                    rHost = d.remoteHosts[userUUIDPrefix]
+                } else if (d.remoteHostsViaDNS) {
+                    rHost = userUUIDPrefix + '.arvadosapi.com'
+                } else {
+                    // This should not happen: having remote user whose uuid prefix
+                    // isn't listed on remoteHosts and dns mechanism is deactivated
+                    return
+                }
+                // Get the remote cluster workbench url & redirect there.
+                db.findAPI(rHost).then(function(apiUrl) {
+                    var doc = db.discoveryDoc({baseURL: apiUrl})
+                    doc.map(function(d) {
+                        document.location = d.workbenchUrl + path
+                    })
+                })
+            })
+        },
     })
 }
index d2a8386405e3127567013ba39307bca439c84b26..c26a643d616d08b3e60396bea597dd8c1af66880 100644 (file)
@@ -2,5 +2,11 @@
 
 SPDX-License-Identifier: AGPL-3.0 -->
 
-<div data-mount-mithril="Search">
-</div>
+<script type="text/javascript">
+    $(document).on('ready', function() {
+        var db = new SessionDB()
+        db.autoRedirectToHomeCluster('/search')
+    })
+</script>
+
+<div data-mount-mithril="Search"></div>
index bf23028ce7c6a75efa2a9a8fac02057bce865822..ee1f63659e88fed3bfef9a7b06d8df3938629e74 100644 (file)
@@ -2,4 +2,11 @@
 
 SPDX-License-Identifier: AGPL-3.0 -->
 
+<script type="text/javascript">
+    $(document).on('ready', function() {
+        var db = new SessionDB()
+        db.autoRedirectToHomeCluster('/sessions')
+    })
+</script>
+
 <div data-mount-mithril="SessionsTable"></div>