feat: go greppy

This commit is contained in:
=
2025-10-10 00:09:48 +05:30
parent fe1bc168f6
commit 97135d9cfa
46 changed files with 150 additions and 106 deletions
@@ -51,8 +51,7 @@ export const membershipUserDALFactory = (db: TDbClient) => {
} else if (scopeData.scope === AccessScope.Namespace) {
void qb
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
} else if (scopeData.scope === AccessScope.Project) {
void qb
.where(`${TableName.Membership}.scope`, AccessScope.Project)
@@ -168,8 +167,7 @@ export const membershipUserDALFactory = (db: TDbClient) => {
} else if (scopeData.scope === AccessScope.Namespace) {
void qb
.where(`${TableName.Membership}.scope`, AccessScope.Namespace)
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId)
.whereNull(`${TableName.Membership}.scopeNamespaceId`);
.where(`${TableName.Membership}.scopeNamespaceId`, scopeData.namespaceId);
} else if (scopeData.scope === AccessScope.Project) {
void qb
.where(`${TableName.Membership}.scope`, AccessScope.Project)
@@ -192,7 +190,7 @@ export const membershipUserDALFactory = (db: TDbClient) => {
case "role":
return [`${TableName.Role}.slug`, `${TableName.MembershipRole}.role`];
case "username":
return `${TableName.Users}.name`;
return `${TableName.Users}.username`;
default:
throw new BadRequestError({ message: `Invalid ${String(attr)} provided` });
}
@@ -131,13 +131,13 @@ export const membershipUserServiceFactory = ({
existingUsers.push(inviteeUser);
const inviteeUserId = inviteeUser?.id;
const existingEncrytionKey = await userDAL.findUserEncKeyByUserId(inviteeUserId, tx);
const existingEncryptionKey = await userDAL.findUserEncKeyByUserId(inviteeUserId, tx);
// when user is missing the encrytion keys
// this could happen either if user doesn't exist or user didn't find step 3 of generating the encryption keys of srp
// So what we do is we generate a random secure password and then encrypt it with a random pub-private key
// Then when user sign in (as login is not possible as isAccepted is false) we rencrypt the private key with the user password
if (!inviteeUser || (inviteeUser && !inviteeUser?.isAccepted && !existingEncrytionKey)) {
if (!inviteeUser || (inviteeUser && !inviteeUser?.isAccepted && !existingEncryptionKey)) {
await userDAL.createUserEncryption(
{
userId: inviteeUserId,
@@ -159,7 +159,7 @@ export const membershipUserServiceFactory = ({
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
if (hasNoPermanentRole) {
throw new BadRequestError({
message: "User must have atleast one permanent role"
message: "User must have at least one permanent role"
});
}
const isInvalidTemporaryRole = data.roles.some((el) => {
@@ -284,7 +284,7 @@ export const membershipUserServiceFactory = ({
const hasNoPermanentRole = data.roles.every((el) => el.isTemporary);
if (hasNoPermanentRole) {
throw new BadRequestError({
message: "User must have atleast one permanent role"
message: "User must have at least one permanent role"
});
}
const isInvalidTemporaryRole = data.roles.some((el) => {