Skip to content

Commit

Permalink
fix for google sign in issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GMayank0310 committed Jan 17, 2025
1 parent 238c76d commit 9a77482
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions kairon/shared/account/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@ def delete_account(account_id: int, email: str = None):
UserActivityLogger.add_log(
a_type=UserActivityType.delete_account.value
, account=account_id)
UserEmailConfirmation.objects().get(email=email).delete()

@staticmethod
def get_location_and_add_trusted_device(
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_test/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from slack_sdk.web.slack_response import SlackResponse

from kairon.shared.account.data_objects import UserActivityLog
from kairon.shared.account.data_objects import UserEmailConfirmation
from kairon.shared.actions.models import ActionParameterType, DbActionOperationType, DbQueryValueType
from kairon.shared.admin.data_objects import LLMSecret
from kairon.shared.callback.data_objects import CallbackLog, CallbackRecordStatusType
Expand Down Expand Up @@ -29530,7 +29531,7 @@ def _password_reset(*args, **kwargs):
"Authorization": pytest.token_type_delete + " " + pytest.access_token_delete
},
).json()

UserEmailConfirmation(email="[email protected]").save()
assert response["success"]
assert response["message"] == "Account deleted"
assert response["error_code"] == 0
Expand Down
39 changes: 30 additions & 9 deletions tests/unit_test/api/api_processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from kairon.exceptions import AppException
from kairon.idp.data_objects import IdpConfig
from kairon.idp.processor import IDPProcessor
from kairon.shared.account.data_objects import Feedback, BotAccess, User, Bot, Account, Organization, TrustedDevice
from kairon.shared.account.data_objects import Feedback, BotAccess, User, Bot, Account, Organization, TrustedDevice, UserEmailConfirmation
from kairon.shared.account.processor import AccountProcessor
from kairon.shared.admin.data_objects import BotSecrets
from kairon.shared.auth import Authentication, LoginSSOFactory
Expand Down Expand Up @@ -479,6 +479,8 @@ def test_delete_account_for_account_bots(self):
"last_name": "Test_Delete_Last",
"password": SecretStr("Welcome@1")
}
email=account.get('email')
UserEmailConfirmation(email=email).save()

loop = asyncio.new_event_loop()
user_detail, mail, link = loop.run_until_complete(AccountProcessor.account_setup(account_setup=account))
Expand All @@ -489,11 +491,13 @@ def test_delete_account_for_account_bots(self):
account_bots_before_delete = list(AccountProcessor.list_bots(pytest.deleted_account))

assert len(account_bots_before_delete) == 2
AccountProcessor.delete_account(pytest.deleted_account)
AccountProcessor.delete_account(pytest.deleted_account, email)

for bot in account_bots_before_delete:
with pytest.raises(DoesNotExist):
Bot.objects(id=bot['_id'], account=pytest.deleted_account, status=True).get()
with pytest.raises(DoesNotExist):
UserEmailConfirmation.objects(email=email).get()

def test_delete_account_for_shared_bot(self):
account = {
Expand All @@ -508,6 +512,9 @@ def test_delete_account_for_shared_bot(self):
user_detail, mail, link = loop.run_until_complete(
AccountProcessor.account_setup(account_setup=account))

email=account.get('email')
UserEmailConfirmation(email=email).save()

# Add shared bot
bot_response = AccountProcessor.add_bot("delete_account_shared_bot", user_detail['account'], "[email protected]", False)
bot_id = bot_response['_id'].__str__()
Expand All @@ -519,10 +526,12 @@ def test_delete_account_for_shared_bot(self):
assert len(accessors_before_delete) == 2
assert accessors_before_delete[0]['accessor_email'] == '[email protected]'
assert accessors_before_delete[1]['accessor_email'] == '[email protected]'
AccountProcessor.delete_account(pytest.deleted_account)
AccountProcessor.delete_account(pytest.deleted_account, email)
accessors_after_delete = list(AccountProcessor.list_bot_accessors(bot_id))
assert len(accessors_after_delete) == 0
assert len(list(Bot.objects(id=bot_id, account=user_detail['account'], status=True))) == 0
with pytest.raises(DoesNotExist):
UserEmailConfirmation.objects(email=email).get()

def test_delete_account_for_account(self):
account = {
Expand All @@ -532,18 +541,23 @@ def test_delete_account_for_account(self):
"last_name": "Test_Delete_Last",
"password": SecretStr("Welcome@1")
}
email=account.get('email')
UserEmailConfirmation(email=email).save()

loop = asyncio.new_event_loop()
user_detail, mail, link = loop.run_until_complete(
AccountProcessor.account_setup(account_setup=account))
pytest.deleted_account = user_detail['account'].__str__()

AccountProcessor.delete_account(pytest.deleted_account)
AccountProcessor.delete_account(pytest.deleted_account, email)
assert AccountProcessor.get_account(pytest.deleted_account)
assert not AccountProcessor.get_account(pytest.deleted_account).get('status')

with pytest.raises(AppException, match="Account does not exist!"):
AccountProcessor.delete_account(pytest.deleted_account)
AccountProcessor.delete_account(pytest.deleted_account, email)

with pytest.raises(DoesNotExist):
UserEmailConfirmation.objects(email=email).get()

def test_delete_account_for_user(self):
account = {
Expand All @@ -553,7 +567,8 @@ def test_delete_account_for_user(self):
"last_name": "Test_Delete_Last",
"password": SecretStr("Welcome@1")
}

email=account.get('email')
UserEmailConfirmation(email=email).save()
loop = asyncio.new_event_loop()
user_detail, mail, link = loop.run_until_complete(
AccountProcessor.account_setup(account_setup=account))
Expand All @@ -573,11 +588,14 @@ def test_delete_account_for_user(self):
assert User.objects(email__iexact="[email protected]", status=True).get()
assert User.objects(email__iexact="[email protected]", status=True).get()

AccountProcessor.delete_account(pytest.deleted_account)
AccountProcessor.delete_account(pytest.deleted_account, email)

assert User.objects(email__iexact="[email protected]", status=False)
assert User.objects(email__iexact="[email protected]", status=False)

with pytest.raises(DoesNotExist):
UserEmailConfirmation.objects(email=email).get()

def test_delete_account_again_add(self):
account = {
"account": "Test_Delete_Account",
Expand All @@ -586,19 +604,22 @@ def test_delete_account_again_add(self):
"last_name": "Test_Delete_Last",
"password": SecretStr("Welcome@1")
}

email=account.get('email')
UserEmailConfirmation(email=email).save()
loop = asyncio.new_event_loop()
user_detail, mail, link = loop.run_until_complete(
AccountProcessor.account_setup(account_setup=account))
pytest.deleted_account = user_detail['account'].__str__()

AccountProcessor.delete_account(pytest.deleted_account)
AccountProcessor.delete_account(pytest.deleted_account, email)

loop = asyncio.new_event_loop()
user_detail, mail, link = loop.run_until_complete(
AccountProcessor.account_setup(account_setup=account))
new_account_id = user_detail['account'].__str__()

with pytest.raises(DoesNotExist):
UserEmailConfirmation.objects(email=email).get()
assert new_account_id
assert AccountProcessor.get_account(new_account_id).get('status')
assert len(list(AccountProcessor.list_bots(new_account_id))) == 0
Expand Down

0 comments on commit 9a77482

Please sign in to comment.