get single message && message rights enforcement

This commit is contained in:
Erkin Alp Güney 2022-04-18 21:21:40 +03:00
parent e2b27a8d2c
commit e10f203c0b
2 changed files with 15 additions and 2 deletions

View File

@ -51,6 +51,18 @@ router.patch("/", route({ body: "MessageCreateSchema", permission: "SEND_MESSAGE
return res.json(message); return res.json(message);
}); });
router.get("/", route({ permission: "VIEW_CHANNEL" }), async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params;
const message = await Message.findOneOrFail({ where: { id: message_id, channel_id }, relations: ["attachments"] });
const permissions = await getPermission(req.user_id, undefined, channel_id);
if (message.author_id !== req.user_id) permissions.hasThrow("READ_MESSAGE_HISTORY");
return res.json(message);
});
router.delete("/", route({}), async (req: Request, res: Response) => { router.delete("/", route({}), async (req: Request, res: Response) => {
const { message_id, channel_id } = req.params; const { message_id, channel_id } = req.params;

View File

@ -8,6 +8,7 @@ import {
Embed, Embed,
emitEvent, emitEvent,
getPermission, getPermission,
getRights,
Message, Message,
MessageCreateEvent, MessageCreateEvent,
uploadFile, uploadFile,
@ -149,7 +150,7 @@ const messageUpload = multer({
}); // max upload 50 mb }); // max upload 50 mb
// TODO: dynamically change limit of MessageCreateSchema with config // TODO: dynamically change limit of MessageCreateSchema with config
// TODO: check: sum of all characters in an embed structure must not exceed 6000 characters // TODO: check: sum of all characters in an embed structure must not exceed instance limits
// https://discord.com/developers/docs/resources/channel#create-message // https://discord.com/developers/docs/resources/channel#create-message
// TODO: text channel slowdown // TODO: text channel slowdown
@ -167,7 +168,7 @@ router.post(
next(); next();
}, },
route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES" }), route({ body: "MessageCreateSchema", permission: "SEND_MESSAGES", right: "SEND_MESSAGES" }),
async (req: Request, res: Response) => { async (req: Request, res: Response) => {
const { channel_id } = req.params; const { channel_id } = req.params;
var body = req.body as MessageCreateSchema; var body = req.body as MessageCreateSchema;