forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: deprecate socket.emit('users.search') use api route
- Loading branch information
1 parent
083c74e
commit 2279e37
Showing
10 changed files
with
58 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,17 @@ | ||
'use strict'; | ||
|
||
const user = require('../../user'); | ||
const pagination = require('../../pagination'); | ||
const privileges = require('../../privileges'); | ||
const api = require('../../api'); | ||
const sockets = require('..'); | ||
|
||
module.exports = function (SocketUser) { | ||
SocketUser.search = async function (socket, data) { | ||
// TODO: depracate and use usersController.search | ||
sockets.warnDeprecated(socket, 'GET /api/users'); | ||
if (!data) { | ||
throw new Error('[[error:invalid-data]]'); | ||
} | ||
const [allowed, isPrivileged] = await Promise.all([ | ||
privileges.global.can('search:users', socket.uid), | ||
user.isPrivileged(socket.uid), | ||
]); | ||
|
||
let filters = data.filters || []; | ||
filters = Array.isArray(filters) ? filters : [filters]; | ||
if (!allowed || | ||
(( | ||
data.searchBy === 'ip' || | ||
data.searchBy === 'email' || | ||
filters.includes('banned') || | ||
filters.includes('flagged') | ||
) && !isPrivileged) | ||
) { | ||
throw new Error('[[error:no-privileges]]'); | ||
} | ||
const result = await user.search({ | ||
query: data.query, | ||
page: data.page, | ||
searchBy: data.searchBy, | ||
sortBy: data.sortBy, | ||
filters: data.filters, | ||
paginate: data.paginate, | ||
uid: socket.uid, | ||
}); | ||
const result = api.users.search(socket, data); | ||
result.pagination = pagination.create(data.page, result.pageCount); | ||
result['route_users:' + data.sortBy] = true; | ||
return result; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters