From b06e31d2ed6206b118ae38d49c394ad4f878708d Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Wed, 8 Aug 2012 14:51:49 -0400 Subject: [PATCH 1/4] fix Close Thread showing for students and empty bracket in search bar --- lms/djangoapps/django_comment_client/forum/views.py | 4 +++- lms/djangoapps/django_comment_client/permissions.py | 7 +++---- lms/static/coffee/src/discussion/content.coffee | 2 ++ lms/templates/discussion/_search_bar.html | 2 +- lms/templates/discussion/_thread.html | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index b8f767e8bd..d4f6fda3c0 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -149,12 +149,14 @@ def forum_form_discussion(request, course_id, discussion_id): def get_annotated_content_info(course_id, content, user, is_thread): - return { + permissions = { 'editable': check_permissions_by_view(user, course_id, content, "update_thread" if is_thread else "update_comment"), 'can_reply': check_permissions_by_view(user, course_id, content, "create_comment" if is_thread else "create_sub_comment"), 'can_endorse': check_permissions_by_view(user, course_id, content, "endorse_comment") if not is_thread else False, 'can_delete': check_permissions_by_view(user, course_id, content, "delete_thread" if is_thread else "delete_comment"), + 'can_openclose': check_permissions_by_view(user, course_id, content, "openclose_thread") if is_thread else False, } + return permissions def get_annotated_content_infos(course_id, thread, user, is_thread=True): infos = {} diff --git a/lms/djangoapps/django_comment_client/permissions.py b/lms/djangoapps/django_comment_client/permissions.py index eae67a8361..0645d57a05 100644 --- a/lms/djangoapps/django_comment_client/permissions.py +++ b/lms/djangoapps/django_comment_client/permissions.py @@ -67,11 +67,10 @@ def check_conditions_permissions(user, permissions, course_id, **kwargs): VIEW_PERMISSIONS = { - 'update_thread' : ['edit_content', ['update_thread', 'is_open', 'author']], - # 'create_comment' : [["create_comment", "is_open"]], - 'create_comment' : ["create_comment"], + 'update_thread' : ['edit_content', ['update_thread', 'is_open', 'is_author']], + 'create_comment' : [["create_comment", "is_open"]], 'delete_thread' : ['delete_thread'], - 'update_comment' : ['edit_content', ['update_comment', 'is_open', 'author']], + 'update_comment' : ['edit_content', ['update_comment', 'is_open', 'is_author']], 'endorse_comment' : ['endorse_comment'], 'openclose_thread' : ['openclose_thread'], 'create_sub_comment': [['create_sub_comment', 'is_open']], diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index 878d8c1789..245511b827 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -372,3 +372,5 @@ initializeFollowThread = (thread) -> $local(".discussion-endorse-control").remove() if not Discussion.getContentInfo id, 'can_delete' $local(".discussion-delete").remove() + if not Discussion.getContentInfo id, 'can_openclose' + $local(".discussion-openclose").remove() diff --git a/lms/templates/discussion/_search_bar.html b/lms/templates/discussion/_search_bar.html index 9fa60d57a7..e93b46efb2 100644 --- a/lms/templates/discussion/_search_bar.html +++ b/lms/templates/discussion/_search_bar.html @@ -12,7 +12,7 @@ def base_url_for_search(): % if query_params.get('tags', None): % else: - + % endif diff --git a/lms/templates/discussion/_thread.html b/lms/templates/discussion/_thread.html index c22e41eaad..6ba88c1b67 100644 --- a/lms/templates/discussion/_thread.html +++ b/lms/templates/discussion/_thread.html @@ -98,7 +98,7 @@ - % if type == "thread" and request.user.is_staff: + % if type == "thread": % if content['closed']: Re-open thread % else: From f4edc050d09906d939810fc3110865875c15b081 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Wed, 8 Aug 2012 14:57:13 -0400 Subject: [PATCH 2/4] confirm before deleting comment/thread --- lms/static/coffee/src/discussion/content.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index 245511b827..daf25405cf 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -226,9 +226,12 @@ initializeFollowThread = (thread) -> handleDelete = (elem) -> if $content.hasClass("thread") url = Discussion.urlFor('delete_thread', id) + c = confirm "Are you sure to delete thread \"" + $content.find("a.thread-title").text() + "\"?" else url = Discussion.urlFor('delete_comment', id) - + c = confirm "Are you sure to delete this comment? " + if c != true + return Discussion.safeAjax $elem: $(elem) url: url From b4493344620a526019db82d2b2ddbf77ab274ade Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Thu, 9 Aug 2012 12:04:38 -0400 Subject: [PATCH 3/4] generate permanent link for thread/comment on client side --- lms/static/coffee/src/discussion/content.coffee | 9 +++++++++ lms/static/coffee/src/discussion/utils.coffee | 4 +++- lms/templates/discussion/_thread.html | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lms/static/coffee/src/discussion/content.coffee b/lms/static/coffee/src/discussion/content.coffee index daf25405cf..16c224d165 100644 --- a/lms/static/coffee/src/discussion/content.coffee +++ b/lms/static/coffee/src/discussion/content.coffee @@ -367,6 +367,15 @@ initializeFollowThread = (thread) -> MathJax.Hub.Queue ["Typeset", MathJax.Hub, $contentBody.attr("id")] id = $content.attr("_id") + + discussion_id = $content.parents(".discussion").attr("_id") + if $content.hasClass("thread") + permalink = Discussion.urlFor("permanent_link_thread", discussion_id, id) + else + thread_id = $content.parents(".thread").attr("_id") + permalink = Discussion.urlFor("permanent_link_comment", discussion_id, thread_id, id) + $local(".discussion-permanent-link").attr "href", permalink + if not Discussion.getContentInfo id, 'editable' $local(".discussion-edit").remove() if not Discussion.getContentInfo id, 'can_reply' diff --git a/lms/static/coffee/src/discussion/utils.coffee b/lms/static/coffee/src/discussion/utils.coffee index 0443f4a03d..47e6ba9131 100644 --- a/lms/static/coffee/src/discussion/utils.coffee +++ b/lms/static/coffee/src/discussion/utils.coffee @@ -16,7 +16,7 @@ wmdEditors = {} .addClass(cls).html(txt) .click -> handler(this) - urlFor: (name, param, param1) -> + urlFor: (name, param, param1, param2) -> { follow_discussion : "/courses/#{$$course_id}/discussion/#{param}/follow" unfollow_discussion : "/courses/#{$$course_id}/discussion/#{param}/unfollow" @@ -43,6 +43,8 @@ wmdEditors = {} tags_autocomplete : "/courses/#{$$course_id}/discussion/threads/tags/autocomplete" retrieve_discussion : "/courses/#{$$course_id}/discussion/forum/#{param}/inline" retrieve_single_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" + permanent_link_thread : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}" + permanent_link_comment : "/courses/#{$$course_id}/discussion/forum/#{param}/threads/#{param1}##{param2}" }[name] safeAjax: (params) -> diff --git a/lms/templates/discussion/_thread.html b/lms/templates/discussion/_thread.html index 6ba88c1b67..653b982503 100644 --- a/lms/templates/discussion/_thread.html +++ b/lms/templates/discussion/_thread.html @@ -88,6 +88,7 @@ ${render_info(content)} ${render_link("discussion-link discussion-reply discussion-reply-" + type, "Reply")} ${render_link("discussion-link discussion-edit", "Edit")} + ${render_link("discussion-link discussion-permanent-link", "Permanent Link")} % if content.get('endorsed', False): From 2fae27d582284ac714589f4c4051eb8cbbb7a396 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Thu, 9 Aug 2012 12:05:19 -0400 Subject: [PATCH 4/4] temporarily disable trending and active if no such data is passed to template. --- .../discussion/_recent_active_posts.html | 12 +++++++----- lms/templates/discussion/_trending_tags.html | 17 +++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lms/templates/discussion/_recent_active_posts.html b/lms/templates/discussion/_recent_active_posts.html index 6a476f3c14..0e087b5eca 100644 --- a/lms/templates/discussion/_recent_active_posts.html +++ b/lms/templates/discussion/_recent_active_posts.html @@ -2,8 +2,10 @@
Recent Activity:
-
- % for thread in recent_active_threads: - ${thread['title']} - % endfor -
+% if recent_active_threads: +
+ % for thread in recent_active_threads: + ${thread['title']} + % endfor +
+% endif \ No newline at end of file diff --git a/lms/templates/discussion/_trending_tags.html b/lms/templates/discussion/_trending_tags.html index 1460cb5888..9cc97c7921 100644 --- a/lms/templates/discussion/_trending_tags.html +++ b/lms/templates/discussion/_trending_tags.html @@ -1,11 +1,12 @@