{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/35486399","id":35486399,"diff_hunk":"@@ -1095,6 +1104,221 @@ def _test_unicode_data(self, text, mock_request):\n             del Thread.commentable_id\n \n \n+@ddt.ddt\n+@patch(\"lms.lib.comment_client.utils.requests.request\")\n+class TeamsPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase, MockRequestSetupMixin):\n+    # Most of the test points use the same ddt data.\n+    # args: user, commentable_id, status_code\n+    ddt_args = [\n+        # Student in team can do operations on threads/comments within the team commentable.\n+        ('student_in_team', 'team_commentable_id', 200),\n+        # Non-team commentables can be edited by any student.\n+        ('student_in_team', 'course_commentable_id', 200),\n+        # Student not in team cannot do operations within the team commentable.\n+        ('student_not_in_team', 'team_commentable_id', 401),\n+        # Non-team commentables can be edited by any student.\n+        ('student_not_in_team', 'course_commentable_id', 200),\n+        # Moderators most be a member of the team for doing \"student actions\".\n+        ('moderator', 'team_commentable_id', 401)\n+    ]\n+\n+    @patch.dict(\"django.conf.settings.FEATURES\", {\"ENABLE_DISCUSSION_SERVICE\": True})\n+    def setUp(self):\n+        super(TeamsPermissionsTestCase, self).setUp()\n+        self.password = \"test password\"\n+        teams_configuration = {\n+            'topics': [{'id': \"topic_id\", 'name': 'Solar Power', 'description': 'Solar power is hot'}]\n+        }\n+        self.course = CourseFactory.create(teams_configuration=teams_configuration)\n+        seed_permissions_roles(self.course.id)\n+\n+        # Create 3 users-- student in team, student not in team, discussion moderator\n+        self.student_in_team = UserFactory.create(password=self.password)\n+        self.student_not_in_team = UserFactory.create(password=self.password)\n+        self.moderator = UserFactory.create(password=self.password)\n+        CourseEnrollmentFactory(user=self.student_in_team, course_id=self.course.id)\n+        CourseEnrollmentFactory(user=self.student_not_in_team, course_id=self.course.id)\n+        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)\n+        self.moderator.roles.add(Role.objects.get(name=\"Moderator\", course_id=self.course.id))\n+\n+        # Create a team.\n+        self.team_commentable_id = \"team_discussion_id\"\n+        self.team = CourseTeamFactory.create(\n+            name=u'The Only Team',\n+            course_id=self.course.id,\n+            topic_id='topic_id',\n+            discussion_id=self.team_commentable_id\n+        )\n+        self.team.add_user(self.student_in_team)\n+\n+        # Dummy commentable ID not linked to a team\n+        self.course_commentable_id = \"course_level_commentable\"\n+\n+    def _setup_mock(self, user, mock_request, data):\n+        user = getattr(self, user)\n+        self._set_mock_request_data(mock_request, data)\n+        self.client.login(username=user.username, password=self.password)\n+\n+    @ddt.data(\n+        # student_in_team will be able to update his own post, regardless of team membership\n+        ('student_in_team', 'student_in_team', 'team_commentable_id', 200),\n+        ('student_in_team', 'student_in_team', 'course_commentable_id', 200),\n+        # students can only update their own posts\n+        ('student_in_team', 'moderator', 'team_commentable_id', 401),\n+        # Even though student_not_in_team is not in the team, he can still modify posts he created while in the team.\n+        ('student_not_in_team', 'student_not_in_team', 'team_commentable_id', 200),\n+        # Moderators can change their own posts and other people's posts.\n+        ('moderator', 'moderator', 'team_commentable_id', 200),\n+        ('moderator', 'student_in_team', 'team_commentable_id', 200),\n+    )\n+    @ddt.unpack\n+    def test_update_thread(self, user, thread_author, commentable_id, status_code, mock_request):","path":"lms/djangoapps/django_comment_client/base/tests.py","position":175,"original_position":175,"commit_id":"c562bfec943b378e44e313e79997331807b8bcc7","original_commit_id":"c562bfec943b378e44e313e79997331807b8bcc7","user":{"login":"cahrens","id":484484,"avatar_url":"https://avatars.githubusercontent.com/u/484484?v=3","gravatar_id":"","url":"https://api.github.com/users/cahrens","html_url":"https://github.com/cahrens","followers_url":"https://api.github.com/users/cahrens/followers","following_url":"https://api.github.com/users/cahrens/following{/other_user}","gists_url":"https://api.github.com/users/cahrens/gists{/gist_id}","starred_url":"https://api.github.com/users/cahrens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cahrens/subscriptions","organizations_url":"https://api.github.com/users/cahrens/orgs","repos_url":"https://api.github.com/users/cahrens/repos","events_url":"https://api.github.com/users/cahrens/events{/privacy}","received_events_url":"https://api.github.com/users/cahrens/received_events","type":"User","site_admin":false},"body":"Note to reviewer: there are a number of permissions that I didn't touch at all. I didn't add tests for any of this except this one. I added this mostly to make it clear that we are always allowing students to update their own posts, even if they have left the team (Leslie signed off on this).","created_at":"2015-07-25T20:05:45Z","updated_at":"2015-07-25T20:05:45Z","html_url":"https://github.com/edx/edx-platform/pull/9009#discussion_r35486399","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/9009","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/35486399"},"html":{"href":"https://github.com/edx/edx-platform/pull/9009#discussion_r35486399"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/9009"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/9009","id":40631170,"html_url":"https://github.com/edx/edx-platform/pull/9009","diff_url":"https://github.com/edx/edx-platform/pull/9009.diff","patch_url":"https://github.com/edx/edx-platform/pull/9009.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/9009","number":9009,"state":"open","locked":false,"title":"Christina/team discussion permissions","user":{"login":"cahrens","id":484484,"avatar_url":"https://avatars.githubusercontent.com/u/484484?v=3","gravatar_id":"","url":"https://api.github.com/users/cahrens","html_url":"https://github.com/cahrens","followers_url":"https://api.github.com/users/cahrens/followers","following_url":"https://api.github.com/users/cahrens/following{/other_user}","gists_url":"https://api.github.com/users/cahrens/gists{/gist_id}","starred_url":"https://api.github.com/users/cahrens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cahrens/subscriptions","organizations_url":"https://api.github.com/users/cahrens/orgs","repos_url":"https://api.github.com/users/cahrens/repos","events_url":"https://api.github.com/users/cahrens/events{/privacy}","received_events_url":"https://api.github.com/users/cahrens/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-23T02:15:14Z","updated_at":"2015-07-25T20:05:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"783de929bdeeafe05ead3e4c60a2906e0f4e90ad","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/9009/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/9009/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/9009/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/c562bfec943b378e44e313e79997331807b8bcc7","head":{"label":"edx:christina/team-discussion-permissions","ref":"christina/team-discussion-permissions","sha":"c562bfec943b378e44e313e79997331807b8bcc7","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-07-25T15:48:09Z","pushed_at":"2015-07-25T19:52:40Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":2080170,"stargazers_count":2053,"watchers_count":2053,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1199,"mirror_url":null,"open_issues_count":157,"forks":1199,"open_issues":157,"watchers":2053,"default_branch":"master"}},"base":{"label":"edx:benmcmorran/team-discussion-context","ref":"benmcmorran/team-discussion-context","sha":"91a07ab473d94bc67148aaec406311f3e5b15b97","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-07-25T15:48:09Z","pushed_at":"2015-07-25T19:52:40Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":2080170,"stargazers_count":2053,"watchers_count":2053,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1199,"mirror_url":null,"open_issues_count":157,"forks":1199,"open_issues":157,"watchers":2053,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/9009"},"html":{"href":"https://github.com/edx/edx-platform/pull/9009"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/9009"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/9009/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/9009/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/9009/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/c562bfec943b378e44e313e79997331807b8bcc7"}}}}