Bladeren bron

HPCC-10266 Disable banner usage from users

Enable set banner messages to only administrators.

Signed-off by: Miguel Vazquez <miguel.vazquez@lexisnexis.com>
Miguel Vazquez 11 jaren geleden
bovenliggende
commit
5d4b460246
2 gewijzigde bestanden met toevoegingen van 56 en 4 verwijderingen
  1. 30 4
      esp/files/scripts/HPCCPlatformWidget.js
  2. 26 0
      esp/files/scripts/ws_access.js

+ 30 - 4
esp/files/scripts/HPCCPlatformWidget.js

@@ -16,6 +16,7 @@
 define([
     "dojo/_base/declare",
     "dojo/_base/lang",
+    "dojo/_base/array",
     "dojo/dom",
     "dojo/dom-style",
 
@@ -27,6 +28,7 @@ define([
     "hpcc/_TabContainerWidget",
     "hpcc/ESPRequest",
     "hpcc/WsAccount",
+    "hpcc/ws_access",
     "hpcc/WsSMC",
     "hpcc/GraphWidget",
 
@@ -51,10 +53,10 @@ define([
     "hpcc/HPCCPlatformRoxieWidget",
     "hpcc/HPCCPlatformOpsWidget"
 
-], function (declare, lang, dom, domStyle,
+], function (declare, lang, arrayUtil, dom, domStyle,
                 registry, Tooltip,
                 UpgradeBar,
-                _TabContainerWidget, ESPRequest, WsAccount, WsSMC, GraphWidget,
+                _TabContainerWidget, ESPRequest, WsAccount, WsAccess, WsSMC, GraphWidget,
                 template) {
     return declare("HPCCPlatformWidget", [_TabContainerWidget], {
         templateString: template,
@@ -118,14 +120,16 @@ define([
         },
 
         init: function (params) {
-             if (this.inherited(arguments))
+            if (this.inherited(arguments))
                 return;
-
             var context = this;
+            registry.byId(context.id + "SetBanner").set("disabled", true);
+
             WsAccount.MyAccount({
             }).then(function (response) {
                 if (lang.exists("MyAccountResponse.username", response)) {
                     dom.byId(context.id + "UserID").innerHTML = response.MyAccountResponse.username;
+                    context.checkIfAdmin(response.MyAccountResponse.username);
                 }
             });
 
@@ -154,6 +158,28 @@ define([
             return "HPCC Platform";
         },
 
+        checkIfAdmin: function (user) {
+            var context = this;
+            if(user == null){
+                registry.byId(context.id + "SetBanner").set("disabled", false);
+            }else{
+                WsAccess.UserEdit({
+                    request: {
+                        username: user
+                    }
+                }).then(function (response) {
+                    if (lang.exists("UserEditResponse.Groups.Group", response)) {
+                        arrayUtil.forEach(response.UserEditResponse.Groups.Group, function (item, idx) {
+                            if(item.name == "Administrators"){
+                                registry.byId(context.id + "SetBanner").set("disabled", false);
+                                return true;
+                            }
+                        });
+                    }
+                });
+            }
+        },
+
         //  Hitched actions  ---
         _onFind: function (evt) {
             this.stackContainer.selectChild(this.mainPage);

+ 26 - 0
esp/files/scripts/ws_access.js

@@ -0,0 +1,26 @@
+/*##############################################################################
+#    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
+#
+#    Licensed 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.
+############################################################################## */
+define([
+    "hpcc/ESPRequest"
+], function (
+    ESPRequest) {
+    return {
+        UserEdit: function (params) {
+            return ESPRequest.send("ws_access", "UserEdit", params);
+        }
+    };
+});
+