mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #3741 from Infisical/fix/inviteUsersByUsernameFix
Fix for inviteUserToOrganization for usernames with no email formats
This commit is contained in:
@@ -835,16 +835,22 @@ export const orgServiceFactory = ({
|
|||||||
|
|
||||||
// if the user doesn't exist we create the user with the email
|
// if the user doesn't exist we create the user with the email
|
||||||
if (!inviteeUser) {
|
if (!inviteeUser) {
|
||||||
inviteeUser = await userDAL.create(
|
// TODO(carlos): will be removed once the function receives usernames instead of emails
|
||||||
{
|
const usersByEmail = await userDAL.findUserByEmail(inviteeEmail, tx);
|
||||||
isAccepted: false,
|
if (usersByEmail?.length === 1) {
|
||||||
email: inviteeEmail,
|
[inviteeUser] = usersByEmail;
|
||||||
username: inviteeEmail,
|
} else {
|
||||||
authMethods: [AuthMethod.EMAIL],
|
inviteeUser = await userDAL.create(
|
||||||
isGhost: false
|
{
|
||||||
},
|
isAccepted: false,
|
||||||
tx
|
email: inviteeEmail,
|
||||||
);
|
username: inviteeEmail,
|
||||||
|
authMethods: [AuthMethod.EMAIL],
|
||||||
|
isGhost: false
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const inviteeUserId = inviteeUser?.id;
|
const inviteeUserId = inviteeUser?.id;
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
const findUserByUsername = async (username: string, tx?: Knex) =>
|
const findUserByUsername = async (username: string, tx?: Knex) =>
|
||||||
(tx || db)(TableName.Users).whereRaw('lower("username") = :username', { username: username.toLowerCase() });
|
(tx || db)(TableName.Users).whereRaw('lower("username") = :username', { username: username.toLowerCase() });
|
||||||
|
|
||||||
|
const findUserByEmail = async (email: string, tx?: Knex) =>
|
||||||
|
(tx || db)(TableName.Users).whereRaw('lower("email") = :email', { email: email.toLowerCase() }).where({
|
||||||
|
isEmailVerified: true
|
||||||
|
});
|
||||||
|
|
||||||
const getUsersByFilter = async ({
|
const getUsersByFilter = async ({
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
@@ -234,6 +239,7 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
findOneUserAction,
|
findOneUserAction,
|
||||||
createUserAction,
|
createUserAction,
|
||||||
getUsersByFilter,
|
getUsersByFilter,
|
||||||
findAllMyAccounts
|
findAllMyAccounts,
|
||||||
|
findUserByEmail
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user