From 12f3f1a45cb33c7f9bad84195423c88ce160cf0c Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Mon, 28 Oct 2013 15:49:12 -0400 Subject: [PATCH] show admin link in header if user is admin, closes #459 --- public/language/en/global.json | 1 + public/src/ajaxify.js | 5 +++-- public/templates/header.tpl | 4 ++++ src/webserver.js | 17 ++++++++++++++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/public/language/en/global.json b/public/language/en/global.json index c0a97b3c75..f1615549d3 100644 --- a/public/language/en/global.json +++ b/public/language/en/global.json @@ -9,6 +9,7 @@ "logout": "Logout", "logout.title": "You are now logged out.", "logout.message": "You have successfully logged out of NodeBB", + "header.admin": "Admin", "header.recent": "Recent", "header.unread": "Unread", "header.users": "Users", diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 01b438b7b0..e18881edfe 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -23,7 +23,8 @@ var ajaxify = {}; window.onpopstate = function (event) { // "quiet": If set to true, will not call pushState - if (event !== null && event.state && event.state.url !== undefined) ajaxify.go(event.state.url, null, null, true); + if (event !== null && event.state && event.state.url !== undefined) + ajaxify.go(event.state.url, null, null, true); }; var pagination; @@ -123,7 +124,7 @@ var ajaxify = {}; if (this.getAttribute('data-ajaxify') == 'false') { return; } - + if (!e.ctrlKey && e.which === 1) { if (this.host === window.location.host) { // Internal link diff --git a/public/templates/header.tpl b/public/templates/header.tpl index a88a02339e..73784aae2c 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -62,6 +62,10 @@
  • [[global:header.users]]
  • +
  • + + [[global:header.admin]] +
  • [[global:header.search]]
  • diff --git a/src/webserver.js b/src/webserver.js index e216c6ebfa..94e662fd4e 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -85,9 +85,20 @@ var express = require('express'), navigation: custom_header.navigation }; - translator.translate(templates.header.parse(templateValues), function(template) { - callback(null, template); - }); + var uid = '0'; + + if(options.req.user && options.req.user.uid) + uid = options.req.user.uid; + + user.isAdministrator(uid, function(isAdmin) { + templateValues.adminDisplay = isAdmin ? 'show' : 'hide'; + + translator.translate(templates.header.parse(templateValues), function(template) { + callback(null, template); + }); + }) + + }); };