瀏覽代碼

AMBARI-10328. No 'Manage Ambari' link on step 9 of Install Wizard after relogin. (akovalenko)

Aleksandr Kovalenko 10 年之前
父節點
當前提交
888a24daa3
共有 4 個文件被更改,包括 80 次插入9 次删除
  1. 1 0
      ambari-web/app/app.js
  2. 11 4
      ambari-web/app/router.js
  3. 7 5
      ambari-web/app/templates/application.hbs
  4. 61 0
      ambari-web/test/router_test.js

+ 1 - 0
ambari-web/app/app.js

@@ -34,6 +34,7 @@ module.exports = Em.Application.create({
   }),
   isAdmin: false,
   isOperator: false,
+  isPermissionDataLoaded: false,
 
   /**
    * state of stack upgrade process

+ 11 - 4
ambari-web/app/router.js

@@ -299,14 +299,17 @@ App.Router = Em.Router.extend({
           var clusterName = clustersData.items[0].Clusters.cluster_name;
           var clusterPermissions = privileges.filterProperty('PrivilegeInfo.cluster_name', clusterName).mapProperty('PrivilegeInfo.permission_name');
           if (clusterPermissions.contains('CLUSTER.OPERATE')) {
-            App.set('isAdmin', true);
-            App.set('isOperator', true);
+            App.setProperties({
+              isAdmin: true,
+              isOperator: true
+            });
             transitionToApp = true;
           } else if (clusterPermissions.contains('CLUSTER.READ')) {
             transitionToApp = true;
           }
         }
       }
+      App.set('isPermissionDataLoaded', true);
       if (transitionToApp) {
         if (!Em.isNone(router.get('preferedPath'))) {
           window.location = router.get('preferedPath');
@@ -384,8 +387,11 @@ App.Router = Em.Router.extend({
     // otherwise, this.set('installerController.currentStep, 0) would have no effect
     // since it's a computed property but we are not setting it as a dependent of App.db.
     App.db.cleanUp();
-    App.set('isAdmin', false);
-    App.set('isOperator', false);
+    App.setProperties({
+      isAdmin: false,
+      isOperator: false,
+      isPermissionDataLoaded: false
+    });
     this.set('loggedIn', false);
     this.clearAllSteps();
     console.log("Log off: " + App.router.getClusterName());
@@ -435,6 +441,7 @@ App.Router = Em.Router.extend({
         if (user.operator) {
           App.set('isOperator', true);
         }
+        App.set('isPermissionDataLoaded', true);
       }
     }
   },

+ 7 - 5
ambari-web/app/templates/application.hbs

@@ -68,11 +68,13 @@
                     {{/isAccessible}}
                   {{/if}}
                 {{else}}
-                  {{#isAccessible upgrade_ONLY_ADMIN}}
-                    <li><a href=""
-                           id="manage-ambari" {{action goToAdminView target="controller"}}>{{t app.manageAmbari}}</a>
-                    </li>
-                  {{/isAccessible}}
+                  {{#if App.isPermissionDataLoaded}}
+                    {{#isAccessible upgrade_ONLY_ADMIN}}
+                      <li><a href=""
+                             id="manage-ambari" {{action goToAdminView target="controller"}}>{{t app.manageAmbari}}</a>
+                      </li>
+                    {{/isAccessible}}
+                  {{/if}}
                 {{/if}}
                 {{#if isClusterDataLoaded}}
                   {{#isAccessible upgrade_ADMIN}}

+ 61 - 0
ambari-web/test/router_test.js

@@ -47,4 +47,65 @@ describe('App.Router', function () {
     })
   });
 
+  describe('#initAdmin()', function () {
+
+    var cases = [
+      {
+        user: {
+          admin: true
+        },
+        isAdmin: true,
+        isOperator: false,
+        isPermissionDataLoaded: true,
+        title: 'admin'
+      },
+      {
+        user: {
+          operator: true
+        },
+        isAdmin: false,
+        isOperator: true,
+        isPermissionDataLoaded: true,
+        title: 'operator'
+      },
+      {
+        user: {},
+        isAdmin: false,
+        isOperator: false,
+        isPermissionDataLoaded: true,
+        title: 'read only access'
+      },
+      {
+        user: null,
+        isAdmin: false,
+        isOperator: false,
+        isPermissionDataLoaded: false,
+        title: 'no user'
+      }
+    ];
+
+    beforeEach(function () {
+      App.setProperties({
+        isAdmin: false,
+        isOperator: false,
+        isPermissionDataLoaded: false
+      });
+    });
+
+    afterEach(function () {
+      App.db.getUser.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        sinon.stub(App.db, 'getUser').returns(item.user);
+        router.initAdmin();
+        expect(App.get('isAdmin')).to.equal(item.isAdmin);
+        expect(App.get('isOperator')).to.equal(item.isOperator);
+        expect(App.get('isPermissionDataLoaded')).to.equal(item.isPermissionDataLoaded);
+      });
+    });
+
+  });
+
 });