Merge branch 'develop' into filter-with-captitalized-opearator-fix

This commit is contained in:
Shariq Ansari 2023-04-13 14:14:24 +05:30 committed by GitHub
commit 4913b679a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 9 deletions

View file

@ -17,6 +17,7 @@ from frappe.core.api.file import (
move_file,
unzip_file,
)
from frappe.core.doctype.file.utils import get_extension
from frappe.exceptions import ValidationError
from frappe.tests.utils import FrappeTestCase
from frappe.utils import get_files_path
@ -461,7 +462,7 @@ class TestFile(FrappeTestCase):
).insert(ignore_permissions=True)
test_file.make_thumbnail()
self.assertTrue(test_file.thumbnail_url.endswith("_small.jpeg"))
self.assertTrue(test_file.thumbnail_url.endswith("_small.jpg"))
# test local image
test_file.db_set("thumbnail_url", None)
@ -739,3 +740,10 @@ class TestFileOptimization(FrappeTestCase):
size_after_rollback = os.stat(image_path).st_size
self.assertEqual(size_before_optimization, size_after_rollback)
def test_image_header_guessing(self):
file_path = frappe.get_app_path("frappe", "tests/data/sample_image_for_optimization.jpg")
with open(file_path, "rb") as f:
file_content = f.read()
self.assertEqual(get_extension("", None, file_content), "jpg")

View file

@ -1,5 +1,4 @@
import hashlib
import imghdr
import mimetypes
import os
import re
@ -7,6 +6,7 @@ from io import BytesIO
from typing import TYPE_CHECKING, Optional
from urllib.parse import unquote
import filetype
import requests
import requests.exceptions
from PIL import Image
@ -76,9 +76,11 @@ def get_extension(
mimetype = mimetypes.guess_type(filename + "." + extn)[0]
if mimetype is None or not mimetype.startswith("image/") and content:
# detect file extension by reading image header properties
extn = imghdr.what(filename + "." + (extn or ""), h=content)
if mimetype is None and extn is None and content:
# detect file extension by using filetype matchers
_type_info = filetype.match(content)
if _type_info:
extn = _type_info.extension
return extn

View file

@ -186,11 +186,13 @@ scheduler_events = {
"frappe.oauth.delete_oauth2_data",
"frappe.website.doctype.web_page.web_page.check_publish_status",
"frappe.twofactor.delete_all_barcodes_for_users",
]
],
"0/10 * * * *": [
"frappe.email.doctype.email_account.email_account.pull",
],
},
"all": [
"frappe.email.queue.flush",
"frappe.email.doctype.email_account.email_account.pull",
"frappe.email.doctype.email_account.email_account.notify_unreplied",
"frappe.utils.global_search.sync_global_search",
"frappe.monitor.flush",

View file

@ -3,7 +3,7 @@ import datetime
import hashlib
import re
from http import cookies
from urllib.parse import unquote, urlparse, urljoin
from urllib.parse import unquote, urljoin, urlparse
import jwt
import pytz

View file

@ -126,7 +126,7 @@ class Workflow(Document):
@frappe.whitelist()
def get_workflow_state_count(doctype, workflow_state_field, states):
frappe.has_permission(doctype=doctype, ptype='read', throw=True)
frappe.has_permission(doctype=doctype, ptype="read", throw=True)
states = frappe.parse_json(states)
result = frappe.get_all(
doctype,

View file

@ -12,6 +12,7 @@ dependencies = [
"Babel~=2.12.1",
"Click~=8.1.3",
"filelock~=3.8.0",
"filetype~=1.2.0",
"GitPython~=3.1.30",
"Jinja2~=3.1.2",
"Pillow~=9.3.0",