mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-13 01:15:47 +01:00
group member search
only look in uids that are member of the group, added custom findUids function to user.search
This commit is contained in:
@@ -1098,65 +1098,42 @@ var async = require('async'),
|
|||||||
|
|
||||||
Groups.searchMembers = function(data, callback) {
|
Groups.searchMembers = function(data, callback) {
|
||||||
|
|
||||||
function userInGroup(userGroups) {
|
function findUids(query, searchBy, startsWith, callback) {
|
||||||
for(var i=0; i<userGroups.length; ++i) {
|
if (!query) {
|
||||||
if (userGroups[i].name === data.groupName) {
|
return Groups.getMembers(data.groupName, 0, -1, callback);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var searchResult;
|
|
||||||
var pagination;
|
|
||||||
|
|
||||||
if (!data.query) {
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
user.getUidsFromSet('group:' + data.groupName + ':members', 0, -1, next);
|
Groups.getMembers(data.groupName, 0, -1, next);
|
||||||
},
|
},
|
||||||
function(uids, next) {
|
function(members, next) {
|
||||||
pagination = user.paginate(1, uids);
|
user.getMultipleUserFields(members, ['uid'].concat(searchBy), next);
|
||||||
|
|
||||||
uids = pagination.data;
|
|
||||||
user.getUsers(uids, data.uid, next);
|
|
||||||
},
|
},
|
||||||
function(users, next) {
|
function(users, next) {
|
||||||
next(null, {
|
var uids = [];
|
||||||
users: users,
|
|
||||||
pagination: pagination.pagination
|
for(var k=0; k<searchBy.length; ++k) {
|
||||||
|
for(var i=0; i<users.length; ++i) {
|
||||||
|
var field = users[i][searchBy[k]];
|
||||||
|
if ((startsWith && field.toLowerCase().startsWith(query)) || (!startsWith && field.toLowerCase().indexOf(query) !== -1)) {
|
||||||
|
uids.push(users[i].uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (searchBy.length > 1) {
|
||||||
|
uids = uids.filter(function(uid, index, array) {
|
||||||
|
return array.indexOf(uid) === index;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next(null, uids);
|
||||||
|
}
|
||||||
], callback);
|
], callback);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
data.findUids = findUids;
|
||||||
function(next) {
|
user.search(data, callback);
|
||||||
data.paginate = false;
|
|
||||||
user.search(data, next);
|
|
||||||
},
|
|
||||||
function(_searchResult, next) {
|
|
||||||
searchResult = _searchResult;
|
|
||||||
var uids = searchResult.users.map(function(user) {
|
|
||||||
return user && user.uid;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!uids.length) {
|
|
||||||
return callback(null, searchResult);
|
|
||||||
}
|
|
||||||
Groups.getUserGroups(uids, next);
|
|
||||||
},
|
|
||||||
function(groups, next) {
|
|
||||||
searchResult.users = searchResult.users.filter(function(user, index) {
|
|
||||||
return user && userInGroup(groups[index]);
|
|
||||||
});
|
|
||||||
|
|
||||||
pagination = user.paginate(data.page, searchResult.users);
|
|
||||||
searchResult.pagination = pagination.pagination;
|
|
||||||
searchResult.users = pagination.data;
|
|
||||||
next(null, searchResult);
|
|
||||||
}
|
|
||||||
], callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}(module.exports));
|
}(module.exports));
|
||||||
|
|||||||
@@ -26,7 +26,11 @@ module.exports = function(User) {
|
|||||||
var searchResult = {};
|
var searchResult = {};
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
|
if (data.findUids) {
|
||||||
|
data.findUids(query, searchBy, startsWith, next);
|
||||||
|
} else {
|
||||||
findUids(query, searchBy, startsWith, next);
|
findUids(query, searchBy, startsWith, next);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function(uids, next) {
|
function(uids, next) {
|
||||||
var filterBy = Array.isArray(data.filterBy) ? data.filterBy : [];
|
var filterBy = Array.isArray(data.filterBy) ? data.filterBy : [];
|
||||||
|
|||||||
Reference in New Issue
Block a user