From c55dcc439e962123ac4c5140808cb5308955e37e Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 13 Sep 2023 13:33:36 +0530 Subject: [PATCH] feat: max_file_size configurable from system settings (#22384) also increase default max_file_size from 10MB to 25MB --- frappe/core/api/file.py | 6 ++++- frappe/core/doctype/file/file.py | 8 +++---- .../system_settings/system_settings.json | 23 +++++++++++++++++-- .../system_settings/system_settings.py | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/frappe/core/api/file.py b/frappe/core/api/file.py index 1a616c3134..aa8be30707 100644 --- a/frappe/core/api/file.py +++ b/frappe/core/api/file.py @@ -84,7 +84,11 @@ def get_files_by_search_text(text: str) -> list[dict]: @frappe.whitelist(allow_guest=True) def get_max_file_size() -> int: - return cint(frappe.conf.get("max_file_size")) or 10485760 + return ( + cint(frappe.get_system_settings("max_file_size")) * 1024 * 1024 + or cint(frappe.conf.get("max_file_size")) + or 25 * 1024 * 1024 + ) @frappe.whitelist() diff --git a/frappe/core/doctype/file/file.py b/frappe/core/doctype/file/file.py index 985e5f50ba..0794852aed 100755 --- a/frappe/core/doctype/file/file.py +++ b/frappe/core/doctype/file/file.py @@ -659,10 +659,10 @@ class File(Document): file_size = len(self._content or b"") if file_size > max_file_size: - frappe.throw( - _("File size exceeded the maximum allowed size of {0} MB").format(max_file_size / 1048576), - exc=MaxFileSizeReachedError, - ) + msg = _("File size exceeded the maximum allowed size of {0} MB").format(max_file_size / 1048576) + if frappe.has_permission("System Settings", "write"): + msg += ".
" + _("You can increase the limit from System Settings.") + frappe.throw(msg, exc=MaxFileSizeReachedError) return file_size diff --git a/frappe/core/doctype/system_settings/system_settings.json b/frappe/core/doctype/system_settings/system_settings.json index 1eea7dcecb..8970c518d1 100644 --- a/frappe/core/doctype/system_settings/system_settings.json +++ b/frappe/core/doctype/system_settings/system_settings.json @@ -81,7 +81,10 @@ "disable_system_update_notification", "disable_change_log_notification", "telemetry_section", - "enable_telemetry" + "enable_telemetry", + "files_section", + "max_file_size", + "column_break_uqma" ], "fields": [ { @@ -571,12 +574,28 @@ "fieldname": "force_web_capture_mode_for_uploads", "fieldtype": "Check", "label": "Force Web Capture Mode for Uploads" + }, + { + "collapsible": 1, + "fieldname": "files_section", + "fieldtype": "Section Break", + "label": "Files" + }, + { + "fieldname": "max_file_size", + "fieldtype": "Int", + "label": "Max File Size (MB)", + "non_negative": 1 + }, + { + "fieldname": "column_break_uqma", + "fieldtype": "Column Break" } ], "icon": "fa fa-cog", "issingle": 1, "links": [], - "modified": "2023-08-31 20:19:07.181041", + "modified": "2023-09-13 12:49:32.309521", "modified_by": "Administrator", "module": "Core", "name": "System Settings", diff --git a/frappe/core/doctype/system_settings/system_settings.py b/frappe/core/doctype/system_settings/system_settings.py index e0c0c58fe7..4fc99d29a2 100644 --- a/frappe/core/doctype/system_settings/system_settings.py +++ b/frappe/core/doctype/system_settings/system_settings.py @@ -64,6 +64,7 @@ class SystemSettings(Document): login_with_email_link_expiry: DF.Int logout_on_password_reset: DF.Check max_auto_email_report_per_user: DF.Int + max_file_size: DF.Int minimum_password_score: DF.Literal["2", "3", "4"] number_format: DF.Literal[ "#,###.##",