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: N Calendar Invites For Collective Events #14610

Closed
wants to merge 11 commits into from

Conversation

joeauyeung
Copy link
Contributor

@joeauyeung joeauyeung commented Apr 16, 2024

What does this PR do?

This PR aims to prevent attendees receiving multiple calendar invites by only creating one calendar event.

Fixes #14580 Fixes CAL-3412 Fixes CAL-3468

https://www.loom.com/share/89fecb968c9a4511869bfa807c273ca4

Requirement/Documentation

  • If there is a requirement document, please, share it here.
  • If there is a UI/UX design document, please, share it here.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How should this be tested?

  • Create a collective team event with each team member having Outlook as a destination calendar
  • Create a booking under the collective event
  • The attendee should receive one email from Outlook and all team members should be invited to the event

Mandatory Tasks

  • [] Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

Copy link

linear bot commented Apr 16, 2024

@graphite-app graphite-app bot requested a review from a team April 16, 2024 13:31
Copy link
Contributor

github-actions bot commented Apr 16, 2024

Thank you for following the naming conventions! 🙏 Feel free to join our discord and post your PR link.

@github-actions github-actions bot added consumer emails area: emails, cancellation email, reschedule email, inbox, spam folder, not getting email teams area: teams, round robin, collective, managed event-types Urgent Created by Linear-GitHub Sync 🐛 bug Something isn't working labels Apr 16, 2024
@dosubot dosubot bot added the bookings area: bookings, availability, timezones, double booking label Apr 16, 2024
@keithwillcode keithwillcode added the core area: core, team members only label Apr 16, 2024
@joeauyeung joeauyeung added the high-risk Requires approval by Foundation team label Apr 16, 2024
@graphite-app graphite-app bot requested a review from a team April 16, 2024 13:33
Copy link

graphite-app bot commented Apr 16, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (04/16/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add foundation team as reviewer" took an action on this PR • (04/16/24)

1 reviewer was added to this PR based on Keith Williams's automation.

Copy link
Contributor

github-actions bot commented Apr 16, 2024

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link

deploysentinel bot commented Apr 16, 2024

Current Playwright Test Results Summary

✅ 222 Passing - ⚠️ 8 Flaky

Run may still be in progress, this comment will be updated as current testing workflow or job completes...

(Last updated on 04/16/2024 07:07:23pm UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: e19d594

Started: 04/16/2024 07:03:28pm UTC

⚠️ Flakes

📄   apps/web/playwright/login.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Login and logout tests -- legacy Login flow validations -- future Should warn when user does not exist
Retry 1Initial Attempt
0% (0) 0 / 284 runs
failed over last 7 days
1.41% (4) 4 / 284 runs
flaked over last 7 days

📄   apps/web/playwright/event-types.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Event Types tests -- legacy user Different Locations Tests Can remove location from multiple locations that are saved
Retry 1Initial Attempt
0% (0) 0 / 291 runs
failed over last 7 days
19.24% (56) 56 / 291 runs
flaked over last 7 days

📄   apps/web/playwright/insights.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Insights should be able to go to insights as admins
Retry 1Initial Attempt
0.34% (1) 1 / 291 run
failed over last 7 days
6.87% (20) 20 / 291 runs
flaked over last 7 days

📄   apps/web/playwright/integrations-stripe.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Stripe integration Pending payment booking should not be confirmed by default
Retry 1Initial Attempt
1.72% (5) 5 / 291 runs
failed over last 7 days
20.96% (61) 61 / 291 runs
flaked over last 7 days

📄   apps/web/playwright/profile.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Update Profile Can verify the newly added secondary email
Retry 1Initial Attempt
0% (0) 0 / 296 runs
failed over last 7 days
7.77% (23) 23 / 296 runs
flaked over last 7 days

📄   apps/web/playwright/signup.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Signup Flow Test Email verification sent if enabled
Retry 1Initial Attempt
0% (0) 0 / 308 runs
failed over last 7 days
2.27% (7) 7 / 308 runs
flaked over last 7 days

📄   apps/web/playwright/change-username.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Change username on settings User can change username
Retry 1Initial Attempt
1.01% (3) 3 / 298 runs
failed over last 7 days
2.68% (8) 8 / 298 runs
flaked over last 7 days

📄   apps/web/playwright/teams.e2e.ts • 1 Flake

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
Teams - NonOrg -- future Can create a booking for Round Robin EventType
Retry 1Initial Attempt
0.65% (2) 2 / 308 runs
failed over last 7 days
1.62% (5) 5 / 308 runs
flaked over last 7 days

View Detailed Build Results


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Outlook since the calendarId is for internal purposes we can only invite the primary email to calendar events. https://www.loom.com/share/60ac4ad245414714979dc2e11d8d347a?sid=6b089642-a97d-40cd-a015-37fc97a3e8d9

Comment on lines +569 to +595
if (!credentialId) {
// Keep this logic here for other events that need to fallback to other calendars
if (eventCreationAttempts === 0) {
const destinationCalendarCredentials = this.calendarCredentials.filter(
(c) => c.type === destinationCalendar.integration
);
// It might not be the first connected calendar as it seems that the order is not guaranteed to be ascending of credentialId.
const firstCalendarCredential = destinationCalendarCredentials[0] as
| (typeof destinationCalendarCredentials)[number]
| undefined;

if (!firstCalendarCredential) {
log.warn(
"No other credentials found of the same type as the destination calendar. Falling back to first connected calendar"
);
await fallbackToFirstConnectedCalendar();
} else {
log.warn(
"No credentialId found for destination calendar, falling back to first found calendar of same type as destination calendar",
safeStringify({
destination: getPiiFreeDestinationCalendar(destinationCalendar),
firstConnectedCalendar: getPiiFreeCredential(firstCalendarCredential),
})
);
createdEvents.push(await createEvent(firstCalendarCredential, event));
eventCreated = true;
break;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge fan of this approach but keeping this in here to maintain what we currently have.

Copy link

vercel bot commented Apr 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
platform-starter-kit ❌ Failed (Inspect) Apr 16, 2024 6:52pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 6:52pm
cal ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 6:52pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 6:52pm

Copy link
Contributor

@keithwillcode keithwillcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joeauyeung I just tested creating an OAuthClient on the preview development and I can't click the Submit button at all

@keithwillcode
Copy link
Contributor

@joeauyeung I just tested creating an OAuthClient on the preview development and I can't click the Submit button at all

Ok. Tested again. Not sure what was going on but now I can submit successfully.

Copy link
Contributor

@keithwillcode keithwillcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's concerning to me that all this logic is changing and no automated tests are updated/added. We need to follow up ASAP with a PR adding unit tests to verify all of this logic.

* When inviting attendees to a calendar event, sometimes the external ID is only used for internal purposes
* Need to process the correct external ID for the calendar service
*/
const processExternalId = (destinationCalendar: DestinationCalendar) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this function has the potential to grow in the number of "if" statements moving forward? i.e. We'll have to have different logic for a large number of different calendar apps. If so, we should move it off to its own file per calendar integration.

Since this is urgent to get fixed, that could be a follow-up refactor.

@joeauyeung
Copy link
Contributor Author

joeauyeung commented Apr 16, 2024

It's concerning to me that all this logic is changing and no automated tests are updated/added. We need to follow up ASAP with a PR adding unit tests to verify all of this logic.

@keithwillcode there are 0 tests for the EventManager class so I'm writing tests out but I'll follow up in another PR so we're not waiting for this one.

Regarding processExternalId AFAIK it's just Outlook that treats calendarIds like this. I see what you're getting at though. If there are other calendars that are added that have their own custom logic we should refactor processing the externalIds under their respective app package.

Co-authored-by: Omar López <zomars@me.com>
@@ -535,78 +535,105 @@ export default class EventManager {
};

if (event.destinationCalendar && event.destinationCalendar.length > 0) {
// Since GCal pushes events to multiple calendars we only want to create one event per booking
let gCalAdded = false;
const destinationCalendars: DestinationCalendar[] = event.destinationCalendar.reduce(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reduce refactor necessary to fix the bug? Or was it done for getting two birds with one stone?

If it's the latter then I'm afraid it is making the PR harder to review since it's not clear "where" is the bug that we're fixing.

Also as @keithwillcode mentioned we don't have EventManager tests to ship this PR with 100% confidence. RN if I approve this I'm not 100% confident this will not break other event type configurations.

My suggestion would be:

Make a PR with "only" the changes needed to fix the current bug. Then other PR for adding tests. Then other PR to do chores and refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactor is necessary since ideally only one calendar event is created for the booking. When inviting team members it should add events to their default destination calendars by inviting those calendars to the event.

Since this is affecting collective events, a PR with "only" the fix would be to remove pushing multiple destination calendars when the event is a collective one. That would be the safest bet. Looking through the CalendarService files of GCal and Outlook we already add team members as the attendees. Although for Outlook we still need to process the externalId properly so all team members are added to the event.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we should focus the rest of the day on getting tests wired up here and we ship this tomorrow.

This is the type of change that is high risk of making things worse than the original bug we are trying to fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests should written against main and not against this code first to verify all existing logic stays the same. Once verified, we then add tests to verify this change in logic

@zomars
Copy link
Member

zomars commented Apr 19, 2024

Closing in favor of #14617

@zomars zomars closed this Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bookings area: bookings, availability, timezones, double booking 🐛 bug Something isn't working consumer core area: core, team members only emails area: emails, cancellation email, reschedule email, inbox, spam folder, not getting email High priority Created by Linear-GitHub Sync high-risk Requires approval by Foundation team teams area: teams, round robin, collective, managed event-types Urgent Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-3412] a collective event of N people sends N invites
4 participants