v1.18.x
barisusakli 10 years ago
parent 73d358edc5
commit 33780e6fdb

@ -25,6 +25,10 @@ usersController.sortByJoinDate = function(req, res, next) {
getUsers('users:joindate', req, res, next); getUsers('users:joindate', req, res, next);
}; };
usersController.banned = function(req, res, next) {
getUsers('users:banned', req, res, next);
};
function getUsers(set, req, res, next) { function getUsers(set, req, res, next) {
user.getUsersFromSet(set, 0, 49, function(err, users) { user.getUsersFromSet(set, 0, 49, function(err, users) {
if (err) { if (err) {

@ -26,6 +26,9 @@ module.exports = function(db, module) {
}; };
function sortedSetAddBulk(key, scores, values, callback) { function sortedSetAddBulk(key, scores, values, callback) {
if (!scores.length || !values.length) {
return callback();
}
if (scores.length !== values.length) { if (scores.length !== values.length) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }

@ -51,6 +51,7 @@ function addRoutes(router, middleware, controllers) {
router.get('/manage/users/latest', controllers.admin.users.sortByJoinDate); router.get('/manage/users/latest', controllers.admin.users.sortByJoinDate);
router.get('/manage/users/sort-posts', controllers.admin.users.sortByPosts); router.get('/manage/users/sort-posts', controllers.admin.users.sortByPosts);
router.get('/manage/users/sort-reputation', controllers.admin.users.sortByReputation); router.get('/manage/users/sort-reputation', controllers.admin.users.sortByReputation);
router.get('/manage/users/banned', controllers.admin.users.banned);
router.get('/manage/groups', controllers.admin.groups.get); router.get('/manage/groups', controllers.admin.groups.get);

@ -19,7 +19,7 @@ var db = require('./database'),
schemaDate, thisSchemaDate, schemaDate, thisSchemaDate,
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
latestSchema = Date.UTC(2014, 8, 27); latestSchema = Date.UTC(2014, 9, 3);
Upgrade.check = function(callback) { Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) { db.get('schemaDate', function(err, value) {
@ -1042,6 +1042,49 @@ Upgrade.upgrade = function(callback) {
winston.info('[2014/9/27] Deleting tid:<tid>:read_by_uid skipped'); winston.info('[2014/9/27] Deleting tid:<tid>:read_by_uid skipped');
next(); next();
} }
},
function(next) {
thisSchemaDate = Date.UTC(2014, 9, 3);
if (schemaDate < thisSchemaDate) {
winston.info('[2014/10/3] Banned users sorted set');
db.getSortedSetRange('users:joindate', 0, -1, function(err, uids) {
if (err) {
return next(err);
}
async.eachLimit(uids, 50, function(uid, next) {
User.getMultipleUserFields(uids, ['uid', 'banned'], function(err, userData) {
if (err) {
return next(err);
}
var bannedUids = userData.filter(function(user) {
return user && parseInt(user.banned, 10) === 1;
}).map(function(user) {
return user.uid;
});
var timestamps = [];
var now = Date.now();
bannedUids.forEach(function() {
timestamps.push(now);
});
db.sortedSetAdd('users:banned', timestamps, bannedUids, next);
});
}, function(err) {
if (err) {
winston.error('[2014/10/3] Error encountered while updating banned users sorted set');
return next(err);
}
winston.info('[2014/10/3] Banned users added to sorted set');
Upgrade.update(thisSchemaDate, next);
});
});
} else {
winston.info('[2014/10/3] Banned users sorted set skipped');
next();
}
} }
// Add new schema updates here // Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!! // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 22!!!

@ -46,11 +46,21 @@ module.exports = function(User) {
}; };
User.ban = function(uid, callback) { User.ban = function(uid, callback) {
User.setUserField(uid, 'banned', 1, callback); User.setUserField(uid, 'banned', 1, function(err) {
if (err) {
return callback();
}
db.sortedSetAdd('users:banned', Date.now(), uid, callback);
});
}; };
User.unban = function(uid, callback) { User.unban = function(uid, callback) {
db.delete('uid:' + uid + ':flagged_by'); db.delete('uid:' + uid + ':flagged_by');
User.setUserField(uid, 'banned', 0, callback); User.setUserField(uid, 'banned', 0, function(err) {
if (err) {
return callback(err);
}
db.sortedSetRemove('users:banned', uid, callback);
});
}; };
}; };

@ -2,12 +2,13 @@
<div class="col-sm-9"> <div class="col-sm-9">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-user"></i> Users</div> <div class="panel-heading"><i class="fa fa-user"></i> Users</div>
<div class="panel-body"> <div class="panel-body">
<ul class="nav nav-pills"> <ul class="nav nav-pills">
<li class='active'><a href='{relative_path}/admin/manage/users/search'>Search</a></li> <li class='active'><a href='{relative_path}/admin/manage/users/search'>Search</a></li>
<li class=''><a href='{relative_path}/admin/manage/users/latest'>Latest Users</a></li> <li class=''><a href='{relative_path}/admin/manage/users/latest'>Latest Users</a></li>
<li class=''><a href='{relative_path}/admin/manage/users/sort-posts'>Top Posters</a></li> <li class=''><a href='{relative_path}/admin/manage/users/sort-posts'>Top Posters</a></li>
<li class=''><a href='{relative_path}/admin/manage/users/sort-reputation'>Most Reputation</a></li> <li class=''><a href='{relative_path}/admin/manage/users/sort-reputation'>Most Reputation</a></li>
<li class=''><a href='{relative_path}/admin/manage/users/banned'>Banned</a></li>
<div class="btn-group pull-right"> <div class="btn-group pull-right">
@ -105,7 +106,7 @@
<button id="load-more-users-btn" class="btn btn-primary">Load More</button> <button id="load-more-users-btn" class="btn btn-primary">Load More</button>
</div> </div>
<input type="hidden" template-variable="yourid" value="{yourid}" /> <input type="hidden" template-variable="yourid" value="{yourid}" />
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save