seitime-frappe/frappe/utils/subscription.py
mergify[bot] 939d926b91
feat: Added Subscription Banner for remotely logging into FrappeCloud dashboard from site (backport #18263) (#18281)
* feat: Added Subscription Banner for remotely logging into FrappeCloud dashboard from site (#18263)

* feat: added Subscription Banner and Manage Subscription button

* feat[patch]: added a patch for adding `Manage Subscription` button in
navbar_settings

* chore: removed console ;)

* refactor: make the `Manage Subscription` navbar item optional

* keep it hidden by default, only show when the site configs are present

* style: prettier, isort and stuff

* chore: handling null responses, translation and refactored patch

* fix: correct index reset

* perf: reduce network/db calls

If not sys manager then why make a request?

* fix: removed network call and added subscription_expiry to boot process

* chore: added enable_manage_susbcriptions as daily background job and refactored patch

* chore: added hook to hooks.py

* this looks clean enough, also don't have insert for child tables ;)

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit 68f315d372cc8c6e41f2aabda61eba0d42dcf6e4)

# Conflicts:
#	frappe/patches.txt

* chore: conflicts

* style: format

[skip ci]

Co-authored-by: Rutwik Hiwalkar <50401596+rutwikhdev@users.noreply.github.com>
2022-10-03 16:41:12 +05:30

35 lines
740 B
Python

import json
import requests
import frappe
@frappe.whitelist()
def remote_login():
try:
login_url = frappe.conf.subscription["login_url"]
if frappe.conf.subscription["expiry"] and login_url:
resp = requests.post(login_url)
if resp.status_code != 200:
return
return json.loads(resp.text)["message"]
except Exception:
return False
return False
def enable_manage_subscription():
if not frappe.db.exists("Navbar Item", {"item_label": "Manage Subscriptions"}):
return
navbar_item, hidden = frappe.db.get_value(
"Navbar Item", {"item_label": "Manage Subscriptions"}, ["name", "hidden"]
)
if navbar_item and hidden:
doc = frappe.get_cached_doc("Navbar Item", navbar_item)
doc.hidden = False
doc.save()