Merge pull request #1769 from pateljannat/issues-137

fix: private file uploads in assignment text editor
This commit is contained in:
Jannat Patel
2025-10-10 16:27:00 +05:30
committed by GitHub
6 changed files with 6615 additions and 5595 deletions

View File

@@ -32,7 +32,7 @@
"dayjs": "^1.11.6", "dayjs": "^1.11.6",
"dompurify": "^3.2.6", "dompurify": "^3.2.6",
"feather-icons": "^4.28.0", "feather-icons": "^4.28.0",
"frappe-ui": "^0.1.200", "frappe-ui": "^0.1.201",
"highlight.js": "^11.11.1", "highlight.js": "^11.11.1",
"lucide-vue-next": "^0.383.0", "lucide-vue-next": "^0.383.0",
"markdown-it": "^14.0.0", "markdown-it": "^14.0.0",

View File

@@ -130,6 +130,9 @@
@change="(val) => (answer = val)" @change="(val) => (answer = val)"
:editable="true" :editable="true"
:fixedMenu="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]" 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> </div>

File diff suppressed because it is too large Load Diff

View File

@@ -14,6 +14,9 @@ class LMSAssignmentSubmission(Document):
self.validate_url() self.validate_url()
self.validate_status() self.validate_status()
def on_update(self):
self.validate_private_attachments()
def validate_duplicates(self): def validate_duplicates(self):
if frappe.db.exists( if frappe.db.exists(
"LMS Assignment Submission", "LMS Assignment Submission",
@@ -34,6 +37,30 @@ class LMSAssignmentSubmission(Document):
if doc_before_save.status != self.status or doc_before_save.comments != self.comments: if doc_before_save.status != self.status or doc_before_save.comments != self.comments:
self.trigger_update_notification() 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): def trigger_update_notification(self):
notification = frappe._dict( notification = frappe._dict(
{ {

6614
yarn.lock

File diff suppressed because it is too large Load Diff