diff --git a/frappe/desk/doctype/custom_html_block/custom_html_block.js b/frappe/desk/doctype/custom_html_block/custom_html_block.js
index 64b794ec44..49f50a72be 100644
--- a/frappe/desk/doctype/custom_html_block/custom_html_block.js
+++ b/frappe/desk/doctype/custom_html_block/custom_html_block.js
@@ -3,6 +3,18 @@
frappe.ui.form.on("Custom HTML Block", {
refresh(frm) {
+ if (
+ !has_common(frappe.user_roles, [
+ "Administrator",
+ "System Manager",
+ "Workspace Manager",
+ ])
+ ) {
+ frm.set_value("private", true);
+ } else {
+ frm.set_df_property("private", "read_only", false);
+ }
+
let wrapper = frm.fields_dict["preview"].wrapper;
wrapper.classList.add("mb-3");
diff --git a/frappe/desk/doctype/custom_html_block/custom_html_block.json b/frappe/desk/doctype/custom_html_block/custom_html_block.json
index 3fab5d7902..8fb06003ce 100644
--- a/frappe/desk/doctype/custom_html_block/custom_html_block.json
+++ b/frappe/desk/doctype/custom_html_block/custom_html_block.json
@@ -6,6 +6,7 @@
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
+ "private",
"preview_section",
"preview",
"html_section",
@@ -80,11 +81,19 @@
"fieldtype": "Table",
"label": "Roles",
"options": "Has Role"
+ },
+ {
+ "default": "0",
+ "depends_on": "eval: doc.private || doc.__unsaved",
+ "fieldname": "private",
+ "fieldtype": "Check",
+ "label": "Private",
+ "read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2023-05-29 18:28:28.326843",
+ "modified": "2023-05-30 14:33:31.994738",
"modified_by": "Administrator",
"module": "Desk",
"name": "Custom HTML Block",
diff --git a/frappe/desk/doctype/custom_html_block/custom_html_block.py b/frappe/desk/doctype/custom_html_block/custom_html_block.py
index 7f85c2db5f..2b65ceeaf4 100644
--- a/frappe/desk/doctype/custom_html_block/custom_html_block.py
+++ b/frappe/desk/doctype/custom_html_block/custom_html_block.py
@@ -1,9 +1,25 @@
# Copyright (c) 2023, Frappe Technologies and contributors
# For license information, please see license.txt
-# import frappe
+import frappe
from frappe.model.document import Document
+from frappe.query_builder.utils import DocType
class CustomHTMLBlock(Document):
pass
+
+
+@frappe.whitelist()
+def get_custom_blocks_for_user(doctype, txt, searchfield, start, page_len, filters):
+ # return logged in users private blocks and all public blocks
+ customHTMLBlock = DocType("Custom HTML Block")
+
+ condition_query = frappe.qb.get_query(customHTMLBlock)
+
+ return (
+ condition_query.select(customHTMLBlock.name).where(
+ (customHTMLBlock.private == 0)
+ | ((customHTMLBlock.owner == frappe.session.user) & (customHTMLBlock.private == 1))
+ )
+ ).run()
diff --git a/frappe/public/js/frappe/widgets/widget_dialog.js b/frappe/public/js/frappe/widgets/widget_dialog.js
index 4f200f390f..51138a7dc4 100644
--- a/frappe/public/js/frappe/widgets/widget_dialog.js
+++ b/frappe/public/js/frappe/widgets/widget_dialog.js
@@ -715,6 +715,11 @@ class CustomBlockDialog extends WidgetDialog {
label: "Custom Block Name",
options: "Custom HTML Block",
reqd: 1,
+ get_query: () => {
+ return {
+ query: "frappe.desk.doctype.custom_html_block.custom_html_block.get_custom_blocks_for_user",
+ };
+ },
},
];
}