[Kimchi-devel] [PATCH V4 2/4] Authorization: remove host/template tabs for non-root users

wenwang at linux.vnet.ibm.com wenwang at linux.vnet.ibm.com
Wed Jul 23 02:26:48 UTC 2014


From: Wen Wang <wenwang at linux.vnet.ibm.com>

v2 -> V3:
Add a global variable "_tabMode" into JS code under kimchi.main.js that
indicates mode for each tab(Yu Xin, Aline)

V1 -> V2:
read only "roles" from cookie instead of roles of each tab(Aline)

This patch removed host/template tabs from non-root users

Signed-off-by: Wen Wang <wenwang at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.main.js |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index 8eb4d73..01ebded 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -15,6 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+var _tabMode = {};
 kimchi.main = function() {
     kimchi.popable();
 
@@ -23,13 +24,16 @@ kimchi.main = function() {
         $(tabs).each(function(i, tab) {
             var title = tab['title'];
             var path = tab['path'];
-            tabsHtml.push(
-                '<li>',
-                    '<a class="item" href="', path, '">',
-                        title,
-                    '</a>',
-                '</li>'
-            );
+            var mode = tab['mode'];
+            if (mode != 'none') {
+                tabsHtml.push(
+                    '<li>',
+                        '<a class="item" href="', path, '">',
+                            title,
+                        '</a>',
+                    '</li>'
+                );
+            }
         });
         return tabsHtml.join('');
     };
@@ -41,9 +45,15 @@ kimchi.main = function() {
             var titleKey = $tab.find('title').text();
             var title = i18n[titleKey] ? i18n[titleKey] : titleKey;
             var path = $tab.find('path').text();
+            var roles = kimchi.cookie.get('roles');
+            var roleString = 'JSON.parse(roles).' + titleKey.toLowerCase();
+            var role = eval(roleString);
+            var mode = $tab.find('[role="' + role + '"]').attr('mode');
+            _tabMode[titleKey.toLowerCase()] = mode;
             tabs.push({
                 title: title,
-                path: path
+                path: path,
+                mode: mode
             });
         });
 
-- 
1.7.1




More information about the Kimchi-devel mailing list