From 76ad2b8fb28a02a1a8c9cbbc1fac3c8c104fa876 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 31 Jul 2014 20:15:11 -0400 Subject: [PATCH] fixed to account header --- public/src/forum/account/header.js | 4 ---- src/controllers/accounts.js | 28 +++++++++++++++------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/public/src/forum/account/header.js b/public/src/forum/account/header.js index 6efa692a0f..f552bf4056 100644 --- a/public/src/forum/account/header.js +++ b/public/src/forum/account/header.js @@ -18,10 +18,6 @@ define('forum/account/header', function() { $this.toggleClass('hide', $this.hasClass('private')); }); } - - if (app.isAdmin) { - $('#editLink, #settingsLink').removeClass('hide'); - } } function selectActivePill() { diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 6fd9393ba0..2225373ee2 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -112,6 +112,7 @@ function getUserDataByUserSlug(userslug, callerUID, callback) { userData.yourid = callerUID; userData.theirid = userData.uid; userData.isSelf = parseInt(callerUID, 10) === parseInt(userData.uid, 10); + userData.showSettings = userData.isSelf || isAdmin; userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1; userData['email:confirmed'] = !!parseInt(userData['email:confirmed'], 10); userData.profile_links = results.profile_links; @@ -213,7 +214,7 @@ function getFollow(route, name, req, res, next) { accountsController.getFavourites = function(req, res, next) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; - getBaseUser(req.params.userslug, function(err, userData) { + getBaseUser(req.params.userslug, callerUID, function(err, userData) { if (err) { return next(err); } @@ -231,8 +232,6 @@ accountsController.getFavourites = function(req, res, next) { return next(err); } - userData.theirid = userData.uid; - userData.yourid = callerUID; userData.posts = favourites.posts; userData.nextStart = favourites.nextStart; @@ -244,7 +243,7 @@ accountsController.getFavourites = function(req, res, next) { accountsController.getPosts = function(req, res, next) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; - getBaseUser(req.params.userslug, function(err, userData) { + getBaseUser(req.params.userslug, callerUID, function(err, userData) { if (err) { return next(err); } @@ -258,8 +257,6 @@ accountsController.getPosts = function(req, res, next) { return next(err); } - userData.theirid = userData.uid; - userData.yourid = callerUID; userData.posts = userPosts.posts; userData.nextStart = userPosts.nextStart; @@ -271,7 +268,7 @@ accountsController.getPosts = function(req, res, next) { accountsController.getTopics = function(req, res, next) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; - getBaseUser(req.params.userslug, function(err, userData) { + getBaseUser(req.params.userslug, callerUID, function(err, userData) { if (err) { return next(err); } @@ -286,8 +283,6 @@ accountsController.getTopics = function(req, res, next) { return next(err); } - userData.theirid = userData.uid; - userData.yourid = callerUID; userData.topics = userTopics.topics; userData.nextStart = userTopics.nextStart; @@ -296,7 +291,7 @@ accountsController.getTopics = function(req, res, next) { }); }; -function getBaseUser(userslug, callback) { +function getBaseUser(userslug, callerUID, callback) { user.getUidByUserslug(userslug, function (err, uid) { if (err || !uid) { return callback(err); @@ -306,6 +301,9 @@ function getBaseUser(userslug, callback) { user: function(next) { user.getUserFields(uid, ['uid', 'username', 'userslug'], next); }, + isAdmin: function(next) { + user.isAdministrator(callerUID, next); + }, profile_links: function(next) { plugins.fireHook('filter:user.profileLinks', [], next); } @@ -313,9 +311,15 @@ function getBaseUser(userslug, callback) { if (err) { return callback(err); } + if (!results.user) { return callback(); } + + results.user.yourid = callerUID; + results.user.theirid = uid; + results.user.isSelf = parseInt(callerUID, 10) === parseInt(uid, 10); + results.user.showSettings = results.user.isSelf || results.isAdmin; results.user.profile_links = results.profile_links; callback(null, results.user); }); @@ -337,7 +341,7 @@ accountsController.accountEdit = function(req, res, next) { accountsController.accountSettings = function(req, res, next) { var callerUID = req.user ? parseInt(req.user.uid, 10) : 0; - getBaseUser(req.params.userslug, function(err, userData) { + getBaseUser(req.params.userslug, callerUID, function(err, userData) { if (err) { return next(err); } @@ -358,8 +362,6 @@ accountsController.accountSettings = function(req, res, next) { return next(err); } - userData.yourid = callerUID; - userData.theirid = userData.uid; userData.settings = results.settings; userData.languages = results.languages;