Merge branch 'single-admin-reports-api' into 'main'

Implement Mastodon API - view single report

Closes #104

See merge request soapbox-pub/ditto!225
This commit is contained in:
Alex Gleason 2024-05-07 14:50:32 +00:00
commit cb89b7a80c
2 changed files with 26 additions and 3 deletions

View File

@ -44,7 +44,7 @@ import {
} from '@/controllers/api/pleroma.ts'; } from '@/controllers/api/pleroma.ts';
import { preferencesController } from '@/controllers/api/preferences.ts'; import { preferencesController } from '@/controllers/api/preferences.ts';
import { relayController } from '@/controllers/nostr/relay.ts'; import { relayController } from '@/controllers/nostr/relay.ts';
import { adminReportsController, reportsController } from '@/controllers/api/reports.ts'; import { adminReportController, adminReportsController, reportsController } from '@/controllers/api/reports.ts';
import { searchController } from '@/controllers/api/search.ts'; import { searchController } from '@/controllers/api/search.ts';
import { import {
bookmarkController, bookmarkController,
@ -209,6 +209,7 @@ app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysContro
app.post('/api/v1/reports', requirePubkey, reportsController); app.post('/api/v1/reports', requirePubkey, reportsController);
app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), adminReportsController); app.get('/api/v1/admin/reports', requirePubkey, requireRole('admin'), adminReportsController);
app.get('/api/v1/admin/reports/:id', requirePubkey, requireRole('admin'), adminReportController);
// Not (yet) implemented. // Not (yet) implemented.
app.get('/api/v1/custom_emojis', emptyArrayController); app.get('/api/v1/custom_emojis', emptyArrayController);

View File

@ -16,7 +16,7 @@ const reportsSchema = z.object({
// TODO: rules_ids[] is not implemented // TODO: rules_ids[] is not implemented
}); });
/** https://docs.joinmastodon.org/methods/reports/ */ /** https://docs.joinmastodon.org/methods/reports/#post */
const reportsController: AppController = async (c) => { const reportsController: AppController = async (c) => {
const store = c.get('store'); const store = c.get('store');
const body = await parseBody(c.req.raw); const body = await parseBody(c.req.raw);
@ -66,4 +66,26 @@ const adminReportsController: AppController = async (c) => {
return c.json(reports); return c.json(reports);
}; };
export { adminReportsController, reportsController }; /** https://docs.joinmastodon.org/methods/admin/reports/#get-one */
const adminReportController: AppController = async (c) => {
const eventId = c.req.param('id');
const { signal } = c.req.raw;
const store = c.get('store');
const pubkey = c.get('pubkey');
const [event] = await store.query([{
kinds: [1984],
ids: [eventId],
limit: 1,
}], { signal });
if (!event) {
return c.json({ error: 'This action is not allowed' }, 403);
}
await hydrateEvents({ events: [event], storage: store, signal });
return c.json(await renderAdminReport(event, { viewerPubkey: pubkey }));
};
export { adminReportController, adminReportsController, reportsController };