You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by pr...@apache.org on 2016/02/12 17:39:04 UTC

allura git commit: Feed correct, update function add.

Repository: allura
Updated Branches:
  refs/heads/pr/4153 [created] 7ae1e420d


Feed correct, update function add.


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

Branch: refs/heads/pr/4153
Commit: 7ae1e420d308cb5124899148c2a09feec43c8bf7
Parents: 7af80f3
Author: dastanforever <pr...@gmail.com>
Authored: Fri Feb 12 22:03:30 2016 +0530
Committer: dastanforever <pr...@gmail.com>
Committed: Fri Feb 12 22:03:30 2016 +0530

----------------------------------------------------------------------
 Allura/allura/model/artifact.py   | 29 +++++++++++++++++++++++------
 ForgeBlog/forgeblog/model/blog.py |  4 ++++
 2 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/7ae1e420/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 3d798fd..3a84f78 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -823,17 +823,21 @@ class Feed(MappedClass):
     artifact_reference = FieldProperty(S.Deprecated)
 
     @classmethod
+    def has_access(cls, artifact):
+        from allura import model as M
+        anon = M.User.anonymous()
+        if not security.has_access(artifact, 'read', user=anon):
+            return False
+        if not security.has_access(c.project, 'read', user=anon):
+            return False
+
+    @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
-        from allura import model as M
-        anon = M.User.anonymous()
-        if not security.has_access(artifact, 'read', user=anon):
-            return
-        if not security.has_access(c.project, 'read', user=anon):
+        if Feed.has_access(artifact) == False:
             return
         idx = artifact.index()
         if author is None:
@@ -867,6 +871,19 @@ 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 Feed.has_access(artifact) == False:
+            return
+        # Modify the previous version.
+        v1 = Feed.query.find({'ref_id': artifact.index_id()}).first()
+        v1.title = title
+        v1.description = 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/7ae1e420/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index 818e207..9b35dc3 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -258,10 +258,14 @@ 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)
         else:
             description = self.text
             subject = '%s created post %s' % (