diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 8804623f4b..32e2117508 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -236,6 +236,7 @@ def forum_form_discussion(request, course_id): 'annotated_content_info': saxutils.escape(json.dumps(annotated_content_info),escapedict), 'course_id': course.id, 'category_map': category_map, + 'roles': saxutils.escape(json.dumps(utils.get_role_ids(course_id)), escapedict), } # print "start rendering.." return render_to_response('discussion/index.html', context) @@ -315,6 +316,7 @@ def single_thread(request, course_id, discussion_id, thread_id): 'thread_id': thread_id, 'threads': saxutils.escape(json.dumps(threads), escapedict), 'category_map': category_map, + 'roles': saxutils.escape(json.dumps(utils.get_role_ids(course_id)), escapedict), } return render_to_response('discussion/single_thread.html', context) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index a4ab9342d2..4ceea6b82c 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -39,6 +39,14 @@ def strip_blank(dic): def merge_dict(dic1, dic2): return dict(dic1.items() + dic2.items()) +def get_role_ids(course_id): + roles = Role.objects.filter(course_id=course_id) + staff = list(User.objects.filter(is_staff=True).values_list('id', flat=True)) + roles_with_ids = {'Staff': staff} + for role in roles: + roles_with_ids[role.name] = list(role.users.values_list('id', flat=True)) + return roles_with_ids + def get_full_modules(): global _FULLMODULES if not _FULLMODULES: diff --git a/lms/static/coffee/src/discussion/utils.coffee b/lms/static/coffee/src/discussion/utils.coffee index c65a3c15fd..52a0b510ac 100644 --- a/lms/static/coffee/src/discussion/utils.coffee +++ b/lms/static/coffee/src/discussion/utils.coffee @@ -15,6 +15,11 @@ class @DiscussionUtil @getTemplate: (id) -> $("script##{id}").html() + @isStaff: (user_id) -> + ids = $("#discussion-container").data("roles") + staff = _.union(ids['Staff'], ids['Moderator'], ids['Administrator']) + _.include(staff, parseInt(user_id)) + @bulkUpdateContentInfo: (infos) -> for id, info of infos Content.getContent(id).updateInfo(info) diff --git a/lms/static/coffee/src/discussion/views/response_comment_view.coffee b/lms/static/coffee/src/discussion/views/response_comment_view.coffee index 34cbaac7ad..fbd3b917a1 100644 --- a/lms/static/coffee/src/discussion/views/response_comment_view.coffee +++ b/lms/static/coffee/src/discussion/views/response_comment_view.coffee @@ -18,6 +18,7 @@ if Backbone? @initLocal() @delegateEvents() @renderAttrs() + @markAsStaff() @$el.find(".timeago").timeago() @convertMath() @ @@ -29,3 +30,7 @@ if Backbone? body.children("p").each (index, elem) -> $(elem).replaceWith($(elem).html()) MathJax.Hub.Queue ["Typeset", MathJax.Hub, body[0]] + + markAsStaff: -> + if DiscussionUtil.isStaff(@model.get("user_id")) + @$el.find("a").after('staff') diff --git a/lms/static/coffee/src/discussion/views/thread_response_view.coffee b/lms/static/coffee/src/discussion/views/thread_response_view.coffee index f4719800cc..c6f0643de6 100644 --- a/lms/static/coffee/src/discussion/views/thread_response_view.coffee +++ b/lms/static/coffee/src/discussion/views/thread_response_view.coffee @@ -18,6 +18,7 @@ if Backbone? @renderAttrs() @$el.find(".posted-details").timeago() @convertMath() + @markAsStaff() @renderComments() @ @@ -26,6 +27,11 @@ if Backbone? element.html DiscussionUtil.postMathJaxProcessor DiscussionUtil.markdownWithHighlight element.html() MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]] + markAsStaff: -> + if DiscussionUtil.isStaff(@model.get("user_id")) + @$el.addClass("staff") + @$el.prepend('
staff
') + renderComments: -> comments = new Comments() comments.comparator = (comment) -> diff --git a/lms/templates/discussion/index.html b/lms/templates/discussion/index.html index 53cbe2d9ed..a0cdcdcb44 100644 --- a/lms/templates/discussion/index.html +++ b/lms/templates/discussion/index.html @@ -23,7 +23,7 @@ -
+
@@ -36,4 +36,4 @@
<%include file="_underscore_templates.html" /> -<%include file="_thread_list_template.html" /> \ No newline at end of file +<%include file="_thread_list_template.html" /> diff --git a/lms/templates/discussion/single_thread.html b/lms/templates/discussion/single_thread.html index 2ddeae4613..0cc1f28b24 100644 --- a/lms/templates/discussion/single_thread.html +++ b/lms/templates/discussion/single_thread.html @@ -24,7 +24,7 @@ <%include file="_new_post.html" /> -
+