Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core,console): invitee emails should be case insensitive #5730

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/afraid-stingrays-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@logto/core": patch
---

Bug fix: organization invitation APIs should handle invitee emails case insensitively
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ const useEmailInputUtils = () => {
const validEmails = new Set<string>();

const existingMemberEmails = new Set<string>(
existingMembers.map(({ primaryEmail }) => primaryEmail ?? '').filter(Boolean)
existingMembers.map(({ primaryEmail }) => primaryEmail?.toLowerCase() ?? '').filter(Boolean)
gao-sun marked this conversation as resolved.
Show resolved Hide resolved
);
const existingInvitationEmails = new Set<string>(
existingInvitations
.filter(({ status }) => status === OrganizationInvitationStatus.Pending)
.map(({ invitee }) => invitee)
.map(({ invitee }) => invitee.toLowerCase())
);

for (const email of emails) {
for (const userInputEmail of emails) {
const email = userInputEmail.toLowerCase();
if (!emailRegEx.test(email)) {
invalidEmails.add(email);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/queries/organization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class OrganizationInvitationsQueries extends SchemaQueries<
return sql`and ${fields.organizationId} = ${id}`;
})}
${conditionalSql(invitee, (email) => {
return sql`and ${fields.invitee} = ${email}`;
return sql`and lower(${fields.invitee}) = lower(${email})`;
})}
`);
}
Expand Down Expand Up @@ -220,7 +220,7 @@ class OrganizationInvitationsQueries extends SchemaQueries<
return sql`and ${fields.inviterId} = ${id}`;
})}
${conditionalSql(invitee, (email) => {
return sql`and ${fields.invitee} = ${email}`;
return sql`and lower(${fields.invitee}) = lower(${email})`;
gao-sun marked this conversation as resolved.
Show resolved Hide resolved
})}
group by ${fields.id}
${conditionalSql(this.orderBy, ({ field, order }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,19 @@ describe('organization invitation creation', () => {
await Promise.all([deleteUser(inviter.id), deleteUser(inviter2.id)]);
});

it('should be able to get invitations by invitee', async () => {
it('should be able to get invitations by invitee email (case insensitive)', async () => {
const organization = await organizationApi.create({ name: 'test' });
const invitee = `${randomId()}@example.com`;
await invitationApi.create({
organizationId: organization.id,
invitee,
// Deliberately use uppercase email when creating the invitation
invitee: invitee.toUpperCase(),
expiresAt: Date.now() + 1_000_000,
});

const invitations = await invitationApi.getList(new URLSearchParams({ invitee }));
expect(invitations.length).toBe(1);
expect(invitations[0]?.invitee).toBe(invitee);
expect(invitations[0]?.invitee.toLocaleLowerCase()).toBe(invitee.toLowerCase());
});

it('should have no pagination', async () => {
Expand Down
Loading