refactor: Use newline as separator instead of comma

This commit is contained in:
Ankush Menat 2023-09-25 16:40:28 +05:30
parent 68bf9f50c4
commit 235ae23c3a
5 changed files with 7 additions and 7 deletions

View file

@ -368,7 +368,7 @@ class File(Document):
if not allowed_extensions:
return
if self.file_type not in allowed_extensions.split(","):
if self.file_type not in allowed_extensions.splitlines():
frappe.throw(
_("File type of {0} is not allowed").format(self.file_type), exc=FileTypeNotAllowed
)

View file

@ -89,7 +89,7 @@ class TestFSRollbacks(FrappeTestCase):
class TestExtensionValidations(FrappeTestCase):
@change_settings("System Settings", {"allowed_file_extensions": "JPG,CSV"})
@change_settings("System Settings", {"allowed_file_extensions": "JPG\nCSV"})
def test_allowed_extension(self):
set_request(method="POST", path="/")
file_name = content = frappe.generate_hash()

View file

@ -593,7 +593,7 @@
"fieldtype": "Column Break"
},
{
"description": "Provide a comma-separated list of allowed file extensions for file uploads. If unset, all file extensions are allowed. Example: CSV, JSON, JPEG, JPG, PNG",
"description": "Provide a list of allowed file extensions for file uploads. Each line should contain one allowed file type. If unset, all file extensions are allowed. Example: <br>CSV<br>JPG<br>PNG",
"fieldname": "allowed_file_extensions",
"fieldtype": "Small Text",
"label": "Allowed File Extensions"
@ -602,7 +602,7 @@
"icon": "fa fa-cog",
"issingle": 1,
"links": [],
"modified": "2023-09-25 15:17:58.964082",
"modified": "2023-09-25 16:49:16.652874",
"modified_by": "Administrator",
"module": "Core",
"name": "System Settings",

View file

@ -156,8 +156,8 @@ class SystemSettings(Document):
if not self.allowed_file_extensions:
return
self.allowed_file_extensions = ",".join(
ext.strip().upper() for ext in self.allowed_file_extensions.split(",")
self.allowed_file_extensions = "\n".join(
ext.strip().upper() for ext in self.allowed_file_extensions.strip().splitlines()
)
def on_update(self):

View file

@ -35,7 +35,7 @@ class FileUploader {
let allowed_extensions = frappe.sys_defaults?.allowed_file_extensions;
if (allowed_extensions) {
restrictions.allowed_file_types = allowed_extensions
.split(",")
.split("\n")
.map((ext) => `.${ext}`);
}
}