add delete_own_comment_enabled option in control panel

This commit is contained in:
Vincent Fretin
2014-09-20 16:02:48 +02:00
parent ee28528f55
commit 2a8082cfa7
9 changed files with 42 additions and 16 deletions
+2 -1
View File
@@ -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"
+8 -2
View File
@@ -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'),
+4 -4
View File
@@ -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):