mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 20:48:01 +08:00
improve active email lower
This commit is contained in:
parent
0fab37edbc
commit
2e874313ec
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask_restx import Resource, fields
|
from flask_restx import Resource, fields
|
||||||
from pydantic import BaseModel, Field, field_validator
|
from pydantic import BaseModel, Field, field_validator
|
||||||
@ -63,10 +65,9 @@ class ActivateCheckApi(Resource):
|
|||||||
args = ActivateCheckQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore
|
args = ActivateCheckQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore
|
||||||
|
|
||||||
workspaceId = args.workspace_id
|
workspaceId = args.workspace_id
|
||||||
reg_email = args.email.lower() if args.email else None
|
|
||||||
token = args.token
|
token = args.token
|
||||||
|
|
||||||
invitation = RegisterService.get_invitation_if_token_valid(workspaceId, reg_email, token)
|
invitation = _get_invitation_with_case_fallback(workspaceId, args.email, token)
|
||||||
if invitation:
|
if invitation:
|
||||||
data = invitation.get("data", {})
|
data = invitation.get("data", {})
|
||||||
tenant = invitation.get("tenant", None)
|
tenant = invitation.get("tenant", None)
|
||||||
@ -101,12 +102,12 @@ class ActivateApi(Resource):
|
|||||||
def post(self):
|
def post(self):
|
||||||
args = ActivatePayload.model_validate(console_ns.payload)
|
args = ActivatePayload.model_validate(console_ns.payload)
|
||||||
|
|
||||||
normalized_email = args.email.lower() if args.email else None
|
normalized_request_email = args.email.lower() if args.email else None
|
||||||
invitation = RegisterService.get_invitation_if_token_valid(args.workspace_id, normalized_email, args.token)
|
invitation = _get_invitation_with_case_fallback(args.workspace_id, args.email, args.token)
|
||||||
if invitation is None:
|
if invitation is None:
|
||||||
raise AlreadyActivateError()
|
raise AlreadyActivateError()
|
||||||
|
|
||||||
RegisterService.revoke_token(args.workspace_id, normalized_email, args.token)
|
RegisterService.revoke_token(args.workspace_id, normalized_request_email, args.token)
|
||||||
|
|
||||||
account = invitation["account"]
|
account = invitation["account"]
|
||||||
account.name = args.name
|
account.name = args.name
|
||||||
@ -121,3 +122,13 @@ class ActivateApi(Resource):
|
|||||||
token_pair = AccountService.login(account, ip_address=extract_remote_ip(request))
|
token_pair = AccountService.login(account, ip_address=extract_remote_ip(request))
|
||||||
|
|
||||||
return {"result": "success", "data": token_pair.model_dump()}
|
return {"result": "success", "data": token_pair.model_dump()}
|
||||||
|
|
||||||
|
|
||||||
|
def _get_invitation_with_case_fallback(
|
||||||
|
workspace_id: str | None, email: str | None, token: str
|
||||||
|
) -> dict[str, Any] | None:
|
||||||
|
invitation = RegisterService.get_invitation_if_token_valid(workspace_id, email, token)
|
||||||
|
if invitation or not email or email == email.lower():
|
||||||
|
return invitation
|
||||||
|
normalized_email = email.lower()
|
||||||
|
return RegisterService.get_invitation_if_token_valid(workspace_id, normalized_email, token)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ This module tests the account activation mechanism including:
|
|||||||
- Initial login after activation
|
- Initial login after activation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, call, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
@ -142,7 +142,10 @@ class TestActivateCheckApi:
|
|||||||
response = api.get()
|
response = api.get()
|
||||||
|
|
||||||
assert response["is_valid"] is True
|
assert response["is_valid"] is True
|
||||||
mock_get_invitation.assert_called_once_with("workspace-123", "invitee@example.com", "valid_token")
|
assert mock_get_invitation.call_args_list == [
|
||||||
|
call("workspace-123", "Invitee@Example.com", "valid_token"),
|
||||||
|
call("workspace-123", "invitee@example.com", "valid_token"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class TestActivateApi:
|
class TestActivateApi:
|
||||||
@ -504,5 +507,8 @@ class TestActivateApi:
|
|||||||
response = api.post()
|
response = api.post()
|
||||||
|
|
||||||
assert response["result"] == "success"
|
assert response["result"] == "success"
|
||||||
mock_get_invitation.assert_called_once_with("workspace-123", "invitee@example.com", "valid_token")
|
assert mock_get_invitation.call_args_list == [
|
||||||
|
call("workspace-123", "Invitee@Example.com", "valid_token"),
|
||||||
|
call("workspace-123", "invitee@example.com", "valid_token"),
|
||||||
|
]
|
||||||
mock_revoke_token.assert_called_once_with("workspace-123", "invitee@example.com", "valid_token")
|
mock_revoke_token.assert_called_once_with("workspace-123", "invitee@example.com", "valid_token")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user