Merge pull request #27934 from cogk/fix-extract-images-as-public-in-published-event

fix(blog_post): Ensure images are public if shown on website
This commit is contained in:
Akhil Narang 2024-10-01 14:57:41 +05:30 committed by GitHub
commit b113b8355b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -216,9 +216,11 @@ def get_file_name(fname: str, optional_suffix: str | None = None) -> str:
return f"{partial}{suffix}{extn}"
def extract_images_from_doc(doc: "Document", fieldname: str):
def extract_images_from_doc(doc: "Document", fieldname: str, is_private=True):
content = doc.get(fieldname)
content = extract_images_from_html(doc, content, is_private=(not doc.meta.make_attachments_public))
if doc.meta.make_attachments_public:
is_private = False
content = extract_images_from_html(doc, content, is_private=is_private)
if frappe.flags.has_dataurl:
doc.set(fieldname, content)

View file

@ -95,6 +95,12 @@ class BlogPost(WebsiteGenerator):
self.set_read_time()
if self.is_website_published():
from frappe.core.doctype.file.utils import extract_images_from_doc
# Extract images first before the standard image extraction to ensure they are public.
extract_images_from_doc(self, "content", is_private=False)
def reset_featured_for_other_blogs(self):
all_posts = frappe.get_all("Blog Post", {"featured": 1})
for post in all_posts: