diff --git a/frappe/apps.py b/frappe/apps.py index 0dd30b4340..fdbb5c74f3 100644 --- a/frappe/apps.py +++ b/frappe/apps.py @@ -53,6 +53,8 @@ def get_apps(): def get_route(app_name): + if app_name not in frappe.get_installed_apps(): + return "/apps" # Invalid defaults apps = frappe.get_hooks("add_to_apps_screen", app_name=app_name) app = next((app for app in apps if app.get("name") == app_name), None) return app.get("route") if app and app.get("route") else "/apps" @@ -89,6 +91,9 @@ def get_default_path(): @frappe.whitelist() def set_app_as_default(app_name: str): + if app_name not in frappe.get_installed_apps(): + frappe.throw(_("App {} is not installed").format(frappe.bold(app_name))) + if frappe.db.get_value("User", frappe.session.user, "default_app") == app_name: frappe.db.set_value("User", frappe.session.user, "default_app", "") else: diff --git a/frappe/core/doctype/user/test_user.py b/frappe/core/doctype/user/test_user.py index a091eeff2e..f6ee4ac838 100644 --- a/frappe/core/doctype/user/test_user.py +++ b/frappe/core/doctype/user/test_user.py @@ -466,6 +466,21 @@ class TestUser(IntegrationTestCase): sorted(m.get("module_name") for m in get_modules_from_all_apps()), ) + def test_default_app(self): + from frappe.apps import get_default_path + + with test_user(roles=["System Manager"]) as user: + user.default_app = "next_erp" + user.save() + self.assertFalse(user.default_app) + + frappe.set_user(user.name) + user.db_set("default_app", "next_erp") + user.reload() + self.assertTrue(user.default_app) + + get_default_path() # defaults will also trigger hooks logic + @IntegrationTestCase.change_settings("System Settings", reset_password_link_expiry_duration=1) def test_reset_password_link_expiry(self): new_password = "new_password" diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index d62c68dc82..2e5adfb0f9 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -248,6 +248,9 @@ class User(Document): if self.language == "Loading...": self.language = None + if self.default_app and self.default_app not in frappe.get_installed_apps(): + self.default_app = "" + if (self.name not in ["Administrator", "Guest"]) and (not self.get_social_login_userid("frappe")): self.set_social_login_userid("frappe", frappe.generate_hash(length=39))