|
|
@@ -2,12 +2,11 @@ from __future__ import unicode_literals |
|
|
|
import frappe |
|
|
|
from frappe.exceptions import DataError |
|
|
|
from frappe.utils.password import get_decrypted_password |
|
|
|
import json |
|
|
|
|
|
|
|
app_list = [ |
|
|
|
{"app_name": "razorpay_integration", "service_name": "Razorpay", "doctype": "Razorpay Settings", "remove": True}, |
|
|
|
{"app_name": "paypal_integration", "service_name": "PayPal", "doctype": "PayPal Settings", "remove": True}, |
|
|
|
{"app_name": "frappe", "service_name": "Dropbox Integration", "doctype": "Dropbox Backup", "remove": False} |
|
|
|
{"app_name": "frappe", "service_name": "Dropbox", "doctype": "Dropbox Backup", "remove": False} |
|
|
|
] |
|
|
|
|
|
|
|
def execute(): |
|
|
@@ -17,24 +16,23 @@ def execute(): |
|
|
|
|
|
|
|
for app_details in app_list: |
|
|
|
if app_details["app_name"] in installed_apps: |
|
|
|
try: |
|
|
|
setup_integration_service(app_details) |
|
|
|
settings = get_app_settings(app_details) |
|
|
|
if app_details["remove"]: |
|
|
|
uninstall_app(app_details["app_name"]) |
|
|
|
|
|
|
|
try: |
|
|
|
setup_integration_service(app_details, settings) |
|
|
|
except DataError: |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
if app_details["remove"]: |
|
|
|
uninstall_app(app_details["app_name"]) |
|
|
|
|
|
|
|
frappe.delete_doc("DocType", "Dropbox Backup") |
|
|
|
|
|
|
|
def setup_integration_service(app_details): |
|
|
|
settings = get_app_settings(app_details) |
|
|
|
|
|
|
|
def setup_integration_service(app_details, settings=None): |
|
|
|
if not settings: |
|
|
|
raise DataError |
|
|
|
|
|
|
|
setup_service_settings(app_details["service_name"], settings) |
|
|
|
|
|
|
|
if frappe.db.exists("Integration Service", app_details["service_name"]): |
|
|
|
integration_service = frappe.get_doc("Integration Service", app_details["service_name"]) |
|
|
|
else: |
|
|
@@ -42,22 +40,19 @@ def setup_integration_service(app_details): |
|
|
|
integration_service.service = app_details["service_name"] |
|
|
|
|
|
|
|
integration_service.enabled = 1 |
|
|
|
integration_service.custom_settings_json = json.dumps(settings) if settings else '' |
|
|
|
integration_service.flags.ignore_mandatory = True |
|
|
|
integration_service.save(ignore_permissions=True) |
|
|
|
|
|
|
|
def get_app_settings(app_details): |
|
|
|
from frappe.integration_broker.doctype.integration_service.integration_service import get_integration_controller |
|
|
|
|
|
|
|
parameters = {} |
|
|
|
doctype = docname = app_details["doctype"] |
|
|
|
|
|
|
|
app_settings = get_parameters(app_details) |
|
|
|
settings = app_settings["settings"] |
|
|
|
|
|
|
|
controller = get_integration_controller(app_details["service_name"]) |
|
|
|
controller = frappe.get_meta("{0} Settings".format(app_details["service_name"])) |
|
|
|
|
|
|
|
for d in controller.parameters_template: |
|
|
|
for d in controller.fields: |
|
|
|
if settings.get(d.fieldname): |
|
|
|
if ''.join(set(settings.get(d.fieldname))) == '*': |
|
|
|
setattr(settings, d.fieldname, get_decrypted_password(doctype, docname, d.fieldname, raise_exception=True)) |
|
|
@@ -86,7 +81,7 @@ def get_parameters(app_details): |
|
|
|
else: |
|
|
|
return {"settings": frappe.get_doc(app_details["doctype"])} |
|
|
|
|
|
|
|
elif app_details["service_name"] == "Dropbox Integration": |
|
|
|
elif app_details["service_name"] == "Dropbox": |
|
|
|
doc = frappe.db.get_value(app_details["doctype"], None, |
|
|
|
["dropbox_access_key", "dropbox_access_secret", "upload_backups_to_dropbox"], as_dict=1) |
|
|
|
|
|
|
@@ -102,3 +97,11 @@ def get_parameters(app_details): |
|
|
|
"backup_frequency": doc.upload_backups_to_dropbox |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
def setup_service_settings(service_name, settings): |
|
|
|
frappe.reload_doc("integrations", "doctype", "{0}_settings".format(service_name.lower())) |
|
|
|
|
|
|
|
service_doc = frappe.get_doc("{0} Settings".format(service_name)) |
|
|
|
service_doc.update(settings) |
|
|
|
service_doc.flags.ignore_mandatory = True |
|
|
|
service_doc.save(ignore_permissions=True) |