mirror of
https://github.com/Infisical/infisical.git
synced 2026-05-02 03:02:03 -04:00
Delete unaccepted users upon merge user op
This commit is contained in:
@@ -94,14 +94,6 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
};
|
||||
|
||||
const findMergeableUsers = async (email: string, tx?: Knex) => {
|
||||
const users = await (tx || db)(TableName.Users).where((builder) => {
|
||||
void builder.where({ email, isEmailVerified: true }).orWhere({ email, isAccepted: false });
|
||||
});
|
||||
|
||||
return users;
|
||||
};
|
||||
|
||||
const updateUserEncryptionByUserId = async (userId: string, data: TUserEncryptionKeysUpdate, tx?: Knex) => {
|
||||
try {
|
||||
const [userEnc] = await (tx || db)(TableName.UserEncryptionKey)
|
||||
@@ -162,7 +154,6 @@ export const userDALFactory = (db: TDbClient) => {
|
||||
findUsersByProjectMembershipIds,
|
||||
upsertUserEncryptionKey,
|
||||
createUserEncryption,
|
||||
findMergeableUsers,
|
||||
findOneUserAction,
|
||||
createUserAction
|
||||
};
|
||||
|
||||
@@ -12,7 +12,6 @@ type TUserServiceFactoryDep = {
|
||||
userDAL: Pick<
|
||||
TUserDALFactory,
|
||||
| "find"
|
||||
| "findMergeableUsers"
|
||||
| "findOne"
|
||||
| "findById"
|
||||
| "transaction"
|
||||
@@ -22,6 +21,7 @@ type TUserServiceFactoryDep = {
|
||||
| "findOneUserAction"
|
||||
| "createUserAction"
|
||||
| "findUserEncKeyByUserId"
|
||||
| "delete"
|
||||
>;
|
||||
userAliasDAL: Pick<TUserAliasDALFactory, "find" | "insertMany">;
|
||||
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "find" | "insertMany">;
|
||||
@@ -86,8 +86,14 @@ export const userServiceFactory = ({
|
||||
tx
|
||||
);
|
||||
|
||||
// check if there are users with the same email.
|
||||
const users = await userDAL.findMergeableUsers(email, tx);
|
||||
// check if there are verified users with the same email.
|
||||
const users = await userDAL.find(
|
||||
{
|
||||
email,
|
||||
isEmailVerified: true
|
||||
},
|
||||
{ tx }
|
||||
);
|
||||
|
||||
if (users.length > 1) {
|
||||
// merge users
|
||||
@@ -129,6 +135,15 @@ export const userServiceFactory = ({
|
||||
);
|
||||
}
|
||||
} else {
|
||||
await userDAL.delete(
|
||||
{
|
||||
email,
|
||||
isAccepted: false,
|
||||
isEmailVerified: false
|
||||
},
|
||||
tx
|
||||
);
|
||||
|
||||
// update current user's username to [email]
|
||||
await userDAL.updateById(
|
||||
user.id,
|
||||
|
||||
Reference in New Issue
Block a user