mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
Send account deletion codes via POST
This commit is contained in:
@ -287,7 +287,7 @@ class AccountDeleteVerifyApi(Resource):
|
|||||||
@setup_required
|
@setup_required
|
||||||
@login_required
|
@login_required
|
||||||
@account_initialization_required
|
@account_initialization_required
|
||||||
def get(self):
|
def post(self):
|
||||||
if not isinstance(current_user, Account):
|
if not isinstance(current_user, Account):
|
||||||
raise ValueError("Invalid user account")
|
raise ValueError("Invalid user account")
|
||||||
account = current_user
|
account = current_user
|
||||||
|
|||||||
@ -0,0 +1,63 @@
|
|||||||
|
import inspect
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
from controllers.console.workspace import account as account_module
|
||||||
|
from controllers.console.workspace.account import AccountDeleteVerifyApi
|
||||||
|
from models.account import Account
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def flask_app():
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config["TESTING"] = True
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def account_user():
|
||||||
|
user = Account(name="Tester", email="tester@example.com")
|
||||||
|
user.id = "user-id"
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
class TestAccountDeleteVerifyApi:
|
||||||
|
def test_post_generates_token_and_sends_email(self, flask_app, account_user, monkeypatch):
|
||||||
|
generate_mock = MagicMock(return_value=("token", "code"))
|
||||||
|
send_mock = MagicMock()
|
||||||
|
|
||||||
|
monkeypatch.setattr(account_module, "current_user", account_user, raising=False)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
account_module.AccountService,
|
||||||
|
"generate_account_deletion_verification_code",
|
||||||
|
generate_mock,
|
||||||
|
raising=False,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
account_module.AccountService,
|
||||||
|
"send_account_deletion_verification_email",
|
||||||
|
send_mock,
|
||||||
|
raising=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
controller = AccountDeleteVerifyApi()
|
||||||
|
handler = inspect.unwrap(AccountDeleteVerifyApi.post)
|
||||||
|
|
||||||
|
with flask_app.test_request_context("/account/delete/verify", method="POST", json={}):
|
||||||
|
response = handler(controller)
|
||||||
|
|
||||||
|
assert response == {"result": "success", "data": "token"}
|
||||||
|
generate_mock.assert_called_once_with(account_user)
|
||||||
|
send_mock.assert_called_once_with(account_user, "code")
|
||||||
|
|
||||||
|
def test_post_requires_account_user(self, flask_app, monkeypatch):
|
||||||
|
monkeypatch.setattr(account_module, "current_user", object(), raising=False)
|
||||||
|
|
||||||
|
controller = AccountDeleteVerifyApi()
|
||||||
|
handler = inspect.unwrap(AccountDeleteVerifyApi.post)
|
||||||
|
|
||||||
|
with flask_app.test_request_context("/account/delete/verify", method="POST", json={}):
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
handler(controller)
|
||||||
@ -375,7 +375,7 @@ export const verifyWebAppResetPasswordCode = (body: { email: string; code: strin
|
|||||||
post<CommonResponse & { is_valid: boolean; token: string }>('/forgot-password/validity', { body }, { isPublicAPI: true })
|
post<CommonResponse & { is_valid: boolean; token: string }>('/forgot-password/validity', { body }, { isPublicAPI: true })
|
||||||
|
|
||||||
export const sendDeleteAccountCode = () =>
|
export const sendDeleteAccountCode = () =>
|
||||||
get<CommonResponse & { data: string }>('/account/delete/verify')
|
post<CommonResponse & { data: string }>('/account/delete/verify', { body: {} })
|
||||||
|
|
||||||
export const verifyDeleteAccountCode = (body: { code: string; token: string }) =>
|
export const verifyDeleteAccountCode = (body: { code: string; token: string }) =>
|
||||||
post<CommonResponse & { is_valid: boolean }>('/account/delete', { body })
|
post<CommonResponse & { is_valid: boolean }>('/account/delete', { body })
|
||||||
|
|||||||
Reference in New Issue
Block a user