mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-25 02:31:16 +02:00
The old route was a DELETE method that took a request body. The body is sometimes stripped by some proxies, so this new method does not require a request body, and the member (to whom the privilege is revoked) is now in the route itself as a parameter.
135 lines
3.8 KiB
JavaScript
135 lines
3.8 KiB
JavaScript
'use strict';
|
|
|
|
const categories = require('../../categories');
|
|
const meta = require('../../meta');
|
|
const activitypub = require('../../activitypub');
|
|
const api = require('../../api');
|
|
|
|
const helpers = require('../helpers');
|
|
|
|
const Categories = module.exports;
|
|
|
|
Categories.list = async (req, res) => {
|
|
helpers.formatApiResponse(200, res, await api.categories.list(req));
|
|
};
|
|
|
|
Categories.get = async (req, res) => {
|
|
helpers.formatApiResponse(200, res, await api.categories.get(req, req.params));
|
|
};
|
|
|
|
Categories.create = async (req, res) => {
|
|
const response = await api.categories.create(req, req.body);
|
|
helpers.formatApiResponse(200, res, response);
|
|
};
|
|
|
|
Categories.update = async (req, res) => {
|
|
await api.categories.update(req, {
|
|
cid: req.params.cid,
|
|
values: req.body,
|
|
});
|
|
|
|
const categoryObjs = await categories.getCategories([req.params.cid]);
|
|
helpers.formatApiResponse(200, res, categoryObjs[0]);
|
|
};
|
|
|
|
Categories.delete = async (req, res) => {
|
|
await api.categories.delete(req, { cid: req.params.cid });
|
|
helpers.formatApiResponse(200, res);
|
|
};
|
|
|
|
Categories.getTopicCount = async (req, res) => {
|
|
helpers.formatApiResponse(200, res, await api.categories.getTopicCount(req, { ...req.params }));
|
|
};
|
|
|
|
Categories.getPosts = async (req, res) => {
|
|
const posts = await api.categories.getPosts(req, { ...req.params });
|
|
helpers.formatApiResponse(200, res, { posts });
|
|
};
|
|
|
|
Categories.getChildren = async (req, res) => {
|
|
const { cid } = req.params;
|
|
const { start } = req.query;
|
|
helpers.formatApiResponse(200, res, await api.categories.getChildren(req, { cid, start }));
|
|
};
|
|
|
|
Categories.getTopics = async (req, res) => {
|
|
const { cid } = req.params;
|
|
const result = await api.categories.getTopics(req, { ...req.query, cid });
|
|
|
|
helpers.formatApiResponse(200, res, result);
|
|
};
|
|
|
|
Categories.setWatchState = async (req, res) => {
|
|
const { cid } = req.params;
|
|
let { uid, state } = req.body;
|
|
|
|
if (req.method === 'DELETE') {
|
|
// DELETE is always setting state to system default in acp
|
|
state = categories.watchStates[meta.config.categoryWatchState];
|
|
} else if (Object.keys(categories.watchStates).includes(state)) {
|
|
state = categories.watchStates[state]; // convert to integer for backend processing
|
|
} else {
|
|
throw new Error('[[error:invalid-data]]');
|
|
}
|
|
|
|
const { cids: modified } = await api.categories.setWatchState(req, { cid, state, uid });
|
|
|
|
helpers.formatApiResponse(200, res, { modified });
|
|
};
|
|
|
|
Categories.getPrivileges = async (req, res) => {
|
|
const privilegeSet = await api.categories.getPrivileges(req, { cid: req.params.cid });
|
|
helpers.formatApiResponse(200, res, privilegeSet);
|
|
};
|
|
|
|
Categories.setPrivilege = async (req, res) => {
|
|
const { cid, privilege, member } = req.params;
|
|
|
|
await api.categories.setPrivilege(req, {
|
|
cid,
|
|
privilege,
|
|
member: member || req.body.member,
|
|
set: req.method === 'PUT',
|
|
});
|
|
|
|
const privilegeSet = await api.categories.getPrivileges(req, { cid: req.params.cid });
|
|
helpers.formatApiResponse(200, res, privilegeSet);
|
|
};
|
|
|
|
Categories.setModerator = async (req, res) => {
|
|
await api.categories.setModerator(req, {
|
|
cid: req.params.cid,
|
|
member: req.params.uid,
|
|
set: req.method === 'PUT',
|
|
});
|
|
|
|
const privilegeSet = await api.categories.getPrivileges(req, { cid: req.params.cid });
|
|
helpers.formatApiResponse(200, res, privilegeSet);
|
|
};
|
|
|
|
Categories.follow = async (req, res, next) => {
|
|
// Priv check done in route middleware
|
|
const { actor } = req.body;
|
|
const id = parseInt(req.params.cid, 10);
|
|
|
|
if (!id) { // disallow cid 0
|
|
return next();
|
|
}
|
|
|
|
await activitypub.out.follow('cid', id, actor);
|
|
|
|
helpers.formatApiResponse(200, res, {});
|
|
};
|
|
|
|
Categories.unfollow = async (req, res, next) => {
|
|
const { actor } = req.body;
|
|
const id = parseInt(req.params.cid, 10);
|
|
|
|
if (!id) { // disallow cid 0
|
|
return next();
|
|
}
|
|
|
|
await activitypub.out.undo.follow('cid', id, actor);
|
|
helpers.formatApiResponse(200, res, {});
|
|
};
|