adminActionController: mark "n" tags on the user
This commit is contained in:
parent
7d54a5c7d0
commit
b9922f96a0
|
@ -26,7 +26,7 @@ import {
|
||||||
updateCredentialsController,
|
updateCredentialsController,
|
||||||
verifyCredentialsController,
|
verifyCredentialsController,
|
||||||
} from '@/controllers/api/accounts.ts';
|
} from '@/controllers/api/accounts.ts';
|
||||||
import { adminAccountAction, adminAccountsController } from '@/controllers/api/admin.ts';
|
import { adminAccountsController, adminActionController } from '@/controllers/api/admin.ts';
|
||||||
import { appCredentialsController, createAppController } from '@/controllers/api/apps.ts';
|
import { appCredentialsController, createAppController } from '@/controllers/api/apps.ts';
|
||||||
import { blocksController } from '@/controllers/api/blocks.ts';
|
import { blocksController } from '@/controllers/api/blocks.ts';
|
||||||
import { bookmarksController } from '@/controllers/api/bookmarks.ts';
|
import { bookmarksController } from '@/controllers/api/bookmarks.ts';
|
||||||
|
@ -251,7 +251,7 @@ app.post(
|
||||||
adminReportResolveController,
|
adminReportResolveController,
|
||||||
);
|
);
|
||||||
|
|
||||||
app.post('/api/v1/admin/accounts/:id{[0-9a-f]{64}}/action', requireSigner, requireRole('admin'), adminAccountAction);
|
app.post('/api/v1/admin/accounts/:id{[0-9a-f]{64}}/action', requireSigner, requireRole('admin'), adminActionController);
|
||||||
|
|
||||||
// Not (yet) implemented.
|
// Not (yet) implemented.
|
||||||
app.get('/api/v1/custom_emojis', emptyArrayController);
|
app.get('/api/v1/custom_emojis', emptyArrayController);
|
||||||
|
|
|
@ -5,8 +5,7 @@ import { Conf } from '@/config.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { booleanParamSchema } from '@/schema.ts';
|
import { booleanParamSchema } from '@/schema.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { paginated, paginationSchema, parseBody, updateListAdminEvent } from '@/utils/api.ts';
|
import { paginated, paginationSchema, parseBody, updateUser } from '@/utils/api.ts';
|
||||||
import { addTag } from '@/utils/tags.ts';
|
|
||||||
import { renderAdminAccount } from '@/views/mastodon/admin-accounts.ts';
|
import { renderAdminAccount } from '@/views/mastodon/admin-accounts.ts';
|
||||||
|
|
||||||
const adminAccountQuerySchema = z.object({
|
const adminAccountQuerySchema = z.object({
|
||||||
|
@ -64,7 +63,7 @@ const adminAccountActionSchema = z.object({
|
||||||
type: z.enum(['none', 'sensitive', 'disable', 'silence', 'suspend']),
|
type: z.enum(['none', 'sensitive', 'disable', 'silence', 'suspend']),
|
||||||
});
|
});
|
||||||
|
|
||||||
const adminAccountAction: AppController = async (c) => {
|
const adminActionController: AppController = async (c) => {
|
||||||
const body = await parseBody(c.req.raw);
|
const body = await parseBody(c.req.raw);
|
||||||
const result = adminAccountActionSchema.safeParse(body);
|
const result = adminAccountActionSchema.safeParse(body);
|
||||||
const authorId = c.req.param('id');
|
const authorId = c.req.param('id');
|
||||||
|
@ -75,17 +74,24 @@ const adminAccountAction: AppController = async (c) => {
|
||||||
|
|
||||||
const { data } = result;
|
const { data } = result;
|
||||||
|
|
||||||
if (data.type !== 'disable') {
|
const n: Record<string, boolean> = {};
|
||||||
return c.json({ error: 'Record invalid' }, 422);
|
|
||||||
|
if (data.type === 'sensitive') {
|
||||||
|
n.sensitive = true;
|
||||||
|
}
|
||||||
|
if (data.type === 'disable') {
|
||||||
|
n.disable = true;
|
||||||
|
}
|
||||||
|
if (data.type === 'silence') {
|
||||||
|
n.silence = true;
|
||||||
|
}
|
||||||
|
if (data.type === 'suspend') {
|
||||||
|
n.suspend = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateListAdminEvent(
|
await updateUser(authorId, n, c);
|
||||||
{ kinds: [10000], authors: [Conf.pubkey], limit: 1 },
|
|
||||||
(tags) => addTag(tags, ['p', authorId]),
|
|
||||||
c,
|
|
||||||
);
|
|
||||||
|
|
||||||
return c.json({}, 200);
|
return c.json({}, 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { adminAccountAction, adminAccountsController };
|
export { adminAccountsController, adminActionController };
|
||||||
|
|
|
@ -107,6 +107,36 @@ async function updateAdminEvent<E extends EventStub>(
|
||||||
return createAdminEvent(fn(prev), c);
|
return createAdminEvent(fn(prev), c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateUser(pubkey: string, n: Record<string, boolean>, c: AppContext): Promise<NostrEvent> {
|
||||||
|
const signer = new AdminSigner();
|
||||||
|
const admin = await signer.getPublicKey();
|
||||||
|
|
||||||
|
return updateAdminEvent(
|
||||||
|
{ kinds: [30382], authors: [admin], '#d': [pubkey], limit: 1 },
|
||||||
|
(prev) => {
|
||||||
|
const prevNames = prev?.tags.reduce((acc, [name, value]) => {
|
||||||
|
if (name === 'n') acc[value] = true;
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<string, boolean>);
|
||||||
|
|
||||||
|
const names = { ...prevNames, ...n };
|
||||||
|
const nTags = Object.entries(names).filter(([, value]) => value).map(([name]) => ['n', name]);
|
||||||
|
const other = prev?.tags.filter(([name]) => !['d', 'n'].includes(name)) ?? [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind: 30382,
|
||||||
|
content: prev?.content,
|
||||||
|
tags: [
|
||||||
|
['d', pubkey],
|
||||||
|
...nTags,
|
||||||
|
...other,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
c,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Push the event through the pipeline, rethrowing any RelayError. */
|
/** Push the event through the pipeline, rethrowing any RelayError. */
|
||||||
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
async function publishEvent(event: NostrEvent, c: AppContext): Promise<NostrEvent> {
|
||||||
debug('EVENT', event);
|
debug('EVENT', event);
|
||||||
|
@ -267,4 +297,5 @@ export {
|
||||||
updateEvent,
|
updateEvent,
|
||||||
updateListAdminEvent,
|
updateListAdminEvent,
|
||||||
updateListEvent,
|
updateListEvent,
|
||||||
|
updateUser,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue