Skip to content

Commit

Permalink
feat: provision to disable frappe-io auth dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh6790 committed Jun 26, 2024
1 parent b98ffc8 commit fca8687
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
5 changes: 4 additions & 1 deletion press/api/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
):
Expand Down
15 changes: 14 additions & 1 deletion press/api/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 11 additions & 1 deletion press/press/doctype/invoice/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion press/press/doctype/press_settings/press_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"erpnext_api_secret",
"column_break_38",
"frappeio_authentication_section",
"disable_frappe_auth",
"frappe_url",
"frappeio_api_key",
"column_break_39",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions press/press/doctype/team/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions press/utils/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fca8687

Please sign in to comment.