check if discussion is allowed for the comments viewlet.

svn path=/plone.app.discussion/trunk/; revision=27190
This commit is contained in:
Timo Stollenwerk 2009-05-28 06:35:47 +00:00
parent 77490ec0d5
commit 2ecd5e76a5
2 changed files with 27 additions and 6 deletions

View File

@ -1,9 +1,13 @@
<tal:block define="errors options/state/getErrors|nothing; <tal:block define="userHasReplyPermission view/can_reply;
replies view/replies | nothing;" isDiscussionAllowed view/is_discussion_allowed;
replies view/get_replies;
isAnon view/is_anonymous;
errors options/state/getErrors|nothing;"
i18n:domain="plone"> i18n:domain="plone">
<div class="discussion"> <div class="discussion"
<tal:getreplies repeat="reply_dict view/replies"> tal:condition="python:replies or (userHasReplyPermission and isDiscussionAllowed) or (isAnon and not userHasReplyPermission and isDiscussionAllowed)">
<tal:getreplies repeat="reply_dict replies">
<div class="comment" <div class="comment"
tal:define="reply reply_dict/comment; tal:define="reply reply_dict/comment;

View File

@ -9,6 +9,8 @@ from zope.viewlet.interfaces import IViewlet
from Acquisition import aq_inner, aq_parent from Acquisition import aq_inner, aq_parent
from AccessControl import getSecurityManager
from Products.Five.browser import BrowserView from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
@ -46,13 +48,28 @@ class CommentsViewlet(BrowserView):
self.portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state") self.portal_state = getMultiAdapter((context, self.request), name=u"plone_portal_state")
def update(self): def update(self):
pass super(CommentsViewlet, self).update()
self.portal_discussion = getToolByName(self.context, 'portal_discussion', None)
self.portal_membership = getToolByName(self.context, 'portal_membership', None)
def replies(self): def can_reply(self):
return getSecurityManager().checkPermission('Reply to item', aq_inner(self.context))
def is_discussion_allowed(self):
if self.portal_discussion is None:
return False
else:
return self.portal_discussion.isDiscussionAllowedFor(aq_inner(self.context))
def get_replies(self):
# Return all direct replies # Return all direct replies
conversation = conversationAdapterFactory(self.context) conversation = conversationAdapterFactory(self.context)
return conversation.getThreads() return conversation.getThreads()
def is_anonymous(self):
return self.portal_state.anonymous()
def format_time(self, time): def format_time(self, time):
# TODO: to localized time not working!!! # TODO: to localized time not working!!!
#util = getToolByName(self.context, 'translation_service') #util = getToolByName(self.context, 'translation_service')