From eb1d942f4a4d033b856ebc20756b73eb162e20e3 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Sat, 2 Sep 2023 08:05:23 +0000 Subject: [PATCH 1/9] feat: display permission level in /query --- src/handlers/comment/handlers/query.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index efee499d1..69f117bfc 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -1,5 +1,6 @@ import { getWalletInfo } from "../../../adapters/supabase"; import { getBotContext, getLogger } from "../../../bindings"; +import { getUserPermission } from "../../../helpers"; import { Payload } from "../../../types"; export const query = async (body: string) => { @@ -22,13 +23,14 @@ export const query = async (body: string) => { const regex = /^\/query\s+@([\w-]+)\s*$/; const matches = body.match(regex); const user = matches?.[1]; + const permissionLevel = await getUserPermission(sender, context); if (user) { const walletInfo = await getWalletInfo(user, id?.toString()); if (!walletInfo?.address) { return `Error retrieving multiplier and wallet address for @${user}`; } else { - return `@${user}'s wallet address is ${walletInfo?.address} and multiplier is ${walletInfo?.multiplier}`; + return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and permission level is ${permissionLevel}`; } } else { logger.error("Invalid body for query command"); From c86011c0fca458ed53c02ba687674aa534ba15a6 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Sun, 3 Sep 2023 06:56:34 +0000 Subject: [PATCH 2/9] feat: display access level in /query --- src/handlers/comment/handlers/query.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index 69f117bfc..d9a07aac3 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -1,6 +1,5 @@ -import { getWalletInfo } from "../../../adapters/supabase"; +import { getAccessLevel, getWalletInfo } from "../../../adapters/supabase"; import { getBotContext, getLogger } from "../../../bindings"; -import { getUserPermission } from "../../../helpers"; import { Payload } from "../../../types"; export const query = async (body: string) => { @@ -23,14 +22,24 @@ export const query = async (body: string) => { const regex = /^\/query\s+@([\w-]+)\s*$/; const matches = body.match(regex); const user = matches?.[1]; - const permissionLevel = await getUserPermission(sender, context); + const repo = payload.repository; if (user) { const walletInfo = await getWalletInfo(user, id?.toString()); if (!walletInfo?.address) { return `Error retrieving multiplier and wallet address for @${user}`; } else { - return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and permission level is ${permissionLevel}`; + return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are +| access type | access level | +| ----------- | ------------ |access type access level +multiplier true +priority true +time true +price true +| multiplier | ${getAccessLevel(sender, repo.full_name, "multiplier")} | +| priority | ${getAccessLevel(sender, repo.full_name, "priority")} | +| time | ${getAccessLevel(sender, repo.full_name, "time")} | +| price | ${getAccessLevel(sender, repo.full_name, "price")} |`; } } else { logger.error("Invalid body for query command"); From cf55a97842ba9f59c86e1a7691116ba1efacfc9f Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Sun, 3 Sep 2023 06:57:29 +0000 Subject: [PATCH 3/9] feat: display access level in /query --- src/handlers/comment/handlers/query.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index d9a07aac3..6bbc342d6 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -31,11 +31,6 @@ export const query = async (body: string) => { } else { return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are | access type | access level | -| ----------- | ------------ |access type access level -multiplier true -priority true -time true -price true | multiplier | ${getAccessLevel(sender, repo.full_name, "multiplier")} | | priority | ${getAccessLevel(sender, repo.full_name, "priority")} | | time | ${getAccessLevel(sender, repo.full_name, "time")} | From 2709407cb09acc32fe1b58b426d26c39dc69dd6e Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Mon, 4 Sep 2023 12:59:18 +0000 Subject: [PATCH 4/9] feat: display access levels in /query --- src/adapters/supabase/helpers/client.ts | 21 +++++++++++++++++++++ src/handlers/comment/handlers/query.ts | 14 +++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index cbd0629f7..7e54f904f 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -5,6 +5,13 @@ import { Database } from "../types"; import { InsertPermit, Permit } from "../../../helpers"; import { BigNumber, BigNumberish } from "ethers"; +interface accessLevels { + multiplier: boolean; + price: boolean; + priority: boolean; + time: boolean; +} + /** * @dev Creates a typescript client which will be used to interact with supabase platform * @@ -340,6 +347,20 @@ export const getAccessLevel = async (username: string, repository: string, label return accessValues; }; +export const getAllAccessLevels = async (username: string, repository: string): Promise => { + const logger = getLogger(); + const { supabase } = getAdapters(); + + const { data } = await supabase.from("access").select("*").eq("user_name", username).eq("repository", repository).single(); + + if (!data) { + logger.info(`Access not found on the database`); + // no access + return false; + } + return { multiplier: data["multiplier_access"], time: data["time_access"], priority: data["priority_access"], price: data["price_access"] }; +}; + /** * Queries the wallet address registered previously * diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index 6bbc342d6..e75e255f4 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -1,4 +1,4 @@ -import { getAccessLevel, getWalletInfo } from "../../../adapters/supabase"; +import { getAccessLevel, getAllAccessLevels, getWalletInfo } from "../../../adapters/supabase"; import { getBotContext, getLogger } from "../../../bindings"; import { Payload } from "../../../types"; @@ -25,16 +25,20 @@ export const query = async (body: string) => { const repo = payload.repository; if (user) { + let data = await getAllAccessLevels(user, repo.full_name); + if (data === false) { + return `Error retrieving access for @${user}`; + } const walletInfo = await getWalletInfo(user, id?.toString()); if (!walletInfo?.address) { return `Error retrieving multiplier and wallet address for @${user}`; } else { return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are | access type | access level | -| multiplier | ${getAccessLevel(sender, repo.full_name, "multiplier")} | -| priority | ${getAccessLevel(sender, repo.full_name, "priority")} | -| time | ${getAccessLevel(sender, repo.full_name, "time")} | -| price | ${getAccessLevel(sender, repo.full_name, "price")} |`; +| multiplier | ${data["multiplier"]} | +| priority | ${data["priority"]} | +| time | ${data["time"]} | +| price | ${data["price"]} |`; } } else { logger.error("Invalid body for query command"); From 9479e6255ef92277a95bc8e452559306b9c69b82 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Wed, 6 Sep 2023 06:06:42 +0000 Subject: [PATCH 5/9] feat: display access levels in /query --- src/adapters/supabase/helpers/client.ts | 6 +++--- src/handlers/comment/handlers/query.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index 7e54f904f..427fc1a04 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -5,7 +5,7 @@ import { Database } from "../types"; import { InsertPermit, Permit } from "../../../helpers"; import { BigNumber, BigNumberish } from "ethers"; -interface accessLevels { +interface AccessLevels { multiplier: boolean; price: boolean; priority: boolean; @@ -347,7 +347,7 @@ export const getAccessLevel = async (username: string, repository: string, label return accessValues; }; -export const getAllAccessLevels = async (username: string, repository: string): Promise => { +export const getAllAccessLevels = async (username: string, repository: string): Promise => { const logger = getLogger(); const { supabase } = getAdapters(); @@ -356,7 +356,7 @@ export const getAllAccessLevels = async (username: string, repository: string): if (!data) { logger.info(`Access not found on the database`); // no access - return false; + return null; } return { multiplier: data["multiplier_access"], time: data["time_access"], priority: data["priority_access"], price: data["price_access"] }; }; diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index e75e255f4..74d37c8ce 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -26,7 +26,7 @@ export const query = async (body: string) => { if (user) { let data = await getAllAccessLevels(user, repo.full_name); - if (data === false) { + if (!data) { return `Error retrieving access for @${user}`; } const walletInfo = await getWalletInfo(user, id?.toString()); @@ -35,10 +35,10 @@ export const query = async (body: string) => { } else { return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are | access type | access level | -| multiplier | ${data["multiplier"]} | -| priority | ${data["priority"]} | -| time | ${data["time"]} | -| price | ${data["price"]} |`; +| multiplier | ${data.multiplier} | +| priority | ${data.priority} | +| time | ${data.time} | +| price | ${data.price} |`; } } else { logger.error("Invalid body for query command"); From ab87dd4f034ec35256b58408269558253e68ce02 Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Wed, 6 Sep 2023 06:08:25 +0000 Subject: [PATCH 6/9] feat: display access levels in /query --- src/handlers/comment/handlers/query.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index 74d37c8ce..3f5a9f0cf 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -1,4 +1,4 @@ -import { getAccessLevel, getAllAccessLevels, getWalletInfo } from "../../../adapters/supabase"; +import { getAllAccessLevels, getWalletInfo } from "../../../adapters/supabase"; import { getBotContext, getLogger } from "../../../bindings"; import { Payload } from "../../../types"; From 408a3d9e632752d03a1e9ab05a50f88eaea4bdef Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Thu, 7 Sep 2023 09:00:15 +0000 Subject: [PATCH 7/9] feat: display access level in /qurey --- src/handlers/comment/handlers/query.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index 3f5a9f0cf..baf9467a4 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -25,7 +25,7 @@ export const query = async (body: string) => { const repo = payload.repository; if (user) { - let data = await getAllAccessLevels(user, repo.full_name); + const data = await getAllAccessLevels(user, repo.full_name); if (!data) { return `Error retrieving access for @${user}`; } @@ -35,10 +35,10 @@ export const query = async (body: string) => { } else { return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are | access type | access level | -| multiplier | ${data.multiplier} | -| priority | ${data.priority} | -| time | ${data.time} | -| price | ${data.price} |`; +| multiplier | ${data.multiplier} | +| priority | ${data.priority} | +| time | ${data.time} | +| price | ${data.price} |`; } } else { logger.error("Invalid body for query command"); From e628f63abe7d3e740c12bf1d21af324c8a90a62d Mon Sep 17 00:00:00 2001 From: EtherealGlow Date: Thu, 7 Sep 2023 09:29:36 +0000 Subject: [PATCH 8/9] feat: display access level in /qurey --- src/handlers/comment/handlers/query.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/handlers/comment/handlers/query.ts b/src/handlers/comment/handlers/query.ts index baf9467a4..8f78c537f 100644 --- a/src/handlers/comment/handlers/query.ts +++ b/src/handlers/comment/handlers/query.ts @@ -34,11 +34,14 @@ export const query = async (body: string) => { return `Error retrieving multiplier and wallet address for @${user}`; } else { return `@${user}'s wallet address is ${walletInfo?.address}, multiplier is ${walletInfo?.multiplier} and access levels are -| access type | access level | -| multiplier | ${data.multiplier} | -| priority | ${data.priority} | -| time | ${data.time} | -| price | ${data.price} |`; + +| access type | access level | +| ----------- | ------------------- | +| multiplier | ${data.multiplier} | +| priority | ${data.priority} | +| time | ${data.time} | +| price | ${data.price} | + `; } } else { logger.error("Invalid body for query command"); From 08b7cc0c8864aa9370a267c961f6c5275578d11b Mon Sep 17 00:00:00 2001 From: whilefoo <139262667+whilefoo@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:46:14 +0200 Subject: [PATCH 9/9] chore: refactor --- src/adapters/supabase/helpers/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index 427fc1a04..eaa7d3d3f 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -358,7 +358,7 @@ export const getAllAccessLevels = async (username: string, repository: string): // no access return null; } - return { multiplier: data["multiplier_access"], time: data["time_access"], priority: data["priority_access"], price: data["price_access"] }; + return { multiplier: data.multiplier_access, time: data.time_access, priority: data.priority_access, price: data.price_access }; }; /**