1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 18:32:29 +01:00

🐛 fix channel permission overwrites

This commit is contained in:
Flam3rboy 2021-09-26 11:34:06 +02:00
parent dd611d0e7c
commit d0f5790235
6 changed files with 113 additions and 106 deletions

View File

@ -1,4 +1,33 @@
{
"LoginSchema": {
"type": "object",
"properties": {
"login": {
"type": "string"
},
"password": {
"type": "string"
},
"undelete": {
"type": "boolean"
},
"captcha_key": {
"type": "string"
},
"login_source": {
"type": "string"
},
"gift_code_sku_id": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"login",
"password"
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
"RegisterSchema": {
"type": "object",
"properties": {
@ -42,35 +71,6 @@
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
"LoginSchema": {
"type": "object",
"properties": {
"login": {
"type": "string"
},
"password": {
"type": "string"
},
"undelete": {
"type": "boolean"
},
"captcha_key": {
"type": "string"
},
"login_source": {
"type": "string"
},
"gift_code_sku_id": {
"type": "string"
}
},
"additionalProperties": false,
"required": [
"login",
"password"
],
"$schema": "http://json-schema.org/draft-07/schema#"
},
"ChannelModifySchema": {
"type": "object",
"properties": {
@ -127,10 +127,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -353,10 +353,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -727,10 +727,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -1050,10 +1050,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -1352,10 +1352,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -1657,10 +1657,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -1758,10 +1758,10 @@
"type": "object",
"properties": {
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
},
"id": {
"type": "string"
@ -1971,10 +1971,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -2278,10 +2278,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -2580,10 +2580,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -2894,10 +2894,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -3221,10 +3221,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -3587,10 +3587,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -3889,10 +3889,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -4191,10 +4191,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -4505,10 +4505,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -4814,10 +4814,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -5119,10 +5119,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -5424,10 +5424,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -5725,10 +5725,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -6046,10 +6046,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -6374,10 +6374,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -6680,10 +6680,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -6988,10 +6988,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -7302,10 +7302,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -7610,10 +7610,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -7939,10 +7939,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -8244,10 +8244,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -8550,10 +8550,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,
@ -9039,10 +9039,10 @@
"$ref": "#/definitions/ChannelPermissionOverwriteType"
},
"allow": {
"type": "bigint"
"type": "string"
},
"deny": {
"type": "bigint"
"type": "string"
}
},
"additionalProperties": false,

View File

@ -14,8 +14,8 @@
"dev": "tsnd --respawn src/start.ts",
"patch": "ts-patch install -s && npx patch-package",
"postinstall": "npm run patch",
"generate:docs": "node scripts/generate_openapi.ts",
"generate:schema": "node scripts/generate_schema.ts"
"generate:docs": "node scripts/generate_openapi",
"generate:schema": "node scripts/generate_schema"
},
"repository": {
"type": "git",

View File

@ -1,9 +1,9 @@
// https://mermade.github.io/openapi-gui/#
// https://editor.swagger.io/
import path from "path";
import fs from "fs";
import * as TJS from "typescript-json-schema";
import "missing-native-js-functions";
const path = require("path");
const fs = require("fs");
const TJS = require("typescript-json-schema");
require("missing-native-js-functions");
const schemaPath = path.join(__dirname, "..", "assets", "schemas.json");
const settings = {

View File

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

View File

@ -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(),

View File

@ -320,8 +320,8 @@ export class Channel extends BaseClass {
}
export interface ChannelPermissionOverwrite {
allow: bigint; // for bitfields we use bigints
deny: bigint; // for bitfields we use bigints
allow: string;
deny: string;
id: string;
type: ChannelPermissionOverwriteType;
}