feat: #9109, ability to delete a post's diffs

This commit is contained in:
gasoved
2021-01-28 21:42:10 +03:00
committed by Julian Lam
parent a87416971b
commit eb642f40b9
6 changed files with 164 additions and 59 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const posts = require('../../posts');
const privileges = require('../../privileges');
const api = require('../../api');
const helpers = require('../helpers');
@@ -94,3 +95,19 @@ Posts.restoreDiff = async (req, res) => {
helpers.formatApiResponse(200, res, await api.posts.restoreDiff(req, { ...req.params }));
};
Posts.deleteDiff = async (req, res) => {
if (!parseInt(req.params.pid, 10)) {
throw new Error('[[error:invalid-data]]');
}
const cid = await posts.getCidByPid(req.params.pid);
const isModerator = privileges.users.isModerator(cid, req.uid);
if (!isModerator) {
return helpers.formatApiResponse(403, res, new Error('[[error:no-privileges]]'));
}
await posts.diffs.delete(req.params.pid, req.params.timestamp, req.uid);
helpers.formatApiResponse(200, res);
};