From d601256ffd510d073de378c38838e78372dbb672 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:27:50 +0530 Subject: [PATCH] feat: move secret_key creation logic to code (#2118) --- press/press/doctype/subscription/subscription.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/press/press/doctype/subscription/subscription.py b/press/press/doctype/subscription/subscription.py index 9879a86fd4..af41eb9071 100644 --- a/press/press/doctype/subscription/subscription.py +++ b/press/press/doctype/subscription/subscription.py @@ -83,6 +83,14 @@ def get_list_query(query, **list_args): return query.run(as_dict=True) + def before_validate(self): + if not self.secret_key and self.document_type == "Marketplace App": + self.secret_key = frappe.utils.generate_hash(length=40) + if not frappe.db.exists("Site Config Key", {"key": f"sk_{self.document_name}"}): + frappe.get_doc( + doctype="Site Config Key", internal=True, key=f"sk_{self.document_name}" + ).insert(ignore_permissions=True) + def validate(self): self.validate_duplicate()