(backend) extract attachment keys from updated content for access

We can't prevent document editors from copy/pasting content to from one
document to another. The problem is that copying content, will copy the
urls pointing to attachments but if we don't do anything, the reader of
the document to which the content is being pasted, may not be allowed to
access the attachment files from the original document.

Using the work from the previous commit, we can grant access to the readers
of the target document by extracting the attachment keys from the content and
adding themto the target document's "attachments" field. Before doing this,
we check that the current user can indeed access the attachment files extracted
from the content and that they are allowed to edit the current document.
This commit is contained in:
Samuel Paccoud - DINUM
2025-01-21 23:56:50 +01:00
committed by Manuel Raynaud
parent 34a208a80d
commit c02f19a2cd
4 changed files with 92 additions and 2 deletions

View File

@@ -69,5 +69,8 @@ def base64_yjs_to_text(base64_string):
def extract_attachments(content):
"""Helper method to extract media paths from a document's content."""
if not content:
return []
xml_content = base64_yjs_to_xml(content)
return re.findall(enums.MEDIA_STORAGE_URL_EXTRACT, xml_content)