add delete_own_comment_enabled option in control panel
This commit is contained in:
parent
ee28528f55
commit
2a8082cfa7
@ -2,6 +2,7 @@
|
|||||||
isDiscussionAllowed view/is_discussion_allowed;
|
isDiscussionAllowed view/is_discussion_allowed;
|
||||||
isAnonymousDiscussionAllowed view/anonymous_discussion_allowed;
|
isAnonymousDiscussionAllowed view/anonymous_discussion_allowed;
|
||||||
isEditCommentAllowed view/edit_comment_allowed;
|
isEditCommentAllowed view/edit_comment_allowed;
|
||||||
|
isDeleteOwnCommentAllowed view/delete_own_comment_allowed;
|
||||||
isAnon view/is_anonymous;
|
isAnon view/is_anonymous;
|
||||||
canReview view/can_review;
|
canReview view/can_review;
|
||||||
replies python:view.get_replies(canReview);
|
replies python:view.get_replies(canReview);
|
||||||
@ -90,7 +91,7 @@
|
|||||||
action=""
|
action=""
|
||||||
method="post"
|
method="post"
|
||||||
class="commentactionsform"
|
class="commentactionsform"
|
||||||
tal:condition="python: not canDelete and view.could_delete_own(reply)"
|
tal:condition="python:not canDelete and isDeleteOwnCommentAllowed and view.could_delete_own(reply)"
|
||||||
tal:attributes="action string:${reply/absolute_url}/@@delete-own-comment;
|
tal:attributes="action string:${reply/absolute_url}/@@delete-own-comment;
|
||||||
style python:view.can_delete_own(reply) and 'display: inline' or 'display: none'">
|
style python:view.can_delete_own(reply) and 'display: inline' or 'display: none'">
|
||||||
<input name="form.button.DeleteComment"
|
<input name="form.button.DeleteComment"
|
||||||
|
@ -346,8 +346,8 @@ class CommentsViewlet(ViewletBase):
|
|||||||
aq_inner(reply))
|
aq_inner(reply))
|
||||||
|
|
||||||
def can_delete(self, reply):
|
def can_delete(self, reply):
|
||||||
"""By default requires 'Review comments'.
|
"""Returns true if current user has the 'Delete comments'
|
||||||
If 'delete own comments' is enabled, requires 'Edit comments'.
|
permission.
|
||||||
"""
|
"""
|
||||||
return getSecurityManager().checkPermission('Delete comments',
|
return getSecurityManager().checkPermission('Delete comments',
|
||||||
aq_inner(reply))
|
aq_inner(reply))
|
||||||
@ -482,6 +482,12 @@ class CommentsViewlet(ViewletBase):
|
|||||||
settings = registry.forInterface(IDiscussionSettings, check=False)
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
||||||
return settings.edit_comment_enabled
|
return settings.edit_comment_enabled
|
||||||
|
|
||||||
|
def delete_own_comment_allowed(self):
|
||||||
|
# Check if delete own comments is allowed in the registry
|
||||||
|
registry = queryUtility(IRegistry)
|
||||||
|
settings = registry.forInterface(IDiscussionSettings, check=False)
|
||||||
|
return settings.delete_own_comment_enabled
|
||||||
|
|
||||||
def show_commenter_image(self):
|
def show_commenter_image(self):
|
||||||
# Check if showing commenter image is enabled in the registry
|
# Check if showing commenter image is enabled in the registry
|
||||||
registry = queryUtility(IRegistry)
|
registry = queryUtility(IRegistry)
|
||||||
|
@ -54,6 +54,8 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
|
|||||||
SingleCheckBoxFieldWidget
|
SingleCheckBoxFieldWidget
|
||||||
self.fields['edit_comment_enabled'].widgetFactory = \
|
self.fields['edit_comment_enabled'].widgetFactory = \
|
||||||
SingleCheckBoxFieldWidget
|
SingleCheckBoxFieldWidget
|
||||||
|
self.fields['delete_own_comment_enabled'].widgetFactory = \
|
||||||
|
SingleCheckBoxFieldWidget
|
||||||
self.fields['anonymous_comments'].widgetFactory = \
|
self.fields['anonymous_comments'].widgetFactory = \
|
||||||
SingleCheckBoxFieldWidget
|
SingleCheckBoxFieldWidget
|
||||||
self.fields['show_commenter_image'].widgetFactory = \
|
self.fields['show_commenter_image'].widgetFactory = \
|
||||||
@ -130,6 +132,9 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
|
|||||||
if settings.edit_comment_enabled:
|
if settings.edit_comment_enabled:
|
||||||
output.append("edit_comment_enabled")
|
output.append("edit_comment_enabled")
|
||||||
|
|
||||||
|
if settings.delete_own_comment_enabled:
|
||||||
|
output.append("delte_own_comment_enabled")
|
||||||
|
|
||||||
# Anonymous comments
|
# Anonymous comments
|
||||||
if settings.anonymous_comments:
|
if settings.anonymous_comments:
|
||||||
output.append("anonymous_comments")
|
output.append("anonymous_comments")
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
$('#formfield-form-widgets-anonymous_comments'),
|
$('#formfield-form-widgets-anonymous_comments'),
|
||||||
$('#formfield-form-widgets-moderation_enabled'),
|
$('#formfield-form-widgets-moderation_enabled'),
|
||||||
$('#formfield-form-widgets-edit_comment_enabled'),
|
$('#formfield-form-widgets-edit_comment_enabled'),
|
||||||
|
$('#formfield-form-widgets-delete_own_comment_enabled'),
|
||||||
$('#formfield-form-widgets-text_transform'),
|
$('#formfield-form-widgets-text_transform'),
|
||||||
$('#formfield-form-widgets-captcha'),
|
$('#formfield-form-widgets-captcha'),
|
||||||
$('#formfield-form-widgets-show_commenter_image'),
|
$('#formfield-form-widgets-show_commenter_image'),
|
||||||
@ -54,6 +55,7 @@
|
|||||||
$('#formfield-form-widgets-anonymous_comments'),
|
$('#formfield-form-widgets-anonymous_comments'),
|
||||||
$('#formfield-form-widgets-moderation_enabled'),
|
$('#formfield-form-widgets-moderation_enabled'),
|
||||||
$('#formfield-form-widgets-edit_comment_enabled'),
|
$('#formfield-form-widgets-edit_comment_enabled'),
|
||||||
|
$('#formfield-form-widgets-delete_own_comment_enabled'),
|
||||||
$('#formfield-form-widgets-text_transform'),
|
$('#formfield-form-widgets-text_transform'),
|
||||||
$('#formfield-form-widgets-captcha'),
|
$('#formfield-form-widgets-captcha'),
|
||||||
$('#formfield-form-widgets-show_commenter_image'),
|
$('#formfield-form-widgets-show_commenter_image'),
|
||||||
|
@ -117,8 +117,8 @@ class DeleteComment(BrowserView):
|
|||||||
return self.context.REQUEST.RESPONSE.redirect(came_from)
|
return self.context.REQUEST.RESPONSE.redirect(came_from)
|
||||||
|
|
||||||
def can_delete(self, reply):
|
def can_delete(self, reply):
|
||||||
"""By default requires 'Review comments'.
|
"""Returns true if current user has the 'Delete comments'
|
||||||
If 'delete own comments' is enabled, requires 'Edit comments'.
|
permission.
|
||||||
"""
|
"""
|
||||||
return getSecurityManager().checkPermission('Delete comments',
|
return getSecurityManager().checkPermission('Delete comments',
|
||||||
aq_inner(reply))
|
aq_inner(reply))
|
||||||
@ -133,7 +133,7 @@ class DeleteOwnComment(DeleteComment):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def could_delete(self, comment=None):
|
def could_delete(self, comment=None):
|
||||||
"""returns true if the comment could be deleted if it had no replies."""
|
"""Returns true if the comment could be deleted if it had no replies."""
|
||||||
sm = getSecurityManager()
|
sm = getSecurityManager()
|
||||||
comment = comment or aq_inner(self.context)
|
comment = comment or aq_inner(self.context)
|
||||||
userid = sm.getUser().getId()
|
userid = sm.getUser().getId()
|
||||||
@ -150,7 +150,7 @@ class DeleteOwnComment(DeleteComment):
|
|||||||
if self.can_delete():
|
if self.can_delete():
|
||||||
super(DeleteOwnComment, self).__call__()
|
super(DeleteOwnComment, self).__call__()
|
||||||
else:
|
else:
|
||||||
raise Unauthorized("Your not allowed to delete this comment.")
|
raise Unauthorized("You're not allowed to delete this comment.")
|
||||||
|
|
||||||
|
|
||||||
class PublishComment(BrowserView):
|
class PublishComment(BrowserView):
|
||||||
|
@ -45,8 +45,8 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<genericsetup:upgradeStep
|
<genericsetup:upgradeStep
|
||||||
title="edit comments"
|
title="edit comments and delete own comments"
|
||||||
description="reload registry config to enable new field edit_comment_enabled"
|
description="reload registry config to enable new fields edit_comment_enabled and delete_own_comment_enabled"
|
||||||
source="100"
|
source="100"
|
||||||
destination="101"
|
destination="101"
|
||||||
handler=".upgrades.update_registry"
|
handler=".upgrades.update_registry"
|
||||||
@ -55,8 +55,8 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<genericsetup:upgradeStep
|
<genericsetup:upgradeStep
|
||||||
title="delete comments"
|
title="delete comments and delete own comments"
|
||||||
description="reload rolemap config to enable new permission 'Delete comments'"
|
description="reload rolemap config to enable new permissions 'Delete comments' and 'Delete own comments'"
|
||||||
source="101"
|
source="101"
|
||||||
destination="102"
|
destination="102"
|
||||||
handler=".upgrades.update_rolemap"
|
handler=".upgrades.update_rolemap"
|
||||||
|
@ -247,13 +247,24 @@ class IDiscussionSettings(Interface):
|
|||||||
title=_(u"label_edit_comment_enabled",
|
title=_(u"label_edit_comment_enabled",
|
||||||
default="Enable editing of comments"),
|
default="Enable editing of comments"),
|
||||||
description=_(u"help_edit_comment_enabled",
|
description=_(u"help_edit_comment_enabled",
|
||||||
default=u"If selected, supports editing and deletion "
|
default=u"If selected, supports editing "
|
||||||
"of comments for users with the 'Edit comments' "
|
"of comments for users with the 'Edit comments' "
|
||||||
"permission."),
|
"permission."),
|
||||||
required=False,
|
required=False,
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
delete_own_comment_enabled = schema.Bool(
|
||||||
|
title=_(u"label_delete_own_comment_enabled",
|
||||||
|
default="Enable deleting own comments"),
|
||||||
|
description=_(u"help_delete_own_comment_enabled",
|
||||||
|
default=u"If selected, supports deleting "
|
||||||
|
"of own comments for users with the "
|
||||||
|
"'Delete own comments' permission."),
|
||||||
|
required=False,
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
||||||
text_transform = schema.Choice(
|
text_transform = schema.Choice(
|
||||||
title=_(u"label_text_transform",
|
title=_(u"label_text_transform",
|
||||||
default="Comment text transform"),
|
default="Comment text transform"),
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
<registry>
|
<registry>
|
||||||
<records interface="plone.app.discussion.interfaces.IDiscussionSettings">
|
<records interface="plone.app.discussion.interfaces.IDiscussionSettings">
|
||||||
<value key="edit_comment_enabled">False</value>
|
<value key="edit_comment_enabled">False</value>
|
||||||
|
<value key="delete_own_comment_enabled">False</value>
|
||||||
</records>
|
</records>
|
||||||
</registry>
|
</registry>
|
||||||
|
@ -89,12 +89,12 @@ class RegistryTest(unittest.TestCase):
|
|||||||
'IDiscussionSettings.edit_comment_enabled'],
|
'IDiscussionSettings.edit_comment_enabled'],
|
||||||
False)
|
False)
|
||||||
|
|
||||||
def test_edit_comment_enabled(self):
|
def test_delete_own_comment_enabled(self):
|
||||||
# Check edit_comment_enabled record
|
# Check delete_own_comment_enabled record
|
||||||
self.assertTrue('edit_comment_enabled' in IDiscussionSettings)
|
self.assertTrue('delete_own_comment_enabled' in IDiscussionSettings)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.registry['plone.app.discussion.interfaces.' +
|
self.registry['plone.app.discussion.interfaces.' +
|
||||||
'IDiscussionSettings.edit_comment_enabled'],
|
'IDiscussionSettings.delete_own_comment_enabled'],
|
||||||
False)
|
False)
|
||||||
|
|
||||||
def test_text_transform(self):
|
def test_text_transform(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user