adding missing files, re: #4827
parent
d5961cfca3
commit
5ecbbd228d
@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
_ = require('underscore'),
|
||||
|
||||
user = require('../../user'),
|
||||
helpers = require('../helpers'),
|
||||
accountHelpers = require('./helpers');
|
||||
|
||||
var infoController = {};
|
||||
|
||||
infoController.get = function(req, res, next) {
|
||||
accountHelpers.getBaseUser(req.params.userslug, req.uid, function(err, userData) {
|
||||
async.parallel({
|
||||
ips: async.apply(user.getIPs, res.locals.uid, 4),
|
||||
history: async.apply(user.getModerationHistory, res.locals.uid)
|
||||
}, function(err, data) {
|
||||
data = _.extend(userData, data);
|
||||
|
||||
userData.title = '[[pages:account/info]]';
|
||||
userData.breadcrumbs = helpers.buildBreadcrumbs([{text: userData.username, url: '/user/' + userData.userslug}, {text: '[[user:settings]]'}]);
|
||||
|
||||
res.render('account/info', data);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = infoController;
|
@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async'),
|
||||
_ = require('underscore');
|
||||
|
||||
var db = require('../database'),
|
||||
posts = require('../posts'),
|
||||
topics = require('../topics');
|
||||
|
||||
module.exports = function(User) {
|
||||
User.getModerationHistory = function(uid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.parallel({
|
||||
flags: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':flag:pids', 0, 20, '+inf', '-inf'),
|
||||
bans: async.apply(db.getSortedSetRevRangeByScoreWithScores, 'uid:' + uid + ':bans', 0, 20, '+inf', '-inf')
|
||||
}, next);
|
||||
},
|
||||
async.apply(getFlagMetadata),
|
||||
async.apply(formatBanData)
|
||||
], function(err, data) {
|
||||
callback(err, data);
|
||||
});
|
||||
};
|
||||
|
||||
function getFlagMetadata(data, callback) {
|
||||
// Retrieve post title & slug from flags list
|
||||
posts.getPostsFields(data.flags.map(function(flagObj) {
|
||||
return parseInt(flagObj.value, 10);
|
||||
}), ['tid'], function(err, postData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var tids = postData.map(function(post) {
|
||||
return post.tid;
|
||||
});
|
||||
|
||||
topics.getTopicsFields(tids, ['title'], function(err, topicData) {
|
||||
data.flags = data.flags.map(function(flagObj, idx) {
|
||||
flagObj.pid = flagObj.value;
|
||||
flagObj.timestamp = flagObj.score;
|
||||
flagObj.timestampISO = new Date(flagObj.score).toISOString();
|
||||
flagObj.timestampReadable = new Date(flagObj.score).toString();
|
||||
|
||||
delete flagObj.value;
|
||||
delete flagObj.score;
|
||||
|
||||
return _.extend(flagObj, topicData[idx]);
|
||||
});
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function formatBanData(data, callback) {
|
||||
data.bans = data.bans.map(function(banObj) {
|
||||
banObj.until = parseInt(banObj.value, 10);
|
||||
banObj.untilReadable = new Date(banObj.until).toString();
|
||||
banObj.timestamp = parseInt(banObj.score, 10);
|
||||
banObj.timestampReadable = new Date(banObj.score).toString();
|
||||
banObj.timestampISO = new Date(banObj.score).toISOString();
|
||||
|
||||
delete banObj.value;
|
||||
delete banObj.score;
|
||||
|
||||
return banObj;
|
||||
});
|
||||
|
||||
setImmediate(callback, null, data);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue