From fca86873ada18381d07d63237f6e687853bdc144 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 26 Jun 2024 19:18:49 +0530 Subject: [PATCH] feat: provision to disable frappe-io auth dependency --- press/api/marketplace.py | 5 ++++- press/api/partner.py | 15 ++++++++++++++- press/press/doctype/invoice/invoice.py | 12 +++++++++++- .../doctype/press_settings/press_settings.json | 9 ++++++++- press/press/doctype/team/team.py | 8 ++++++-- .../team_deletion_request.py | 5 ++++- press/utils/billing.py | 4 ++++ 7 files changed, 51 insertions(+), 7 deletions(-) diff --git a/press/api/marketplace.py b/press/api/marketplace.py index ce18836237..a25b04e047 100644 --- a/press/api/marketplace.py +++ b/press/api/marketplace.py @@ -25,7 +25,7 @@ get_plans_for_app, ) from press.utils import get_app_tag, get_current_team, get_last_doc, unique -from press.utils.billing import get_frappe_io_connection +from press.utils.billing import get_frappe_io_connection, disabled_frappeio_auth @frappe.whitelist() @@ -961,6 +961,9 @@ def get_discount_percent(plan, discount=0.0): "Bronze": 30.0, } + if disabled_frappeio_auth(): + return discount + if team.erpnext_partner and frappe.get_value( "Marketplace App Plan", plan, "partner_discount" ): diff --git a/press/api/partner.py b/press/api/partner.py index 008e2dcc8c..d3e815771e 100644 --- a/press/api/partner.py +++ b/press/api/partner.py @@ -44,7 +44,20 @@ def update_partnership_date(team, partnership_date): @frappe.whitelist() def get_partner_details(partner_email): - from press.utils.billing import get_frappe_io_connection + from press.utils.billing import get_frappe_io_connection, disabled_frappeio_auth + + if disabled_frappeio_auth(): + return frappe._dict( + { + "email": "", + "partner_type": "", + "company_name": "", + "custom_ongoing_period_fc_invoice_contribution": "", + "custom_ongoing_period_enterprise_invoice_contribution": "", + "partner_name": "", + "custom_number_of_certified_members": "", + } + ) client = get_frappe_io_connection() data = client.get_doc( diff --git a/press/press/doctype/invoice/invoice.py b/press/press/doctype/invoice/invoice.py index 7867f79553..b9b17dc190 100644 --- a/press/press/doctype/invoice/invoice.py +++ b/press/press/doctype/invoice/invoice.py @@ -12,7 +12,11 @@ from frappe.model.document import Document from press.overrides import get_permission_query_conditions_for_doctype -from press.utils.billing import get_frappe_io_connection, convert_stripe_money +from press.utils.billing import ( + get_frappe_io_connection, + convert_stripe_money, + disabled_frappeio_auth, +) from press.api.client import dashboard_whitelist @@ -760,6 +764,9 @@ def create_invoice_on_frappeio(self): return try: + if disabled_frappeio_auth(): + return + team = frappe.get_doc("Team", self.team) address = ( frappe.get_doc("Address", team.billing_address) if team.billing_address else None @@ -814,6 +821,9 @@ def fetch_invoice_pdf(self): if self.frappe_invoice: from urllib.parse import urlencode + if disabled_frappeio_auth(): + return + client = self.get_frappeio_connection() print_format = frappe.db.get_single_value("Press Settings", "print_format") params = urlencode( diff --git a/press/press/doctype/press_settings/press_settings.json b/press/press/doctype/press_settings/press_settings.json index 0ee8dcae84..7568ef5a5e 100644 --- a/press/press/doctype/press_settings/press_settings.json +++ b/press/press/doctype/press_settings/press_settings.json @@ -43,6 +43,7 @@ "erpnext_api_secret", "column_break_38", "frappeio_authentication_section", + "disable_frappe_auth", "frappe_url", "frappeio_api_key", "column_break_39", @@ -1197,11 +1198,17 @@ "fieldtype": "Currency", "label": "Micro Debit Charge (USD)", "precision": "0" + }, + { + "default": "0", + "fieldname": "disable_frappe_auth", + "fieldtype": "Check", + "label": "Disable Frappe Auth" } ], "issingle": 1, "links": [], - "modified": "2024-06-25 16:39:20.923646", + "modified": "2024-06-26 16:39:20.923646", "modified_by": "Administrator", "module": "Press", "name": "Press Settings", diff --git a/press/press/doctype/team/team.py b/press/press/doctype/team/team.py index 70422ff9af..d230ca8635 100644 --- a/press/press/doctype/team/team.py +++ b/press/press/doctype/team/team.py @@ -21,6 +21,7 @@ get_frappe_io_connection, get_stripe, process_micro_debit_test_charge, + disabled_frappeio_auth, ) from press.utils.telemetry import capture from press.api.client import dashboard_whitelist @@ -443,7 +444,7 @@ def create_partner_referral_code(self): self.save(ignore_permissions=True) def get_partnership_start_date(self): - if frappe.flags.in_test: + if frappe.flags.in_test or disabled_frappeio_auth(): return frappe.utils.getdate() client = get_frappe_io_connection() @@ -607,7 +608,7 @@ def update_billing_details_on_draft_invoices(self): frappe.get_doc("Invoice", draft_invoice).save() def update_billing_details_on_frappeio(self): - if frappe.flags.in_install: + if frappe.flags.in_install or disabled_frappeio_auth(): return try: @@ -894,6 +895,9 @@ def billing_details(self, timezone=None): def get_partner_level(self): # fetch partner level from frappe.io + if disabled_frappeio_auth(): + return "", "" + client = get_frappe_io_connection() response = client.session.get( f"{client.url}/api/method/get_partner_level", diff --git a/press/press/doctype/team_deletion_request/team_deletion_request.py b/press/press/doctype/team_deletion_request/team_deletion_request.py index 4a6c92187c..6115654cf8 100644 --- a/press/press/doctype/team_deletion_request/team_deletion_request.py +++ b/press/press/doctype/team_deletion_request/team_deletion_request.py @@ -168,7 +168,10 @@ def delete_stripe_customer(self): @handle_exc def delete_data_on_frappeio(self): """Anonymize data on frappe.io""" - from press.utils.billing import get_frappe_io_connection + from press.utils.billing import get_frappe_io_connection, disabled_frappeio_auth + + if disabled_frappeio_auth(): + return client = get_frappe_io_connection() response = client.session.delete( diff --git a/press/utils/billing.py b/press/utils/billing.py index 9556a080e7..d9e68cf5f6 100644 --- a/press/utils/billing.py +++ b/press/utils/billing.py @@ -77,6 +77,10 @@ def get_erpnext_com_connection(): ) +def disabled_frappeio_auth(): + return frappe.db.get_single_value("Press Settings", "disable_frappe_auth", cache=True) + + def get_frappe_io_connection(): if hasattr(frappe.local, "press_frappeio_conn"): return frappe.local.press_frappeio_conn