mirror of
https://github.com/frappe/lms.git
synced 2026-05-02 13:39:31 +03:00
Merge pull request #1769 from pateljannat/issues-137
fix: private file uploads in assignment text editor
This commit is contained in:
+1
-1
Submodule frappe-ui updated: c9a0fc937c...8b85a70d21
@@ -32,7 +32,7 @@
|
||||
"dayjs": "^1.11.6",
|
||||
"dompurify": "^3.2.6",
|
||||
"feather-icons": "^4.28.0",
|
||||
"frappe-ui": "^0.1.200",
|
||||
"frappe-ui": "^0.1.201",
|
||||
"highlight.js": "^11.11.1",
|
||||
"lucide-vue-next": "^0.383.0",
|
||||
"markdown-it": "^14.0.0",
|
||||
|
||||
@@ -130,6 +130,9 @@
|
||||
@change="(val) => (answer = val)"
|
||||
:editable="true"
|
||||
:fixedMenu="true"
|
||||
:uploadArgs="{
|
||||
private: true,
|
||||
}"
|
||||
editorClass="prose-sm max-w-none border-b border-x bg-surface-gray-2 rounded-b-md py-1 px-2 min-h-[7rem]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
-5562
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,9 @@ class LMSAssignmentSubmission(Document):
|
||||
self.validate_url()
|
||||
self.validate_status()
|
||||
|
||||
def on_update(self):
|
||||
self.validate_private_attachments()
|
||||
|
||||
def validate_duplicates(self):
|
||||
if frappe.db.exists(
|
||||
"LMS Assignment Submission",
|
||||
@@ -34,6 +37,30 @@ class LMSAssignmentSubmission(Document):
|
||||
if doc_before_save.status != self.status or doc_before_save.comments != self.comments:
|
||||
self.trigger_update_notification()
|
||||
|
||||
def validate_private_attachments(self):
|
||||
if self.type == "Text":
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
soup = BeautifulSoup(self.answer, "html.parser")
|
||||
images = soup.find_all("img")
|
||||
self.attach_images_to_document(images)
|
||||
|
||||
def attach_images_to_document(self, images):
|
||||
for img in images:
|
||||
src = img.get("src", "")
|
||||
if src.startswith("/private/files/"):
|
||||
file_name = frappe.db.get_value("File", {"file_url": src}, "name")
|
||||
if file_name:
|
||||
frappe.db.set_value(
|
||||
"File",
|
||||
file_name,
|
||||
{
|
||||
"attached_to_doctype": self.doctype,
|
||||
"attached_to_name": self.name,
|
||||
"attached_to_field": "answer",
|
||||
},
|
||||
)
|
||||
|
||||
def trigger_update_notification(self):
|
||||
notification = frappe._dict(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user