mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-02 10:31:23 +01:00
closes #6154
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
"pills.banned": "Banned",
|
||||
"pills.search": "User Search",
|
||||
|
||||
"search.uid": "By User ID",
|
||||
"search.uid-placeholder": "Enter a user ID to search",
|
||||
"search.username": "By User Name",
|
||||
"search.username-placeholder": "Enter a username to search",
|
||||
"search.email": "By Email",
|
||||
|
||||
@@ -306,7 +306,7 @@ define('admin/manage/users', ['translator', 'benchpress'], function (translator,
|
||||
|
||||
var timeoutId = 0;
|
||||
|
||||
$('#search-user-name, #search-user-email, #search-user-ip').on('keyup', function () {
|
||||
$('#search-user-uid, #search-user-name, #search-user-email, #search-user-ip').on('keyup', function () {
|
||||
if (timeoutId !== 0) {
|
||||
clearTimeout(timeoutId);
|
||||
timeoutId = 0;
|
||||
|
||||
@@ -183,7 +183,11 @@ User.search = function (socket, data, callback) {
|
||||
var searchData;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.search({ query: data.query, searchBy: data.searchBy, uid: socket.uid }, next);
|
||||
user.search({
|
||||
query: data.query,
|
||||
searchBy: data.searchBy,
|
||||
uid: socket.uid,
|
||||
}, next);
|
||||
},
|
||||
function (_searchData, next) {
|
||||
searchData = _searchData;
|
||||
|
||||
@@ -14,17 +14,19 @@ module.exports = function (User) {
|
||||
var uid = data.uid || 0;
|
||||
var paginate = data.hasOwnProperty('paginate') ? data.paginate : true;
|
||||
|
||||
if (searchBy === 'ip') {
|
||||
return searchByIP(query, uid, callback);
|
||||
}
|
||||
|
||||
var startTime = process.hrtime();
|
||||
|
||||
var searchResult = {};
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
var searchMethod = data.findUids || findUids;
|
||||
searchMethod(query, searchBy, data.hardCap, next);
|
||||
if (searchBy === 'ip') {
|
||||
searchByIP(query, next);
|
||||
} else if (searchBy === 'uid') {
|
||||
next(null, [query]);
|
||||
} else {
|
||||
var searchMethod = data.findUids || findUids;
|
||||
searchMethod(query, searchBy, data.hardCap, next);
|
||||
}
|
||||
},
|
||||
function (uids, next) {
|
||||
filterAndSortUids(uids, data, next);
|
||||
@@ -153,20 +155,7 @@ module.exports = function (User) {
|
||||
}
|
||||
}
|
||||
|
||||
function searchByIP(ip, uid, callback) {
|
||||
var start = process.hrtime();
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next);
|
||||
},
|
||||
function (uids, next) {
|
||||
User.getUsers(uids, uid, next);
|
||||
},
|
||||
function (users, next) {
|
||||
var diff = process.hrtime(start);
|
||||
var timing = ((diff[0] * 1e3) + (diff[1] / 1e6)).toFixed(1);
|
||||
next(null, { timing: timing, users: users });
|
||||
},
|
||||
], callback);
|
||||
function searchByIP(ip, callback) {
|
||||
db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, callback);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,6 +49,9 @@
|
||||
<br />
|
||||
|
||||
<div class="search {search_display}">
|
||||
<label>[[admin/manage/users:search.uid]]</label>
|
||||
<input class="form-control" id="search-user-uid" data-search-type="uid" type="text" placeholder="[[admin/manage/users:search.uid-placeholder]]"/><br />
|
||||
|
||||
<label>[[admin/manage/users:search.username]]</label>
|
||||
<input class="form-control" id="search-user-name" data-search-type="username" type="text" placeholder="[[admin/manage/users:search.username-placeholder]]"/><br />
|
||||
|
||||
|
||||
11
test/user.js
11
test/user.js
@@ -273,9 +273,11 @@ describe('User', function () {
|
||||
});
|
||||
|
||||
describe('.search()', function () {
|
||||
var uid;
|
||||
it('should return an object containing an array of matching users', function (done) {
|
||||
User.search({ query: 'john' }, function (err, searchData) {
|
||||
assert.ifError(err);
|
||||
uid = searchData.users[0].uid;
|
||||
assert.equal(Array.isArray(searchData.users) && searchData.users.length > 0, true);
|
||||
assert.equal(searchData.users[0].username, 'John Smith');
|
||||
done();
|
||||
@@ -321,6 +323,15 @@ describe('User', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should search users by ip', function (done) {
|
||||
socketUser.search({ uid: testUid }, { query: uid, searchBy: 'uid' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
assert(Array.isArray(data.users));
|
||||
assert.equal(data.users[0].uid, uid);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return empty array if query is empty', function (done) {
|
||||
socketUser.search({ uid: testUid }, { query: '' }, function (err, data) {
|
||||
assert.ifError(err);
|
||||
|
||||
Reference in New Issue
Block a user