Merge branch 'admin-delete' into 'main'

Let admins delete events

See merge request soapbox-pub/ditto!99
This commit is contained in:
Alex Gleason 2024-01-12 01:33:31 +00:00
commit 8b3aee7e48
3 changed files with 31 additions and 12 deletions

View File

@ -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);

View File

@ -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 };

View File

@ -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,14 +87,19 @@ async function storeEvent(event: Event, data: EventData, opts: StoreEventOpts =
async function processDeletions(event: Event): Promise<void> {
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);
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 }]);
}
}
}
/** Track whenever a hashtag is used, for processing trending tags. */