removed some methods

helpers.getBaseUser
exposeUid, exposeGroupName
v1.18.x
barisusakli 9 years ago
parent 001eb3454c
commit aefba6e2b1

@ -27,7 +27,7 @@ function getFollow(tpl, name, req, res, callback) {
async.waterfall([
function(next) {
accountHelpers.getBaseUser(req.params.userslug, req.uid, next);
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
function(data, next) {
userData = data;

@ -1,11 +1,11 @@
'use strict';
var async = require('async'),
var async = require('async');
groups = require('../../groups'),
helpers = require('../helpers'),
accountHelpers = require('./helpers');
var groups = require('../../groups');
var helpers = require('../helpers');
var accountHelpers = require('./helpers');
var groupsController = {};
@ -15,7 +15,7 @@ groupsController.get = function(req, res, callback) {
var groupsData;
async.waterfall([
function (next) {
accountHelpers.getBaseUser(req.params.userslug, req.uid, next);
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
function (_userData, next) {
userData = _userData;

@ -3,6 +3,7 @@
var async = require('async');
var validator = require('validator');
var winston = require('winston');
var user = require('../../user');
var groups = require('../../groups');
@ -35,6 +36,9 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
isGlobalModerator: function(next) {
user.isGlobalModerator(callerUID, next);
},
isFollowing: function(next) {
user.isFollowing(callerUID, uid, next);
},
ips: function(next) {
user.getIPs(uid, 4, next);
},
@ -88,6 +92,7 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
userData.canBan = isAdmin || isGlobalModerator;
userData.canChangePassword = isAdmin || (isSelf && parseInt(meta.config['password:disableEdit'], 10) !== 1);
userData.isSelf = isSelf;
userData.isFollowing = results.isFollowing;
userData.showHidden = isSelf || isAdmin || isGlobalModerator;
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
@ -122,66 +127,8 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
helpers.getBaseUser = function(userslug, callerUID, callback) {
async.waterfall([
function (next) {
user.getUidByUserslug(userslug, next);
},
function (uid, next) {
if (!uid) {
return callback(null, null);
}
async.parallel({
user: function(next) {
user.getUserFields(uid, [
'uid',
'username',
'userslug',
'picture',
'cover:url',
'cover:position',
'status',
'lastonline',
'groupTitle',
'followingCount',
'followerCount'
], next);
},
isAdmin: function(next) {
user.isAdministrator(callerUID, next);
},
isGlobalModerator: function(next) {
user.isGlobalModerator(callerUID, next);
},
isFollowing: function(next) {
user.isFollowing(callerUID, uid, next);
},
profile_links: function(next) {
plugins.fireHook('filter:user.profileLinks', [], next);
}
}, next);
},
function (results, next) {
if (!results.user) {
return callback();
}
results.user.yourid = callerUID;
results.user.theirid = results.user.uid;
results.user.status = user.getStatus(results.user);
results.user.isSelf = parseInt(callerUID, 10) === parseInt(results.user.uid, 10);
results.user.isFollowing = results.isFollowing;
results.user.showHidden = results.user.isSelf || results.isAdmin || results.isGlobalModerator;
results.user.profile_links = filterLinks(results.profile_links, results.user.isSelf);
results.user['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
results.user['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
results.user['cover:url'] = results.user['cover:url'] || require('../../coverPhoto').getDefaultProfileCover(results.user.uid);
results.user['cover:position'] = results.user['cover:position'] || '50% 50%';
next(null, results.user);
}
], callback);
winston.warn('helpers.getBaseUser deprecated please use helpers.getUserDataByUserSlug');
helpers.getUserDataByUserSlug(userslug, callerUID, callback);
};
function filterLinks(links, self) {

@ -1,7 +1,6 @@
'use strict';
var async = require('async');
var _ = require('underscore');
var user = require('../../user');
var helpers = require('../helpers');
@ -9,33 +8,33 @@ var accountHelpers = require('./helpers');
var infoController = {};
infoController.get = function(req, res, next) {
accountHelpers.getBaseUser(req.params.userslug, req.uid, function(err, userData) {
infoController.get = function(req, res, callback) {
var userData;
async.waterfall([
function(next) {
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
function(_userData, next) {
userData = _userData;
if (!userData) {
return callback();
}
async.parallel({
history: async.apply(user.getModerationHistory, userData.uid),
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID)
}, next);
}
], function(err, data) {
if (err) {
return next(err);
return callback(err);
}
async.parallel({
ips: async.apply(user.getIPs, res.locals.uid, 4),
history: async.apply(user.getModerationHistory, res.locals.uid),
fields: async.apply(user.getUserFields, res.locals.uid, ['banned']),
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID)
}, function(err, data) {
if (err) {
return next(err);
}
userData = _.extend(userData, {
ips: data.ips,
history: data.history
}, data.fields);
userData.sessions = data.sessions;
userData.title = '[[pages:account/info]]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:account_info]]'}]);
userData.history = data.history;
userData.sessions = data.sessions;
userData.title = '[[pages:account/info]]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:account_info]]'}]);
res.render('account/info', userData);
});
res.render('account/info', userData);
});
};

@ -1,15 +1,15 @@
'use strict';
var async = require('async'),
var async = require('async');
db = require('../../database'),
user = require('../../user'),
posts = require('../../posts'),
topics = require('../../topics'),
pagination = require('../../pagination'),
helpers = require('../helpers'),
accountHelpers = require('./helpers');
var db = require('../../database');
var user = require('../../user');
var posts = require('../../posts');
var topics = require('../../topics');
var pagination = require('../../pagination');
var helpers = require('../helpers');
var accountHelpers = require('./helpers');
var postsController = {};
@ -103,7 +103,7 @@ function getFromUserSet(data, req, res, next) {
user.getSettings(req.uid, next);
},
userData: function(next) {
accountHelpers.getBaseUser(req.params.userslug, req.uid, next);
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
}
}, function(err, results) {
if (err || !results.userData) {

@ -13,10 +13,17 @@ sessionController.revoke = function(req, res, next) {
}
var _id;
var uid;
async.waterfall([
function (next) {
db.getSortedSetRange('uid:' + res.locals.uid + ':sessions', 0, -1, next);
user.getUidByUserslug(req.params.userslug, next);
},
function (_uid, next) {
uid = _uid;
if (!uid) {
return next(new Error('[[error:no-session-found]]'));
}
db.getSortedSetRange('uid:' + uid + ':sessions', 0, -1, next);
},
function (sids, done) {
async.eachSeries(sids, function(sid, next) {
@ -38,7 +45,7 @@ sessionController.revoke = function(req, res, next) {
return next(new Error('[[error:no-session-found]]'));
}
user.auth.revokeSession(_id, res.locals.uid, next);
user.auth.revokeSession(_id, uid, next);
}
], function(err) {
if (err) {

@ -20,7 +20,7 @@ settingsController.get = function(req, res, callback) {
var userData;
async.waterfall([
function(next) {
accountHelpers.getBaseUser(req.params.userslug, req.uid, next);
accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, next);
},
function(_userData, next) {
userData = _userData;

@ -46,23 +46,30 @@ groupsController.getGroupsFromSet = function(uid, sort, start, stop, callback) {
};
groupsController.details = function(req, res, callback) {
var groupName;
async.waterfall([
async.apply(groups.exists, res.locals.groupName),
function (exists, next) {
if (!exists) {
function(next) {
groups.getGroupNameByGroupSlug(req.params.slug, next);
},
function(groupName, next) {
if (!groupName) {
return callback();
}
groups.isHidden(res.locals.groupName, next);
async.parallel({
exists: async.apply(groups.exists, groupName),
hidden: async.apply(groups.isHidden, groupName)
}, next);
},
function (hidden, next) {
if (!hidden) {
function (results, next) {
if (!results.exists) {
return callback();
}
if (!results.hidden) {
return next();
}
async.parallel({
isMember: async.apply(groups.isMember, req.uid, res.locals.groupName),
isInvited: async.apply(groups.isInvited, req.uid, res.locals.groupName)
isMember: async.apply(groups.isMember, req.uid, groupName),
isInvited: async.apply(groups.isInvited, req.uid, groupName)
}, function(err, checks) {
if (err || checks.isMember || checks.isInvited) {
return next(err);
@ -73,14 +80,14 @@ groupsController.details = function(req, res, callback) {
function (next) {
async.parallel({
group: function(next) {
groups.get(res.locals.groupName, {
groups.get(groupName, {
uid: req.uid,
truncateUserList: true,
userListCount: 20
}, next);
},
posts: function(next) {
groups.getLatestMemberPosts(res.locals.groupName, 10, req.uid, next);
groups.getLatestMemberPosts(groupName, 10, req.uid, next);
},
isAdmin:function(next) {
user.isAdministrator(req.uid, next);

@ -112,28 +112,6 @@ middleware.privateTagListing = function(req, res, next) {
}
};
middleware.exposeGroupName = function(req, res, next) {
expose('groupName', groups.getGroupNameByGroupSlug, 'slug', req, res, next);
};
middleware.exposeUid = function(req, res, next) {
expose('uid', user.getUidByUserslug, 'userslug', req, res, next);
};
function expose(exposedField, method, field, req, res, next) {
if (!req.params.hasOwnProperty(field)) {
return next();
}
method(req.params[field], function(err, id) {
if (err) {
return next(err);
}
res.locals[exposedField] = id;
next();
});
}
middleware.privateUploads = function(req, res, next) {
if (req.user || parseInt(meta.config.privateUploads, 10) !== 1) {
return next();

@ -5,7 +5,7 @@ var setupPageRoute = helpers.setupPageRoute;
module.exports = function (app, middleware, controllers) {
var middlewares = [middleware.checkGlobalPrivacySettings];
var accountMiddlewares = [middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions, middleware.exposeUid];
var accountMiddlewares = [middleware.checkGlobalPrivacySettings, middleware.checkAccountPermissions];
setupPageRoute(app, '/uid/:uid/:section?', middleware, [], middleware.redirectUidToUserslug);
@ -28,7 +28,7 @@ module.exports = function (app, middleware, controllers) {
setupPageRoute(app, '/user/:userslug/info', middleware, accountMiddlewares, controllers.accounts.info.get);
setupPageRoute(app, '/user/:userslug/settings', middleware, accountMiddlewares, controllers.accounts.settings.get);
app.delete('/api/user/:userslug/session/:uuid', [middleware.requireUser, middleware.exposeUid], controllers.accounts.session.revoke);
app.delete('/api/user/:userslug/session/:uuid', [middleware.requireUser], controllers.accounts.session.revoke);
setupPageRoute(app, '/notifications', middleware, [middleware.authenticate], controllers.accounts.notifications.get);
setupPageRoute(app, '/chats/:roomid?', middleware, [middleware.authenticate], controllers.accounts.chats.get);

@ -77,7 +77,7 @@ function userRoutes(app, middleware, controllers) {
}
function groupRoutes(app, middleware, controllers) {
var middlewares = [middleware.checkGlobalPrivacySettings, middleware.exposeGroupName];
var middlewares = [middleware.checkGlobalPrivacySettings];
setupPageRoute(app, '/groups', middleware, middlewares, controllers.groups.list);
setupPageRoute(app, '/groups/:slug', middleware, middlewares, controllers.groups.details);

Loading…
Cancel
Save