Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workspace): Allow user to choose a default workspace #25257

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions frappe/core/doctype/user/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
frappe.ui.form.on("User", {
setup: function (frm) {
frm.set_query("default_workspace", () => {
return {
filters: {
for_user: ["in", [null, frappe.session.user]],
title: ["!=", "Welcome Workspace"],
},
};
});
},
before_load: function (frm) {
let update_tz_options = function () {
frm.fields_dict.time_zone.set_data(frappe.all_timezones);
Expand Down
17 changes: 16 additions & 1 deletion frappe/core/doctype/user/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"send_me_a_copy",
"allowed_in_mentions",
"user_emails",
"workspace_section",
"default_workspace",
"sb2",
"defaults",
"sb3",
Expand Down Expand Up @@ -711,6 +713,19 @@
"label": "Role Profiles",
"options": "User Role Profile",
"permlevel": 1
},
{
"description": "If left empty, the default workspace will be the last visited workspace",
"fieldname": "default_workspace",
"fieldtype": "Link",
"label": "Default Workspace",
"options": "Workspace"
},
{
"collapsible": 1,
"fieldname": "workspace_section",
"fieldtype": "Section Break",
"label": "Workspace"
}
],
"icon": "fa fa-user",
Expand Down Expand Up @@ -773,7 +788,7 @@
"link_fieldname": "user"
}
],
"modified": "2024-02-11 13:16:29.574666",
"modified": "2024-03-20 17:15:19.200383",
"modified_by": "Administrator",
"module": "Core",
"name": "User",
Expand Down
1 change: 1 addition & 0 deletions frappe/core/doctype/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class User(Document):
birth_date: DF.Date | None
block_modules: DF.Table[BlockModule]
bypass_restrict_ip_check_if_2fa_enabled: DF.Check
default_workspace: DF.Link | None
defaults: DF.Table[DefaultValue]
desk_theme: DF.Literal["Light", "Dark", "Automatic"]
document_follow_frequency: DF.Literal["Hourly", "Daily", "Weekly"]
Expand Down
7 changes: 6 additions & 1 deletion frappe/public/js/frappe/views/workspace/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ frappe.views.Workspace = class Workspace {
get_page_to_show() {
let default_page;

if (
if (frappe.boot.user.default_workspace) {
default_page = {
name: frappe.boot.user.default_workspace.name,
public: frappe.boot.user.default_workspace.public,
};
} else if (
localStorage.current_page &&
this.all_pages.filter((page) => page.title == localStorage.current_page).length != 0
) {
Expand Down
5 changes: 5 additions & 0 deletions frappe/utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,18 @@ def load_user(self):
"send_me_a_copy",
"user_type",
"onboarding_status",
"default_workspace",
],
as_dict=True,
)

if not self.can_read:
self.build_permissions()

if d.get("default_workspace"):
public = frappe.get_cached_value("Workspace", d.default_workspace, "public")
d.default_workspace = {"name": d.default_workspace, "public": public}

d.name = self.name
d.onboarding_status = frappe.parse_json(d.onboarding_status)
d.roles = self.get_roles()
Expand Down