summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-05 13:44:52 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-05 13:44:52 +0200
commit43a38ba46ce92ca5cd1e363c25c03cbccce901dc (patch)
tree421a1b1b00abe856bcca6e0bd1716fb61bc39b5e /src
parent:arrow_up: update demo test client (diff)
parentMerge pull request #181 from luth31/master (diff)
downloadserver-43a38ba46ce92ca5cd1e363c25c03cbccce901dc.tar.xz
Merge branch 'master' of https://github.com/fosscord/fosscord-api
Diffstat (limited to 'src')
-rw-r--r--src/util/Channel.ts22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/util/Channel.ts b/src/util/Channel.ts

index 8dfc03bc..4d322812 100644 --- a/src/util/Channel.ts +++ b/src/util/Channel.ts
@@ -13,11 +13,21 @@ import { emitEvent } from "./Event"; // TODO: DM channel export async function createChannel(channel: Partial<TextChannel | VoiceChannel>, user_id: string = "0") { - if (!channel.permission_overwrites) channel.permission_overwrites = []; + + // Always check if user has permission first + const permissions = await getPermission(user_id, channel.guild_id); + permissions.hasThrow("MANAGE_CHANNELS"); switch (channel.type) { case ChannelType.GUILD_TEXT: case ChannelType.GUILD_VOICE: + if (channel.parent_id) { + const exists = await ChannelModel.findOne({ id: channel.parent_id }, { guild_id: true }).exec(); + if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400); + if (exists.guild_id !== channel.guild_id) throw new HTTPError("The category channel needs to be in the guild"); + } + break; + case ChannelType.GUILD_CATEGORY: break; case ChannelType.DM: case ChannelType.GROUP_DM: @@ -29,15 +39,7 @@ export async function createChannel(channel: Partial<TextChannel | VoiceChannel> throw new HTTPError("Not yet supported"); } - const permissions = await getPermission(user_id, channel.guild_id); - permissions.hasThrow("MANAGE_CHANNELS"); - - if (channel.parent_id) { - const exists = await ChannelModel.findOne({ id: channel.parent_id }, { guild_id: true }).exec(); - if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400); - if (exists.guild_id !== channel.guild_id) throw new HTTPError("The category channel needs to be in the guild"); - } - + if (!channel.permission_overwrites) channel.permission_overwrites = []; // TODO: auto generate position channel = await new ChannelModel({