From b5c81cc0152bc7a365f0f2f82d41ab5803d9b1bf Mon Sep 17 00:00:00 2001 From: phot0n Date: Sun, 15 Jan 2023 21:01:03 +0530 Subject: [PATCH] chore(patch): disable all email accounts with oauth mechanism --- .../email/doctype/email_account/email_account.py | 2 +- frappe/patches.txt | 1 + .../v14_0/disable_email_accounts_with_oauth.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 frappe/patches/v14_0/disable_email_accounts_with_oauth.py diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index d20dd995ba..f754869938 100755 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -911,7 +911,7 @@ def remove_user_email_inbox(email_account): @frappe.whitelist() def set_email_password(email_account, password): account = frappe.get_doc("Email Account", email_account) - if account.awaiting_password and not account.auth_method == "OAuth": + if account.awaiting_password and account.auth_method != "OAuth": account.awaiting_password = 0 account.password = password try: diff --git a/frappe/patches.txt b/frappe/patches.txt index cf1e509e78..b345e7f106 100644 --- a/frappe/patches.txt +++ b/frappe/patches.txt @@ -198,6 +198,7 @@ frappe.patches.v14_0.delete_payment_gateways frappe.patches.v15_0.remove_event_streaming frappe.patches.v15_0.remove_prepared_report_settings_from_system_settings frappe.patches.v15_0.copy_disable_prepared_report_to_prepared_report +frappe.patches.v14_0.disable_email_accounts_with_oauth [post_model_sync] frappe.patches.v14_0.drop_data_import_legacy diff --git a/frappe/patches/v14_0/disable_email_accounts_with_oauth.py b/frappe/patches/v14_0/disable_email_accounts_with_oauth.py new file mode 100644 index 0000000000..27c322c60a --- /dev/null +++ b/frappe/patches/v14_0/disable_email_accounts_with_oauth.py @@ -0,0 +1,15 @@ +import click + +import frappe + + +def execute(): + # Setting awaiting password to 1 for email accounts where Oauth is enabled. + # This is done so that people can resetup their email accounts with connected app mechanism. + doctype = frappe.qb.DocType("Email Account") + frappe.qb.update(doctype).set(doctype.awaiting_password, 1).where(doctype.auth_mehtod == "OAuth") + + click.secho( + "Email Accounts with auth method as OAuth have been disabled." + "Please re-setup your OAuth based email accounts with the connected app mechanism to re-enable them." + )