diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 9ab0603d42..56009f0209 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -62,19 +62,31 @@ def ajax_content_response(request, course_id, content, template_name): @login_required @permitted def create_thread(request, course_id, commentable_id): + course = get_course_with_access(request.user, course_id, 'load') post = request.POST + + if course.metadata.get("allow_anonymous", True): + anonymous = post.get('anonymous', 'false').lower() == 'true' + else: + anonymous = False + + if course.metadata.get("allow_anonymous_to_peers", False): + anonymous_to_peers = post.get('anonymous_to_peers', 'false').lower() == 'true' + else: + anonymous_to_peers = False + thread = cc.Thread(**extract(post, ['body', 'title', 'tags'])) thread.update_attributes(**{ - 'anonymous' : post.get('anonymous', 'false').lower() == 'true', - 'commentable_id' : commentable_id, - 'course_id' : course_id, - 'user_id' : request.user.id, + 'anonymous' : anonymous, + 'anonymous_to_peers' : anonymous_to_peers, + 'commentable_id' : commentable_id, + 'course_id' : course_id, + 'user_id' : request.user.id, }) thread.save() if post.get('auto_subscribe', 'false').lower() == 'true': user = cc.User.from_django_user(request.user) user.follow(thread) - course = get_course_with_access(request.user, course_id, 'load') courseware_context = get_courseware_context(thread, course) data = thread.to_dict() if courseware_context: @@ -99,8 +111,20 @@ def update_thread(request, course_id, thread_id): def _create_comment(request, course_id, thread_id=None, parent_id=None): post = request.POST comment = cc.Comment(**extract(post, ['body'])) + + if course.metadata.get("allow_anonymous", True): + anonymous = post.get('anonymous', 'false').lower() == 'true' + else: + anonymous = False + + if course.metadata.get("allow_anonymous_to_peers", False): + anonymous_to_peers = post.get('anonymous_to_peers', 'false').lower() == 'true' + else: + anonymous_to_peers = False + comment.update_attributes(**{ - 'anonymous' : post.get('anonymous', 'false').lower() == 'true', + 'anonymous' : anonymous, + 'anonymous_to_peers' : anonymous_to_peers, 'user_id' : request.user.id, 'course_id' : course_id, 'thread_id' : thread_id, diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 4708037fe7..2297cd9fa7 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -92,6 +92,8 @@ def inline_discussion(request, course_id, discussion_id): Renders JSON for DiscussionModules """ + course = get_course_with_access(request.user, course_id, 'load') + try: threads, query_params = get_threads(request, course_id, discussion_id, per_page=INLINE_THREADS_PER_PAGE) user_info = cc.User.from_django_user(request.user).to_dict() @@ -106,6 +108,9 @@ def inline_discussion(request, course_id, discussion_id): annotated_content_info = reduce(merge_dict, map(infogetter, threads), {}) + allow_anonymous = course.metadata.get("allow_anonymous", True) + allow_anonymous_to_peers = course.metadata.get("allow_anonymous_to_peers", False) + return utils.JsonResponse({ 'discussion_data': map(utils.safe_content, threads), 'user_info': user_info, @@ -113,6 +118,8 @@ def inline_discussion(request, course_id, discussion_id): 'page': query_params['page'], 'num_pages': query_params['num_pages'], 'roles': utils.get_role_ids(course_id), + 'allow_anonymous_to_peers': allow_anonymous_to_peers, + 'allow_anonymous': allow_anonymous, }) @login_required diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 9ebae79fa2..d7c1884580 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -188,7 +188,9 @@ def initialize_discussion_info(course): "sort_key": entry["sort_key"], "start_date": entry["start_date"]} - for topic, entry in course.metadata.get('discussion_topics', {}).items(): + default_topics = {'General': course.location.html_id()} + discussion_topics = course.metadata.get('discussion_topics', default_topics) + for topic, entry in discussion_topics.items(): category_map['entries'][topic] = {"id": entry["id"], "sort_key": entry.get("sort_key", topic), "start_date": time.gmtime()} @@ -327,15 +329,14 @@ def get_courseware_context(content, course): def safe_content(content): fields = [ - 'id', 'title', 'body', 'course_id', 'anonymous', 'endorsed', - 'parent_id', 'thread_id', 'votes', 'closed', - 'created_at', 'updated_at', 'depth', 'type', - 'commentable_id', 'comments_count', 'at_position_list', - 'children', 'highlighted_title', 'highlighted_body', + 'id', 'title', 'body', 'course_id', 'anonymous', 'anonymous_to_peers', + 'endorsed', 'parent_id', 'thread_id', 'votes', 'closed', 'created_at', + 'updated_at', 'depth', 'type', 'commentable_id', 'comments_count', + 'at_position_list', 'children', 'highlighted_title', 'highlighted_body', 'courseware_title', 'courseware_location', 'tags' ] - if content.get('anonymous') is False: + if (content.get('anonymous') is False) and (content.get('anonymous_to_peers') is False): fields += ['username', 'user_id'] return strip_none(extract(content, fields)) diff --git a/lms/lib/comment_client/comment.py b/lms/lib/comment_client/comment.py index 52a0aef70f..6d0bafee02 100644 --- a/lms/lib/comment_client/comment.py +++ b/lms/lib/comment_client/comment.py @@ -7,15 +7,14 @@ import settings class Comment(models.Model): accessible_fields = [ - 'id', 'body', 'anonymous', 'course_id', - 'endorsed', 'parent_id', 'thread_id', - 'username', 'votes', 'user_id', 'closed', - 'created_at', 'updated_at', 'depth', - 'at_position_list', 'type', 'commentable_id', + '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', ] updatable_fields = [ - 'body', 'anonymous', 'course_id', 'closed', + 'body', 'anonymous', 'anonymous_to_peers', 'course_id', 'closed', 'user_id', 'endorsed', ] diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 98ce4c3640..bda032bbdf 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -6,17 +6,14 @@ import settings class Thread(models.Model): accessible_fields = [ - 'id', 'title', 'body', 'anonymous', - 'course_id', 'closed', 'tags', 'votes', - 'commentable_id', 'username', 'user_id', - 'created_at', 'updated_at', 'comments_count', - 'at_position_list', 'children', 'type', - 'highlighted_title', 'highlighted_body', - 'endorsed' + 'id', 'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id', + 'closed', 'tags', 'votes', 'commentable_id', 'username', 'user_id', + 'created_at', 'updated_at', 'comments_count', 'at_position_list', + 'children', 'type', 'highlighted_title', 'highlighted_body', 'endorsed' ] updatable_fields = [ - 'title', 'body', 'anonymous', 'course_id', + 'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id', 'closed', 'tags', 'user_id', 'commentable_id', ] diff --git a/lms/static/coffee/src/discussion/discussion_module_view.coffee b/lms/static/coffee/src/discussion/discussion_module_view.coffee index 01199ac106..63bd6bc733 100644 --- a/lms/static/coffee/src/discussion/discussion_module_view.coffee +++ b/lms/static/coffee/src/discussion/discussion_module_view.coffee @@ -68,10 +68,12 @@ if Backbone? window.user = new DiscussionUser(response.user_info) Content.loadContentInfos(response.annotated_content_info) DiscussionUtil.loadRoles(response.roles) + allow_anonymous = response.allow_anonymous + allow_anonymous_to_peers = response.allow_anonymous_to_peers # $elem.html("Hide Discussion") @discussion = new Discussion() @discussion.reset(response.discussion_data, {silent: false}) - $discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId}) + $discussion = $(Mustache.render $("script#_inline_discussion").html(), {'threads':response.discussion_data, 'discussionId': discussionId, 'allow_anonymous_to_peers': allow_anonymous_to_peers, 'allow_anonymous': allow_anonymous}) if @$('section.discussion').length @$('section.discussion').replaceWith($discussion) else 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 79ff3116de..a8e95c2565 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 @@ -134,6 +134,6 @@ if Backbone? renderTemplate: -> @template = DiscussionUtil.getTemplate('_inline_thread_show') params = @model.toJSON() - if not @model.get('anonymous') + if @model.get('username')? params = $.extend(params, user:{username: @model.username, user_url: @model.user_url}) Mustache.render(@template, params) diff --git a/lms/static/coffee/src/discussion/views/new_post_inline_vew.coffee b/lms/static/coffee/src/discussion/views/new_post_inline_vew.coffee index 4b00cd25f0..ed5ee13919 100644 --- a/lms/static/coffee/src/discussion/views/new_post_inline_vew.coffee +++ b/lms/static/coffee/src/discussion/views/new_post_inline_vew.coffee @@ -8,7 +8,9 @@ if Backbone? @maxNameWidth = 100 DiscussionUtil.makeWmdEditor @$el, $.proxy(@$, @), "new-post-body" - @$(".new-post-tags").tagsInput DiscussionUtil.tagsInputOptions() + + # TODO tags: commenting out til we know what to do with them + #@$(".new-post-tags").tagsInput DiscussionUtil.tagsInputOptions() events: "submit .new-post-form": "createPost" @@ -23,9 +25,12 @@ if Backbone? event.preventDefault() title = @$(".new-post-title").val() body = @$(".new-post-body").find(".wmd-input").val() - tags = @$(".new-post-tags").val() - anonymous = false || @$("input.discussion-anonymous").is(":checked") + # TODO tags: commenting out til we know what to do with them + #tags = @$(".new-post-tags").val() + + anonymous = false || @$("input.discussion-anonymous").is(":checked") + anonymous_to_peers = false || @$("input.discussion-anonymous-to-peers").is(":checked") follow = false || @$("input.discussion-follow").is(":checked") url = DiscussionUtil.urlFor('create_thread', @topicId) @@ -40,8 +45,12 @@ if Backbone? data: title: title body: body - tags: tags + + # TODO tags: commenting out til we know what to do with them + #tags: tags + anonymous: anonymous + anonymous_to_peers: anonymous_to_peers auto_subscribe: follow error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors")) success: (response, textStatus) => @@ -51,6 +60,9 @@ if Backbone? @$el.hide() @$(".new-post-title").val("").attr("prev-text", "") @$(".new-post-body textarea").val("").attr("prev-text", "") - @$(".new-post-tags").val("") - @$(".new-post-tags").importTags("") + + # TODO tags, commenting out til we know what to do with them + #@$(".new-post-tags").val("") + #@$(".new-post-tags").importTags("") + @collection.add thread diff --git a/lms/static/coffee/src/discussion/views/new_post_view.coffee b/lms/static/coffee/src/discussion/views/new_post_view.coffee index 86dbffa5b8..2400a3b18e 100644 --- a/lms/static/coffee/src/discussion/views/new_post_view.coffee +++ b/lms/static/coffee/src/discussion/views/new_post_view.coffee @@ -116,8 +116,9 @@ if Backbone? body = @$(".new-post-body").find(".wmd-input").val() tags = @$(".new-post-tags").val() - anonymous = false || @$("input.discussion-anonymous").is(":checked") - follow = false || @$("input.discussion-follow").is(":checked") + anonymous = false || @$("input.discussion-anonymous").is(":checked") + anonymous_to_peers = false || @$("input.discussion-anonymous-to-peers").is(":checked") + follow = false || @$("input.discussion-follow").is(":checked") $formTopicDropBtn.bind('click', showFormTopicDrop) $formTopicDropMenu.bind('click', setFormTopic) @@ -136,6 +137,7 @@ if Backbone? body: body tags: tags anonymous: anonymous + anonymous_to_peers: anonymous_to_peers auto_subscribe: follow error: DiscussionUtil.formErrorHandler(@$(".new-post-form-errors")) success: (response, textStatus) => diff --git a/lms/templates/discussion/_inline_new_post.html b/lms/templates/discussion/_inline_new_post.html index 7bc17d4467..7af66c0cdd 100644 --- a/lms/templates/discussion/_inline_new_post.html +++ b/lms/templates/discussion/_inline_new_post.html @@ -7,7 +7,11 @@
- ${"<% if (!obj.anonymous) { %>"} + ${"<% if (obj.username) { %>"} ${'<%- username %>'} ${"<% } else {print('anonymous');} %>"} ${'<%- created_at %>'} diff --git a/lms/templates/discussion/mustache/_inline_discussion.mustache b/lms/templates/discussion/mustache/_inline_discussion.mustache index 22c0564426..0140a6221a 100644 --- a/lms/templates/discussion/mustache/_inline_discussion.mustache +++ b/lms/templates/discussion/mustache/_inline_discussion.mustache @@ -14,15 +14,21 @@
-