def public_commentators(self): retval = set() for comment in self._comments.values(): if not user_nobody.has_permission('View', comment): continue retval.add(comment.author_username) return tuple(retval)
def last_comment_date(self): # self._comments is an Instance of a btree. The keys # are always ordered comment_keys = self._comments.keys() for comment_key in reversed(comment_keys): comment = self._comments[comment_key] if user_nobody.has_permission('View', comment): return comment.creation_date return None
def test_view_permission(self): """Test that if the View permission on Discussion Items is acquired, Anonymous can view comments on published items.""" # Anonymous has View permission on commented objects. self.assertTrue(_anonymousCanView(self.archetypes_object)) self.assertTrue(_anonymousCanView(self.dexterity_object)) self.assertTrue( user_nobody.has_permission("View", self.archetypes_object)) self.assertTrue( user_nobody.has_permission("View", self.dexterity_object)) # Anonymous also passes the user_nobody.has_permission() test # on comments. self.assertTrue( user_nobody.has_permission("View", self.archetypes_comment)) self.assertTrue( user_nobody.has_permission("View", self.dexterity_comment)) # Fails: Anonymous should therefore have View permission on the # comments when we use rolesOfPermission. self.assertTrue(_anonymousCanView(self.archetypes_comment)) self.assertTrue(_anonymousCanView(self.dexterity_comment))
def public_comments(self): """Count total comments. The @property decorator used on ``total_comments`` method doesn't work when combined with acquisition, that's a fact of life. Thus the total_comments indexer (on p.a.discussion.catalog.py) fails to index properly if acquisition is involved. To solve it, this method takes over the indexing and is being used by total_comments itself so that backwards compatibility is kept. """ public_comments = [ x for x in self.values() if user_nobody.has_permission('View', x) ] return len(public_comments)
def total_comments(self): public_comments = [ x for x in self._comments.values() if user_nobody.has_permission('View', x) ] return len(public_comments)