Merge pull request #39048 from ankush/fix_invalid_apps
fix: invalid default app
This commit is contained in:
commit
b011532a7e
6 changed files with 26 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ frappe.ui.form.on("System Settings", {
|
|||
|
||||
frappe.xcall("frappe.apps.get_apps").then((r) => {
|
||||
let apps = r?.map((r) => r.name) || [];
|
||||
frm.set_df_property("default_app", "options", [" ", ...apps]);
|
||||
frm.set_df_property("default_app", "options", ["", ...apps]);
|
||||
});
|
||||
|
||||
frm.trigger("set_rounding_method_options");
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ frappe.ui.form.on("User", {
|
|||
|
||||
frappe.xcall("frappe.apps.get_apps").then((r) => {
|
||||
let apps = r?.map((r) => r.name) || [];
|
||||
frm.set_df_property("default_app", "options", [" ", ...apps]);
|
||||
frm.set_df_property("default_app", "options", ["", ...apps]);
|
||||
});
|
||||
|
||||
if (frm.is_new()) {
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ frappe.listview_settings["User"] = {
|
|||
|
||||
frappe.xcall("frappe.apps.get_apps").then((r) => {
|
||||
let apps = r?.map((r) => r.name) || [];
|
||||
default_app_field.options = [" ", ...apps].join("\n");
|
||||
default_app_field.options = ["", ...apps].join("\n");
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue