From 20f8f50ccb3076bbea500b3307fe6ed2310e298a Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 13 Apr 2013 09:40:01 -0400 Subject: [PATCH 1/3] Add allow_comments configuration setting. --- mediagoblin/config_spec.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index e830e863..545d02e2 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -34,6 +34,9 @@ allow_registration = boolean(default=True) # tag parsing tags_max_length = integer(default=50) +# Enable/disable comments +allow_comments = boolean(default=True) + # Whether comments are ascending or descending comments_ascending = boolean(default=True) From aa4f958a40b933e94eb8ea86093eedf0bcc0e029 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 13 Apr 2013 09:40:34 -0400 Subject: [PATCH 2/3] Do not render 'Add a comment' button if comments are disabled. --- .../templates/mediagoblin/user_pages/media.html | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index b77c12b9..04be81aa 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -43,7 +43,7 @@ {%- endtrans -%}

{% include "mediagoblin/utils/prev_next.html" %} -
+
{% block mediagoblin_media %} {% set display_media = request.app.public_store.file_url( @@ -71,7 +71,7 @@ {{ media.title }} {% if request.user and - (media.uploader == request.user.id or + (media.uploader == request.user.id or request.user.is_admin) %} {% set edit_url = request.urlgen('mediagoblin.edit.edit_media', user= media.get_uploader.username, @@ -90,11 +90,13 @@ {% if not request.user %} href="{{ request.urlgen('mediagoblin.auth.login') }}" {% endif %} - class="button_action" id="button_addcomment" title="Add a comment"> - {% trans %}Add a comment{% endtrans %} + {% if app_config['allow_comments'] %} + class="button_action" id="button_addcomment" title="Add a comment"> + {% trans %}Add a comment{% endtrans %} + {% endif %} {% if request.user %} -
{{ wtforms_util.render_divs(comment_form) }} @@ -154,7 +156,7 @@ {% include "mediagoblin/utils/license.html" %} {% include "mediagoblin/utils/exif.html" %} - + {%- if media.attachment_files|count %}

{% trans %}Attachments{% endtrans %}

    From 99338b6a6419e6d8c044b82b2dd398a435e477f0 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 13 Apr 2013 10:42:40 -0400 Subject: [PATCH 3/3] Do not allow comments to be posted when they are disabled. --- mediagoblin/user_pages/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 61c23f16..b3e613c4 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -159,7 +159,13 @@ def media_post_comment(request, media): comment.author = request.user.id comment.content = unicode(request.form['comment_content']) - if not comment.content.strip(): + # Show error message if commenting is disabled. + if not mg_globals.app_config['allow_comments']: + messages.add_message( + request, + messages.ERROR, + _("Sorry, comments are disabled.")) + elif not comment.content.strip(): messages.add_message( request, messages.ERROR,