[Pki-devel] [PATCH] 569 Customized TPS UI menu based on user roles.

Endi Sukma Dewata edewata at redhat.com
Thu Apr 16 13:44:31 UTC 2015


On 4/10/2015 11:27 PM, Endi Sukma Dewata wrote:
> On 4/10/2015 7:24 PM, Endi Sukma Dewata wrote:
>> The TPS UI has been modified to customize the navigation menu
>> based on the roles of the user currently logged in. TPS agents
>> do not have access to user, group, config, authenticator,
>> connector, profile mapping, audit, and self test services, so
>> the corresponding menu items will not be visible. TPS admins
>> have access to all menu items.
>>
>> https://fedorahosted.org/pki/ticket/1292
>
> New patch attached to fix the links in the home page.

New patch attached for some cleanups.

-- 
Endi S. Dewata
-------------- next part --------------
>From f0d0efa089ed15c60667be98f9bea2c8a3a03eee Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata at redhat.com>
Date: Fri, 10 Apr 2015 04:44:30 -0400
Subject: [PATCH] Customized TPS UI menu based on user roles.

The TPS UI has been modified to customize the navigation menu
based on the roles of the user currently logged in. TPS agents
do not have access to users, groups, config, authenticators,
connectors, profile mappings, audit, and self tests, so the
corresponding menu items will be hidden. TPS admins have
access to all menu items.

https://fedorahosted.org/pki/ticket/1292
---
 base/server/share/webapps/pki/css/pki-ui.css       |  5 +++
 base/server/share/webapps/pki/js/pki-ui.js         | 20 ++++++-----
 base/tps/shared/webapps/tps/js/audit.js            |  4 +--
 base/tps/shared/webapps/tps/js/token.js            |  4 +--
 base/tps/shared/webapps/tps/js/tps.js              | 24 +++++++++++--
 base/tps/shared/webapps/tps/ui/audit.html          |  4 +--
 base/tps/shared/webapps/tps/ui/authenticator.html  |  4 +--
 base/tps/shared/webapps/tps/ui/config.html         |  4 +--
 base/tps/shared/webapps/tps/ui/connector.html      |  4 +--
 base/tps/shared/webapps/tps/ui/group.html          |  4 +--
 base/tps/shared/webapps/tps/ui/home.html           | 34 +++++++++++--------
 base/tps/shared/webapps/tps/ui/index.html          | 39 ++++++++++++++++------
 .../tps/shared/webapps/tps/ui/profile-mapping.html |  4 +--
 base/tps/shared/webapps/tps/ui/profile.html        |  4 +--
 base/tps/shared/webapps/tps/ui/token.html          |  4 +--
 base/tps/shared/webapps/tps/ui/user.html           |  4 +--
 16 files changed, 108 insertions(+), 58 deletions(-)

diff --git a/base/server/share/webapps/pki/css/pki-ui.css b/base/server/share/webapps/pki/css/pki-ui.css
index c0202887654dfade26bec31a1e70194119927d34..0d5edd7fd59f38c31932473fbe20e51c9bdbd2c6 100644
--- a/base/server/share/webapps/pki/css/pki-ui.css
+++ b/base/server/share/webapps/pki/css/pki-ui.css
@@ -41,6 +41,11 @@
   display: inline-block;
 }
 
