cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [6/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Date Sat, 08 Aug 2015 19:07:02 GMT
CLOUDSTACK-8701: Allow users to switch across SAML account/domains from topbar

Moves the previous switch account logic to its own ui-custom module

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/37f30a60
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/37f30a60
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/37f30a60

Branch: refs/heads/4.5-samlfixes
Commit: 37f30a60e23cdaa35a65523ba6ec0654324a38c5
Parents: 8c51449
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Wed Aug 5 21:16:38 2015 +0530
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Sun Aug 9 00:34:55 2015 +0530

----------------------------------------------------------------------
 ui/css/cloudstack3.css       |  6 +--
 ui/index.jsp                 |  1 +
 ui/scripts/ui-custom/saml.js | 96 +++++++++++++++++++++++++++++++++++++++
 ui/scripts/ui/core.js        | 77 -------------------------------
 4 files changed, 100 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/css/cloudstack3.css
----------------------------------------------------------------------
diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css
index ef33dea..06abbb8 100644
--- a/ui/css/cloudstack3.css
+++ b/ui/css/cloudstack3.css
@@ -9651,7 +9651,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group
div.loadBal
 }
 
 /*** View switcher (drop-down)*/
-.project-switcher {
+.project-switcher, .domain-switcher {
   float: left;
   width: 223px;
   padding: 9px 17px 0 19px;
@@ -9662,7 +9662,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group
div.loadBal
   border-radius: 4px;
 }
 
-.project-switcher label {
+.project-switcher label, .domain-switcher label {
   top: 29px;
   color: #FFFFFF;
   font-size: 13px;
@@ -9671,7 +9671,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group
div.loadBal
   margin-top: 5px;
 }
 
-.project-switcher select {
+.project-switcher select, .domain-switcher select {
   width: 70%;
   float: left;
   margin-top: 0px;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/index.jsp
----------------------------------------------------------------------
diff --git a/ui/index.jsp b/ui/index.jsp
index 3b7d310..60f3cc3 100644
--- a/ui/index.jsp
+++ b/ui/index.jsp
@@ -1798,6 +1798,7 @@
         <script type="text/javascript" src="scripts/docs.js?t=<%=now%>"></script>
         <script type="text/javascript" src="scripts/vm_snapshots.js?t=<%=now%>"></script>
         <script type="text/javascript" src="scripts/ui-custom/projectSelect.js?t=<%=now%>"></script>
+        <script type="text/javascript" src="scripts/ui-custom/saml.js?t=<%=now%>"></script>
 
         <!-- Plugin/module API -->
         <script type="text/javascript" src="scripts/ui-custom/pluginListing.js?t=<%=now%>"></script>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/scripts/ui-custom/saml.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/saml.js b/ui/scripts/ui-custom/saml.js
new file mode 100644
index 0000000..391e7f8
--- /dev/null
+++ b/ui/scripts/ui-custom/saml.js
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+(function($, cloudStack) {
+    $(window).bind('cloudStack.ready', function() {
+        var showSamlDomainSwitcher = false;
+        if (g_idpList) {
+            showSamlDomainSwitcher = true;
+        }
+        if (!showSamlDomainSwitcher) {
+            return;
+        }
+
+        var $label = $('<label>').html('Domain:');
+        var $header = $('#header .controls');
+        var $domainSwitcher = $('<div>').addClass('domain-switcher');
+        var $domainSelect = $('<select>');
+        $domainSwitcher.append($label, $domainSelect);
+
+        var switchAccount = function(userId, domainId) {
+            var toReload = true;
+            $.ajax({
+                url: createURL('listAndSwitchSamlAccount'),
+                type: 'POST',
+                async: false,
+                data: {
+                    userid: userId,
+                    domainid: domainId
+                },
+                success: function(data, textStatus) {
+                    document.location.reload(true);
+                },
+                error: function(data) {
+                    cloudStack.dialog.notice({
+                        message: parseXMLHttpResponse(data)
+                    });
+                    if (data.status !== 200) {
+                        toReload = false;
+                    }
+                },
+                complete: function() {
+                    if (toReload) {
+                        document.location.reload(true);
+                    }
+                    toReload = true;
+                }
+            });
+        };
+
+        $domainSelect.change(function() {
+            var selectedOption = $domainSelect.val();
+            var userId = selectedOption.split('/')[0];
+            var domainId = selectedOption.split('/')[1];
+            switchAccount(userId, domainId);
+        });
+
+        $.ajax({
+            url: createURL('listAndSwitchSamlAccount'),
+            success: function(json) {
+                var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
+                if (accounts.length < 2) {
+                    return;
+                };
+                $domainSelect.empty();
+                for (var i = 0; i < accounts.length; i++) {
+                    var option = $('<option>');
+                    option.data("userId", accounts[i].userId);
+                    option.data("domainId", accounts[i].domainId);
+                    option.val(accounts[i].userId + '/' + accounts[i].domainId);
+                    option.html(accounts[i].accountName + "/" + accounts[i].domainName);
+                    option.appendTo($domainSelect);
+                }
+                var currentAccountDomain = g_userid + '/' + g_domainid;
+                $domainSelect.find('option[value="' + currentAccountDomain + '"]').attr("selected",
"selected");
+                $domainSwitcher.insertAfter($header.find('.region-switcher'));
+            },
+            error: function(data) {
+                // if call fails, the logged in user in not a SAML authenticated user
+            }
+        });
+    });
+}(jQuery, cloudStack));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/scripts/ui/core.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/core.js b/ui/scripts/ui/core.js
index 26a5a1c..e64f386 100644
--- a/ui/scripts/ui/core.js
+++ b/ui/scripts/ui/core.js
@@ -304,83 +304,6 @@
         })
             .appendTo($('#user'));
 
-        // Switch account option for SAML users
-        if (g_idpList) {
-            $.ajax({
-                url: createURL('listAndSwitchSamlAccount'),
-                success: function(json) {
-                    var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
-                    if (accounts.length < 2) {
-                        return
-                    };
-                    var switchAccount = function() {
-                        var toReload = true;
-                        $.ajax({
-                            url: createURL('listAndSwitchSamlAccount'),
-                            type: 'POST',
-                            async: false,
-                            data: {
-                                userid: $(this).data("userId"),
-                                domainid: $(this).data("domainId")
-                            },
-                            success: function(data, textStatus) {
-                                document.location.reload(true);
-                            },
-                            error: function(data) {
-                               cloudStack.dialog.notice({
-                                    message: parseXMLHttpResponse(data)
-                                });
-                                if (data.status !== 200) {
-                                    toReload = false;
-                                }
-                            },
-                            complete: function() {
-                                if (toReload) {
-                                    document.location.reload(true);
-                                }
-                                toReload = true;
-                            }
-                        });
-                    };
-
-                    $('<a>').attr({
-                            href: '#'
-                        })
-                        .text('Switch Account')
-                        .appendTo($options).click(function() {
-                            var $switchSamlAccount = $('<div>');
-                            for (var i = 0; i < accounts.length; i++) {
-                                var item = $('<a>').html(accounts[i].accountName +
"/" + accounts[i].domainName);
-                                item.data("userId", accounts[i].userId);
-                                item.data("domainId", accounts[i].domainId);
-                                item.click(switchAccount);
-                                item.appendTo($switchSamlAccount);
-                                item.attr("href", "#");
-                                $('<br>').appendTo($switchSamlAccount);
-                            }
-                            $switchSamlAccount.dialog({
-                                modal: true,
-                                width: 400,
-                                title: 'Switch Account',
-                                closeOnEscape: false,
-                                dialogClass: 'dialog-about',
-                                buttons: {
-                                    'Close': function() {
-                                        $(this).dialog("close");
-                                        $(':ui-dialog, .overlay').remove();
-                                    }
-                                }
-                            }).closest('.ui-dialog').overlay();
-
-                            return false;
-                        });
-                },
-                error: function(data) {
-                }
-            });
-        }
-
-
         $(['label.logout', 'label.help', 'label.about']).each(function() {
             var $link = $('<a>')
                 .attr({


Mime
View raw message