-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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: account delete #11829
Open
GareArc
wants to merge
29
commits into
main
Choose a base branch
from
feat/account-deletion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+535
−1
Open
feat: account delete #11829
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
571495c
feat: account delete
GareArc db66860
fix: use get method for verification code
GareArc cffcca3
feat: add rate limiter
GareArc 56fe09e
feat: add migration
GareArc 5647fe7
update
GareArc f7ca0a2
fix: token wrong position
GareArc 4f39322
fix: params of celery function should be serializable
GareArc 4be59e1
fix: db session error
GareArc ed97f76
fix: refactor task
GareArc 3ee1de6
minor fix
GareArc 424c7ee
feat: add email templates
douxc cd437ef
fix: update emial template style
douxc 6d93a09
fix: add detailed deletion log
GareArc 3c090e7
fix: migration
GareArc a4921c1
fix: remove custom json serializer
GareArc 577eb8f
fix: serializer
GareArc 44c2bfb
fix: bad import
GareArc d9687ee
fix: add email check in register service
GareArc d9bba39
reformat
GareArc ab4afa5
fix: rebase migration head
GareArc 356c3d5
fix: remove deletion logic
GareArc ec5f312
fix: delete migration and config
GareArc f475431
reformat
GareArc 5bf4431
fix wrong import
GareArc ec1c126
fix: change celery queue name
GareArc 53e1127
fix: type check
GareArc 5f4bb97
fix: bugs
GareArc c99254d
fix: ignore type for celey in mypy
GareArc 3a62679
reformat
GareArc 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
|
||
from celery import shared_task | ||
|
||
from extensions.ext_database import db | ||
from models.account import Account | ||
from services.billing_service import BillingService | ||
from tasks.mail_account_deletion_task import send_deletion_success_task | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task(queue="dataset") | ||
GareArc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def delete_account_task(account_id, reason: str): | ||
try: | ||
BillingService.delete_account(account_id, reason) | ||
except Exception as e: | ||
logger.exception(f"Failed to delete account {account_id} from billing service.") | ||
raise | ||
|
||
account = db.session.query(Account).filter(Account.id == account_id).first() | ||
# send success email | ||
send_deletion_success_task.delay(account.interface_language, account.email) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import logging | ||
import time | ||
|
||
import click | ||
from celery import shared_task | ||
from flask import render_template | ||
|
||
from extensions.ext_mail import mail | ||
|
||
|
||
@shared_task(queue="mail") | ||
def send_deletion_success_task(language, to): | ||
"""Send email to user regarding account deletion. | ||
Args: | ||
log (AccountDeletionLog): Account deletion log object | ||
""" | ||
if not mail.is_inited(): | ||
return | ||
|
||
logging.info(click.style(f"Start send account deletion success email to {to}", fg="green")) | ||
start_at = time.perf_counter() | ||
|
||
try: | ||
if language == "zh-Hans": | ||
html_content = render_template( | ||
"delete_account_success_template_zh-CN.html", | ||
to=to, | ||
email=to, | ||
) | ||
mail.send(to=to, subject="Dify 账户删除成功", html=html_content) | ||
else: | ||
html_content = render_template( | ||
"delete_account_success_template_en-US.html", | ||
to=to, | ||
email=to, | ||
) | ||
mail.send(to=to, subject="Dify Account Deleted", html=html_content) | ||
|
||
end_at = time.perf_counter() | ||
logging.info( | ||
click.style( | ||
"Send account deletion success email to {}: latency: {}".format(to, end_at - start_at), fg="green" | ||
) | ||
) | ||
except Exception: | ||
logging.exception("Send account deletion success email to {} failed".format(to)) | ||
|
||
|
||
@shared_task(queue="mail") | ||
def send_account_deletion_verification_code(language, to, code): | ||
"""Send email to user regarding account deletion verification code. | ||
Args: | ||
to (str): Recipient email address | ||
code (str): Verification code | ||
""" | ||
if not mail.is_inited(): | ||
return | ||
|
||
logging.info(click.style(f"Start send account deletion verification code email to {to}", fg="green")) | ||
start_at = time.perf_counter() | ||
|
||
try: | ||
if language == "zh-Hans": | ||
html_content = render_template("delete_account_code_email_template_zh-CN.html", to=to, code=code) | ||
mail.send(to=to, subject="Dify 的删除账户验证码", html=html_content) | ||
else: | ||
html_content = render_template("delete_account_code_email_en-US.html", to=to, code=code) | ||
mail.send(to=to, subject="Delete Your Dify Account", html=html_content) | ||
|
||
end_at = time.perf_counter() | ||
logging.info( | ||
click.style( | ||
"Send account deletion verification code email to {} succeeded: latency: {}".format( | ||
to, end_at - start_at | ||
), | ||
fg="green", | ||
) | ||
) | ||
except Exception: | ||
logging.exception("Send account deletion verification code email to {} failed".format(to)) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
body { | ||
font-family: 'Arial', sans-serif; | ||
line-height: 16pt; | ||
color: #101828; | ||
background-color: #e9ebf0; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.container { | ||
width: 600px; | ||
height: 360px; | ||
margin: 40px auto; | ||
padding: 36px 48px; | ||
background-color: #fcfcfd; | ||
border-radius: 16px; | ||
border: 1px solid #ffffff; | ||
box-shadow: 0 2px 4px -2px rgba(9, 9, 11, 0.08); | ||
} | ||
.header { | ||
margin-bottom: 24px; | ||
} | ||
.header img { | ||
max-width: 100px; | ||
height: auto; | ||
} | ||
.title { | ||
font-weight: 600; | ||
font-size: 24px; | ||
line-height: 28.8px; | ||
} | ||
.description { | ||
font-size: 13px; | ||
line-height: 16px; | ||
color: #676f83; | ||
margin-top: 12px; | ||
} | ||
.code-content { | ||
padding: 16px 32px; | ||
text-align: center; | ||
border-radius: 16px; | ||
background-color: #f2f4f7; | ||
margin: 16px auto; | ||
} | ||
.code { | ||
line-height: 36px; | ||
font-weight: 700; | ||
font-size: 30px; | ||
} | ||
.tips { | ||
line-height: 16px; | ||
color: #676f83; | ||
font-size: 13px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="header"> | ||
<!-- Optional: Add a logo or a header image here --> | ||
<img src="https://cloud.dify.ai/logo/logo-site.png" alt="Dify Logo" /> | ||
</div> | ||
<p class="title">Delete your Dify account</p> | ||
<p class="description">Copy and paste this code, this code will only be valid for the next 5 minutes.</p> | ||
<div class="code-content"> | ||
<span class="code">{{code}}</span> | ||
</div> | ||
<p class="tips">If you didn't request, don't worry. You can safely ignore this email.</p> | ||
</div> | ||
</body> | ||
</html> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.