mirror of
https://github.com/logto-io/logto.git
synced 2025-04-14 23:11:31 -05:00
fix(core): trigger webhook in organization invitation flow (#7005)
* fix(core): trigger webhook in organization invitation flow should trigger the Organization.Membership.Updated webhook event when a organization invitation is accepted. * chore: update changeset update changeset
This commit is contained in:
parent
0dfbdaa563
commit
bf2d3007c3
3 changed files with 54 additions and 3 deletions
7
.changeset/afraid-turkeys-swim.md
Normal file
7
.changeset/afraid-turkeys-swim.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
"@logto/core": patch
|
||||
---
|
||||
|
||||
fix(core): trigger the `Organization.Membership.Updated` webhook when a user accepts an invitation and join an organization.
|
||||
|
||||
Added a new `Organization.Membership.Accepted` webhook event in the `PUT /api/organization-invitations/{id}/status` endpoint. This event will be triggered when the organization-invitation status is updated to `accepted`, and user is added to the organization.
|
|
@ -145,7 +145,15 @@ export default function organizationInvitationRoutes<T extends ManagementApiRout
|
|||
})
|
||||
);
|
||||
|
||||
ctx.body = await organizationInvitations.updateStatus(id, status, acceptedUserId);
|
||||
const result = await organizationInvitations.updateStatus(id, status, acceptedUserId);
|
||||
|
||||
const { organizationId } = result;
|
||||
ctx.appendDataHookContext('Organization.Membership.Updated', {
|
||||
organizationId,
|
||||
});
|
||||
|
||||
ctx.body = result;
|
||||
|
||||
return next();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { SignInIdentifier, hookEvents, userInfoSelectFields } from '@logto/schemas';
|
||||
import {
|
||||
OrganizationInvitationStatus,
|
||||
SignInIdentifier,
|
||||
hookEvents,
|
||||
userInfoSelectFields,
|
||||
} from '@logto/schemas';
|
||||
import { pick } from '@silverhand/essentials';
|
||||
|
||||
import { deleteUser } from '#src/api/admin-user.js';
|
||||
|
@ -10,7 +15,7 @@ import { SsoConnectorApi } from '#src/api/sso-connector.js';
|
|||
import { setEmailConnector, setSmsConnector } from '#src/helpers/connector.js';
|
||||
import { WebHookApiTest } from '#src/helpers/hook.js';
|
||||
import { registerWithEmail } from '#src/helpers/interactions.js';
|
||||
import { OrganizationApiTest } from '#src/helpers/organization.js';
|
||||
import { OrganizationApiTest, OrganizationInvitationApiTest } from '#src/helpers/organization.js';
|
||||
import { enableAllVerificationCodeSignInMethods } from '#src/helpers/sign-in-experience.js';
|
||||
import { registerNewUserWithSso } from '#src/helpers/single-sign-on.js';
|
||||
import { UserApiTest } from '#src/helpers/user.js';
|
||||
|
@ -169,4 +174,35 @@ describe('manual data hook tests', () => {
|
|||
await assertOrganizationMembershipUpdated(organization.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('organization membership update by accept organization invitation', () => {
|
||||
const invitationApi = new OrganizationInvitationApiTest();
|
||||
|
||||
afterEach(async () => {
|
||||
await invitationApi.cleanUp();
|
||||
});
|
||||
|
||||
it('should trigger `Organization.Membership.Updated` event when user accept organization invitation', async () => {
|
||||
const organization = await organizationApi.create({ name: generateName() });
|
||||
const invitation = await invitationApi.create({
|
||||
organizationId: organization.id,
|
||||
invitee: generateEmail(),
|
||||
expiresAt: Date.now() + 1_000_000,
|
||||
});
|
||||
expect(invitation.status).toBe('Pending');
|
||||
|
||||
const user = await userApi.create({
|
||||
primaryEmail: invitation.invitee,
|
||||
});
|
||||
|
||||
const updated = await invitationApi.updateStatus(
|
||||
invitation.id,
|
||||
OrganizationInvitationStatus.Accepted,
|
||||
user.id
|
||||
);
|
||||
|
||||
expect(updated.status).toBe('Accepted');
|
||||
await assertOrganizationMembershipUpdated(organization.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue