Commit f5840489 by Daniel Friedman Committed by Andy Armstrong

Allow editing of own post in team discussion

parent dd67f8aa
...@@ -1193,7 +1193,11 @@ class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSe ...@@ -1193,7 +1193,11 @@ class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSe
thread_author = getattr(self, thread_author) thread_author = getattr(self, thread_author)
self._setup_mock( self._setup_mock(
user, mock_request, # user is the person making the request. 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( response = self.client.post(
reverse( reverse(
...@@ -1203,7 +1207,7 @@ class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSe ...@@ -1203,7 +1207,7 @@ class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSe
"thread_id": "dummy" "thread_id": "dummy"
} }
), ),
data={"body": "foo", "title": "foo"} data={"body": "foo", "title": "foo", "commentable_id": commentable_id}
) )
self.assertEqual(response.status_code, status_code) self.assertEqual(response.status_code, status_code)
......
...@@ -250,11 +250,13 @@ def update_thread(request, course_id, thread_id): ...@@ -250,11 +250,13 @@ def update_thread(request, course_id, thread_id):
if "thread_type" in request.POST: if "thread_type" in request.POST:
thread.thread_type = request.POST["thread_type"] thread.thread_type = request.POST["thread_type"]
if "commentable_id" in request.POST: if "commentable_id" in request.POST:
commentable_id = request.POST["commentable_id"]
course = get_course_with_access(request.user, 'load', course_key) course = get_course_with_access(request.user, 'load', course_key)
if discussion_category_id_access(course, request.user, request.POST.get("commentable_id")): thread_context = getattr(thread, "context", "course")
thread.commentable_id = request.POST["commentable_id"] if thread_context == "course" and not discussion_category_id_access(course, request.user, commentable_id):
else:
return JsonError(_("Topic doesn't exist")) return JsonError(_("Topic doesn't exist"))
else:
thread.commentable_id = commentable_id
thread.save() thread.save()
if request.is_ajax(): if request.is_ajax():
......
...@@ -336,7 +336,8 @@ def single_thread(request, course_key, discussion_id, thread_id): ...@@ -336,7 +336,8 @@ def single_thread(request, course_key, discussion_id, thread_id):
raise raise
# Verify that the student has access to this thread if belongs to a course discussion module # 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 raise Http404
# verify that the thread belongs to the requesting student's cohort # verify that the thread belongs to the requesting student's cohort
......
...@@ -351,6 +351,7 @@ def get_discussion_category_map(course, user, cohorted_if_in_list=False, exclude ...@@ -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): def discussion_category_id_access(course, user, discussion_id):
""" """
Returns True iff the given discussion_id is accessible for user in course. 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 Uses the discussion id cache if available, falling back to
get_discussion_categories_ids if there is no cache. get_discussion_categories_ids if there is no cache.
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment