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

feat: Add Google Profile Photo when connecting Google Calendar #13627

Merged
merged 2 commits into from
Feb 15, 2024

Conversation

zeeshanbhati
Copy link
Contributor

@zeeshanbhati zeeshanbhati commented Feb 9, 2024

What does this PR do?

If a user links their Google Calendar and hasn't set an avatar, we'll retrieve their profile photo from their connected Google account and use it as their profile picture.

Fixes : #13492

Requirement/Documentation

  • A new Scope https://www.googleapis.com/auth/userinfo.profile will be added to the calendar scope.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How should this be tested?

  • Create an account using email and password.
  • Do not set a profile picture during profile creation or through the profile section.
  • Go to the Apps section and install Google Calendar. Ensure that you use an account that has a profile picture.
  • Verify if that profile picture has been set as the profile picture for cal.com.

Checklist

  • I haven't checked if my changes generate no new warnings
  • 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

vercel bot commented Feb 9, 2024

@zeeshanbhati is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLAassistant commented Feb 9, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

github-actions bot commented Feb 9, 2024

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

@zeeshanbhati zeeshanbhati changed the title Add Google Profile Photo feat : Add Google Profile Photo Feb 9, 2024
@zeeshanbhati zeeshanbhati changed the title feat : Add Google Profile Photo feat : Add-Google-Profile-Photo Feb 9, 2024
@zeeshanbhati zeeshanbhati changed the title feat : Add-Google-Profile-Photo feat: Add-Google-Profile-Photo Feb 9, 2024
Copy link
Contributor

github-actions bot commented Feb 10, 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! 🙌

@keithwillcode keithwillcode requested a review from a team February 10, 2024 10:04
@keithwillcode keithwillcode added this to the v3.9 milestone Feb 10, 2024
@keithwillcode keithwillcode added Low priority Created by Linear-GitHub Sync community Created by Linear-GitHub Sync labels Feb 10, 2024
@PeerRich PeerRich added the ⚡ Quick Wins A collection of quick wins/quick fixes that are less than 30 minutes of work label Feb 10, 2024
@PeerRich PeerRich changed the title feat: Add-Google-Profile-Photo feat: Add Google Profile Photo when connecting Google Calendar Feb 10, 2024
@keithwillcode
Copy link
Contributor

@joeauyeung is it worth adding another scope just to get the profile image?

@baileypumfleet
Copy link
Contributor

The scope change could add a lot of friction to making this PR possible

@zeeshanbhati
Copy link
Contributor Author

Can we fetch the profile picture without using this scope ?

This is also a non critical scope

Also, what kind of friction can it introduce?

Is it something related to compliance or something?

@keithwillcode keithwillcode requested a review from a team February 14, 2024 01:10
@joeauyeung
Copy link
Contributor

@zeeshanbhati the fear was if we added a new scope would it invalidate access tokens from other users. Testing this by authenticating GCal w/o the profile scope. Then on another account authenticating w/ the scope. When refreshing the token and creating a calendar event with the token w/o the profile scope, it worked as expected.

@baileypumfleet @keithwillcode the profile scope is non-sensitive.
CleanShot 2024-02-14 at 10 48 24

Copy link
Contributor

@joeauyeung joeauyeung left a comment

Choose a reason for hiding this comment

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

Reviewed new scope change (see #13627 (comment))

Test cases:

  • With no avatar set ✅
  • Shouldn't overwrite preset avatar ✅
  • Throwing an error in setProfilePicture doesn't block creation of calendar credential ✅

@github-actions github-actions bot added the ui area: UI, frontend, button, form, input label Feb 14, 2024
@PeerRich PeerRich merged commit 9455d14 into calcom:main Feb 15, 2024
30 of 38 checks passed
@keithwillcode keithwillcode modified the milestones: v3.9, v3.8 Feb 15, 2024
@@ -91,6 +93,10 @@ async function getHandler(req: NextApiRequest, res: NextApiResponse) {
throw new HttpError({ message: "Internal Error", statusCode: 500 });
}

// Update the user's profile photo with google profile photo if it's null
// Since we don't want to block the user from using the app if this fails, we don't await this
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't really work in serverless environments. If you don't await and the main endpoint responds first the call will be dropped.

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL. Can we just wrap it in a try/catch block and if it fails just continue on with the rest of the code?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zomars there's already a try/catch in the function it's self. I tested throw an error in the function and it still creates the credential. I'll add the await and one more change in a follow up PR.

@zomars
Copy link
Member

zomars commented Feb 15, 2024

There's a race condition happening in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Created by Linear-GitHub Sync Low priority Created by Linear-GitHub Sync ⚡ Quick Wins A collection of quick wins/quick fixes that are less than 30 minutes of work ui area: UI, frontend, button, form, input
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-3065] Prefill Avatar with Google avatar after connecting a Google Calendar
7 participants