This is an automated email from the ASF dual-hosted git repository. brondsem pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/allura.git
commit 35412f2d925dcdb272f047129a3c5ad867645bca Author: Dillon Walls <[email protected]> AuthorDate: Fri Jul 21 03:21:03 2023 +0000 [#8516] Artifacts, when deleted, now also delete their attachments --- Allura/allura/model/artifact.py | 23 ++++++++++++++++++++--- Allura/allura/model/discuss.py | 1 - 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py index 00cc43a91..6eaa12214 100644 --- a/Allura/allura/model/artifact.py +++ b/Allura/allura/model/artifact.py @@ -464,12 +464,26 @@ class Artifact(MappedClass, SearchIndexable): @LazyProperty def attachments(self): + return self._get_attachments() + + def _get_attachments(self, unique_files_only=True, include_thumbnails=False): if hasattr(self, '_attachments'): atts = self._attachments else: - atts = self.attachment_class().query.find(dict( - app_config_id=self.app_config_id, artifact_id=self._id, type='attachment')).all() - return utils.unique_attachments(atts) + try: + atts = self.attachment_class().query.find({ + 'app_config_id': self.app_config_id, + 'artifact_id': { + # some artifact_ids are ObjectIds and some are strings + '$in': [self._id, str(self._id)] + }, + 'type': {'$in': ['attachment'] + (['thumbnail'] if include_thumbnails else [])} + }).all() + except NotImplementedError: + atts = [] + if unique_files_only: + atts = utils.unique_attachments(atts) + return atts def delete(self): """Delete this Artifact. @@ -478,6 +492,9 @@ class Artifact(MappedClass, SearchIndexable): thread = self._get_discussion_thread() if thread: thread.delete() + for att in self._get_attachments(unique_files_only=False, include_thumbnails=True): + att.delete() + session(att).flush(att) ArtifactReference.query.remove(dict(_id=self.index_id())) super().delete() session(self).flush(self) diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py index f208119cc..f1eeed32c 100644 --- a/Allura/allura/model/discuss.py +++ b/Allura/allura/model/discuss.py @@ -458,7 +458,6 @@ class Thread(Artifact, ActivityObject): def delete(self): for p in self.post_class().query.find(dict(thread_id=self._id)): p.delete() - self.attachment_class().remove(dict(thread_id=self._id)) super().delete() def spam(self):
