From 5ee6aabbc03e2c076661fc2f75e38b408354327c Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Thu, 5 Feb 2026 11:40:02 -0600 Subject: [PATCH] edit tags --- src/api/routes/channels/#channel_id/index.ts | 22 +++++++++++++++++++ .../uncategorised/ChannelModifySchema.ts | 1 + 2 files changed, 23 insertions(+) diff --git a/src/api/routes/channels/#channel_id/index.ts b/src/api/routes/channels/#channel_id/index.ts index a73e795a7..b7777511b 100644 --- a/src/api/routes/channels/#channel_id/index.ts +++ b/src/api/routes/channels/#channel_id/index.ts @@ -174,6 +174,28 @@ router.patch( channel.available_tags = channel.available_tags.filter((_) => filter.has(_.id)); } } + if (payload.applied_tags) { + if (channel.isThread()) { + const parent = await Channel.findOneOrFail({ + where: { + id: channel.parent_id as string, + }, + relations: ["available_tags"], + }); + if (!parent.available_tags) throw new Error("shoot, internetal error"); + const realTags = new Map(parent.available_tags.map((tag) => [tag.id, tag])); + const bad = payload.applied_tags.find((tag) => !realTags.has(tag)); + //TODO better error + if (bad) throw new Error("Invalid tag " + bad); + const permsNeeded = payload.applied_tags.find((_) => realTags.get(_)?.moderated); + if (permsNeeded) { + req.permission?.hasThrow("MANAGE_THREADS"); + } + } else { + //TODO maybe error instead? + payload.applied_tags = undefined; + } + } if (payload.icon) payload.icon = await handleFile(`/channel-icons/${channel_id}`, payload.icon); diff --git a/src/schemas/uncategorised/ChannelModifySchema.ts b/src/schemas/uncategorised/ChannelModifySchema.ts index 70501b993..b83dc12e9 100644 --- a/src/schemas/uncategorised/ChannelModifySchema.ts +++ b/src/schemas/uncategorised/ChannelModifySchema.ts @@ -37,6 +37,7 @@ export interface ChannelModifySchema { allow: string; deny: string; }[]; + applied_tags?: string[]; parent_id?: string; id?: string; // is not used (only for guild create) nsfw?: boolean;