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

Endi Sukma Dewata edewata at redhat.com
Sat Apr 11 04:27:44 UTC 2015


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.

-- 
Endi S. Dewata
-------------- next part --------------
>From 6ade54dbcb39890c20bee57f345565debad6566f 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
and links 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 and links are hidden.
TPS admins have access to all menu items and links.

https://fedorahosted.org/pki/ticket/1292
---
 base/server/share/webapps/pki/css/pki-ui.css |  5 ++++
 base/tps/shared/webapps/tps/js/tps.js        | 20 ++++++++++++++
 base/tps/shared/webapps/tps/ui/home.html     | 34 ++++++++++++++----------
 base/tps/shared/webapps/tps/ui/index.html    | 39 ++++++++++++++++++++--------
 4 files changed, 73 insertions(+), 25 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..fae4c6a6e365f1e2e7e5f57f7a32a57ae1042fac 100644
--- a/base/server/share/webapps/pki/css/pki-ui.css
+++ b/base/server/share/webapps/pki/css/pki-ui.css
@@ -46,6 +46,11 @@
   display: inline-block;
 }
 
+.pki-links {
+    list-style-type: none;
+    padding: 0;
+}
+
 .pki-fields {
   margin-bottom: 5px;
 }
diff --git a/base/tps/shared/webapps/tps/js/tps.js b/base/tps/shared/webapps/tps/js/tps.js
index 4765337592ff2acebda0fe3f3d54793c56d4c47c..30fade968a9adf79b4449cf4c959a2ba9bad8747 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;
diff --git a/base/tps/shared/webapps/tps/ui/home.html b/base/tps/shared/webapps/tps/ui/home.html
index f21040fdbe034169a46900c47980bd605f8ef849..cdb68eebf84976131e616a033ce986a27c7aa0ea 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-links">
+        <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-links">
+        <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-links">
+        <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>
-- 
1.9.3



More information about the Pki-devel mailing list