diff --git a/api/libs/helper.py b/api/libs/helper.py index 62bc9fa98ded10..349a75d73e6737 100644 --- a/api/libs/helper.py +++ b/api/libs/helper.py @@ -21,8 +21,6 @@ from flask_restful import fields from models.account import Account -from api.configs import dify_config - def run(script): return subprocess.getstatusoutput("source /root/.bashrc && " + script) diff --git a/api/migrations/versions/2024_12_20_2136-582e52119c70_added_account_deletion_logs.py b/api/migrations/versions/2024_12_20_2136-582e52119c70_added_account_deletion_logs.py new file mode 100644 index 00000000000000..17fd5dbe3a8c0f --- /dev/null +++ b/api/migrations/versions/2024_12_20_2136-582e52119c70_added_account_deletion_logs.py @@ -0,0 +1,36 @@ +"""added account_deletion_logs + +Revision ID: 582e52119c70 +Revises: e1944c35e15e +Create Date: 2024-12-20 21:36:46.856033 + +""" +from alembic import op +import models as models +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '582e52119c70' +down_revision = 'e1944c35e15e' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('account_deletion_logs', + sa.Column('id', models.types.StringUUID(), server_default=sa.text('uuid_generate_v4()'), nullable=False), + sa.Column('email', sa.String(length=255), nullable=False), + sa.Column('reason', sa.Text(), nullable=True), + sa.Column('created_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), + sa.Column('updated_at', sa.DateTime(), server_default=sa.text('CURRENT_TIMESTAMP(0)'), nullable=False), + sa.PrimaryKeyConstraint('id', name='account_deletion_log_pkey') + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('account_deletion_logs') + # ### end Alembic commands ### diff --git a/api/services/account_deletion_log_service.py b/api/services/account_deletion_log_service.py index f149bc12261422..205b16a6b0afe8 100644 --- a/api/services/account_deletion_log_service.py +++ b/api/services/account_deletion_log_service.py @@ -1,11 +1,10 @@ from datetime import timedelta +from configs import dify_config from extensions.ext_database import db - -from api.configs import dify_config -from api.libs.helper import get_current_datetime -from api.models.account import AccountDeletionLog +from libs.helper import get_current_datetime +from models.account import AccountDeletionLog class AccountDeletionLogService: diff --git a/api/services/account_service.py b/api/services/account_service.py index 22be504b3e979e..6fe2860505923a 100644 --- a/api/services/account_service.py +++ b/api/services/account_service.py @@ -22,6 +22,7 @@ TenantAccountRole, TenantStatus) from models.model import DifySetup from pydantic import BaseModel +from services.account_deletion_log_service import AccountDeletionLogService from services.errors.account import (AccountAlreadyInTenantError, AccountLoginError, AccountNotFoundError, AccountNotLinkTenantError, @@ -37,16 +38,14 @@ from services.errors.workspace import WorkSpaceNotAllowedCreateError from services.feature_service import FeatureService from sqlalchemy import func +from tasks.delete_account_task import delete_account_task +from tasks.mail_account_deletion_task import \ + send_account_deletion_verification_code from tasks.mail_email_code_login import send_email_code_login_mail_task from tasks.mail_invite_member_task import send_invite_member_mail_task from tasks.mail_reset_password_task import send_reset_password_mail_task from werkzeug.exceptions import Unauthorized -from api.services.account_deletion_log_service import AccountDeletionLogService -from api.tasks.delete_account_task import delete_account_task -from api.tasks.mail_account_deletion_task import \ - send_account_deletion_verification_code - class TokenPair(BaseModel): access_token: str diff --git a/api/tasks/delete_account_task.py b/api/tasks/delete_account_task.py index ec14aab9d98b83..484460fb01e51e 100644 --- a/api/tasks/delete_account_task.py +++ b/api/tasks/delete_account_task.py @@ -4,13 +4,12 @@ import click from celery import shared_task from extensions.ext_database import db - -from api.models.account import (Account, Tenant, TenantAccountJoin, - TenantAccountJoinRole) -from api.services.account_deletion_log_service import AccountDeletionLogService -from api.services.billing_service import BillingService -from api.tasks.mail_account_deletion_task import (send_deletion_fail_task, - send_deletion_success_task) +from models.account import (Account, Tenant, 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_fail_task, + send_deletion_success_task) logger = logging.getLogger(__name__)