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

Gcal Integration #378

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Gcal Integration #378

wants to merge 11 commits into from

Conversation

mrshwah
Copy link
Collaborator

@mrshwah mrshwah commented Nov 15, 2020

Opening a draft PR for now. Includes the work that I demoed on Tuesday. Please comment with any concerns!

Some todos:

  • After google auth, redirect to frontend page with user friendly message and button to redirect to slack
  • Send user message to set up google integration after creating penny chat (if no credentials exist)
  • Update google event when penny chat is updated
  • Fix Add to Google Calendar link in penny chat share
  • Send signal to create google events for all of the existing penny chat invites

related

closes #122 because of addition of lru_cache decorator

@mrshwah mrshwah requested review from JnBrymn and a user November 15, 2020 17:46
@JnBrymn
Copy link
Collaborator

JnBrymn commented Nov 15, 2020

  • Keep in mind any place where you might be adding any more effort on the part of our users. You changed the Share to Submit for a bit but changed it back. In the final state I think that we share the chat as soon as the modal closes. Is that right? I just want to make sure that we don't have a new, required step at the end.
  • If I choose not to connect google, I'm going to see the same modal pop up after every chat I create. (Right?) That's going to feel a bit intrusive. What do you think about just making that an ephemeral post?
  • get_or_create_social_profile_from_slack_id was written a little sloppily in that it calls to slack upon every request. Maybe memoize the function so that it's used at most once per call.

@@ -197,11 +197,13 @@ def _penny_chat_details_blocks(penny_chat_invitation, mode=None):
if include_calendar_link:
start_date = penny_chat_invitation.date.astimezone(utc).strftime('%Y%m%dT%H%M%SZ')
end_date = (penny_chat_invitation.date.astimezone(utc) + timedelta(hours=1)).strftime('%Y%m%dT%H%M%SZ')

description = f'{penny_chat_invitation.description} [Video Link]({penny_chat_invitation.video_conference_link})'
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add a new line? ...description}\n[Video...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lol, I totally forgot to revisit this. Adding to todos...

@ghost
Copy link

ghost commented Nov 16, 2020

Agreed with John on everything here.

If we're moving to a .env here, it might also be good to do that for SLACK_API_KEY as well.

From a user experience perspective, we might want to include a short blurb on the connection modal detailing what data we access (from what I remember Google's OAuth page for this is very vague) and what benefit they get from connecting Google. ex. When you connect with Google, we use your calendar to keep you updated on your upcoming Penny Chats and automatically create video chats for you!

Really like the way you structured this in the code, makes it simple to expand on for other integrations. I think the more an app integrates with other existing tools, the more a company or organization is willing to adopt it into that workflow, and starting with this we'll have a lot of room to grow on that idea.

Copy link
Collaborator

@JnBrymn JnBrymn left a comment

Choose a reason for hiding this comment

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

I think it looks good so far. The main thing I'm wondering about is the user experience in the various paths through this. Would you mind demoing that again this week? (Especially if anything has changed.)

@@ -240,6 +242,45 @@ def _penny_chat_details_blocks(penny_chat_invitation, mode=None):
date_time_block
]

if penny_chat_invitation.video_conference_link:
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably a nit pick, but rather than have 3 sections here, I'd just have a {PREVIEW, INVITE, UPDATE} section with a parenthetical (A video link will be provided shortly before the chat starts) and a REMIND section with the full details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So just remove the Video Link header from the invite and add parentheses?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yup, just like you did - looks good

bot/tasks/pennychat.py Outdated Show resolved Hide resolved
self.calendar_id = calendar_id

@property
def events(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious, why not just create self.events = self.service.events() in the init? 🤔 I wonder what calling events() each time you want self.events does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I should do that instead.

error = request.GET.get('error')
# TODO: Redirect to frontend page
if error:
return HttpResponse(f"<h1/>There was an error authorizing with Google.</h1><p>{request.GET.get('error')}</p>")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably log details to sentry here. Probably sentry_sdk.capture_message since this isn't a raised exception.

@mrshwah
Copy link
Collaborator Author

mrshwah commented Nov 16, 2020

@JnBrymn

In the final state I think that we share the chat as soon as the modal closes. Is that right? I just want to make sure that we don't have a new, required step at the end.

Yes, this is correct! I didn't mean to originally commit the wording change on the button. I was messing around with having several modals at one point and forgot to change it back before committing.

What do you think about just making that an ephemeral post?

I actually moved to this in my latest commit before seeing your message! Great minds, yada yada...

@deadbender

If we're moving to a .env here, it might also be good to do that for SLACK_API_KEY as well.

My intention isn't for everyone to move to a .env, I just did so because I prefer it to direnv which I was using before. Contributors can use whatever they like for setting up their environments which is why it is gitignored. We don't want to commit those files with our API keys to the repo.

From a user experience perspective, we might want to include a short blurb on the connection modal detailing what data we access (from what I remember Google's OAuth page for this is very vague) and what benefit they get from connecting Google.

The message from Google says that it will allow us to "view and edit events" on their calendar. I think that is clear enough. I will definitely add that language you suggested for the benefits though!

@mrshwah mrshwah marked this pull request as ready for review November 25, 2020 01:58
@@ -9,7 +9,7 @@
post_organizer_edit_after_share_blocks,
share_penny_chat_invitation,
add_google_meet,
add_google_integration_blocks,
add_google_integration_blocks, update_google_meet,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, new line

def update_google_meet(penny_chat_id):
penny_chat_invitation = PennyChatSlackInvitation.objects.get(id=penny_chat_id)

calendar = get_user_google_calendar_from_slack_id(penny_chat_invitation.organizer_slack_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the user retracts google permissions then calendar will be None here, add an if calendar is None here or we'll error on line 112. In this case I guess we just keep the calendar invite as is? (I presume it will still work)

@@ -240,6 +242,45 @@ def _penny_chat_details_blocks(penny_chat_invitation, mode=None):
date_time_block
]

if penny_chat_invitation.video_conference_link:
Copy link
Collaborator

Choose a reason for hiding this comment

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

yup, just like you did - looks good

if credentials:
user = credentials.user
slack_ids = [profile.slack_id for profile in user.social_profiles.all()]
invites = PennyChatSlackInvitation.objects.filter(organizer_slack_id__in=slack_ids, date__gt=timezone.now())
Copy link
Collaborator

Choose a reason for hiding this comment

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

would there ever be any invites with date__gt=timezone.now() ? is this a bug

Copy link
Collaborator

Choose a reason for hiding this comment

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

disregard ... hey this box wine is great!

f'{urllib.parse.quote(penny_chat_invitation.description)}'
f'{urllib.parse.quote(penny_chat_invitation.title)}&dates=' \
f'{start_date}/{end_date}&details=' \
f'{urllib.parse.quote(description)}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function has grown in complexity, can you pull out the contents of this if statement into it's own helpful func that lives in this file?

@mrshwah
Copy link
Collaborator Author

mrshwah commented Nov 25, 2020

Before merging todos:

  • Add production google api and add to secrets
  • Update docs
  • Privacy policy (another PR)

@mrshwah
Copy link
Collaborator Author

mrshwah commented Dec 30, 2020

I have submitted to google for verification... And now we wait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_or_create_user_profile_from_slack_ids is too expensive
2 participants