Files
Makap/makap_backend/makap_backend/portal_shortcut.py
T
2026-10-05 16:04:29 +03:00

39 lines
1.2 KiB
Python

import json
import frappe
LABEL = "MAKAP Portal"
URL = "/makap-portal"
def ensure_portal_shortcut():
names = frappe.get_all(
"Workspace",
or_filters=[["name", "like", "MAKAP%"], ["label", "like", "MAKAP%"], ["title", "like", "MAKAP%"]],
pluck="name",
)
for name in names:
ws = frappe.get_doc("Workspace", name)
if not any(s.label == LABEL for s in ws.shortcuts):
ws.append("shortcuts", {"label": LABEL, "type": "URL", "url": URL})
try:
blocks = json.loads(ws.content or "[]")
except ValueError:
blocks = []
blocks = [
b for b in blocks
if not (b.get("type") == "shortcut" and b.get("data", {}).get("shortcut_name") == LABEL)
]
block = {
"id": frappe.generate_hash(length=10),
"type": "shortcut",
"data": {"shortcut_name": LABEL, "col": 3},
}
blocks.insert(1 if blocks else 0, block)
ws.content = json.dumps(blocks)
ws.flags.ignore_permissions = True
ws.save()
print("Portal shortcut set on workspace: " + name)
frappe.db.commit()
frappe.clear_cache()