From 50db11a647bf9805a41b3752e9487ebbc5e7ea5b Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Wed, 5 Dec 2012 17:08:29 -0500 Subject: [PATCH] urls and views for comment flagging --- .../django_comment_client/base/urls.py | 8 ++++-- .../django_comment_client/base/views.py | 12 ++++++++ lms/envs/common.py | 2 +- lms/lib/comment_client/comment.py | 28 +++++++++++++++++++ lms/lib/comment_client/thread.py | 8 +++--- .../coffee/src/discussion/content.coffee | 6 ++-- 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py index 2d8e6cf263..87b427d73a 100644 --- a/lms/djangoapps/django_comment_client/base/urls.py +++ b/lms/djangoapps/django_comment_client/base/urls.py @@ -11,8 +11,8 @@ urlpatterns = patterns('django_comment_client.base.views', url(r'threads/(?P[\w\-]+)/delete', 'delete_thread', name='delete_thread'), url(r'threads/(?P[\w\-]+)/upvote$', 'vote_for_thread', {'value': 'up'}, name='upvote_thread'), url(r'threads/(?P[\w\-]+)/flagAbuse$', 'flag_abuse_for_thread', {'value': 'up'}, name='flag_abuse_for_thread'), - url(r'threads/(?P[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_thread', {'value': 'up'}, name='un_flag_abuse_for_thread'), - url(r'threads/(?P[\w\-]+)/downvote$', 'vote_for_thread', {'value': 'down'}, name='downvote_thread'), + url(r'threads/(?P[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_thread', name='un_flag_abuse_for_thread'), + url(r'threads/(?P[\w\-]+)/downvote$', 'vote_for_thread', name='downvote_thread'), url(r'threads/(?P[\w\-]+)/unvote$', 'undo_vote_for_thread', name='undo_vote_for_thread'), url(r'threads/(?P[\w\-]+)/follow$', 'follow_thread', name='follow_thread'), url(r'threads/(?P[\w\-]+)/unfollow$', 'unfollow_thread', name='unfollow_thread'), @@ -25,7 +25,9 @@ urlpatterns = patterns('django_comment_client.base.views', url(r'comments/(?P[\w\-]+)/upvote$', 'vote_for_comment', {'value': 'up'}, name='upvote_comment'), url(r'comments/(?P[\w\-]+)/downvote$', 'vote_for_comment', {'value': 'down'}, name='downvote_comment'), url(r'comments/(?P[\w\-]+)/unvote$', 'undo_vote_for_comment', name='undo_vote_for_comment'), - + url(r'threads/(?P[\w\-]+)/flagAbuse$', 'flag_abuse_for_comment', name='flag_abuse_for_comment'), + url(r'threads/(?P[\w\-]+)/unFlagAbuse$', 'un_flag_abuse_for_comment', name='un_flag_abuse_for_comment'), + url(r'(?P[\w\-]+)/threads/create$', 'create_thread', name='create_thread'), # TODO should we search within the board? url(r'(?P[\w\-]+)/threads/search_similar$', 'search_similar_threads', name='search_similar_threads'), diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 29cc3d03e9..9958fe5171 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -250,6 +250,18 @@ def un_flag_abuse_for_thread(request, course_id, thread_id, value): thread.unFlagAbuse(user,thread, value) return JsonResponse(utils.safe_content(thread.to_dict())) +def flag_abuse_for_comment(request, course_id, comment_id, value): + user = cc.User.from_django_user(request.user) + comment = cc.Comment.find(thread_id) + comment.flagAbuse(user,comment, value) + return JsonResponse(utils.safe_content(comment.to_dict())) + +def un_flag_abuse_for_comment(request, course_id, comment_id, value): + user = cc.User.from_django_user(request.user) + comment = cc.Comment.find(thread_id) + comment.unFlagAbuse(user,comment, value) + return JsonResponse(utils.safe_content(comment.to_dict())) + @require_POST @login_required @permitted diff --git a/lms/envs/common.py b/lms/envs/common.py index dd9013bcb3..a9d91dc167 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -46,7 +46,7 @@ MITX_FEATURES = { 'USE_DJANGO_PIPELINE' : True, 'DISPLAY_HISTOGRAMS_TO_STAFF' : True, 'REROUTE_ACTIVATION_EMAIL' : False, # nonempty string = address for all activation emails - 'DEBUG_LEVEL' : 0, # 0 = lowest level, least verbose, 255 = max level, most verbose + 'DEBUG_LEVEL' : 255, # 0 = lowest level, least verbose, 255 = max level, most verbose ## DO NOT SET TO True IN THIS FILE ## Doing so will cause all courses to be released on production diff --git a/lms/lib/comment_client/comment.py b/lms/lib/comment_client/comment.py index 02d74370db..ed0cfcd8c5 100644 --- a/lms/lib/comment_client/comment.py +++ b/lms/lib/comment_client/comment.py @@ -40,9 +40,37 @@ class Comment(models.Model): return cls.url_for_comments(params) else: return super(Comment, cls).url(action, params) + + def flagAbuse(self, user, voteable, value): + if voteable.type == 'thread': + url = _url_for_flag_abuse_thread(voteable.id) + elif voteable.type == 'comment': + url = _url_for_flag_comment(voteable.id) + else: + raise CommentClientError("Can only flag/unflag threads or comments") + params = {'user_id': user.id} + request = perform_request('put', url, params) + voteable.update_attributes(request) + + def unFlagAbuse(self, user, voteable, value): + if voteable.type == 'thread': + url = _url_for_unflag_abuse_thread(voteable.id) + elif voteable.type == 'comment': + url = _url_for_unflag_comment(voteable.id) + else: + raise CommentClientError("Can flag/unflag for threads or comments") + params = {'user_id': user.id} + request = perform_request('put', url, params) + voteable.update_attributes(request) def _url_for_thread_comments(thread_id): return "{prefix}/threads/{thread_id}/comments".format(prefix=settings.PREFIX, thread_id=thread_id) def _url_for_comment(comment_id): return "{prefix}/comments/{comment_id}".format(prefix=settings.PREFIX, comment_id=comment_id) + +def _url_for_flag_abuse_comment(comment_id): + return "{prefix}/threads/{comment_id}/abuse_flags".format(prefix=settings.PREFIX, thread_id=thread_id) + +def _url_for_unflag_abuse_thread(comment_id): + return "{prefix}/threads/{comment_id}/abuse_unflags".format(prefix=settings.PREFIX, thread_id=thread_id) diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 1bb70d6b9f..5fd10a3e69 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -77,9 +77,9 @@ class Thread(models.Model): if voteable.type == 'thread': url = _url_for_flag_abuse_thread(voteable.id) elif voteable.type == 'comment': - url = _url_for_vote_comment(voteable.id) + url = _url_for_flag_comment(voteable.id) else: - raise CommentClientError("Can only vote / unvote for threads or comments") + raise CommentClientError("Can only flag/unflag threads or comments") params = {'user_id': user.id} request = perform_request('put', url, params) voteable.update_attributes(request) @@ -88,9 +88,9 @@ class Thread(models.Model): if voteable.type == 'thread': url = _url_for_unflag_abuse_thread(voteable.id) elif voteable.type == 'comment': - url = _url_for_vote_comment(voteable.id) + url = _url_for_unflag_comment(voteable.id) else: - raise CommentClientError("Can only vote / unvote for threads or comments") + raise CommentClientError("Can flag/unflag for threads or comments") params = {'user_id': user.id} request = perform_request('put', url, params) voteable.update_attributes(request) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index 2edc4114e0..778f763020 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -94,8 +94,6 @@ if Backbone? urlMappers: 'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @discussion.id, @id) 'reply' : -> DiscussionUtil.urlFor('create_comment', @id) - 'flagAbuse' : -> DiscussionUtil.urlFor("flagAbuse_#{@get('type')}", @id) - 'unFlagAbuse' : -> DiscussionUtil.urlFor("unFlagAbuse_#{@get('type')}", @id) 'unvote' : -> DiscussionUtil.urlFor("undo_vote_for_#{@get('type')}", @id) 'upvote' : -> DiscussionUtil.urlFor("upvote_#{@get('type')}", @id) 'downvote' : -> DiscussionUtil.urlFor("downvote_#{@get('type')}", @id) @@ -104,6 +102,10 @@ if Backbone? 'delete' : -> DiscussionUtil.urlFor('delete_thread', @id) 'follow' : -> DiscussionUtil.urlFor('follow_thread', @id) 'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id) + 'flagAbuse' : -> DiscussionUtil.urlFor("flagAbuse_#{@get('type')}", @id) + 'unFlagAbuse' : -> DiscussionUtil.urlFor("unFlagAbuse_#{@get('type')}", @id) + + initialize: -> @set('thread', @)