summary refs log tree commit diff
path: root/api/src/routes/channels/#channel_id
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-26 11:34:06 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-26 11:34:06 +0200
commitd0f57902350edd0165673513ecdbfe9a2c8fd073 (patch)
treef928ba0428a0f284ffc4c2146f412249c9693b7e /api/src/routes/channels/#channel_id
parent:bug: fix role can't set permission (diff)
downloadserver-d0f57902350edd0165673513ecdbfe9a2c8fd073.tar.xz
:bug: fix channel permission overwrites
Diffstat (limited to 'api/src/routes/channels/#channel_id')
-rw-r--r--api/src/routes/channels/#channel_id/index.ts4
-rw-r--r--api/src/routes/channels/#channel_id/permissions.ts21
2 files changed, 16 insertions, 9 deletions
diff --git a/api/src/routes/channels/#channel_id/index.ts b/api/src/routes/channels/#channel_id/index.ts
index 61c851e8..2fca4fdf 100644
--- a/api/src/routes/channels/#channel_id/index.ts
+++ b/api/src/routes/channels/#channel_id/index.ts
@@ -62,8 +62,8 @@ export interface ChannelModifySchema {
 	permission_overwrites?: {
 		id: string;
 		type: ChannelPermissionOverwriteType;
-		allow: bigint;
-		deny: bigint;
+		allow: string;
+		deny: string;
 	}[];
 	parent_id?: string;
 	id?: string; // is not used (only for guild create)
diff --git a/api/src/routes/channels/#channel_id/permissions.ts b/api/src/routes/channels/#channel_id/permissions.ts
index bc7ad5b8..6ebf721a 100644
--- a/api/src/routes/channels/#channel_id/permissions.ts
+++ b/api/src/routes/channels/#channel_id/permissions.ts
@@ -1,4 +1,13 @@
-import { Channel, ChannelPermissionOverwrite, ChannelUpdateEvent, emitEvent, getPermission, Member, Role } from "@fosscord/util";
+import {
+	Channel,
+	ChannelPermissionOverwrite,
+	ChannelPermissionOverwriteType,
+	ChannelUpdateEvent,
+	emitEvent,
+	getPermission,
+	Member,
+	Role
+} from "@fosscord/util";
 import { Router, Response, Request } from "express";
 import { HTTPError } from "lambert-server";
 
@@ -14,7 +23,7 @@ router.put(
 	route({ body: "ChannelPermissionOverwriteSchema", permission: "MANAGE_ROLES" }),
 	async (req: Request, res: Response) => {
 		const { channel_id, overwrite_id } = req.params;
-		const body = req.body as { allow: bigint; deny: bigint; type: number; id: string };
+		const body = req.body as ChannelPermissionOverwriteSchema;
 
 		var channel = await Channel.findOneOrFail({ id: channel_id });
 		if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
@@ -31,14 +40,12 @@ router.put(
 			// @ts-ignore
 			overwrite = {
 				id: overwrite_id,
-				type: body.type,
-				allow: body.allow,
-				deny: body.deny
+				type: body.type
 			};
 			channel.permission_overwrites!.push(overwrite);
 		}
-		overwrite.allow = body.allow;
-		overwrite.deny = body.deny;
+		overwrite.allow = String(req.permission!.bitfield & (BigInt(body.allow) || 0n));
+		overwrite.deny = String(req.permission!.bitfield & (BigInt(body.deny) || 0n));
 
 		await Promise.all([
 			channel.save(),