🐛 fix permissions if user is only member of guild
This commit is contained in:
parent
85ef7410b2
commit
8d69c9a871
@ -15,13 +15,13 @@ export default router;
|
|||||||
|
|
||||||
export function isTextChannel(type: ChannelType): boolean {
|
export function isTextChannel(type: ChannelType): boolean {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case ChannelType.GUILD_STORE:
|
||||||
case ChannelType.GUILD_VOICE:
|
case ChannelType.GUILD_VOICE:
|
||||||
case ChannelType.GUILD_CATEGORY:
|
case ChannelType.GUILD_CATEGORY:
|
||||||
throw new HTTPError("not a text channel", 400);
|
throw new HTTPError("not a text channel", 400);
|
||||||
case ChannelType.DM:
|
case ChannelType.DM:
|
||||||
case ChannelType.GROUP_DM:
|
case ChannelType.GROUP_DM:
|
||||||
case ChannelType.GUILD_NEWS:
|
case ChannelType.GUILD_NEWS:
|
||||||
case ChannelType.GUILD_STORE:
|
|
||||||
case ChannelType.GUILD_TEXT:
|
case ChannelType.GUILD_TEXT:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -48,8 +48,7 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
if (!limit) limit = 50;
|
if (!limit) limit = 50;
|
||||||
var halfLimit = Math.floor(limit / 2);
|
var halfLimit = Math.floor(limit / 2);
|
||||||
|
|
||||||
// @ts-ignore
|
const permissions = await getPermission(req.user_id, channel.guild_id, channel_id);
|
||||||
const permissions = await getPermission(req.user_id, channel.guild_id, channel_id, { channel });
|
|
||||||
permissions.hasThrow("VIEW_CHANNEL");
|
permissions.hasThrow("VIEW_CHANNEL");
|
||||||
if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]);
|
if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]);
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ export async function getPermission(
|
|||||||
if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
|
if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
|
||||||
|
|
||||||
member = await Member.findOneOrFail({
|
member = await Member.findOneOrFail({
|
||||||
where: { guild_id, user_id },
|
where: { guild_id, id: user_id },
|
||||||
relations: ["roles", ...(opts.member_relations || [])],
|
relations: ["roles", ...(opts.member_relations || [])],
|
||||||
select: [
|
select: [
|
||||||
"id",
|
"id",
|
||||||
@ -265,6 +265,9 @@ export async function getPermission(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let recipient_ids: any = channel?.recipients?.map((x) => x.id);
|
||||||
|
if (!recipient_ids?.length) recipient_ids = null;
|
||||||
|
|
||||||
// TODO: remove guild.roles and convert recipient_ids to recipients
|
// TODO: remove guild.roles and convert recipient_ids to recipients
|
||||||
var permission = Permissions.finalPermission({
|
var permission = Permissions.finalPermission({
|
||||||
user: {
|
user: {
|
||||||
@ -277,7 +280,7 @@ export async function getPermission(
|
|||||||
channel: {
|
channel: {
|
||||||
overwrites: channel?.permission_overwrites,
|
overwrites: channel?.permission_overwrites,
|
||||||
owner_id: channel?.owner_id,
|
owner_id: channel?.owner_id,
|
||||||
recipient_ids: channel?.recipients?.map((x) => x.id),
|
recipient_ids,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user