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: account delete #11829

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
11e7ecb
feat: account delete
GareArc Dec 19, 2024
cbd8045
fix: use get method for verification code
GareArc Dec 19, 2024
4fde7a5
feat: add rate limiter
GareArc Dec 21, 2024
ed2e260
feat: add migration
GareArc Dec 21, 2024
b7e8e74
update
GareArc Dec 21, 2024
5e25799
fix: token wrong position
GareArc Dec 21, 2024
ff5b846
fix: params of celery function should be serializable
GareArc Dec 21, 2024
7b49e74
fix: db session error
GareArc Dec 21, 2024
e1b0903
fix: refactor task
GareArc Dec 22, 2024
d31161d
minor fix
GareArc Dec 22, 2024
0dc870a
feat: add email templates
douxc Dec 23, 2024
341cc22
fix: update emial template style
douxc Dec 23, 2024
c016c44
fix: add detailed deletion log
GareArc Dec 23, 2024
40653f4
fix: migration
GareArc Dec 23, 2024
bf7d30f
fix: remove custom json serializer
GareArc Dec 23, 2024
be1b7bc
fix: serializer
GareArc Dec 23, 2024
bdfc41d
fix: bad import
GareArc Dec 23, 2024
4254c4d
fix: add email check in register service
GareArc Dec 23, 2024
ee52a74
reformat
GareArc Dec 23, 2024
fa7393d
fix: rebase migration head
GareArc Dec 23, 2024
968ee8c
fix: remove deletion logic
GareArc Dec 24, 2024
6caf17f
fix: delete migration and config
GareArc Dec 24, 2024
8275a0f
reformat
GareArc Dec 24, 2024
4cf190f
fix wrong import
GareArc Dec 24, 2024
8b453f8
fix: change celery queue name
GareArc Dec 25, 2024
3492f15
fix: type check
GareArc Dec 25, 2024
65eed9a
fix: bugs
GareArc Dec 25, 2024
d313a71
fix: ignore type for celey in mypy
GareArc Dec 25, 2024
f65fa9b
reformat
GareArc Dec 25, 2024
7c2d43f
feat: add seperate feedback api
GareArc Dec 25, 2024
a1205ea
fix: change task queue
GareArc Dec 25, 2024
018e932
fix: wrong api route
GareArc Dec 25, 2024
e96a6e6
fix: bug
GareArc Dec 25, 2024
a37ac27
reformat
GareArc Dec 25, 2024
e768fb2
fix: update api
GareArc Dec 25, 2024
a9c0bc6
fix: add logic for blocking login when email is in freeze
GareArc Dec 26, 2024
99a0178
reformat
GareArc Dec 26, 2024
e6bf5e4
reformat
GareArc Dec 26, 2024
aef4e98
fix: wrong error object
GareArc Dec 26, 2024
6f02bad
reformat
GareArc Dec 26, 2024
271dd9d
fix: error handling
GareArc Dec 26, 2024
056c95f
fix: error description
GareArc Dec 26, 2024
cc79543
fix: reject before sending email
GareArc Dec 26, 2024
b5b989b
fix: block login if email in freeze
GareArc Dec 26, 2024
3c2d401
fix: wrong email value
GareArc Dec 26, 2024
e127283
fix: update email template
douxc Dec 26, 2024
ae0aee5
fix: update email workflow
GareArc Dec 26, 2024
f008c26
fix: remove redundant error description
GareArc Dec 26, 2024
7ac4113
fix: update delete account email template style
douxc Dec 26, 2024
d45958a
fix: bug
GareArc Dec 26, 2024
79c96aa
fix: update delete account email template style
douxc Dec 26, 2024
f0c30ea
fix: update delete account email template style
douxc Dec 26, 2024
04cb7bf
fix: add account register error message
GareArc Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: serializer
  • Loading branch information
GareArc committed Dec 26, 2024
commit be1b7bc5a9ff2f412f6f67852dc56049d2f63c0c
17 changes: 17 additions & 0 deletions api/libs/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,20 @@ def increment_rate_limit(self, email: str):

def get_current_datetime():
return datetime.now(tz.utc).replace(tzinfo=None)


def serialize_sqlalchemy(obj):
"""
Serializes an SQLAlchemy object into a JSON string.
"""
data = {}
for column in obj.__table__.columns:
value = getattr(obj, column.name)
if isinstance(value, datetime):
data[column.name] = value.isoformat() # ISO 8601 format for datetime
elif isinstance(value, uuid.UUID):
data[column.name] = str(value) # String representation for UUID
else:
data[column.name] = value

return json.dumps(data, separators=(",", ":"))
6 changes: 3 additions & 3 deletions api/services/account_deletion_log_service.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import json
from datetime import timedelta

from configs import dify_config
from extensions.ext_database import db
from flask import jsonify
from libs.helper import get_current_datetime
from libs.helper import get_current_datetime, serialize_sqlalchemy
from models.account import Account, AccountDeletionLog


Expand All @@ -15,7 +15,7 @@ def create_account_deletion_log(account: Account, reason):
account_deletion_log.email = account.email
account_deletion_log.reason = reason
account_deletion_log.account_id = account.id
account_deletion_log.snapshot = jsonify(account)
account_deletion_log.snapshot = json.dumps(serialize_sqlalchemy(account), separators=(",", ":"))
account_deletion_log.updated_at = get_current_datetime()

return account_deletion_log
Expand Down
18 changes: 10 additions & 8 deletions api/tasks/delete_account_task.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import json
import logging
import time

import click
from celery import shared_task
from extensions.ext_database import db
from flask import jsonify
from models.account import (Account, AccountDeletionLogDetail,
TenantAccountJoin, TenantAccountJoinRole)
from services.account_deletion_log_service import AccountDeletionLogService
from services.billing_service import BillingService
from tasks.mail_account_deletion_task import send_deletion_success_task

from api.libs.helper import serialize_sqlalchemy

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -84,10 +86,10 @@ def _handle_owner_tenant_deletion(ta: TenantAccountJoin):
account_deletion_log_detail = AccountDeletionLogDetail()
account_deletion_log_detail.account_id = ta.account_id
account_deletion_log_detail.tenant_id = tenant_id
account_deletion_log_detail.snapshot = jsonify({
"tenant_account_join_info": ta,
"dismissed_members": members_to_dismiss
})
account_deletion_log_detail.snapshot = json.dumps({
"tenant_account_join_info": serialize_sqlalchemy(ta),
"dismissed_members": [serialize_sqlalchemy(member) for member in members_to_dismiss]
}, separators=(",", ":"))
account_deletion_log_detail.role = ta.role
db.session.add(account_deletion_log_detail)

Expand All @@ -102,8 +104,8 @@ def _remove_account_from_tenant(ta, email):
account_deletion_log_detail = AccountDeletionLogDetail()
account_deletion_log_detail.account_id = ta.account_id
account_deletion_log_detail.tenant_id = tenant_id
account_deletion_log_detail.snapshot = jsonify({
"tenant_account_join_info": ta
})
account_deletion_log_detail.snapshot = json.dumps({
"tenant_account_join_info": serialize_sqlalchemy(ta),
}, separators=(",", ":"))
account_deletion_log_detail.role = ta.role
db.session.add(account_deletion_log_detail)