mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
refactor(socket.io): deprecate categories.get in favour of api.categories.list
This commit is contained in:
@@ -15,6 +15,22 @@ const hasAdminPrivilege = async (uid, privilege = 'categories') => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
categoriesAPI.list = async (caller) => {
|
||||||
|
async function getCategories() {
|
||||||
|
const cids = await categories.getCidsByPrivilege('categories:cid', caller.uid, 'find');
|
||||||
|
return await categories.getCategoriesData(cids);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [isAdmin, categoriesData] = await Promise.all([
|
||||||
|
user.isAdministrator(caller.uid),
|
||||||
|
getCategories(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
categories: categoriesData.filter(category => category && (!category.disabled || isAdmin)),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
categoriesAPI.get = async function (caller, data) {
|
categoriesAPI.get = async function (caller, data) {
|
||||||
const [userPrivileges, category] = await Promise.all([
|
const [userPrivileges, category] = await Promise.all([
|
||||||
privileges.categories.get(data.cid, caller.uid),
|
privileges.categories.get(data.cid, caller.uid),
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ const helpers = require('../helpers');
|
|||||||
|
|
||||||
const Categories = module.exports;
|
const Categories = module.exports;
|
||||||
|
|
||||||
|
Categories.list = async (req, res) => {
|
||||||
|
helpers.formatApiResponse(200, res, await api.categories.list(req));
|
||||||
|
};
|
||||||
|
|
||||||
Categories.get = async (req, res) => {
|
Categories.get = async (req, res) => {
|
||||||
helpers.formatApiResponse(200, res, await api.categories.get(req, req.params));
|
helpers.formatApiResponse(200, res, await api.categories.get(req, req.params));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const { setupApiRoute } = routeHelpers;
|
|||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
const middlewares = [middleware.ensureLoggedIn];
|
const middlewares = [middleware.ensureLoggedIn];
|
||||||
|
|
||||||
|
setupApiRoute(router, 'get', '/', [...middlewares], controllers.write.categories.list);
|
||||||
setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['name'])], controllers.write.categories.create);
|
setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['name'])], controllers.write.categories.create);
|
||||||
setupApiRoute(router, 'get', '/:cid', [], controllers.write.categories.get);
|
setupApiRoute(router, 'get', '/:cid', [], controllers.write.categories.get);
|
||||||
setupApiRoute(router, 'put', '/:cid', [...middlewares], controllers.write.categories.update);
|
setupApiRoute(router, 'put', '/:cid', [...middlewares], controllers.write.categories.update);
|
||||||
|
|||||||
@@ -18,15 +18,9 @@ SocketCategories.getRecentReplies = async function (socket, cid) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketCategories.get = async function (socket) {
|
SocketCategories.get = async function (socket) {
|
||||||
async function getCategories() {
|
sockets.warnDeprecated(socket, 'GET /api/v3/categories');
|
||||||
const cids = await categories.getCidsByPrivilege('categories:cid', socket.uid, 'find');
|
const { categories } = await api.categories.list(socket);
|
||||||
return await categories.getCategoriesData(cids);
|
return categories;
|
||||||
}
|
|
||||||
const [isAdmin, categoriesData] = await Promise.all([
|
|
||||||
user.isAdministrator(socket.uid),
|
|
||||||
getCategories(),
|
|
||||||
]);
|
|
||||||
return categoriesData.filter(category => category && (!category.disabled || isAdmin));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketCategories.getWatchedCategories = async function (socket) {
|
SocketCategories.getWatchedCategories = async function (socket) {
|
||||||
|
|||||||
Reference in New Issue
Block a user