diff --git a/.flake8 b/.flake8 index 2de7a154c9..e783fbbeb3 100644 --- a/.flake8 +++ b/.flake8 @@ -69,6 +69,7 @@ ignore = F841, E713, E712, + B028, max-line-length = 200 exclude=,test_*.py diff --git a/frappe/__init__.py b/frappe/__init__.py index b7fd117868..2cf833ea57 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -23,7 +23,7 @@ import click from werkzeug.local import Local, release_local from frappe.query_builder import ( - get_qb_engine, + get_query, get_query_builder, patch_query_aggregation, patch_query_execute, @@ -244,7 +244,7 @@ def init(site: str, sites_path: str = ".", new_site: bool = False) -> None: local.session = _dict() local.dev_server = _dev_server local.qb = get_query_builder(local.conf.db_type or "mariadb") - local.qb.engine = get_qb_engine() + local.qb.get_query = get_query setup_module_map() if not _qb_patched.get(local.conf.db_type): @@ -770,7 +770,12 @@ def is_whitelisted(method): is_guest = session["user"] == "Guest" if method not in whitelisted or is_guest and method not in guest_methods: - throw(_("Not permitted"), PermissionError) + summary = _("You are not permitted to access this resource.") + detail = _("Function {0} is not whitelisted.").format( + bold(f"{method.__module__}.{method.__name__}") + ) + msg = f"
{summary}{detail}
" + throw(msg, PermissionError, title="Method Not Allowed") if is_guest and method not in xss_safe_methods: # strictly sanitize form_dict @@ -1399,23 +1404,37 @@ def get_all_apps(with_internal_apps=True, sites_path=None): @request_cache -def get_installed_apps(sort=False, frappe_last=False): - """Get list of installed apps in current site.""" +def get_installed_apps(sort=False, frappe_last=False, *, _ensure_on_bench=False): + """ + Get list of installed apps in current site. + + :param sort: [DEPRECATED] Sort installed apps based on the sequence in sites/apps.txt + :param frappe_last: [DEPRECATED] Keep frappe last. Do not use this, reverse the app list instead. + :param ensure_on_bench: Only return apps that are present on bench. + """ + from frappe.utils.deprecations import deprecation_warning + if getattr(flags, "in_install_db", True): return [] if not db: connect() - if not local.all_apps: - local.all_apps = cache().get_value("all_apps", get_all_apps) - installed = json.loads(db.get_global("installed_apps") or "[]") if sort: + if not local.all_apps: + local.all_apps = cache().get_value("all_apps", get_all_apps) + + deprecation_warning("`sort` argument is deprecated and will be removed in v15.") installed = [app for app in local.all_apps if app in installed] + if _ensure_on_bench: + all_apps = cache().get_value("all_apps", get_all_apps) + installed = [app for app in installed if app in all_apps] + if frappe_last: + deprecation_warning("`frappe_last` argument is deprecated and will be removed in v15.") if "frappe" in installed: installed.remove("frappe") installed.append("frappe") @@ -1445,7 +1464,7 @@ def _load_app_hooks(app_name: str | None = None): import types hooks = {} - apps = [app_name] if app_name else get_installed_apps(sort=True) + apps = [app_name] if app_name else get_installed_apps(_ensure_on_bench=True) for app in apps: try: diff --git a/frappe/core/doctype/file/file.js b/frappe/core/doctype/file/file.js index 4fd092a00b..159cf1ce39 100644 --- a/frappe/core/doctype/file/file.js +++ b/frappe/core/doctype/file/file.js @@ -24,6 +24,8 @@ frappe.ui.form.on("File", { preview_file: function (frm) { let $preview = ""; + let file_name = frm.doc.file_name.split("?")[0]; + let file_extension = file_name.split(".").pop()?.toLowerCase(); if (frappe.utils.is_image_file(frm.doc.file_url)) { $preview = $(`
@@ -40,7 +42,7 @@ frappe.ui.form.on("File", { ${__("Your browser does not support the video element.")}
`); - } else if (frm.doc.file_name.split("?")[0].endsWith(".pdf")) { + } else if (file_extension === "pdf") { $preview = $(`
`); - } else if (frm.doc.file_name.split("?")[0].endsWith(".mp3")) { + } else if (file_extension === "mp3") { $preview = $(`
- +