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

refactor: invite members handler #12442

Merged
merged 21 commits into from
Nov 27, 2023
Merged

Conversation

ThyMinimalDev
Copy link
Contributor

@ThyMinimalDev ThyMinimalDev commented Nov 20, 2023

What does this PR do?

Refactor trpc invite handler to treat the operations as batches

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • create an organization
  • create a team inside the organization
  • invite members to the organization
  • invite members to the organization's team

Mandatory Tasks

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

Checklist

  • I haven't checked if my PR needs changes to the documentation

Copy link

linear bot commented Nov 20, 2023

CAL-2698 Refactor InviteMember handler

file: packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.ts

Currently inviteMember allows bulk invite of team members, which can be overloading our database very quickly

the problems are the following:

  • unlimited amount of members can be invited at once,
  • this is a bulk operation but the code treats each member to invite one by one in a for loop,
  • do all the required checks before calling the database when possible

Copy link

vercel bot commented Nov 20, 2023

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

Name Status Preview Comments Updated (UTC)
api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2023 7:53am
dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 27, 2023 7:53am
5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2023 7:53am
cal ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2023 7:53am
cal-demo ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2023 7:53am
qa ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2023 7:53am
ui ⬜️ Ignored (Inspect) Visit Preview Nov 27, 2023 7:53am

Copy link
Contributor

github-actions bot commented Nov 20, 2023

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

@zomars zomars added admin core area: core, team members only devops labels Nov 20, 2023
@ThyMinimalDev ThyMinimalDev force-pushed the cal-2698-refactor-invitemember-handler branch from 25e43a4 to d0e6d34 Compare November 20, 2023 14:58
Copy link
Contributor

github-actions bot commented Nov 20, 2023

📦 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 Nov 20, 2023

Current Playwright Test Results Summary

✅ 38 Passing - ⚠️ 1 Flaky

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

(Last updated on 11/27/2023 08:20:51am UTC)

Run Details

Running Workflow PR Update on Github Actions

Commit: c9bf49e

Started: 11/27/2023 08:19:42am UTC

⚠️ Flakes

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

Test Case Results

Test Case Last 7 days Failures Last 7 days Flakes
FORM_SUBMITTED on submitting team form, triggers team webhook
Retry 1Initial Attempt
3.47% (9) 9 / 259 runs
failed over last 7 days
17.37% (45) 45 / 259 runs
flaked over last 7 days

View Detailed Build Results


@ThyMinimalDev ThyMinimalDev marked this pull request as ready for review November 21, 2023 12:42
Comment on lines +203 to +209
teams: {
create: {
teamId: input.teamId,
role: input.role as MembershipRole,
accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could conditionally create the membership to the Organization here instead of doing it in the if parentId statement below, but it would not have any impact since prisma would still make different sql queries

Copy link
Member

@sean-brydon sean-brydon left a comment

Choose a reason for hiding this comment

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

LGTM!

Tested locally - tests cover pretty much all edge cases we need
much much faster when testing locally compared to main (like take a look at the difference its crazy )

@sean-brydon sean-brydon merged commit 2094d59 into main Nov 27, 2023
37 checks passed
@sean-brydon sean-brydon deleted the cal-2698-refactor-invitemember-handler branch November 27, 2023 09:27
jakazzy pushed a commit to jakazzy/cal.com that referenced this pull request Dec 5, 2023
* refactor: invite members handler

* fixup! refactor: invite members handler

* fixup! fixup! refactor: invite members handler

* refactor: promise all settled send emails

* fixup! refactor: promise all settled send emails

* fixup! fixup! refactor: promise all settled send emails

* fixup! fixup! fixup! refactor: promise all settled send emails

* fix: opening team invite link in email throws error on signup page

* fixup! Merge branch 'main' into cal-2698-refactor-invitemember-handler

* fix: centralize validation if invitee can be invited

* fix: improve select query and fix tests

* fixup! Merge branch 'main' into cal-2698-refactor-invitemember-handler

* rename functions and add some tests
hbjORbj pushed a commit to codemod-com/cal.com-demo that referenced this pull request Dec 21, 2023
* refactor: invite members handler

* fixup! refactor: invite members handler

* fixup! fixup! refactor: invite members handler

* refactor: promise all settled send emails

* fixup! refactor: promise all settled send emails

* fixup! fixup! refactor: promise all settled send emails

* fixup! fixup! fixup! refactor: promise all settled send emails

* fix: opening team invite link in email throws error on signup page

* fixup! Merge branch 'main' into cal-2698-refactor-invitemember-handler

* fix: centralize validation if invitee can be invited

* fix: improve select query and fix tests

* fixup! Merge branch 'main' into cal-2698-refactor-invitemember-handler

* rename functions and add some tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admin api area: API, enterprise API, access token, OAuth core area: core, team members only devops Medium priority Created by Linear-GitHub Sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants