mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-18 05:22:48 +01:00
feat: flag rescinding logic + api method
This commit is contained in:
@@ -192,6 +192,8 @@ paths:
|
|||||||
$ref: 'write/flags.yaml'
|
$ref: 'write/flags.yaml'
|
||||||
/flags/{flagId}:
|
/flags/{flagId}:
|
||||||
$ref: 'write/flags/flagId.yaml'
|
$ref: 'write/flags/flagId.yaml'
|
||||||
|
/flags/{flagId}/report:
|
||||||
|
$ref: 'write/flags/flagId/report.yaml'
|
||||||
/flags/{flagId}/notes:
|
/flags/{flagId}/notes:
|
||||||
$ref: 'write/flags/flagId/notes.yaml'
|
$ref: 'write/flags/flagId/notes.yaml'
|
||||||
/flags/{flagId}/notes/{datetime}:
|
/flags/{flagId}/notes/{datetime}:
|
||||||
|
|||||||
26
public/openapi/write/flags/flagId/report.yaml
Normal file
26
public/openapi/write/flags/flagId/report.yaml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- flags
|
||||||
|
summary: rescind a flag report
|
||||||
|
description: This operation rescinds the report made for a given flag.
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: flagId
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid flag id
|
||||||
|
example: 2
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Flag report rescinded
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
@@ -49,6 +49,16 @@ flagsApi.update = async (caller, data) => {
|
|||||||
|
|
||||||
flagsApi.delete = async (_, { flagId }) => await flags.purge([flagId]);
|
flagsApi.delete = async (_, { flagId }) => await flags.purge([flagId]);
|
||||||
|
|
||||||
|
flagsApi.rescind = async ({ uid }, { flagId }) => {
|
||||||
|
const { type, targetId } = await flags.get(flagId);
|
||||||
|
const exists = await flags.exists(type, targetId, uid);
|
||||||
|
if (!exists) {
|
||||||
|
throw new Error('[[error:no-flag]]');
|
||||||
|
}
|
||||||
|
|
||||||
|
await flags.rescindReport(type, targetId, uid);
|
||||||
|
};
|
||||||
|
|
||||||
flagsApi.appendNote = async (caller, data) => {
|
flagsApi.appendNote = async (caller, data) => {
|
||||||
const allowed = await user.isPrivileged(caller.uid);
|
const allowed = await user.isPrivileged(caller.uid);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ Flags.delete = async (req, res) => {
|
|||||||
helpers.formatApiResponse(200, res);
|
helpers.formatApiResponse(200, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Flags.rescind = async (req, res) => {
|
||||||
|
await api.flags.rescind(req, { flagId: req.params.flagId });
|
||||||
|
helpers.formatApiResponse(200, res);
|
||||||
|
};
|
||||||
|
|
||||||
Flags.appendNote = async (req, res) => {
|
Flags.appendNote = async (req, res) => {
|
||||||
const { note, datetime } = req.body;
|
const { note, datetime } = req.body;
|
||||||
const payload = await api.flags.appendNote(req, {
|
const payload = await api.flags.appendNote(req, {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ Flags.get = async function (flagId) {
|
|||||||
Flags.getReports(flagId),
|
Flags.getReports(flagId),
|
||||||
]);
|
]);
|
||||||
if (!base) {
|
if (!base) {
|
||||||
return;
|
throw new Error('[[error:no-flag]]');
|
||||||
}
|
}
|
||||||
const flagObj = {
|
const flagObj = {
|
||||||
state: 'open',
|
state: 'open',
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ module.exports = function () {
|
|||||||
setupApiRoute(router, 'put', '/:flagId', [...middlewares, middleware.assert.flag], controllers.write.flags.update);
|
setupApiRoute(router, 'put', '/:flagId', [...middlewares, middleware.assert.flag], controllers.write.flags.update);
|
||||||
setupApiRoute(router, 'delete', '/:flagId', [...middlewares, middleware.assert.flag], controllers.write.flags.delete);
|
setupApiRoute(router, 'delete', '/:flagId', [...middlewares, middleware.assert.flag], controllers.write.flags.delete);
|
||||||
|
|
||||||
|
setupApiRoute(router, 'delete', '/:flagId/report', middlewares, controllers.write.flags.rescind);
|
||||||
|
|
||||||
setupApiRoute(router, 'post', '/:flagId/notes', [...middlewares, middleware.assert.flag], controllers.write.flags.appendNote);
|
setupApiRoute(router, 'post', '/:flagId/notes', [...middlewares, middleware.assert.flag], controllers.write.flags.appendNote);
|
||||||
setupApiRoute(router, 'delete', '/:flagId/notes/:datetime', [...middlewares, middleware.assert.flag], controllers.write.flags.deleteNote);
|
setupApiRoute(router, 'delete', '/:flagId/notes/:datetime', [...middlewares, middleware.assert.flag], controllers.write.flags.deleteNote);
|
||||||
|
|
||||||
|
|||||||
@@ -1004,6 +1004,22 @@ describe('Flags', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('.rescind()', () => {
|
||||||
|
it('should remove a flag\'s report', async () => {
|
||||||
|
const response = await request({
|
||||||
|
method: 'delete',
|
||||||
|
uri: `${nconf.get('url')}/api/v3/flags/2/report`,
|
||||||
|
jar,
|
||||||
|
headers: {
|
||||||
|
'x-csrf-token': csrfToken,
|
||||||
|
},
|
||||||
|
resolveWithFullResponse: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(response.statusCode, 200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('.appendNote()', () => {
|
describe('.appendNote()', () => {
|
||||||
it('should append a note to the flag', async () => {
|
it('should append a note to the flag', async () => {
|
||||||
const { response } = await request({
|
const { response } = await request({
|
||||||
|
|||||||
Reference in New Issue
Block a user