Skip to content

Commit d1dcd94

Browse files
committed
fixup! fixup! ✨(backend) extract attachment keys from updated content for access
1 parent 045fa09 commit d1dcd94

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/backend/core/api/serializers.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,30 @@ def save(self, **kwargs):
282282
new_attachments = extracted_attachments - existing_attachments
283283

284284
if new_attachments:
285+
attachments_documents = (
286+
models.Document.objects.filter(
287+
attachments__overlap=list(new_attachments)
288+
)
289+
.only("path", "attachments")
290+
.order_by("path")
291+
)
292+
285293
user = self.context["request"].user
286-
readable_documents = models.Document.objects.readable(user).filter(
287-
Q(attachments__overlap=list(new_attachments))
294+
readable_per_se_paths = (
295+
models.Document.objects.readable_per_se(user)
296+
.order_by("path")
297+
.values_list("path", flat=True)
298+
)
299+
readable_attachments_paths = utils.filter_descendants(
300+
[doc.path for doc in attachments_documents],
301+
readable_per_se_paths,
302+
skip_sorting=True,
288303
)
289304

290305
readable_attachments = set()
291-
for document in readable_documents:
306+
for document in attachments_documents:
307+
if document.path not in readable_attachments_paths:
308+
continue
292309
readable_attachments.update(set(document.attachments) & new_attachments)
293310

294311
# Update attachments with readable keys

0 commit comments

Comments
 (0)