Requested changes

This commit is contained in:
Daniel Hougaard
2024-02-22 05:00:26 +01:00
parent 419916ee0c
commit a6e263eded
21 changed files with 53 additions and 41 deletions
@@ -3,30 +3,30 @@ import { Knex } from "knex";
import { ProjectVersion, TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
const hasGhostUserColumn = await knex.schema.hasColumn(TableName.Users, "ghost");
const hasGhostUserColumn = await knex.schema.hasColumn(TableName.Users, "isGhost");
const hasProjectVersionColumn = await knex.schema.hasColumn(TableName.Project, "version");
if (!hasGhostUserColumn) {
await knex.schema.alterTable(TableName.Users, (t) => {
t.boolean("ghost").defaultTo(false).notNullable();
t.boolean("isGhost").defaultTo(false).notNullable();
});
}
if (!hasProjectVersionColumn) {
await knex.schema.alterTable(TableName.Project, (t) => {
t.string("version").defaultTo(ProjectVersion.V1).notNullable();
t.text("upgradeStatus").nullable();
t.integer("version").defaultTo(ProjectVersion.V1).notNullable();
t.string("upgradeStatus").nullable();
});
}
}
export async function down(knex: Knex): Promise<void> {
const hasGhostUserColumn = await knex.schema.hasColumn(TableName.Users, "ghost");
const hasGhostUserColumn = await knex.schema.hasColumn(TableName.Users, "isGhost");
const hasProjectVersionColumn = await knex.schema.hasColumn(TableName.Project, "version");
if (hasGhostUserColumn) {
await knex.schema.alterTable(TableName.Users, (t) => {
t.dropColumn("ghost");
t.dropColumn("isGhost");
});
}
+2 -2
View File
@@ -113,8 +113,8 @@ export enum SecretType {
}
export enum ProjectVersion {
V1 = "v1",
V2 = "v2"
V1 = 1,
V2 = 2
}
export enum ProjectUpgradeStatus {
+1 -1
View File
@@ -15,7 +15,7 @@ export const ProjectsSchema = z.object({
orgId: z.string().uuid(),
createdAt: z.date(),
updatedAt: z.date(),
version: z.string().default("v1"),
version: z.number().default(1),
upgradeStatus: z.string().nullable().optional()
});
+1 -1
View File
@@ -20,7 +20,7 @@ export const UsersSchema = z.object({
devices: z.unknown().nullable().optional(),
createdAt: z.date(),
updatedAt: z.date(),
ghost: z.boolean().default(false)
isGhost: z.boolean().default(false)
});
export type TUsers = z.infer<typeof UsersSchema>;
@@ -339,7 +339,7 @@ export const samlConfigServiceFactory = ({
firstName,
lastName,
authMethods: [AuthMethod.EMAIL],
ghost: false
isGhost: false
},
tx
);
@@ -275,7 +275,7 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:
if (isOauthSignUpDisabled) throw new BadRequestError({ message: "User signup disabled", name: "Oauth 2 login" });
if (!user) {
user = await userDAL.create({ email, firstName, lastName, authMethods: [authMethod], ghost: false });
user = await userDAL.create({ email, firstName, lastName, authMethods: [authMethod], isGhost: false });
}
const isLinkingRequired = !user?.authMethods?.includes(authMethod);
const isUserCompleted = user.isAccepted;
@@ -50,7 +50,7 @@ export const authSignupServiceFactory = ({
throw new Error("Failed to send verification code for complete account");
}
if (!user) {
user = await userDAL.create({ authMethods: [AuthMethod.EMAIL], email, ghost: false });
user = await userDAL.create({ authMethods: [AuthMethod.EMAIL], email, isGhost: false });
}
if (!user) throw new Error("Failed to create user");
+3 -3
View File
@@ -77,7 +77,7 @@ export const orgDALFactory = (db: TDbClient) => {
db.ref("id").withSchema(TableName.Users).as("userId"),
db.ref("publicKey").withSchema(TableName.UserEncryptionKey)
)
.where({ ghost: false }); // MAKE SURE USER IS NOT A GHOST USER
.where({ isGhost: false }); // MAKE SURE USER IS NOT A GHOST USER
return members.map(({ email, firstName, lastName, userId, publicKey, ...data }) => ({
...data,
user: { email, firstName, lastName, id: userId, publicKey }
@@ -136,7 +136,7 @@ export const orgDALFactory = (db: TDbClient) => {
db.ref("id").withSchema(TableName.Users).as("userId"),
db.ref("publicKey").withSchema(TableName.UserEncryptionKey)
)
.where({ ghost: true });
.where({ isGhost: true });
return member;
} catch (error) {
return null;
@@ -150,7 +150,7 @@ export const orgDALFactory = (db: TDbClient) => {
.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({ ghost: true });
.where({ isGhost: true });
return !!member;
} catch (error) {
return false;
+2 -2
View File
@@ -138,7 +138,7 @@ export const orgServiceFactory = ({
const user = await userDAL.create(
{
ghost: true,
isGhost: true,
authMethods: [AuthMethod.EMAIL],
email,
isAccepted: true
@@ -401,7 +401,7 @@ export const orgServiceFactory = ({
email: inviteeEmail,
isAccepted: false,
authMethods: [AuthMethod.EMAIL],
ghost: false
isGhost: false
},
tx
);
@@ -119,7 +119,7 @@ export const projectBotServiceFactory = ({
throw new BadRequestError({ message: "Failed to find project by bot ID" });
}
if (project.version === "v2") {
if (project.version === ProjectVersion.V2) {
throw new BadRequestError({ message: "Failed to set bot active, project has a default bot enabled" });
}
@@ -24,17 +24,17 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
db.ref("projectId").withSchema(TableName.ProjectMembership),
db.ref("role").withSchema(TableName.ProjectMembership),
db.ref("roleId").withSchema(TableName.ProjectMembership),
db.ref("ghost").withSchema(TableName.Users),
db.ref("isGhost").withSchema(TableName.Users),
db.ref("email").withSchema(TableName.Users),
db.ref("publicKey").withSchema(TableName.UserEncryptionKey),
db.ref("firstName").withSchema(TableName.Users),
db.ref("lastName").withSchema(TableName.Users),
db.ref("id").withSchema(TableName.Users).as("userId")
)
.where({ ghost: false });
return members.map(({ email, firstName, lastName, publicKey, ghost, ...data }) => ({
.where({ isGhost: false });
return members.map(({ email, firstName, lastName, publicKey, isGhost, ...data }) => ({
...data,
user: { email, firstName, lastName, id: data.userId, publicKey, ghost }
user: { email, firstName, lastName, id: data.userId, publicKey, isGhost }
}));
} catch (error) {
throw new DatabaseError({ error, name: "Find all project members" });
@@ -47,7 +47,7 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
.where({ projectId })
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
.select(selectAllTableCols(TableName.Users))
.where({ ghost: true })
.where({ isGhost: true })
.first();
return ghostUser;
@@ -72,7 +72,7 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
db.ref("email").withSchema(TableName.Users)
)
.whereIn("email", emails)
.where({ ghost: false });
.where({ isGhost: false });
return members.map(({ userId, email, ...data }) => ({
...data,
user: { id: userId, email }
@@ -16,11 +16,11 @@ import { getConfig } from "@app/lib/config/env";
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
import { BadRequestError } from "@app/lib/errors";
import { groupBy } from "@app/lib/fn";
import { createWsMembers } from "@app/lib/project";
import { ActorType } from "../auth/auth-type";
import { TOrgDALFactory } from "../org/org-dal";
import { TProjectDALFactory } from "../project/project-dal";
import { createWsMembers } from "../project/project-fns";
import { TProjectBotDALFactory } from "../project-bot/project-bot-dal";
import { TProjectKeyDALFactory } from "../project-key/project-key-dal";
import { TProjectRoleDALFactory } from "../project-role/project-role-dal";
@@ -320,7 +320,7 @@ export const projectMembershipServiceFactory = ({
const membershipUser = await userDAL.findUserByProjectMembershipId(membershipId);
if (membershipUser?.ghost) {
if (membershipUser?.isGhost) {
throw new BadRequestError({
message: "Unauthorized member update",
name: "Update project membership"
@@ -365,7 +365,7 @@ export const projectMembershipServiceFactory = ({
const member = await userDAL.findUserByProjectMembershipId(membershipId);
if (member?.ghost) {
if (member?.isGhost) {
throw new BadRequestError({
message: "Unauthorized member delete",
name: "Delete project membership"
+1 -1
View File
@@ -60,7 +60,7 @@ export const projectDALFactory = (db: TDbClient) => {
.where({ projectId })
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
.select(selectAllTableCols(TableName.Users))
.where({ ghost: true })
.where({ isGhost: true })
.first();
return ghostUser;
} catch (error) {
@@ -70,7 +70,7 @@ export const superAdminServiceFactory = ({
lastName,
email,
superAdmin: true,
ghost: false,
isGhost: false,
isAccepted: true,
authMethods: [AuthMethod.EMAIL]
},
+1 -1
View File
@@ -23,7 +23,7 @@ export const userDALFactory = (db: TDbClient) => {
const findUserEncKeyByEmail = async (email: string) => {
try {
return await db(TableName.Users)
.where({ email, ghost: false })
.where({ email, isGhost: false })
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
.first();
} catch (error) {