From 31a6d0305f922ee6370633ad1a7a99000d71afb8 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 11 Jan 2024 18:47:26 -0600 Subject: [PATCH 1/3] Add admin status deletion endpoint --- src/app.ts | 8 +++++++- src/controllers/api/pleroma.ts | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index f4e99dc..1006862 100644 --- a/src/app.ts +++ b/src/app.ts @@ -44,7 +44,12 @@ import { instanceController } from './controllers/api/instance.ts'; import { mediaController } from './controllers/api/media.ts'; import { notificationsController } from './controllers/api/notifications.ts'; import { createTokenController, oauthAuthorizeController, oauthController } from './controllers/api/oauth.ts'; -import { configController, frontendConfigController, updateConfigController } from './controllers/api/pleroma.ts'; +import { + configController, + frontendConfigController, + pleromaAdminDeleteStatusController, + updateConfigController, +} from './controllers/api/pleroma.ts'; import { preferencesController } from './controllers/api/preferences.ts'; import { relayController } from './controllers/nostr/relay.ts'; import { searchController } from './controllers/api/search.ts'; @@ -189,6 +194,7 @@ app.get('/api/v1/blocks', requirePubkey, blocksController); app.get('/api/v1/admin/accounts', adminAccountsController); app.get('/api/v1/pleroma/admin/config', requireRole('admin'), configController); app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController); +app.delete('/api/v1/pleroma/admin/statuses/:id', requireRole('admin'), pleromaAdminDeleteStatusController); // Not (yet) implemented. app.get('/api/v1/custom_emojis', emptyArrayController); diff --git a/src/controllers/api/pleroma.ts b/src/controllers/api/pleroma.ts index cc6addb..b9656da 100644 --- a/src/controllers/api/pleroma.ts +++ b/src/controllers/api/pleroma.ts @@ -85,4 +85,13 @@ const updateConfigController: AppController = async (c) => { return c.json({ configs: newConfigs, need_reboot: false }); }; -export { configController, frontendConfigController, updateConfigController }; +const pleromaAdminDeleteStatusController: AppController = async (c) => { + await createAdminEvent({ + kind: 5, + tags: [['e', c.req.param('id')]], + }, c); + + return c.json({}); +}; + +export { configController, frontendConfigController, pleromaAdminDeleteStatusController, updateConfigController }; From c4920ccb2e2f9eb1261a54170e0938a404fea006 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 11 Jan 2024 19:05:34 -0600 Subject: [PATCH 2/3] pipeline: let the admin pubkey delete anything with kind 5's --- src/pipeline.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index 79b88c7..2ffc6b9 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -66,12 +66,11 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts = const { force = false } = opts; if (force || data.user || isAdminEvent(event) || await isLocallyFollowed(event.pubkey)) { - const [deletion] = await eventsDB.filter( - [{ kinds: [5], authors: [event.pubkey], '#e': [event.id], limit: 1 }], - { limit: 1 }, - ); + const isDeleted = await eventsDB.count( + [{ kinds: [5], authors: [Conf.pubkey, event.pubkey], '#e': [event.id], limit: 1 }], + ) > 0; - if (deletion) { + if (isDeleted) { return Promise.reject(new RelayError('blocked', 'event was deleted')); } else { await Promise.all([ @@ -88,12 +87,13 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts = async function processDeletions(event: Event): Promise { if (event.kind === 5) { const ids = getTagSet(event.tags, 'e'); - const events = await eventsDB.filter([{ ids: [...ids] }]); - const deleteIds = events - .filter(({ pubkey, id }) => pubkey === event.pubkey && ids.has(id)) - .map((event) => event.id); + const events = await eventsDB.filter([{ + ids: [...ids], + authors: [Conf.pubkey, event.pubkey], + }]); + const deleteIds = events.map(({ id }) => id); await eventsDB.deleteFilters([{ ids: deleteIds }]); } } From e3631104a6010bba9ac57e138158317166eccf19 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 11 Jan 2024 19:11:04 -0600 Subject: [PATCH 3/3] pipeline: fix admin event deletion --- src/pipeline.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index 2ffc6b9..3333bec 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -88,13 +88,17 @@ async function processDeletions(event: Event): Promise { if (event.kind === 5) { const ids = getTagSet(event.tags, 'e'); - const events = await eventsDB.filter([{ - ids: [...ids], - authors: [Conf.pubkey, event.pubkey], - }]); + if (event.pubkey === Conf.pubkey) { + await eventsDB.deleteFilters([{ ids: [...ids] }]); + } else { + const events = await eventsDB.filter([{ + ids: [...ids], + authors: [event.pubkey], + }]); - const deleteIds = events.map(({ id }) => id); - await eventsDB.deleteFilters([{ ids: deleteIds }]); + const deleteIds = events.map(({ id }) => id); + await eventsDB.deleteFilters([{ ids: deleteIds }]); + } } }