From a7bc62f8e449c0cb16714773b579581177258d8d Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Sat, 17 Feb 2024 02:50:49 +0100 Subject: [PATCH] Akhil requested changes --- backend/src/services/org/org-dal.ts | 12 +++++++----- backend/src/services/org/org-service.ts | 2 +- .../src/services/project-bot/project-bot-types.ts | 6 ------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/backend/src/services/org/org-dal.ts b/backend/src/services/org/org-dal.ts index e4f81769f..4ff5e97a7 100644 --- a/backend/src/services/org/org-dal.ts +++ b/backend/src/services/org/org-dal.ts @@ -122,7 +122,7 @@ export const orgDALFactory = (db: TDbClient) => { const findOrgGhostUser = async (orgId: string) => { try { - const [member] = await db(TableName.OrgMembership) + const member = await db(TableName.OrgMembership) .where({ orgId }) .join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`) .leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`) @@ -136,7 +136,8 @@ export const orgDALFactory = (db: TDbClient) => { db.ref("id").withSchema(TableName.Users).as("userId"), db.ref("publicKey").withSchema(TableName.UserEncryptionKey) ) - .where({ isGhost: true }); + .where({ isGhost: true }) + .first(); return member; } catch (error) { return null; @@ -145,13 +146,14 @@ export const orgDALFactory = (db: TDbClient) => { const ghostUserExists = async (orgId: string) => { try { - const [member] = await db(TableName.OrgMembership) + const member = await db(TableName.OrgMembership) .where({ orgId }) .join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`) .leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`) .select(db.ref("id").withSchema(TableName.Users).as("userId")) - .where({ isGhost: true }); - return !!member; + .where({ isGhost: true }) + .first(); + return Boolean(member); } catch (error) { return false; } diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts index fac65dc1f..7a6e4c795 100644 --- a/backend/src/services/org/org-service.ts +++ b/backend/src/services/org/org-service.ts @@ -133,7 +133,7 @@ export const orgServiceFactory = ({ }; const addGhostUser = async (orgId: string, tx?: Knex) => { - const email = `ghost@${nanoid(16)}-${orgId}.com`; // We add a nanoid because the email is unique. And we have to create a new ghost user each time, so we can have access to the private key. + const email = `ghost-${nanoid(16)}-${orgId}@infisical.com`; // We add a nanoid because the email is unique. And we have to create a new ghost user each time, so we can have access to the private key. const password = crypto.randomBytes(128).toString("hex"); const user = await userDAL.create( diff --git a/backend/src/services/project-bot/project-bot-types.ts b/backend/src/services/project-bot/project-bot-types.ts index 47e3885c7..50fec2200 100644 --- a/backend/src/services/project-bot/project-bot-types.ts +++ b/backend/src/services/project-bot/project-bot-types.ts @@ -1,4 +1,3 @@ -// import { SecretKeyEncoding } from "@app/db/schemas"; import { TProjectBots } from "@app/db/schemas"; import { TProjectPermission } from "@app/lib/types"; @@ -21,10 +20,5 @@ export type TFindBotByProjectIdDTO = { } & TProjectPermission; export type TGetPrivateKeyDTO = { - // encoding: SecretKeyEncoding; - // nonce: string; - // tag: string; - // encryptedPrivateKey: string; - bot: TProjectBots; };