Team webhooks (#8917)

* allow event type specific webhooks for all event types

* first version of team webhooks

* add empty view

* design fixes when no teams + invalidate query on delete/update

* linke to new webhooks page with teamId in query

* make one button with dropdown instead of a button for every team

* add subtitle to dropdown

* add avatar fallback

* authorization when editing webhook

* fix event type webhooks

* fix authorization for delete handler

* code clean up

* fix disabled switch

* add migration

* fix subscriberUrlReservered function and fix authorization

* fix type error

* fix type error

* fix switch not updating

* make sure webhooks are triggered for the correct even types

* code clean up

* only show teams were user has write access

* make webhooks read-only for members

* fix comment

* fix type error

* fix webhook tests for team event types

* implement feedback

* code clean up from feedback

* code clean up (feedback)

* throw error if param missing in subscriberUrlReservered

* handle null/undefined values in getWebhooks itself

* better variable naming

* better check if webhook is readonly

* create assertPartOfTeamWithRequiredAccessLevel to remove duplicate code

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: alannnc <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-05-23 01:15:29 +00:00
1 parent b83ee2d57d
commit 84efda07e9
33 files changed
+691 -211

No files matched your search

@@ -52,8 +52,21 @@ test.describe("Manage Booking Questions", () => {
// Considering there are many steps in it, it would need more than default test timeout
test.setTimeout(testInfo.timeout * 3);
const user = await createAndLoginUserWithEventTypes({ users });
const team = await prisma.team.findFirst({
where: {
members: {
some: {
userId: user.id,
},
},
},
select: {
id: true,
},
});
const webhookReceiver = await addWebhook(user);
const teamId = team?.id ?? 0;
const webhookReceiver = await addWebhook(undefined, teamId);
await test.step("Go to First Team Event", async () => {
const $eventTypes = page.locator("[data-testid=event-types]").nth(1).locator("li a");
@@ -79,7 +92,6 @@ async function runTestStepsCommonForTeamAndUserEventType(
bookerVariant: BookerVariants
) {
await page.click('[href$="tabName=advanced"]');
await test.step("Add Question and see that it's shown on Booking Page at appropriate position", async () => {
await addQuestionAndSave({
page,
@@ -391,19 +403,35 @@ async function saveEventType(page: Page) {
await page.locator("[data-testid=update-eventtype]").click();
}
async function addWebhook(user: Awaited<ReturnType<typeof createAndLoginUserWithEventTypes>>) {
async function addWebhook(
user?: Awaited<ReturnType<typeof createAndLoginUserWithEventTypes>>,
teamId?: number | null
) {
const webhookReceiver = createHttpServer();
await prisma.webhook.create({
data: {
id: uuid(),
userId: user.id,
subscriberUrl: webhookReceiver.url,
eventTriggers: [
WebhookTriggerEvents.BOOKING_CREATED,
WebhookTriggerEvents.BOOKING_CANCELLED,
WebhookTriggerEvents.BOOKING_RESCHEDULED,
],
},
});
const data: {
id: string;
subscriberUrl: string;
eventTriggers: WebhookTriggerEvents[];
userId?: number;
teamId?: number;
} = {
id: uuid(),
subscriberUrl: webhookReceiver.url,
eventTriggers: [
WebhookTriggerEvents.BOOKING_CREATED,
WebhookTriggerEvents.BOOKING_CANCELLED,
WebhookTriggerEvents.BOOKING_RESCHEDULED,
],
};
if (teamId) {
data.teamId = teamId;
} else if (user) {
data.userId = user.id;
}
await prisma.webhook.create({ data });
return webhookReceiver;
}