You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rz...@apache.org on 2015/11/20 00:06:52 UTC

ambari git commit: AMBARI-13805. Add permission label to to the dataset returned by the privilege resource provider (rzang)

Repository: ambari
Updated Branches:
  refs/heads/trunk 15a7f1c62 -> e8cc76e6e


AMBARI-13805. Add permission label to to the dataset returned by the privilege resource provider (rzang)


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

Branch: refs/heads/trunk
Commit: e8cc76e6e3546f6ac769e29c7345359c6b1c17e8
Parents: 15a7f1c
Author: Richard Zang <rz...@apache.org>
Authored: Thu Nov 19 15:04:57 2015 -0800
Committer: Richard Zang <rz...@apache.org>
Committed: Thu Nov 19 15:06:32 2015 -0800

----------------------------------------------------------------------
 .../global/user_settings_controller.js          | 65 +++++++++++++++++++-
 ambari-web/app/styles/application.less          |  4 ++
 ambari-web/app/templates/common/settings.hbs    | 55 +++++++++++++++++
 3 files changed, 122 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e8cc76e6/ambari-web/app/controllers/global/user_settings_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/user_settings_controller.js b/ambari-web/app/controllers/global/user_settings_controller.js
index e78ada0..80d9189 100644
--- a/ambari-web/app/controllers/global/user_settings_controller.js
+++ b/ambari-web/app/controllers/global/user_settings_controller.js
@@ -181,11 +181,69 @@ App.UserSettingsController = Em.Controller.extend(App.UserPref, {
    * @method showSettingsPopup
    */
   showSettingsPopup: function() {
+    var self = this;
     // Settings only for admins
     if (!App.isAccessible('upgrade_ADMIN')) {
       return;
     }
-    this.dataLoading().done(this._showSettingsPopup.bind(this));
+
+    this.dataLoading()
+    .done(function(response) {
+      self.loadPrivileges().complete(function() {
+        self._showSettingsPopup(response);
+      });
+    });
+  },
+
+  loadPrivileges: function() {
+    return App.ajax.send({
+      name: 'router.user.privileges',
+      sender: this,
+      data: {
+        userName: App.db.getLoginName()
+      },
+      success: 'loadPrivilegesSuccessCallback'
+    });
+  },
+
+  loadPrivilegesSuccessCallback: function(data) {
+    var privileges = {
+      clusters: {},
+      views: {}
+    };
+    data.items.forEach(function(privilege) {
+      privilege = privilege.PrivilegeInfo;
+      if(privilege.type === 'CLUSTER'){
+        // This is cluster
+        privileges.clusters[privilege.cluster_name] = privileges.clusters[privilege.cluster_name] || [];
+        privileges.clusters[privilege.cluster_name].push(privilege.permission_label);
+      } else if ( privilege.type === 'VIEW'){
+        privileges.views[privilege.instance_name] = privileges.views[privilege.instance_name] || { privileges:[]};
+        privileges.views[privilege.instance_name].version = privilege.version;
+        privileges.views[privilege.instance_name].view_name = privilege.view_name;
+        privileges.views[privilege.instance_name].privileges.push(privilege.permission_label);
+      }
+    });
+    // restructure data for view
+    var clusters = [];
+    var views = [];
+    for (key in privileges.clusters){
+      clusters.push({
+        name: key,
+        privileges: privileges.clusters[key]
+      });
+    }
+    for (key in privileges.views) {
+      views.push({
+        instance_name: key,
+        privileges: privileges.views[key].privileges,
+        version: privileges.views[key].version,
+        view_name: privileges.views[key].view_name
+      });
+    }
+    privileges.clusters = clusters;
+    privileges.views = views;
+    this.set('privileges', data.items.length ? privileges : null);
   },
 
   /**
@@ -218,8 +276,11 @@ App.UserSettingsController = Em.Controller.extend(App.UserPref, {
           curValue = !this.get('isNotShowBgChecked');
         }.observes('isNotShowBgChecked'),
 
-        timezonesList: timezonesFormatted
+        timezonesList: timezonesFormatted,
+
+        privileges: self.get('privileges'),
 
+        isAdmin: App.get('isAmbariAdmin')
       }),
 
       /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/e8cc76e6/ambari-web/app/styles/application.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/application.less b/ambari-web/app/styles/application.less
index 52a573d..58c5f14 100644
--- a/ambari-web/app/styles/application.less
+++ b/ambari-web/app/styles/application.less
@@ -6083,3 +6083,7 @@ input[type="radio"].align-checkbox, input[type="checkbox"].align-checkbox {
     text-decoration: none;
   }
 }
+
+.view-permission-header th {
+  padding-top: 40px;
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/e8cc76e6/ambari-web/app/templates/common/settings.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/settings.hbs b/ambari-web/app/templates/common/settings.hbs
index 2ca2991..899b9cf 100644
--- a/ambari-web/app/templates/common/settings.hbs
+++ b/ambari-web/app/templates/common/settings.hbs
@@ -39,4 +39,59 @@
         }}
     </label>
   </div>
+  <div>
+    {{#unless view.isAdmin}}
+      <table class="table">
+        <thead>
+        <tr>
+          <th>Cluster</th>
+          <th>Cluster Role</th>
+        </tr>
+        </thead>
+        <tbody>
+        {{#each cluster in view.privileges.clusters}}
+          <tr>
+            <td>
+              <span class="glyphicon glyphicon-cloud"></span>
+              <span>{{cluster.name}}</span>
+            </td>
+            <td>
+              {{#each privilege in cluster.privileges}}
+                <span tooltip="{{privilege}}">{{privilege}}&nbsp;</span>
+              {{/each}}
+            </td>
+          </tr>
+        {{/each}}
+        </tbody>
+        <thead class="view-permission-header">
+        <tr>
+          <th>View</th>
+          <th>View Permissions</th>
+        </tr>
+        </thead>
+        <tbody ng-hide="user.admin">
+        {{#each v in view.privileges.views}}
+          <tr>
+            <td>
+              <span class="glyphicon glyphicon-th"></span>
+              <span>{{v.instance_name}}</span>
+            </td>
+            <td>
+              {{#each privilege in v.privileges}}
+                <span tooltip="{{privilege}}" >{{privilege}}&nbsp;</span>
+              {{/each}}
+            </td>
+          </tr>
+        {{/each}}
+        </tbody>
+      </table>
+    {{/unless}}
+    {{#if view.isAdmin}}
+      <div class="alert alert-info">This user is an Ambari Admin and has all privileges.</div>
+    {{else}}
+      {{#unless view.privileges}}
+        <div class="alert alert-info">This user does not have any privileges.</div>
+      {{/unless}}
+    {{/if}}
+  </div>
 </div>