diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py index cf0ef68916..2d8e6cf263 100644 --- a/lms/djangoapps/django_comment_client/base/urls.py +++ b/lms/djangoapps/django_comment_client/base/urls.py @@ -11,6 +11,7 @@ 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\-]+)/unvote$', 'undo_vote_for_thread', name='undo_vote_for_thread'), url(r'threads/(?P[\w\-]+)/follow$', 'follow_thread', name='follow_thread'), diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 9c750423ef..29cc3d03e9 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -244,6 +244,12 @@ def flag_abuse_for_thread(request, course_id, thread_id, value): thread.flagAbuse(user,thread, value) return JsonResponse(utils.safe_content(thread.to_dict())) +def un_flag_abuse_for_thread(request, course_id, thread_id, value): + user = cc.User.from_django_user(request.user) + thread = cc.Thread.find(thread_id) + thread.unFlagAbuse(user,thread, value) + return JsonResponse(utils.safe_content(thread.to_dict())) + @require_POST @login_required @permitted diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index e442225c4d..396af3e637 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -352,7 +352,7 @@ def safe_content(content): 'updated_at', 'depth', 'type', 'commentable_id', 'comments_count', 'at_position_list', 'children', 'highlighted_title', 'highlighted_body', 'courseware_title', 'courseware_url', 'tags', 'unread_comments_count', - 'read', "abuse_flaggers", "spoiler_flaggers" + 'read', "abuse_flaggers" ] if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False): diff --git a/lms/lib/comment_client/comment.py b/lms/lib/comment_client/comment.py index 5d49c0a869..02d74370db 100644 --- a/lms/lib/comment_client/comment.py +++ b/lms/lib/comment_client/comment.py @@ -10,7 +10,7 @@ class Comment(models.Model): 'id', 'body', 'anonymous', 'anonymous_to_peers', 'course_id', 'endorsed', 'parent_id', 'thread_id', 'username', 'votes', 'user_id', 'closed', 'created_at', 'updated_at', 'depth', 'at_position_list', - 'type', 'commentable_id', 'abuse_flaggers', 'spoiler_flaggers' + 'type', 'commentable_id', 'abuse_flaggers' ] updatable_fields = [ diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 3d1945730c..637196ebab 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -10,7 +10,7 @@ class Thread(models.Model): 'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id', 'created_at', 'updated_at', 'comments_count', 'unread_comments_count', 'at_position_list', 'children', 'type', 'highlighted_title', - 'highlighted_body', 'endorsed', 'read', 'abuse_flaggers', 'spoiler_flaggers' + 'highlighted_body', 'endorsed', 'read', 'abuse_flaggers' ] updatable_fields = [ @@ -74,6 +74,17 @@ class Thread(models.Model): 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_vote_comment(voteable.id) + else: + raise CommentClientError("Can only vote / unvote for threads or comments") + params = {'user_id': user.id, 'value': value} + request = perform_request('put', url, params) + voteable.update_attributes(request) + + def unFlagAbuse(self, user, voteable, value): if voteable.type == 'thread': url = _url_for_flag_abuse_thread(voteable.id) elif voteable.type == 'comment': diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index 6a25a07ec2..ac6fbe38b2 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -82,17 +82,18 @@ if Backbone? class @Thread extends @Content urlMappers: - 'retrieve' : -> DiscussionUtil.urlFor('retrieve_single_thread', @discussion.id, @id) - 'reply' : -> DiscussionUtil.urlFor('create_comment', @id) - 'flagAbuse': -> DiscussionUtil.urlFor("flagAbuse_#{@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) - 'close' : -> DiscussionUtil.urlFor('openclose_thread', @id) - 'update' : -> DiscussionUtil.urlFor('update_thread', @id) - 'delete' : -> DiscussionUtil.urlFor('delete_thread', @id) - 'follow' : -> DiscussionUtil.urlFor('follow_thread', @id) - 'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id) + '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) + 'close' : -> DiscussionUtil.urlFor('openclose_thread', @id) + 'update' : -> DiscussionUtil.urlFor('update_thread', @id) + 'delete' : -> DiscussionUtil.urlFor('delete_thread', @id) + 'follow' : -> DiscussionUtil.urlFor('follow_thread', @id) + 'unfollow' : -> DiscussionUtil.urlFor('unfollow_thread', @id) initialize: -> @set('thread', @) @@ -120,7 +121,7 @@ if Backbone? @trigger "change", @ unflagAbuse: -> - @get("votes")["up_count"] = parseInt(@get("votes")["up_count"]) - 1 + @get("abuse_flaggers").push window.user.get('id') @trigger "change", @ display_body: -> diff --git a/lms/static/coffee/src/discussion/utils.coffee b/lms/static/coffee/src/discussion/utils.coffee index 6947eb6529..6a05d92f60 100644 --- a/lms/static/coffee/src/discussion/utils.coffee +++ b/lms/static/coffee/src/discussion/utils.coffee @@ -49,6 +49,7 @@ class @DiscussionUtil create_comment : "/courses/#{$$course_id}/discussion/threads/#{param}/reply" delete_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/delete" flagAbuse_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/flagAbuse" + unflagAbuse_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unFlagAbuse" upvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/upvote" downvote_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/downvote" undo_vote_for_thread : "/courses/#{$$course_id}/discussion/threads/#{param}/unvote" diff --git a/lms/static/coffee/src/discussion/views/discussion_thread_show_view.coffee b/lms/static/coffee/src/discussion/views/discussion_thread_show_view.coffee index 93f48d5339..21282fbd2e 100644 --- a/lms/static/coffee/src/discussion/views/discussion_thread_show_view.coffee +++ b/lms/static/coffee/src/discussion/views/discussion_thread_show_view.coffee @@ -4,7 +4,6 @@ if Backbone? events: "click .discussion-vote": "toggleVote" "click .discussion-flag-abuse": "toggleFlagAbuse" - "click .discussion-flag-spoiler": "toggleFlagSpoiler" "click .action-follow": "toggleFollowing" "click .action-edit": "edit" "click .action-delete": "delete" @@ -26,6 +25,7 @@ if Backbone? @delegateEvents() @renderDogear() @renderVoted() + @renderFlagged() @renderAttrs() @$("span.timeago").timeago() @convertMath() @@ -42,9 +42,18 @@ if Backbone? @$("[data-role=discussion-vote]").addClass("is-cast") else @$("[data-role=discussion-vote]").removeClass("is-cast") + + renderFlagged: => + if window.user.id in @model.get("abuse_flaggers") + @$("[thread-flag]").addClass("flagged") + @$("[thread-flag]").removeClass("notflagged") + else + @$("[thread-flag]").removeClass("flagged") + @$("[thread-flag]").addClass("notflagged") updateModelDetails: => @renderVoted() + @renderFlagged() @$("[data-role=discussion-vote] .votes-count-number").html(@model.get("votes")["up_count"]) convertMath: -> @@ -60,20 +69,13 @@ if Backbone? @vote() toggleFlagAbuse: (event) -> - alert('flag') event.preventDefault() if window.user in @model.get("abuse_flaggers") - @flagAbuse() - else @unFlagAbuse() - - toggleFlagSpoiler: (event) -> - event.preventDefault() - if window.user in @model.abuse_flaggers - @unFlagAbuse() else @flagAbuse() + toggleFollowing: (event) -> $elem = $(event.target) url = null @@ -100,6 +102,7 @@ if Backbone? @model.set(response, {silent: true}) flagAbuse: -> + alert('flag abuse') url = @model.urlFor("flagAbuse") DiscussionUtil.safeAjax $elem: @$(".discussion-flag-abuse") @@ -121,10 +124,10 @@ if Backbone? @model.set(response, {silent: true}) unFlagAbuse: -> - window.user.unvote(@model) - url = @model.urlFor("unvote") + alert('unflag abuse') + url = @model.urlFor("unFlagAbuse") DiscussionUtil.safeAjax - $elem: @$(".discussion-vote") + $elem: @$(".discussion-flag-abuse") url: url type: "POST" success: (response, textStatus) => diff --git a/lms/templates/discussion/_underscore_templates.html b/lms/templates/discussion/_underscore_templates.html index 892c048add..d4a6e6db06 100644 --- a/lms/templates/discussion/_underscore_templates.html +++ b/lms/templates/discussion/_underscore_templates.html @@ -44,7 +44,7 @@
${'<%- body %>'}
- + Report Misuse ${'<% if (obj.courseware_url) { %>'}