Skip to content

Commit

Permalink
fix: allow creation of workspace based on desk role perms
Browse files Browse the repository at this point in the history
(cherry picked from commit 61807dd)

# Conflicts:
#	frappe/desk/doctype/workspace/workspace.json
  • Loading branch information
GursheenK authored and mergify[bot] committed Jun 4, 2024
1 parent c34c1d1 commit fb898f7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
6 changes: 5 additions & 1 deletion frappe/desk/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,11 @@ def get_workspace_sidebar_items():
pages = [frappe.get_doc("Workspace", "Welcome Workspace").as_dict()]
pages[0]["label"] = _("Welcome Workspace")

return {"pages": pages, "has_access": has_access}
return {
"pages": pages,
"has_access": has_access,
"has_create_access": frappe.has_permission(doctype="Workspace", ptype="create"),
}


def get_table_with_counts():
Expand Down
16 changes: 16 additions & 0 deletions frappe/desk/doctype/workspace/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@
],
"in_create": 1,
"links": [],
<<<<<<< HEAD
"modified": "2023-08-25 15:04:03.419848",
=======
"modified": "2024-05-30 17:30:36.791171",
>>>>>>> 61807dda71 (fix: allow creation of workspace based on desk role perms)
"modified_by": "Administrator",
"module": "Desk",
"name": "Workspace",
Expand All @@ -237,6 +241,18 @@
"role": "Workspace Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Desk User",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
Expand Down
10 changes: 7 additions & 3 deletions frappe/desk/doctype/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class Workspace(Document):
if TYPE_CHECKING:
from frappe.core.doctype.has_role.has_role import HasRole
from frappe.desk.doctype.workspace_chart.workspace_chart import WorkspaceChart
from frappe.desk.doctype.workspace_custom_block.workspace_custom_block import (
WorkspaceCustomBlock,
)
from frappe.desk.doctype.workspace_custom_block.workspace_custom_block import WorkspaceCustomBlock
from frappe.desk.doctype.workspace_link.workspace_link import WorkspaceLink
from frappe.desk.doctype.workspace_number_card.workspace_number_card import WorkspaceNumberCard
from frappe.desk.doctype.workspace_quick_list.workspace_quick_list import WorkspaceQuickList
Expand Down Expand Up @@ -251,6 +249,12 @@ def new_page(new_page):
):
frappe.throw(_("Cannot create private workspace of other users"), frappe.PermissionError)

elif not frappe.has_permission(doctype="Workspace", ptype="create"):
frappe.flags.error_message = _("User {0} does not have the permission to create a Workspace.").format(
frappe.bold(frappe.session.user)
)
raise frappe.PermissionError

doc = frappe.new_doc("Workspace")
doc.title = page.get("title")
doc.icon = page.get("icon")
Expand Down
8 changes: 5 additions & 3 deletions frappe/public/js/frappe/views/workspace/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ frappe.views.Workspace = class Workspace {
this.cached_pages = $.extend(true, {}, this.sidebar_pages);
this.all_pages = this.sidebar_pages.pages;
this.has_access = this.sidebar_pages.has_access;
this.has_create_access = this.sidebar_pages.has_create_access;

this.all_pages.forEach((page) => {
page.is_editable = !page.public || this.has_access;
Expand Down Expand Up @@ -473,9 +474,10 @@ frappe.views.Workspace = class Workspace {
"es-line-edit"
);
// need to add option for icons in inner buttons as well
this.page.add_inner_button(__("Create Workspace"), () => {
this.initialize_new_page();
});
if (this.has_create_access)
this.page.add_inner_button(__("Create Workspace"), () => {
this.initialize_new_page(true);
});
}

initialize_editorjs_undo() {
Expand Down

0 comments on commit fb898f7

Please sign in to comment.