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