-
-
Notifications
You must be signed in to change notification settings - Fork 56
Add subscription info to invite emails & endpoint for sending "trial ending soon" emails #2799
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f2d8a03
add subscription info to invite emails
emma-sg 4dc8362
add endpoint to send "trial will end" email
emma-sg ac17ae5
format
emma-sg 0663db8
format & fix lint issues
emma-sg 1f22023
revert unnecessary change to email
emma-sg d60e092
fix date calculation
emma-sg a96cfd7
fail if not admins found for org
emma-sg d07d0ab
trim trailing slash from org urls
emma-sg 3d8ab20
use same day counting logic in invites & trial_ending_soon emails
emma-sg 490bb4b
remove unused import
emma-sg 9514ebf
allow `null` values for trial_end_date
emma-sg 3aa5a9c
simplify email template dates with `z.coerce.date()`
emma-sg 061afd1
swap to 400 error codes when sending subscription reminder email
emma-sg 899fd18
enable `use_attribute_docstrings` in Subscription
emma-sg 9934fcc
update trial end text for when user has cancelled trial
emma-sg a0555b5
add "read-only" state for trial end emails
emma-sg 2bdcbc4
update trial cancellation text when user has cancelled manually
emma-sg e1bacd8
include commit hash with email service logs
emma-sg 099f0a2
simplify & use commit hash from github action env
emma-sg 4719d5a
remove script from package.json
emma-sg 6c52344
Apply suggestion from @ikreymer
ikreymer a49cfc4
tweaks:
ikreymer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
SubscriptionPortalUrlRequest, | ||
SubscriptionPortalUrlResponse, | ||
SubscriptionCanceledResponse, | ||
SubscriptionTrialEndReminder, | ||
SubscriptionReminderResponse, | ||
Organization, | ||
InviteToOrgRequest, | ||
InviteAddedResponse, | ||
|
@@ -182,6 +184,51 @@ async def cancel_subscription(self, cancel: SubscriptionCancel) -> dict[str, boo | |
await self.add_sub_event("cancel", cancel, org.id) | ||
return {"canceled": True, "deleted": deleted} | ||
|
||
async def send_trial_end_reminder( | ||
self, | ||
reminder: SubscriptionTrialEndReminder, | ||
): | ||
"""Send a trial end reminder email to the organization admins""" | ||
|
||
org = await self.org_ops.find_org_by_subscription_id(reminder.subId) | ||
|
||
if not org: | ||
print(f"Organization not found for subscription ID {reminder.subId}") | ||
raise HTTPException( | ||
status_code=404, detail="org_for_subscription_not_found" | ||
) | ||
|
||
if not org.subscription: | ||
print( | ||
f"Subscription not found for organization ID {org.id} with sub id {reminder.subId}" | ||
) | ||
raise HTTPException(status_code=500, detail="subscription_not_found") | ||
|
||
emma-sg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if not org.subscription.futureCancelDate: | ||
print(f"Future cancel date not found for subscription ID {reminder.subId}") | ||
raise HTTPException(status_code=500, detail="future_cancel_date_not_found") | ||
emma-sg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
users = await self.org_ops.get_users_for_org(org, UserRole.OWNER) | ||
|
||
if len(users) == 0: | ||
print(f"No admin users found for organization ID {org.id}") | ||
raise HTTPException(status_code=500, detail="no_admin_users_found") | ||
emma-sg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
await asyncio.gather( | ||
*[ | ||
self.user_manager.email.send_subscription_trial_ending_soon( | ||
trial_end_date=org.subscription.futureCancelDate, | ||
user_name=user.name, | ||
receiver_email=user.email, | ||
org=org, | ||
behavior_on_trial_end=reminder.behavior_on_trial_end, | ||
) | ||
for user in users | ||
] | ||
) | ||
|
||
return SubscriptionReminderResponse(sent=True) | ||
|
||
|
||
async def add_sub_event( | ||
self, | ||
type_: str, | ||
|
@@ -395,6 +442,17 @@ async def cancel_subscription( | |
): | ||
return await ops.cancel_subscription(cancel) | ||
|
||
@app.post( | ||
"/subscriptions/trial-end-reminder", | ||
ikreymer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
tags=["subscriptions"], | ||
dependencies=[Depends(user_or_shared_secret_dep)], | ||
response_model=SubscriptionReminderResponse, | ||
) | ||
async def send_trial_end_reminder( | ||
reminder: SubscriptionTrialEndReminder, | ||
): | ||
return await ops.send_trial_end_reminder(reminder) | ||
|
||
assert org_ops.router | ||
|
||
@app.get( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.