allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [02/39] allura git commit: [#1731] ticket:767 Mark comments as deleted instead of actually deleting them
Date Tue, 02 Jun 2015 20:06:53 GMT
[#1731] ticket:767 Mark comments as deleted instead of actually deleting them


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

Branch: refs/heads/hs/7825
Commit: 89b65ffb35f24aff0366ec2fc0ecdc1531501930
Parents: 1accce5
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon May 18 14:43:38 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon May 25 13:31:52 2015 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py        |  3 ++-
 Allura/allura/model/discuss.py                  | 26 +++++++++++---------
 .../forgediscussion/controllers/root.py         |  1 +
 ForgeDiscussion/forgediscussion/forum_main.py   |  7 +++++-
 ForgeDiscussion/forgediscussion/site_stats.py   |  4 ++-
 ForgeImporters/forgeimporters/trac/tickets.py   |  3 ++-
 ForgeTracker/forgetracker/tracker_main.py       |  8 ++++--
 ForgeWiki/forgewiki/wiki_main.py                |  7 ++++--
 8 files changed, 40 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 055a74a..9a68e1a 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -178,7 +178,8 @@ class TracRef2(Pattern):
         comments = ticket.discussion_thread.post_class().query.find(dict(
             discussion_id=ticket.discussion_thread.discussion_id,
             thread_id=ticket.discussion_thread._id,
-            status={'$in': ['ok', 'pending']})).sort('timestamp')
+            status={'$in': ['ok', 'pending']},
+            deleted=False)).sort('timestamp')
 
         if comment_num <= comments.count():
             return comments.all()[comment_num - 1].slug

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 581eb21..aa16255 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -92,16 +92,15 @@ class Discussion(Artifact, ActivityObject):
         self.num_topics = self.thread_class().query.find(
             dict(discussion_id=self._id)).count()
         self.num_posts = self.post_class().query.find(
-            dict(discussion_id=self._id, status='ok')).count()
+            dict(discussion_id=self._id, status='ok', deleted=False)).count()
 
     @LazyProperty
     def last_post(self):
         q = self.post_class().query.find(dict(
             discussion_id=self._id,
-            status='ok'
-        ))\
-            .sort('timestamp', pymongo.DESCENDING)\
-            .limit(1)
+            status='ok',
+            deleted=False,
+        )).sort('timestamp', pymongo.DESCENDING).limit(1)
         return q.first()
 
     def url(self):
@@ -129,7 +128,7 @@ class Discussion(Artifact, ActivityObject):
         super(Discussion, self).delete()
 
     def find_posts(self, **kw):
-        q = dict(kw, discussion_id=self._id)
+        q = dict(kw, discussion_id=self._id, deleted=False)
         return self.post_class().query.find(q)
 
 
@@ -238,7 +237,9 @@ class Thread(Artifact, ActivityObject):
         return Post.query.find(dict(
             discussion_id=self.discussion_id,
             thread_id=self._id,
-            status={'$in': ['ok', 'pending']})).count()
+            status={'$in': ['ok', 'pending']},
+            deleted=False,
+        )).count()
 
     def primary(self):
         if self.ref is None:
@@ -340,12 +341,14 @@ class Thread(Artifact, ActivityObject):
 
     def update_stats(self):
         self.num_replies = self.post_class().query.find(
-            dict(thread_id=self._id, status='ok')).count() - 1
+            dict(thread_id=self._id, status='ok', deleted=False)).count() - 1
 
     @property
     def last_post(self):
         q = self.post_class().query.find(dict(
-            thread_id=self._id)).sort('timestamp', pymongo.DESCENDING)
+            thread_id=self._id,
+            deleted=False,
+        )).sort('timestamp', pymongo.DESCENDING)
         return q.first()
 
     def create_post_threads(self, posts):
@@ -370,6 +373,7 @@ class Thread(Artifact, ActivityObject):
                          status={'$in': ['ok', 'pending']})
         if status:
             terms['status'] = status
+        terms['deleted'] = False
         q = self.post_class().query.find(terms)
         if style == 'threaded':
             q = q.sort('full_slug')
@@ -675,8 +679,8 @@ class Post(Message, VersionedArtifact, ActivityObject):
             return 'Re: ' + (self.subject or '(no subject)')
 
     def delete(self):
-        self.attachment_class().remove(dict(post_id=self._id))
-        super(Post, self).delete()
+        self.deleted = True
+        session(self).flush(self)
         self.thread.num_replies = max(0, self.thread.num_replies - 1)
 
     def approve(self, file_info=None, notify=True, notification_text=None):

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index 7548cd0..9f6ab76 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -264,6 +264,7 @@ class RootController(BaseController, DispatchIndex, FeedController):
                     '$gte': datetime.combine(begin, time.min),
                     '$lte': datetime.combine(end, time.max),
                 },
+                'deleted': False,
             }},
             {'$group': {
                 '_id': grouping,

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/ForgeDiscussion/forgediscussion/forum_main.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/forum_main.py b/ForgeDiscussion/forgediscussion/forum_main.py
index e66ec43..542b3f0 100644
--- a/ForgeDiscussion/forgediscussion/forum_main.py
+++ b/ForgeDiscussion/forgediscussion/forum_main.py
@@ -158,9 +158,14 @@ class ForgeDiscussionApp(Application):
             for f in forums:
                 if has_access(f, 'read')():
                     if f.url() in request.url and h.has_access(f, 'moderate')():
+                        num_moderate = DM.ForumPost.query.find({
+                            'discussion_id': f._id,
+                            'status': {'$ne': 'ok'},
+                            'deleted': False,
+                        }).count()
                         moderate_link = SitemapEntry(
                             'Moderate', "%smoderate/" % f.url(), ui_icon=g.icons['pencil'],
-                            small=DM.ForumPost.query.find({'discussion_id': f._id, 'status':
{'$ne': 'ok'}}).count())
+                            small=num_moderate)
                     forum_links.append(
                         SitemapEntry(f.name, f.url(), small=f.num_topics))
             url = c.app.url + 'create_topic/'

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/ForgeDiscussion/forgediscussion/site_stats.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/site_stats.py b/ForgeDiscussion/forgediscussion/site_stats.py
index 6918137..cabb5dd 100644
--- a/ForgeDiscussion/forgediscussion/site_stats.py
+++ b/ForgeDiscussion/forgediscussion/site_stats.py
@@ -22,4 +22,6 @@ from . import model as DM
 
 def posts_24hr():
     window = datetime.utcnow() - timedelta(hours=24)
-    return DM.ForumPost.query.find({'timestamp': {'$gte': window}}).count()
+    q = {'timestamp': {'$gte': window},
+         'deleted': False}
+    return DM.ForumPost.query.find(q).count()

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index 177652b..466b4f7 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -169,7 +169,8 @@ class TracImportSupport(ImportSupport):
         comments = ticket.discussion_thread.post_class().query.find(dict(
             discussion_id=ticket.discussion_thread.discussion_id,
             thread_id=ticket.discussion_thread._id,
-            status={'$in': ['ok', 'pending']})).sort('timestamp')
+            status={'$in': ['ok', 'pending']},
+            deleted=False)).sort('timestamp')
 
         if comment <= comments.count():
             return comments.all()[comment - 1].slug

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 52e7b28..596ec54 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -354,8 +354,11 @@ class ForgeTrackerApp(Application):
         links.append(SitemapEntry('View Stats', self.config.url()
                      + 'stats', ui_icon=g.icons['stats']))
         discussion = c.app.config.discussion
-        pending_mod_count = M.Post.query.find(
-            {'discussion_id': discussion._id, 'status': 'pending'}).count()
+        pending_mod_count = M.Post.query.find({
+            'discussion_id': discussion._id,
+            'status': 'pending',
+            'deleted': False,
+        }).count()
         if pending_mod_count and has_access(discussion, 'moderate')():
             links.append(
                 SitemapEntry(
@@ -1022,6 +1025,7 @@ class RootController(BaseController, FeedController):
         q = dict(
             discussion_id=c.app.config.discussion_id,
             status='ok',
+            deleted=False,
         )
         if when is not None:
             q['timestamp'] = {'$gte': when}

http://git-wip-us.apache.org/repos/asf/allura/blob/89b65ffb/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 5f15779..a87ce8d 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -231,8 +231,11 @@ The wiki uses [Markdown](%s) syntax.
         links += [SitemapEntry('Browse Pages', self.url + 'browse_pages/'),
                   SitemapEntry('Browse Labels', self.url + 'browse_tags/')]
         discussion = c.app.config.discussion
-        pending_mod_count = M.Post.query.find(
-            {'discussion_id': discussion._id, 'status': 'pending'}).count() if discussion
else 0
+        pending_mod_count = M.Post.query.find({
+            'discussion_id': discussion._id,
+            'status': 'pending',
+            'deleted': False
+        }).count() if discussion else 0
         if pending_mod_count and h.has_access(discussion, 'moderate')():
             links.append(
                 SitemapEntry(


Mime
View raw message