You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2016/01/06 00:14:46 UTC

[2/4] allura git commit: [#8003] ticket:877 Delete all attachments with equal filename

[#8003] ticket:877 Delete all attachments with equal filename


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/f75277cf
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/f75277cf
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/f75277cf

Branch: refs/heads/master
Commit: f75277cfb80bba0cb95cc3d5acdb4e7b0a0cd82f
Parents: 9e952a6
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Dec 24 17:35:15 2015 +0200
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Dec 24 17:35:15 2015 +0200

----------------------------------------------------------------------
 Allura/allura/controllers/attachments.py | 31 ++++++++++++++++-----------
 1 file changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f75277cf/Allura/allura/controllers/attachments.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/attachments.py b/Allura/allura/controllers/attachments.py
index a175bf9..6766d02 100644
--- a/Allura/allura/controllers/attachments.py
+++ b/Allura/allura/controllers/attachments.py
@@ -67,12 +67,22 @@ class AttachmentController(BaseController):
         self.filename = filename
         self.artifact = artifact
 
-    @LazyProperty
-    def attachment(self):
+    @property
+    def attachments_query(self):
         metadata = self.AttachmentClass.metadata_for(self.artifact)
         metadata['type'] = 'attachment'
+        return dict(filename=self.filename, **metadata)
+
+    @property
+    def thumbnails_query(self):
+        metadata = self.AttachmentClass.metadata_for(self.artifact)
+        metadata['type'] = 'thumbnail'
+        return dict(filename=self.filename, **metadata)
+
+    @LazyProperty
+    def attachment(self):
         attachment = self.AttachmentClass.query.find(
-            dict(filename=self.filename, **metadata)
+            self.attachments_query
         ).sort('_id', -1).limit(1).first()
         if attachment is None:
             raise exc.HTTPNotFound
@@ -80,10 +90,8 @@ class AttachmentController(BaseController):
 
     @LazyProperty
     def thumbnail(self):
-        metadata = self.AttachmentClass.metadata_for(self.artifact)
-        metadata['type'] = 'thumbnail'
         attachment = self.AttachmentClass.query.find(
-            dict(filename=self.filename, **metadata)
+            self.thumbnails_query
         ).sort('_id', -1).limit(1).first()
         if attachment is None:
             raise exc.HTTPNotFound
@@ -92,12 +100,11 @@ class AttachmentController(BaseController):
     def handle_post(self, delete, **kw):
         require_access(self.artifact, self.edit_perm)
         if delete:
-            self.attachment.delete()
-            try:
-                if self.thumbnail:
-                    self.thumbnail.delete()
-            except exc.HTTPNotFound:
-                pass
+            # Remove all attachments with such filename. Since we're showing
+            # only the most recent one we don't want previous attachments
+            # with such filename (if there was any) to show up after delete
+            self.AttachmentClass.query.remove(self.attachments_query)
+            self.AttachmentClass.query.remove(self.thumbnails_query)
 
     @expose()
     def index(self, delete=False, **kw):