+.pki-menu {
+  padding: 0;
+  list-style-type: none;
+}
+
 .pki-actions {
   float: right;
   display: inline-block;
diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js
index 7d8e6eef6c14ae1d913a191cc834d6a279e48333..98e3330c0bcba248e0ee76dacf1839e19927eb94 100644
--- a/base/server/share/webapps/pki/js/pki-ui.js
+++ b/base/server/share/webapps/pki/js/pki-ui.js
@@ -925,12 +925,14 @@ var EntryPage = Page.extend({
     setup: function() {
         var self = this;
 
-        self.menu = self.$(".pki-menu");
-        self.editLink = $("a[name='edit']", self.menu);
+        self.actions = self.$(".pki-actions");
 
-        self.buttons = self.$(".pki-buttons");
-        self.cancelButton = $("button[name='cancel']", self.buttons);
-        self.saveButton = $("button[name='save']", self.buttons);
+        self.viewMenu = $(".pki-actions-menu[name='view']", self.actions);
+        self.editLink = $("a[name='edit']", self.viewMenu);
+
+        self.editMenu = $(".pki-actions-menu[name='edit']", self.actions);
+        self.cancelButton = $("button[name='cancel']", self.editMenu);
+        self.saveButton = $("button[name='save']", self.editMenu);
 
         self.idField = self.$("input[name='id']");
         self.statusField = self.$("input[name='status']");
@@ -996,11 +998,10 @@ var EntryPage = Page.extend({
                 input.attr("readonly", "readonly");
             });
 
-            self.buttons.hide();
-            self.menu.show();
+            self.viewMenu.show();
+            self.editMenu.hide();
 
         } else {
-            self.menu.hide();
 
             // Show editable fields.
             self.$(".pki-fields input").each(function(index) {
@@ -1013,7 +1014,8 @@ var EntryPage = Page.extend({
                 }
             });
 
-            self.buttons.show();
+            self.viewMenu.hide();
+            self.editMenu.show();
         }
 
         self.$(".pki-fields input").each(function(index) {
diff --git a/base/tps/shared/webapps/tps/js/audit.js b/base/tps/shared/webapps/tps/js/audit.js
index 986596e1d0ddee440a5f87f5a6e2a14ff991f5f8..62e6b099e72f5ca48ab4c3b2decd01fa3c5c818b 100644
--- a/base/tps/shared/webapps/tps/js/audit.js
+++ b/base/tps/shared/webapps/tps/js/audit.js
@@ -142,8 +142,8 @@ var AuditPage = EntryPage.extend({
 
         AuditPage.__super__.setup.call(self);
 
-        self.enableLink = $("a[name='enable']", self.menu);
-        self.disableLink = $("a[name='disable']", self.menu);
+        self.enableLink = $("a[name='enable']", self.viewMenu);
+        self.disableLink = $("a[name='disable']", self.viewMenu);
 
         self.enableLink.click(function(e) {
 
diff --git a/base/tps/shared/webapps/tps/js/token.js b/base/tps/shared/webapps/tps/js/token.js
index c1f27b13248b4072fbd4f61072c28ed3c7505a8f..4cc3b5bcf01c77ca5cc479e5ee5e8bb293999bdd 100644
--- a/base/tps/shared/webapps/tps/js/token.js
+++ b/base/tps/shared/webapps/tps/js/token.js
@@ -110,7 +110,7 @@ var TokenPage = EntryPage.extend({
 
         TokenPage.__super__.setup.call(self);
 
-        self.changeStatusLink = $("a[name='changeStatus']", self.menu);
+        self.changeStatusLink = $("a[name='changeStatus']", self.viewMenu);
 
         self.changeStatusLink.click(function(e) {
 
@@ -154,7 +154,7 @@ var TokenPage = EntryPage.extend({
             dialog.open();
         });
 
-        self.showCertsLink = $("a[name='showCerts']", self.menu);
+        self.showCertsLink = $("a[name='showCerts']", self.viewMenu);
 
         self.showCertsLink.click(function(e) {
 
diff --git a/base/tps/shared/webapps/tps/js/tps.js b/base/tps/shared/webapps/tps/js/tps.js
index 4765337592ff2acebda0fe3f3d54793c56d4c47c..85d1751eb7cb0e721f94d8619dc1a914f21464da 100644
--- a/base/tps/shared/webapps/tps/js/tps.js
+++ b/base/tps/shared/webapps/tps/js/tps.js
@@ -19,6 +19,8 @@
  * @author Endi S. Dewata
  */
 
+var tps = {};
+
 var PropertiesTableItem = TableItem.extend({
     initialize: function(options) {
         var self = this;
@@ -114,6 +116,24 @@ var PropertiesTable = Table.extend({
     }
 });
 
+var HomePage = Page.extend({
+    load: function() {
+        var roles = tps.user.Roles.Role;
+        var home_accounts = self.$("[name=home-accounts]");
+        var home_system = self.$("[name=home-system]");
+
+        if (_.contains(roles, "Administrators")) {
+            home_accounts.show();
+            $("li", home_system).show();
+
+        } else if (_.contains(roles, "TPS Agents")) {
+            home_accounts.hide();
+            $("li", home_system).hide();
+            $("[name=profiles]", home_system).show();
+        }
+    }
+});
+
 var ConfigEntryPage = EntryPage.extend({
     initialize: function(options) {
         var self = this;
@@ -126,8 +146,8 @@ var ConfigEntryPage = EntryPage.extend({
 
         ConfigEntryPage.__super__.setup.call(self);
 
-        self.enableLink = $("a[name='enable']", self.menu);
-        self.disableLink = $("a[name='disable']", self.menu);
+        self.enableLink = $("a[name='enable']", self.viewMenu);
+        self.disableLink = $("a[name='disable']", self.viewMenu);
 
         self.enableLink.click(function(e) {
 
diff --git a/base/tps/shared/webapps/tps/ui/audit.html b/base/tps/shared/webapps/tps/ui/audit.html
index 3e6cc6cbbc8cb402b128cbef67559073b664b775..f9da85196df4a0a01f8ca9ebe0a1da6838ae5658 100644
--- a/base/tps/shared/webapps/tps/ui/audit.html
+++ b/base/tps/shared/webapps/tps/ui/audit.html
@@ -25,12 +25,12 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 <a name="enable" href="#">Enable</a><a name="disable" href="#" style="display: none;">Disable</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/authenticator.html b/base/tps/shared/webapps/tps/ui/authenticator.html
index 6da1fbf123e83795d20601d3aa4e3b615d07ea37..cde9e65c401b0ff3861db4bb8ddffec91c8315a9 100644
--- a/base/tps/shared/webapps/tps/ui/authenticator.html
+++ b/base/tps/shared/webapps/tps/ui/authenticator.html
@@ -26,12 +26,12 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 <a name="enable" href="#">Enable</a><a name="disable" href="#" style="display: none;">Disable</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/config.html b/base/tps/shared/webapps/tps/ui/config.html
index d94a0fa288909da49d86fe0c91953d29303e510e..2a8e85902b8807aabc21b0b2afa1229f3f0b89db 100644
--- a/base/tps/shared/webapps/tps/ui/config.html
+++ b/base/tps/shared/webapps/tps/ui/config.html
@@ -25,11 +25,11 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/connector.html b/base/tps/shared/webapps/tps/ui/connector.html
index 015a7ac6d7fe7b1af4a31b174426517646a9c3a2..782c6d2458161ea575aaa319b97b911cced4c6da 100644
--- a/base/tps/shared/webapps/tps/ui/connector.html
+++ b/base/tps/shared/webapps/tps/ui/connector.html
@@ -26,12 +26,12 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 <a name="enable" href="#">Enable</a><a name="disable" href="#" style="display: none;">Disable</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/group.html b/base/tps/shared/webapps/tps/ui/group.html
index 493b79488d40a5944b88af9488bf998c18f3ea78..11c9944b281602213d66c569a997e13f4b714f7f 100644
--- a/base/tps/shared/webapps/tps/ui/group.html
+++ b/base/tps/shared/webapps/tps/ui/group.html
@@ -26,11 +26,11 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/home.html b/base/tps/shared/webapps/tps/ui/home.html
index f21040fdbe034169a46900c47980bd605f8ef849..08c4672558003da4bc0cc380cefadd381b6b530e 100644
--- a/base/tps/shared/webapps/tps/ui/home.html
+++ b/base/tps/shared/webapps/tps/ui/home.html
@@ -28,33 +28,39 @@
         <h3 class="panel-title">Token Management</h3>
     </div>
     <div class="panel-body">
-        <a href="#tokens">Tokens</a><br>
-        <a href="#certs">Certificates</a><br>
-        <a href="#activities">Activities</a><br>
+        <ul class="pki-menu">
+        <li><a href="#tokens">Tokens</a></li>
+        <li><a href="#certs">Certificates</a></li>
+        <li><a href="#activities">Activities</a></li>
+        </ul>
     </div>
 </div>
 
-<div class="panel panel-default">
+<div name="home-accounts" class="panel panel-default">
     <div class="panel-heading">
         <h3 class="panel-title">Account Management</h3>
     </div>
     <div class="panel-body">
-        <a href="#users">Users</a><br>
-        <a href="#groups">Groups</a><br>
+        <ul class="pki-menu">
+        <li><a href="#users">Users</a></li>
+        </li><a href="#groups">Groups</a></li>
+        </ul>
     </div>
 </div>
 
-<div class="panel panel-default">
+<div name="home-system" class="panel panel-default">
     <div class="panel-heading">
         <h3 class="panel-title">System Management</h3>
     </div>
     <div class="panel-body">
-        <a href="#config">General Configuration</a><br>
-        <a href="#authenticators">Authentication Sources</a><br>
-        <a href="#connectors">Subsystem Connections</a><br>
-        <a href="#profiles">Profiles</a><br>
-        <a href="#profile-mappings">Profile Mappings</a><br>
-        <a href="#audit">Audit Logging</a><br>
-        <a href="#selftests">Self Tests</a><br>
+        <ul class="pki-menu">
+        <li name="config" style="display: none;"><a href="#config">General Configuration</a></li>
+        <li name="authenticators" style="display: none;"><a href="#authenticators">Authentication Sources</a></li>
+        <li name="connectors" style="display: none;"><a href="#connectors">Subsystem Connections</a></li>
+        <li name="profiles" style="display: none;"><a href="#profiles">Profiles</a></li>
+        <li name="profile-mappings" style="display: none;"><a href="#profile-mappings">Profile Mappings</a></li>
+        <li name="audit" style="display: none;"><a href="#audit">Audit Logging</a></li>
+        <li name="selftests" style="display: none;"><a href="#selftests">Self Tests</a></li>
+        </ul>
     </div>
 </div>
diff --git a/base/tps/shared/webapps/tps/ui/index.html b/base/tps/shared/webapps/tps/ui/index.html
index 74adeadd14a7355c67dd92bba9c03958221d9023..3bda3cb40f764b1cb8d5adb4069aa829b25e8caa 100644
--- a/base/tps/shared/webapps/tps/ui/index.html
+++ b/base/tps/shared/webapps/tps/ui/index.html
@@ -47,10 +47,26 @@ $(function() {
     var account = new Account();
     account.login({
         success: function(data, textStatus, jqXHR) {
+            tps.user = data;
+            var roles = tps.user.Roles.Role;
+
             var user = $("#user");
             user.text(data.FullName);
+
+            var accounts_menu = $("#navigation [name=accounts]");
+            var system_menu = $("#navigation [name=system]");
+
+            if (_.contains(roles, "Administrators")) {
+                accounts_menu.show();
+                $("li", system_menu).show();
+
+            } else if (_.contains(roles, "TPS Agents")) {
+                accounts_menu.hide();
+                $("li", system_menu).hide();
+                $("[name=profiles]", system_menu).show();
+            }
         },
-        error: function() {
+        error: function(jqXHR, textStatus, errorThrown) {
             window.location.href = "/tps";
         }
     });
@@ -60,7 +76,7 @@ $(function() {
     var router = new Backbone.Router();
 
     router.route("", "home", function() {
-        new Page({
+        new HomePage({
             el: content,
             url: "home.html"
         }).open();
@@ -330,6 +346,7 @@ $(function() {
         // destroy server session
         account.logout({
             success: function() {
+                tps.user = null;
                 // clear browser cache
                 PKI.logout({
                     success: function() {
@@ -382,7 +399,7 @@ $(function() {
     <li><a href="#tokens">Tokens</a></li>
     <li><a href="#certs">Certificates</a></li>
     <li><a href="#activities">Activities</a></li>
-    <li class="dropdown context">
+    <li name="accounts" class="dropdown context" style="display: none;">
       <a href="#" class="dropdown-toggle" data-toggle="dropdown">
         Accounts
         <b class="caret"></b>
@@ -392,19 +409,19 @@ $(function() {
         <li><a href="#groups">Groups</a></li>
       </ul>
     </li>
-    <li class="dropdown context">
+    <li name="system" class="dropdown context">
       <a href="#" class="dropdown-toggle" data-toggle="dropdown">
         System
         <b class="caret"></b>
       </a>
       <ul class="dropdown-menu">
-        <li><a href="#config">General Configuration</a></li>
-        <li><a href="#authenticators">Authentication Sources</a></li>
-        <li><a href="#connectors">Subsystem Connections</a></li>
-        <li><a href="#profiles">Profiles</a></li>
-        <li><a href="#profile-mappings">Profile Mappings</a></li>
-        <li><a href="#audit">Audit Logging</a></li>
-        <li><a href="#selftests">Self Tests</a></li>
+        <li name="config" style="display: none;"><a href="#config">General Configuration</a></li>
+        <li name="authenticators" style="display: none;"><a href="#authenticators">Authentication Sources</a></li>
+        <li name="connectors" style="display: none;"><a href="#connectors">Subsystem Connections</a></li>
+        <li name="profiles" style="display: none;"><a href="#profiles">Profiles</a></li>
+        <li name="profile-mappings" style="display: none;"><a href="#profile-mappings">Profile Mappings</a></li>
+        <li name="audit" style="display: none;"><a href="#audit">Audit Logging</a></li>
+        <li name="selftests" style="display: none;"><a href="#selftests">Self Tests</a></li>
       </ul>
     </li>
     </ul>
diff --git a/base/tps/shared/webapps/tps/ui/profile-mapping.html b/base/tps/shared/webapps/tps/ui/profile-mapping.html
index 139d2126200d4708ed2a071dad4232f0d04a6f3f..fea71ce9d9cda3c8bd8c215e06815c4eead10c97 100644
--- a/base/tps/shared/webapps/tps/ui/profile-mapping.html
+++ b/base/tps/shared/webapps/tps/ui/profile-mapping.html
@@ -26,12 +26,12 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 <a name="enable" href="#">Enable</a><a name="disable" href="#" style="display: none;">Disable</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/profile.html b/base/tps/shared/webapps/tps/ui/profile.html
index 61811bcc349dfc83348c4140f3821855d17efb4f..1720d48507cc40ac4a117e39e5dc4c77a2a0a164 100644
--- a/base/tps/shared/webapps/tps/ui/profile.html
+++ b/base/tps/shared/webapps/tps/ui/profile.html
@@ -26,12 +26,12 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 <a name="enable" href="#">Enable</a><a name="disable" href="#" style="display: none;">Disable</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/token.html b/base/tps/shared/webapps/tps/ui/token.html
index 8be08f09ac27531c1485e099cf5f67616c178dca..39d54c6cd09ddb175685da4da07e00ba2e1b92bb 100644
--- a/base/tps/shared/webapps/tps/ui/token.html
+++ b/base/tps/shared/webapps/tps/ui/token.html
@@ -26,13 +26,13 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 <a name="changeStatus" href="#">Change Status</a><br>
 <a name="showCerts" href="#">Show Certificates</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
diff --git a/base/tps/shared/webapps/tps/ui/user.html b/base/tps/shared/webapps/tps/ui/user.html
index 8463d0bef18edd2af63ee8bf853834f19adf46b3..9d6b0597ac400f110de3ecd0153a327e00f30f52 100644
--- a/base/tps/shared/webapps/tps/ui/user.html
+++ b/base/tps/shared/webapps/tps/ui/user.html
@@ -26,11 +26,11 @@
 
 <span class="pki-actions">
 
-<span class="pki-menu" style="display: none;">
+<span name="view" class="pki-actions-menu">
 <a name="edit" href="#">Edit</a><br>
 </span>
 
-<span class="pki-buttons" style="display: none;">
+<span name="edit" class="pki-actions-menu" style="display: none;">
 <button name="cancel">Cancel</button>
 <button name="save" class="primary">Save</button>
 </span>
-- 
1.9.3



More information about the Pki-devel mailing list