From ab8188e3dfa957012610c33e6e9dc8d7c1d62ef7 Mon Sep 17 00:00:00 2001 From: Ninjasoturi <52629375+Ninjasoturi@users.noreply.github.com> Date: Sun, 22 May 2022 14:25:31 +0300 Subject: [PATCH] Added user id to array of chat id's to check in TG auth This allows setting user specific permissions --- server/src/strategies/telegram.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/strategies/telegram.js b/server/src/strategies/telegram.js index 3597baab3..604325528 100644 --- a/server/src/strategies/telegram.js +++ b/server/src/strategies/telegram.js @@ -21,7 +21,7 @@ const authHandler = async (req, profile, done) => { }, } - const groupInfo = [] + const chatInfo = [user.id] await Promise.all(strategyConfig.groups.map(async (group) => { try { const response = await Fetch.json(`https://api.telegram.org/bot${strategyConfig.botToken}/getChatMember?chat_id=${group}&user_id=${user.id}`) @@ -32,7 +32,7 @@ const authHandler = async (req, profile, done) => { throw new Error(`Telegram API error: ${response.status} ${response.statusText}`) } if (response.result.status !== 'left' && response.result.status !== 'kicked') { - groupInfo.push(group) + chatInfo.push(group) } } catch (e) { console.error(e.message, `Telegram Group: ${group}`, `User: ${user.id} (${user.username})`) @@ -42,14 +42,14 @@ const authHandler = async (req, profile, done) => { Object.entries(perms).forEach(([perm, info]) => { if (info.enabled && (alwaysEnabledPerms.includes(perm) - || info.roles.some(role => groupInfo.includes(role)))) { + || info.roles.some(role => chatInfo.includes(role)))) { user.perms[perm] = true } }) - user.perms.areaRestrictions = Utility.areaPerms(groupInfo, 'telegram') - user.perms.webhooks = Utility.webhookPerms(groupInfo, 'telegramGroups') - user.perms.scanner = Utility.scannerPerms(groupInfo, 'telegramGroups') + user.perms.areaRestrictions = Utility.areaPerms(chatInfo, 'telegram') + user.perms.webhooks = Utility.webhookPerms(chatInfo, 'telegramGroups') + user.perms.scanner = Utility.scannerPerms(chatInfo, 'telegramGroups') try { await User.query()