fix(workspace_sidebar): reexport after rename
This commit is contained in:
parent
8cd03ba19b
commit
bd39a0a7ca
2 changed files with 24 additions and 17 deletions
|
|
@ -50,32 +50,30 @@ class WorkspaceSidebar(Document):
|
|||
self.user.build_permissions()
|
||||
|
||||
def before_save(self):
|
||||
allow_export = self.app and not frappe.flags.in_import and frappe.conf.developer_mode
|
||||
if allow_export:
|
||||
self.export_sidebar()
|
||||
self.export_sidebar()
|
||||
self.set_module()
|
||||
|
||||
def export_sidebar(self):
|
||||
folder_path = create_directory_on_app_path("workspace_sidebar", self.app)
|
||||
file_path = os.path.join(folder_path, f"{frappe.scrub(self.title)}.json")
|
||||
doc_export = self.as_dict(no_nulls=True, no_private_properties=True)
|
||||
doc_export = strip_default_fields(self, doc_export)
|
||||
with open(file_path, "w+") as doc_file:
|
||||
doc_file.write(frappe.as_json(doc_export) + "\n")
|
||||
|
||||
def delete_file(self):
|
||||
folder_path = create_directory_on_app_path("workspace_sidebar", self.app)
|
||||
file_path = os.path.join(folder_path, f"{frappe.scrub(self.title)}.json")
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
allow_export = self.app and not frappe.flags.in_import and frappe.conf.developer_mode
|
||||
if allow_export:
|
||||
folder_path = create_directory_on_app_path("workspace_sidebar", self.app)
|
||||
file_path = os.path.join(folder_path, f"{frappe.scrub(self.title)}.json")
|
||||
doc_export = self.as_dict(no_nulls=True, no_private_properties=True)
|
||||
doc_export = strip_default_fields(self, doc_export)
|
||||
with open(file_path, "w+") as doc_file:
|
||||
doc_file.write(frappe.as_json(doc_export) + "\n")
|
||||
|
||||
def on_trash(self):
|
||||
if is_workspace_manager():
|
||||
if frappe.conf.developer_mode and self.app:
|
||||
self.delete_file()
|
||||
delete_file(self.app, self.title)
|
||||
else:
|
||||
frappe.throw(_("You need to be Workspace Manager to delete a public workspace."))
|
||||
|
||||
def after_rename(self, old, new, merge):
|
||||
delete_file(self.app, old)
|
||||
self.export_sidebar()
|
||||
|
||||
def is_item_allowed(self, name, item_type, allowed_workspaces):
|
||||
if frappe.session.user == "Administrator":
|
||||
return True
|
||||
|
|
@ -138,6 +136,13 @@ class WorkspaceSidebar(Document):
|
|||
return self.user.allow_modules
|
||||
|
||||
|
||||
def delete_file(app, title):
|
||||
folder_path = create_directory_on_app_path("workspace_sidebar", app)
|
||||
file_path = os.path.join(folder_path, f"{frappe.scrub(title)}.json")
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
||||
|
||||
def is_workspace_manager():
|
||||
return "Workspace Manager" in frappe.get_roles()
|
||||
|
||||
|
|
|
|||
|
|
@ -1001,7 +1001,9 @@ class DesktopIcon {
|
|||
} else {
|
||||
this.icon.on("click", function (event) {
|
||||
frappe.msgprint(
|
||||
"Icon is not correctly configured please check the workspace sidebar to it"
|
||||
__(
|
||||
"Icon is not correctly configured please check the workspace sidebar to it"
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue