allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#4153] Delete and update blog rss feed entries
Date Thu, 10 Mar 2016 18:03:38 GMT
Repository: allura
Updated Branches:
  refs/heads/master 9647a2832 -> c91eb67da


[#4153] Delete and update blog rss feed entries


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

Branch: refs/heads/master
Commit: c91eb67da5fbf847cdb94d1c4838ed376766a50e
Parents: 9647a28
Author: dastanforever <pranav.sharma.nits@gmail.com>
Authored: Fri Feb 12 22:03:30 2016 +0530
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Mar 10 18:03:22 2016 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py   | 40 ++++++++++++++++++++++++++++------
 ForgeBlog/forgeblog/model/blog.py |  7 ++++++
 2 files changed, 40 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c91eb67d/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 1ccfad9..ed5d424 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -823,17 +823,26 @@ class Feed(MappedClass):
     artifact_reference = FieldProperty(S.Deprecated)
 
     @classmethod
-    def post(cls, artifact, title=None, description=None, author=None, author_link=None,
author_name=None, pubdate=None, link=None, **kw):
-        """
-        Create a Feed item.  Returns the item.
-        But if anon doesn't have read access, create does not happen and None is returned
-        """
-        # TODO: fix security system so we can do this correctly and fast
+    def has_access(cls, artifact):
+        # Enable only for development.
+        # return True
         from allura import model as M
         anon = M.User.anonymous()
         if not security.has_access(artifact, 'read', user=anon):
-            return
+            return False
         if not security.has_access(c.project, 'read', user=anon):
+            return False
+        return True
+
+    @classmethod
+    def post(cls, artifact, title=None, description=None, author=None,
+            author_link=None, author_name=None, pubdate=None, link=None, **kw):
+        """
+        Create a Feed item.  Returns the item.
+        But if anon doesn't have read access, create does not happen and None is
+        returned.
+        """
+        if not Feed.has_access(artifact):
             return
         idx = artifact.index()
         if author is None:
@@ -867,6 +876,23 @@ class Feed(MappedClass):
         return item
 
     @classmethod
+    def update(cls, artifact, title=None, description=None, author=None,
+            author_link=None, author_name=None, pubdate=None, link=None, **kw):
+        """
+        For a blog post which is present already but to be updated.
+        """
+        if not Feed.has_access(artifact):
+            return
+        v1 = Feed.query.find({'ref_id': artifact.index_id()}).first()
+        if artifact.state == 'draft':
+            Feed.delete(v1)
+        # Modify the previous version.
+        else:
+            v1.title = title
+            v1.description = g.markdown.convert(description)
+            return v1
+
+    @classmethod
     def feed(cls, q, feed_type, title, link, description,
              since=None, until=None, page=None, limit=None):
         "Produces webhelper.feedgenerator Feed"

http://git-wip-us.apache.org/repos/asf/allura/blob/c91eb67d/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index ef76bfc..6983c96 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -258,10 +258,17 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
                     activity('renamed', self)
                     subject = '%s renamed post %s to %s' % (
                         c.user.username, v1.title, v2.title)
+                    M.Feed.update(self, self.title, self.text, author=self.author(),
+                                pubdate=self.get_version(1).timestamp)
                 else:
                     activity('modified', self)
                     subject = '%s modified post %s' % (
                         c.user.username, self.title)
+                    M.Feed.update(self, self.title, self.text, author=self.author(),
+                                pubdate=self.get_version(1).timestamp)
+            elif v1.state == 'published' and v2.state == 'draft':
+                ### Delete it from the feed.
+                M.Feed.update(v2)
         else:
             description = self.text
             subject = '%s created post %s' % (


Mime
View raw message