Fix container authorization - front end 04/504/1
authorYevgeny Khodorkovsky <ykhodork@cisco.com>
Wed, 19 Jun 2013 22:43:27 +0000 (15:43 -0700)
committerYevgeny Khodorkovsky <ykhodork@cisco.com>
Wed, 19 Jun 2013 22:43:27 +0000 (15:43 -0700)
This complements commit 168aaa8d2474bc82f1fac82521cf93e53e362df7

Change-Id: I40c32907050da81902065e5d73e0213f20a05252
Signed-off-by: Yevgeny Khodorkovsky <ykhodork@cisco.com>
opendaylight/web/devices/src/main/resources/js/page.js
opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java
opendaylight/web/flows/src/main/resources/js/page.js

index 96b16bf..e0d052d 100644 (file)
@@ -104,18 +104,27 @@ one.f.switchmanager.nodesLearnt = {
        modal : {
                initialize: {
                        updateNode: function(evt) {
-                               var nodeId = decodeURIComponent(evt.target.id);
-                               var h3 = "Update Node Information";
-                   var footer = one.f.switchmanager.nodesLearnt.modal.footer.updateNode();
-                   var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.modal, h3, "", footer);
-                   
-                   // bind save button
-                   $('#' + one.f.switchmanager.nodesLearnt.id.modal.save, $modal).click(function() {
-                       one.f.switchmanager.nodesLearnt.modal.save($modal);
-                   });
-                   // inject body (nodePorts)
                    one.f.switchmanager.nodesLearnt.ajax.main(one.f.switchmanager.rootUrl + "/tiers", function(tiers) {
-                       var $body = one.f.switchmanager.nodesLearnt.modal.body.updateNode(nodeId, evt.target.switchDetails, tiers);
+
+                    var nodeId = decodeURIComponent(evt.target.id);
+                    var h3;
+                    var footer = [];
+                    var $body = one.f.switchmanager.nodesLearnt.modal.body.updateNode(nodeId, evt.target.switchDetails, tiers);
+                    if (one.main.registry.container == 'default' && evt.target.privilege == 'WRITE'){
+                        h3 = "Update Node Information";
+                        footer = one.f.switchmanager.nodesLearnt.modal.footer.updateNode();
+                    } else { //disable node edit
+                        $body.find('*').attr('disabled', 'disabled');
+                        h3 = 'Node Information';
+                    }
+
+                    var $modal = one.lib.modal.spawn(one.f.switchmanager.nodesLearnt.id.modal.modal, h3, "", footer);
+                    // bind save button
+                    $('#' + one.f.switchmanager.nodesLearnt.id.modal.save, $modal).click(function() {
+                        one.f.switchmanager.nodesLearnt.modal.save($modal);
+                    });
+
+                       // inject body (nodePorts)
                        one.lib.modal.inject.body($modal, $body);
                        $modal.modal();
                    });
@@ -160,7 +169,6 @@ one.f.switchmanager.nodesLearnt = {
                                $select.attr('id', one.f.switchmanager.nodesLearnt.id.modal.form.operationMode);
                                $select.val(switchDetails["mode"]);
                                $fieldset.append($label).append($select);
-                               
                                $form.append($fieldset);
                                return $form;
                        },
@@ -205,11 +213,10 @@ one.f.switchmanager.nodesLearnt = {
                footer: {
                        updateNode: function() {
                                var footer = [];
-                               if(one.role < 2) {
-                                       var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.nodesLearnt.id.modal.save, "btn-success", "");
-                           var $saveButton = one.lib.dashlet.button.button(saveButton);
-                           footer.push($saveButton);
-                               }
+                var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.nodesLearnt.id.modal.save, "btn-success", "");
+                var $saveButton = one.lib.dashlet.button.button(saveButton);
+                footer.push($saveButton);
+
                    return footer;
                        },
                        popout: function() {
@@ -226,14 +233,17 @@ one.f.switchmanager.nodesLearnt = {
                                var tr = {};
                                var entry = [];
                                var nodenameentry = value["nodeName"] ? value["nodeName"] : "Click to update";
+
                                // TODO: Move anchor tag creation to one.lib.form.
-                               var aTag = document.createElement("a");
-                               aTag.setAttribute("id", encodeURIComponent(value["nodeId"]));
-                               aTag.switchDetails = value;
-                               aTag.addEventListener("click", one.f.switchmanager.nodesLearnt.modal.initialize.updateNode);
-                               aTag.addEventListener("mouseover", function(evt) {
-                                       evt.target.style.cursor = "pointer";
-                               }, false);
+                               var aTag;
+                aTag = document.createElement("a");
+                aTag.privilege = data.privilege;
+                aTag.addEventListener("click", one.f.switchmanager.nodesLearnt.modal.initialize.updateNode);
+                aTag.addEventListener("mouseover", function(evt) {
+                    evt.target.style.cursor = "pointer";
+                }, false);
+                aTag.setAttribute("id", encodeURIComponent(value["nodeId"]));
+                aTag.switchDetails = value;
                                aTag.innerHTML = nodenameentry;
                                entry.push(aTag);
                                entry.push(value["nodeId"]);
@@ -287,55 +297,56 @@ one.f.switchmanager.subnetGatewayConfig = {
                one.lib.dashlet.empty($dashlet);
                $dashlet.append(one.lib.dashlet.header(one.f.dashlet.subnetGatewayConfig.name));
                // Add gateway IP Address button
-               if(one.role < 2) {
-                       var button = one.lib.dashlet.button.single("Add Gateway IP Address", 
-                                       one.f.switchmanager.subnetGatewayConfig.id.dashlet.addIPAddress, "btn-primary", "btn-mini");
-               var $button = one.lib.dashlet.button.button(button);
-               $button.click(function() {
-                       var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.gateway();
-                   $modal.modal();
-               });
-                       $dashlet.append($button);
-               
-               
-                       // Delete gateway ip address button
-               var button = one.lib.dashlet.button.single("Delete Gateway IP Address(es)", 
-                               one.f.switchmanager.subnetGatewayConfig.id.dashlet.removeIPAddress, "btn-primary", "btn-mini");
-               var $button = one.lib.dashlet.button.button(button);
-               $button.click(function() {
-                       var requestData = {};
-                       var gatewaysToDelete = [];
-                       var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
-                       checkedCheckBoxes.each(function(index, value) {
-                               gatewaysToDelete.push(checkedCheckBoxes[index].id);
-                       }); 
-                       if(gatewaysToDelete.length > 0) {
-                               requestData["gatewaysToDelete"] = gatewaysToDelete.toString();
-                       var url = one.f.switchmanager.rootUrl + "/subnetGateway/delete";
-                               one.f.switchmanager.subnetGatewayConfig.ajax.main(url, requestData, function(response) {
-                                       if(response.status == true) {
-                                               // refresh dashlet by passing dashlet div as param
-                               one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
-                                       } else {
-                                               alert(response.message);
-                                       }
-                               });
-                       } 
-               });
-               $dashlet.append($button);
-       
-                       // Add Ports button
-                       var button = one.lib.dashlet.button.single("Add Ports", 
-                                       one.f.switchmanager.subnetGatewayConfig.id.dashlet.addPorts, "btn-primary", "btn-mini");
-               var $button = one.lib.dashlet.button.button(button);
-               $button.click(function() {
-                       var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.ports();
-                   $modal.modal();
-               });
-                       $dashlet.append($button);
-               }
                var url = one.f.switchmanager.rootUrl + "/subnets";
                one.f.switchmanager.subnetGatewayConfig.ajax.main(url, {}, function(content) {
+
+            if (content.privilege === 'WRITE') {
+                var button = one.lib.dashlet.button.single("Add Gateway IP Address",
+                    one.f.switchmanager.subnetGatewayConfig.id.dashlet.addIPAddress, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+                $button.click(function() {
+                    var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.gateway();
+                    $modal.modal();
+                });
+                $dashlet.append($button);
+
+                // Delete gateway ip address button
+                var button = one.lib.dashlet.button.single("Delete Gateway IP Address(es)",
+                    one.f.switchmanager.subnetGatewayConfig.id.dashlet.removeIPAddress, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+                $button.click(function() {
+                    var requestData = {};
+                    var gatewaysToDelete = [];
+                    var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
+                    checkedCheckBoxes.each(function(index, value) {
+                        gatewaysToDelete.push(checkedCheckBoxes[index].id);
+                    });
+                    if (gatewaysToDelete.length > 0) {
+                        requestData["gatewaysToDelete"] = gatewaysToDelete.toString();
+                        var url = one.f.switchmanager.rootUrl + "/subnetGateway/delete";
+                        one.f.switchmanager.subnetGatewayConfig.ajax.main(url, requestData, function(response) {
+                            if (response.status == true) {
+                                // refresh dashlet by passing dashlet div as param
+                                one.f.switchmanager.subnetGatewayConfig.dashlet($("#right-bottom .dashlet"));
+                            } else {
+                                alert(response.message);
+                            }
+                        });
+                    }
+                });
+                $dashlet.append($button);
+
+                // Add Ports button
+                var button = one.lib.dashlet.button.single("Add Ports",
+                    one.f.switchmanager.subnetGatewayConfig.id.dashlet.addPorts, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+                $button.click(function() {
+                    var $modal = one.f.switchmanager.subnetGatewayConfig.modal.initialize.ports();
+                    $modal.modal();
+                });
+                $dashlet.append($button);
+            }
+
                        var body = one.f.switchmanager.subnetGatewayConfig.data.devices(content);
                        // first column contains checkbox. no need for header
                        content.columnNames.splice(0,0," ");
@@ -502,11 +513,9 @@ one.f.switchmanager.subnetGatewayConfig = {
                },
                footer : function() {
             var footer = [];
-            if(one.role < 2) {
-                var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.subnetGatewayConfig.id.modal.save, "btn-success", "");
-                 var $saveButton = one.lib.dashlet.button.button(saveButton);
-                 footer.push($saveButton);
-            }
+            var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.subnetGatewayConfig.id.modal.save, "btn-success", "");
+            var $saveButton = one.lib.dashlet.button.button(saveButton);
+            footer.push($saveButton);
             return footer;
         }
        },
@@ -591,47 +600,47 @@ one.f.switchmanager.staticRouteConfig = {
        dashlet: function($dashlet) {
                one.lib.dashlet.empty($dashlet);
                
-               if(one.role < 2) {
-                       // Add static route button
-                       var button = one.lib.dashlet.button.single("Add Static Route", 
-                                       one.f.switchmanager.staticRouteConfig.id.dashlet.add, "btn-primary", "btn-mini");
-               var $button = one.lib.dashlet.button.button(button);
-               $button.click(function() {
-                       var $modal = one.f.switchmanager.staticRouteConfig.modal.initialize();
-                   $modal.modal();
-               });
-               $dashlet.append(one.lib.dashlet.header(one.f.dashlet.staticRouteConfig.name));
-               $dashlet.append($button);
-               
-               // Delete static route button
-               var button = one.lib.dashlet.button.single("Delete Static Route(s)", 
-                               one.f.switchmanager.staticRouteConfig.id.dashlet.remove, "btn-primary", "btn-mini");
-               var $button = one.lib.dashlet.button.button(button);
-               $button.click(function() {
-                       var requestData = {};
-                       var routesToDelete = [];
-                       var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
-                       checkedCheckBoxes.each(function(index, value) {
-                               routesToDelete.push(checkedCheckBoxes[index].id);
-                       }); 
-                       if(routesToDelete.length > 0) {
-                               requestData["routesToDelete"] = routesToDelete.toString();
-                       var url = one.f.switchmanager.rootUrl + "/staticRoute/delete";
-                               one.f.switchmanager.staticRouteConfig.ajax.main(url, requestData, function(response) {
-                                       if(response.status == true) {
-                                               // refresh dashlet by passing dashlet div as param
-                               one.f.switchmanager.staticRouteConfig.dashlet($("#left-bottom .dashlet"));
-                                       } else {
-                                               alert(response.message);
-                                       }
-                               });
-                       } 
-               });
-               $dashlet.append($button);
-               }
-               
+
                var url = one.f.switchmanager.rootUrl + "/staticRoutes";
                one.f.switchmanager.staticRouteConfig.ajax.main(url, {}, function(content) {
+
+            if (content.privilege === 'WRITE') {
+                // Add static route button
+                var button = one.lib.dashlet.button.single("Add Static Route", one.f.switchmanager.staticRouteConfig.id.dashlet.add, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+                $button.click(function() {
+                    var $modal = one.f.switchmanager.staticRouteConfig.modal.initialize();
+                    $modal.modal();
+                });
+                $dashlet.append(one.lib.dashlet.header(one.f.dashlet.staticRouteConfig.name));
+                $dashlet.append($button);
+
+                // Delete static route button
+                var button = one.lib.dashlet.button.single("Delete Static Route(s)", one.f.switchmanager.staticRouteConfig.id.dashlet.remove, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+                $button.click(function() {
+                    var requestData = {};
+                    var routesToDelete = [];
+                    var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
+                    checkedCheckBoxes.each(function(index, value) {
+                        routesToDelete.push(checkedCheckBoxes[index].id);
+                    });
+                    if (routesToDelete.length > 0) {
+                        requestData["routesToDelete"] = routesToDelete.toString();
+                        var url = one.f.switchmanager.rootUrl + "/staticRoute/delete";
+                        one.f.switchmanager.staticRouteConfig.ajax.main(url, requestData, function(response) {
+                            if (response.status == true) {
+                                // refresh dashlet by passing dashlet div as param
+                                one.f.switchmanager.staticRouteConfig.dashlet($("#left-bottom .dashlet"));
+                            } else {
+                                alert(response.message);
+                            }
+                        });
+                    }
+                });
+                $dashlet.append($button);
+            }
+
                        var body = one.f.switchmanager.staticRouteConfig.data.staticRouteConfig(content);
                        // first column contains checkbox. no need for header
                        content.columnNames.splice(0,0," ");
@@ -712,11 +721,9 @@ one.f.switchmanager.staticRouteConfig = {
         },
                footer : function() {
             var footer = [];
-            if (one.role < 2) {
-                var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.staticRouteConfig.id.modal.save, "btn-success", "");
-                 var $saveButton = one.lib.dashlet.button.button(saveButton);
-                 footer.push($saveButton);
-            }
+            var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.staticRouteConfig.id.modal.save, "btn-success", "");
+            var $saveButton = one.lib.dashlet.button.button(saveButton);
+            footer.push($saveButton);
             return footer;
         }
        },
@@ -761,51 +768,52 @@ one.f.switchmanager.spanPortConfig = {
        },
        dashlet: function($dashlet) {
                one.lib.dashlet.empty($dashlet);
-               if(one.role < 2) {
-
-                       // Add span port button
-                       var button = one.lib.dashlet.button.single("Add Span Port", one.f.switchmanager.spanPortConfig.id.dashlet.add, "btn-primary", "btn-mini");
-                       var $button = one.lib.dashlet.button.button(button);
-
-                       $button.click(function() {
-                               var $modal = one.f.switchmanager.spanPortConfig.modal.initialize();
-                               $modal.modal();
-                       });
-                       $dashlet.append(one.lib.dashlet.header(one.f.dashlet.spanPortConfig.name));
-                       $dashlet.append($button);
-
-                       // Delete span port button
-                       var button = one.lib.dashlet.button.single("Delete SPAN Port(s)", 
-                                       one.f.switchmanager.spanPortConfig.id.dashlet.remove, "btn-primary", "btn-mini");
-                       var $button = one.lib.dashlet.button.button(button);
-                       $button.click(function() {
-
-                               var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
-                               if(checkedCheckBoxes.length > 0) {
-                                       var spanPortsToDelete = "";
-                                       checkedCheckBoxes.each(function(index, value) {
-                                               spanPortsToDelete += checkedCheckBoxes[index].spanPort + "###";
-                                       }); 
-
-                                       var requestData = {};
-                                       requestData["spanPortsToDelete"] = spanPortsToDelete;
-                                       var url = one.f.switchmanager.rootUrl + "/spanPorts/delete";
-                                       one.f.switchmanager.spanPortConfig.ajax.main(url, requestData, function(response) {
-                                               if(response.status == true) {
-                                                       // refresh dashlet by passing dashlet div as param
-                                                       one.f.switchmanager.spanPortConfig.dashlet($("#right-bottom .dashlet"));
-                                               } else {
-                                                       alert(response.message);
-                                               }
-                                       });
-                               }
-                       });
-                       $dashlet.append($button);
-               }
         
         //populate table in dashlet
                var url = one.f.switchmanager.rootUrl + "/spanPorts";
                one.f.switchmanager.spanPortConfig.ajax.main(url, {}, function(content) {
+
+            if (content.privilege === 'WRITE') {
+
+                // Add span port button
+                var button = one.lib.dashlet.button.single("Add Span Port", one.f.switchmanager.spanPortConfig.id.dashlet.add, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+
+                $button.click(function() {
+                    var $modal = one.f.switchmanager.spanPortConfig.modal.initialize();
+                    $modal.modal();
+                });
+                $dashlet.append(one.lib.dashlet.header(one.f.dashlet.spanPortConfig.name));
+                $dashlet.append($button);
+
+                // Delete span port button
+                var button = one.lib.dashlet.button.single("Delete SPAN Port(s)", one.f.switchmanager.spanPortConfig.id.dashlet.remove, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+                $button.click(function() {
+
+                    var checkedCheckBoxes = $("input:checked", $(this).closest(".dashlet").find("table"));
+                    if (checkedCheckBoxes.length > 0) {
+                        var spanPortsToDelete = "";
+                        checkedCheckBoxes.each(function(index, value) {
+                            spanPortsToDelete += checkedCheckBoxes[index].spanPort + "###";
+                        });
+
+                        var requestData = {};
+                        requestData["spanPortsToDelete"] = spanPortsToDelete;
+                        var url = one.f.switchmanager.rootUrl + "/spanPorts/delete";
+                        one.f.switchmanager.spanPortConfig.ajax.main(url, requestData, function(response) {
+                            if (response.status == true) {
+                                // refresh dashlet by passing dashlet div as param
+                                one.f.switchmanager.spanPortConfig.dashlet($("#right-bottom .dashlet"));
+                            } else {
+                                alert(response.message);
+                            }
+                        });
+                    }
+                });
+                $dashlet.append($button);
+            }
+
                        var body = one.f.switchmanager.spanPortConfig.data.devices(content);
                        // first column contains the checkbox. no header required.
                        content.columnNames.splice(0,0," ");
@@ -911,11 +919,9 @@ one.f.switchmanager.spanPortConfig = {
         },
                footer : function() {
             var footer = [];
-            if (one.role < 2) {
-                var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.spanPortConfig.id.modal.save, "btn-success", "");
-                var $saveButton = one.lib.dashlet.button.button(saveButton);
-                footer.push($saveButton);
-            }
+            var saveButton = one.lib.dashlet.button.single("Save", one.f.switchmanager.spanPortConfig.id.modal.save, "btn-success", "");
+            var $saveButton = one.lib.dashlet.button.button(saveButton);
+            footer.push($saveButton);
             return footer;
         }
        },
index f9e6a6a..c434134 100644 (file)
@@ -75,12 +75,13 @@ public class Flows implements IDaylightWeb {
 
     @RequestMapping(value = "/main")
     @ResponseBody
-    public Set<Map<String, Object>> getFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
+    public Map<String, Object> getFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
         String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
 
         // Derive the privilege this user has on the current container
         String userName = request.getUserPrincipal().getName();
-        if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
+        Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
+        if (privilege  == Privilege.NONE) {
             return null;
         }
 
@@ -100,7 +101,7 @@ public class Flows implements IDaylightWeb {
 
         // get static flow list
         List<FlowConfig> staticFlowList = frm.getStaticFlows();
-        Set<Map<String, Object>> output = new HashSet<Map<String, Object>>();
+        Set<Map<String, Object>> flowSet = new HashSet<Map<String, Object>>();
         for (FlowConfig flowConfig : staticFlowList) {
             Map<String, Object> entry = new HashMap<String, Object>();
             entry.put("flow", flowConfig);
@@ -110,9 +111,12 @@ public class Flows implements IDaylightWeb {
             entry.put("node", (description.isEmpty() || description
                     .equalsIgnoreCase("none")) ? node.toString() : description);
             entry.put("nodeId", node.toString());
-            output.add(entry);
+            flowSet.add(entry);
         }
 
+        Map <String, Object> output = new HashMap<String, Object>(2);
+        output.put("flows", flowSet);
+        output.put("privilege", privilege);
         return output;
     }
 
index f92e596..577570f 100644 (file)
@@ -1,9 +1,9 @@
 
-/* 
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved. 
- * 
- * This program and the accompanying materials are made available under the 
- * terms of the Eclipse Public License v1.0 which accompanies this distribution, 
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
@@ -60,7 +60,7 @@ one.f.nodes = {
     dashlet : function($dashlet) {
         var $h4 = one.lib.dashlet.header("Nodes");
         $dashlet.append($h4);
-        
+
         // load body
         one.f.nodes.ajax.dashlet(function($table) {
                        // total nodes count
@@ -109,14 +109,14 @@ one.f.nodes = {
         dashlet : function(body, callback) {
             var attributes = ['table-striped', 'table-bordered', 'table-hover', 'table-condensed'];
             var $table = one.lib.dashlet.table.table(attributes);
-            
+
             var headers = ['Node', 'Flows'];
             var $thead = one.lib.dashlet.table.header(headers);
             $table.append($thead);
-            
+
             var $tbody = one.lib.dashlet.table.body(body);
             $table.append($tbody);
-            
+
             return $table;
         }
     }
@@ -129,7 +129,7 @@ one.f.detail = {
     dashlet : function($dashlet, details) {
         var $h4 = one.lib.dashlet.header("Flow Details");
         $dashlet.append($h4);
-        
+
         // details
         if (details == undefined) {
                var $none = $(document.createElement('div'));
@@ -137,7 +137,7 @@ one.f.detail = {
             var $p = $(document.createElement('p'));
             $p.text('Please select a flow');
             $p.addClass('text-center').addClass('text-info');
-            
+
             $dashlet.append($none)
                .append($p);
         }
@@ -302,23 +302,32 @@ one.f.flows = {
     },
     registry : {},
     dashlet : function($dashlet, callback) {
-        var $h4 = one.lib.dashlet.header("Flow Entries");
-        
-        if (one.role < 2) {
-               var button = one.lib.dashlet.button.single("Add Flow Entry", one.f.flows.id.dashlet.add, "btn-primary", "btn-mini");
-               var $button = one.lib.dashlet.button.button(button);
-               
-               $button.click(function() {
-                   var $modal = one.f.flows.modal.initialize();
-                   $modal.modal();
-               });
-        }
-        
-        $dashlet.append($h4);
-        if (one.role < 2) $dashlet.append($button);
-        
+
         // load body
         one.f.flows.ajax.dashlet(function($table) {
+
+            var $h4 = one.lib.dashlet.header("Flow Entries");
+
+            $dashlet.append($h4);
+            if (one.f.flows.registry.privilege === 'WRITE') {
+                var button = one.lib.dashlet.button.single("Add Flow Entry", one.f.flows.id.dashlet.add, "btn-primary", "btn-mini");
+                var $button = one.lib.dashlet.button.button(button);
+
+                $button.click(function() {
+                    var $modal = one.f.flows.modal.initialize();
+                    $modal.modal();
+                });
+                $dashlet.append($button);
+
+            }
+
+            // table bindings
+            $table.find('tbody').find('tr').click(function() {
+                var id = $($(this).find('td')[0]).text();
+                var node = $(this).data('id');
+                one.f.flows.detail(id, node);
+            });
+
                        // total flows
                        var flowCount = $table.find('tbody').find('tr').size();
                        // prompt output
@@ -332,13 +341,7 @@ one.f.flows = {
                        $p = $(document.createElement('p'));
                        $p.append(out);
                        $dashlet.append($p);
-            // table bindings
-            $table.find('tbody').find('tr').click(function() {
-                var id = $($(this).find('td')[0]).text();
-                               var node = $(this).data('id');
-                one.f.flows.detail(id, node);
-            });
-            // add to dashlet
+            // add table to dashlet
             $dashlet.append($table);
             // details callback
             if(callback != undefined) callback();
@@ -350,7 +353,7 @@ one.f.flows = {
         $detailDashlet.empty();
         var $h4 = one.lib.dashlet.header("Flow Overview");
         $detailDashlet.append($h4);
-        
+
         // details
         var flows = one.f.flows.registry.flows;
         var flow;
@@ -359,7 +362,7 @@ one.f.flows = {
                 flow = value;
             }
         });
-        if (one.role < 2) {
+        if (one.f.flows.registry.privilege === 'WRITE') {
                // remove button
                var button = one.lib.dashlet.button.single("Remove Flow", one.f.flows.id.dashlet.remove, "btn-danger", "btn-mini");
                var $button = one.lib.dashlet.button.button(button);
@@ -395,11 +398,12 @@ one.f.flows = {
                        }
                    });
                });
+
+               $detailDashlet.append($button).append($toggle);
         }
         // append details
         var body = one.f.detail.data.dashlet(flow);
         var $body = one.f.detail.body.dashlet(body);
-        if (one.role < 2) $detailDashlet.append($button).append($toggle);
         $detailDashlet.append($body);
                var body = one.f.detail.data.description(flow);
                var $body = one.f.detail.body.description(body);
@@ -436,15 +440,15 @@ one.f.flows = {
             },
             footer : function() {
                 var footer = [];
-                
+
                 var removeButton = one.lib.dashlet.button.single("Remove Flow", one.f.flows.id.modal.dialog.remove, "btn-danger", "");
                 var $removeButton = one.lib.dashlet.button.button(removeButton);
                 footer.push($removeButton);
-                
+
                 var closeButton = one.lib.dashlet.button.single("Cancel", one.f.flows.id.modal.dialog.close, "", "");
                 var $closeButton = one.lib.dashlet.button.button(closeButton);
                 footer.push($closeButton);
-                
+
                 return footer;
             },
             body : function(id) {
@@ -457,12 +461,12 @@ one.f.flows = {
             var h3 = "Add Flow Entry";
             var footer = one.f.flows.modal.footer();
             var $modal = one.lib.modal.spawn(one.f.flows.id.modal.modal, h3, "", footer);
-            
+
             // bind close button
             $('#'+one.f.flows.id.modal.close, $modal).click(function() {
                 $modal.modal('hide');
             });
-            
+
             // bind add flow button
             $('#'+one.f.flows.id.modal.add, $modal).click(function() {
                 one.f.flows.modal.add($modal, 'false');
@@ -472,18 +476,18 @@ one.f.flows = {
             $('#'+one.f.flows.id.modal.install, $modal).click(function() {
                 one.f.flows.modal.add($modal, 'true');
             });
-            
+
             // inject body (nodePorts)
             one.f.flows.modal.ajax.nodes(function(nodes, nodeports) {
                 var $body = one.f.flows.modal.body(nodes, nodeports);
                 one.lib.modal.inject.body($modal, $body);
             });
-            
+
             return $modal;
         },
         add : function($modal, install) {
             var result = {};
-            
+
             result['name'] = $('#'+one.f.flows.id.modal.form.name, $modal).val();
             result['ingressPort'] = $('#'+one.f.flows.id.modal.form.port, $modal).val();
             result['priority'] = $('#'+one.f.flows.id.modal.form.priority, $modal).val();
@@ -505,11 +509,11 @@ one.f.flows = {
                        result['installInHw'] = install;
 
             var nodeId = $('#'+one.f.flows.id.modal.form.nodes, $modal).val();
-            
+
             $.each(result, function(key, value) {
                 if (value == "") delete result[key];
             });
-            
+
             var action = [];
             var $table = $('#'+one.f.flows.id.modal.action.table, $modal);
             $($table.find('tbody').find('tr')).each(function(index, value) {
@@ -518,7 +522,7 @@ one.f.flows = {
                                }
             });
             result['actions'] = action;
-            
+
             // frontend validation
                        if (result['name'] == undefined) {
                                alert('Need flow name');
@@ -532,13 +536,13 @@ one.f.flows = {
                                alert('Please specify an action');
                                return;
                        }
-            
+
                        // package for ajax call
             var resource = {};
             resource['body'] = JSON.stringify(result);
             resource['action'] = 'add';
                        resource['nodeId'] = nodeId;
-            
+
             one.f.flows.modal.ajax.saveflow(resource, function(data) {
                 if (data == "Success") {
                     $modal.modal('hide');
@@ -556,7 +560,7 @@ one.f.flows = {
                     var nodes = one.f.flows.modal.data.nodes(data);
                     var nodeports = data;
                     one.f.flows.registry['nodeports'] = nodeports;
-                    
+
                     successCallback(nodes, nodeports);
                 });
             },
@@ -606,7 +610,7 @@ one.f.flows = {
                        one.lib.form.select.prepend($select, { '' : 'Please Select a Node' });
                        $select.val($select.find("option:first").val());
                        $select.attr('id', one.f.flows.id.modal.form.nodes);
-                       
+
                        // bind onchange
                        $select.change(function() {
                            // retrieve port value
@@ -763,9 +767,9 @@ one.f.flows = {
                 one.f.flows.modal.action.parse(action.attr('value'));
                                $select[0].selectedIndex = 0;
             });
-            
+
                        $fieldset.append($select).append($table);
-            
+
                        // return
                        $form.append($fieldset);
                        return $form;
@@ -1128,11 +1132,11 @@ one.f.flows = {
                 var addButton = one.lib.dashlet.button.single("Add Action", one.f.flows.id.modal.action.add, "btn-primary", "");
                 var $addButton = one.lib.dashlet.button.button(addButton);
                 footer.push($addButton);
-                
+
                 var closeButton = one.lib.dashlet.button.single("Close", one.f.flows.id.modal.action.close, "", "");
                 var $closeButton = one.lib.dashlet.button.button(closeButton);
                 footer.push($closeButton);
-                
+
                 return footer;
             }
         },
@@ -1142,23 +1146,24 @@ one.f.flows = {
                        var installButton = one.lib.dashlet.button.single("Install Flow", one.f.flows.id.modal.install, "btn-success", "");
                        var $installButton = one.lib.dashlet.button.button(installButton);
                        footer.push($installButton);
-            
+
             var addButton = one.lib.dashlet.button.single("Save Flow", one.f.flows.id.modal.add, "btn-primary", "");
             var $addButton = one.lib.dashlet.button.button(addButton);
             footer.push($addButton);
-            
+
             var closeButton = one.lib.dashlet.button.single("Close", one.f.flows.id.modal.close, "", "");
             var $closeButton = one.lib.dashlet.button.button(closeButton);
             footer.push($closeButton);
-            
+
             return footer;
         }
     },
     ajax : {
         dashlet : function(callback) {
             $.getJSON(one.f.address.root+one.f.address.flows.main, function(data) {
-                one.f.flows.registry['flows'] = data;
-                var body = one.f.flows.data.dashlet(data);
+                one.f.flows.registry['flows'] = data.flows;
+                one.f.flows.registry['privilege'] = data.privilege;
+                var body = one.f.flows.data.dashlet(data.flows);
                 var $body = one.f.flows.body.dashlet(body, callback);
                 callback($body);
             });
@@ -1178,7 +1183,7 @@ one.f.flows = {
                        tr['type'] = ['warning'];
                 tr['entry'] = entry;
                 tr['id'] = value['nodeId'];
-                
+
                 body.push(tr);
             });
             return body;
@@ -1188,14 +1193,14 @@ one.f.flows = {
         dashlet : function(body, callback) {
             var attributes = ['table-striped', 'table-bordered', 'table-hover', 'table-condensed', 'table-cursor'];
             var $table = one.lib.dashlet.table.table(attributes);
-            
+
             var headers = ['Flow Name', 'Node'];
             var $thead = one.lib.dashlet.table.header(headers);
             $table.append($thead);
-            
+
             var $tbody = one.lib.dashlet.table.body(body);
             $table.append($tbody);
-            
+
             return $table;
         }
     }