From f5840489a0e708f13ccf7d334ce88514345a9660 Mon Sep 17 00:00:00 2001 From: Daniel Friedman Date: Tue, 4 Aug 2015 13:52:40 -0400 Subject: [PATCH] Allow editing of own post in team discussion --- lms/djangoapps/django_comment_client/base/tests.py | 8 ++++++-- lms/djangoapps/django_comment_client/base/views.py | 8 +++++--- lms/djangoapps/django_comment_client/forum/views.py | 3 ++- lms/djangoapps/django_comment_client/utils.py | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py index 6cc18b361f..be3adc135c 100644 --- a/lms/djangoapps/django_comment_client/base/tests.py +++ b/lms/djangoapps/django_comment_client/base/tests.py @@ -1193,7 +1193,11 @@ class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSe thread_author = getattr(self, thread_author) self._setup_mock( user, mock_request, # user is the person making the request. - {"user_id": str(thread_author.id), "closed": False, "commentable_id": commentable_id} + { + "user_id": str(thread_author.id), + "closed": False, "commentable_id": commentable_id, + "context": "standalone" + } ) response = self.client.post( reverse( @@ -1203,7 +1207,7 @@ class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSe "thread_id": "dummy" } ), - data={"body": "foo", "title": "foo"} + data={"body": "foo", "title": "foo", "commentable_id": commentable_id} ) self.assertEqual(response.status_code, status_code) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 119bd59697..aacc1cc571 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -250,11 +250,13 @@ def update_thread(request, course_id, thread_id): if "thread_type" in request.POST: thread.thread_type = request.POST["thread_type"] if "commentable_id" in request.POST: + commentable_id = request.POST["commentable_id"] course = get_course_with_access(request.user, 'load', course_key) - if discussion_category_id_access(course, request.user, request.POST.get("commentable_id")): - thread.commentable_id = request.POST["commentable_id"] - else: + thread_context = getattr(thread, "context", "course") + if thread_context == "course" and not discussion_category_id_access(course, request.user, commentable_id): return JsonError(_("Topic doesn't exist")) + else: + thread.commentable_id = commentable_id thread.save() if request.is_ajax(): diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 3ff0a9a8c3..484bccd7d8 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -336,7 +336,8 @@ def single_thread(request, course_key, discussion_id, thread_id): raise # Verify that the student has access to this thread if belongs to a course discussion module - if thread.context == "course" and not utils.discussion_category_id_access(course, request.user, discussion_id): + thread_context = getattr(thread, "context", "course") + if thread_context == "course" and not utils.discussion_category_id_access(course, request.user, discussion_id): raise Http404 # verify that the thread belongs to the requesting student's cohort diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index e50402e0df..e0c83e29ec 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -351,6 +351,7 @@ def get_discussion_category_map(course, user, cohorted_if_in_list=False, exclude def discussion_category_id_access(course, user, discussion_id): """ Returns True iff the given discussion_id is accessible for user in course. + Assumes that the commentable identified by discussion_id has a null or 'course' context. Uses the discussion id cache if available, falling back to get_discussion_categories_ids if there is no cache. """