GitHub PullRequestReviewCommentEvent at 2014-10-03 01:24:32
Repository: kitsune
Actor: rlr
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/kitsune/pulls/comments/18377801","id":18377801,"diff_hunk":"@@ -0,0 +1,176 @@\n+from django.core.exceptions import ValidationError\n+from rest_framework import serializers, viewsets, permissions, filters\n+\n+from kitsune.questions.models import Question, Answer\n+\n+\n+class OnlyCreatorEdits(permissions.BasePermission):\n+    \"\"\"\n+    Only allow objects to be edited and deleted by their creators.\n+\n+    TODO: This should be tied to user and object permissions better, but\n+    for now this is a bandaid.\n+    \"\"\"\n+\n+    def has_object_permission(self, request, view, obj):\n+        # SAFE_METHODS is a list containing all the read-only methods.\n+        if request.method in permissions.SAFE_METHODS:\n+            return True\n+        # If flow gets here, the method will modify something.\n+        user = getattr(request, 'user', None)\n+        owner = getattr(obj, 'creator', None)\n+        # Only the owner can modify things.\n+        return user == owner\n+\n+\n+class QuestionShortSerializer(serializers.ModelSerializer):\n+    # Use slugs for product and topic instead of ids.\n+    products = serializers.SlugRelatedField(many=True, slug_field='slug')\n+    topics = serializers.SlugRelatedField(many=True, slug_field='slug')\n+    # Use usernames for product and topic instead of ids.\n+    creator = serializers.SlugRelatedField(\n+        slug_field='username', required=False)\n+    updated_by = serializers.SlugRelatedField(\n+        slug_field='username', required=False)\n+\n+    class Meta:\n+        model = Question\n+        fields = (\n+            'id',\n+            'created',\n+            'creator',\n+            'is_archived',\n+            'is_locked',\n+            'is_spam',\n+            'last_answer',\n+            'locale',\n+            'num_answers',\n+            'num_votes_past_week',\n+            'products',\n+            'title',\n+            'topics',\n+            'updated_by',\n+            'updated',\n+        )\n+\n+    def validate_creator(self, attrs, source):\n+        user = getattr(self.context.get('request'), 'user')\n+        if user and not user.is_anonymous() and attrs.get('creator') is None:\n+            attrs['creator'] = user\n+        return attrs\n+\n+    def validate_products(self, attrs, source):\n+        if not attrs.get('products', []):\n+            raise ValidationError('At least one required.')\n+        return attrs\n+\n+    def validate_topics(self, attrs, source):\n+        if not attrs.get('topics', []):\n+            raise ValidationError('At least one required.')\n+        return attrs\n+\n+\n+class QuestionDetailSerializer(QuestionShortSerializer):\n+    class Meta:\n+        model = Question\n+        fields = QuestionShortSerializer.Meta.fields + (\n+            'content',\n+            'answers',\n+        )\n+\n+\n+class QuestionViewSet(viewsets.ModelViewSet):\n+    serializer_class = QuestionDetailSerializer\n+    queryset = Question.objects.all()\n+    paginate_by = 100\n+    permission_classes = [\n+        OnlyCreatorEdits,","path":"kitsune/questions/api.py","position":87,"original_position":87,"commit_id":"61f2d37a48730592a56179c127b4f039362fcc3b","original_commit_id":"61f2d37a48730592a56179c127b4f039362fcc3b","user":{"login":"rlr","id":36629,"avatar_url":"https://avatars.githubusercontent.com/u/36629?v=2","gravatar_id":"","url":"https://api.github.com/users/rlr","html_url":"https://github.com/rlr","followers_url":"https://api.github.com/users/rlr/followers","following_url":"https://api.github.com/users/rlr/following{/other_user}","gists_url":"https://api.github.com/users/rlr/gists{/gist_id}","starred_url":"https://api.github.com/users/rlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlr/subscriptions","organizations_url":"https://api.github.com/users/rlr/orgs","repos_url":"https://api.github.com/users/rlr/repos","events_url":"https://api.github.com/users/rlr/events{/privacy}","received_events_url":"https://api.github.com/users/rlr/received_events","type":"User","site_admin":false},"body":"No moderation for now. Right? :+1: \r\nTo add it, we just need to add another class here?","created_at":"2014-10-03T01:24:32Z","updated_at":"2014-10-03T01:24:32Z","html_url":"https://github.com/mozilla/kitsune/pull/2122#discussion_r18377801","pull_request_url":"https://api.github.com/repos/mozilla/kitsune/pulls/2122","_links":{"self":{"href":"https://api.github.com/repos/mozilla/kitsune/pulls/comments/18377801"},"html":{"href":"https://github.com/mozilla/kitsune/pull/2122#discussion_r18377801"},"pull_request":{"href":"https://api.github.com/repos/mozilla/kitsune/pulls/2122"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/kitsune/pulls/2122","id":21667490,"html_url":"https://github.com/mozilla/kitsune/pull/2122","diff_url":"https://github.com/mozilla/kitsune/pull/2122.diff","patch_url":"https://github.com/mozilla/kitsune/pull/2122.patch","issue_url":"https://api.github.com/repos/mozilla/kitsune/issues/2122","number":2122,"state":"open","locked":false,"title":"Questions/Answers API WIP","user":{"login":"mythmon","id":305049,"avatar_url":"https://avatars.githubusercontent.com/u/305049?v=2","gravatar_id":"","url":"https://api.github.com/users/mythmon","html_url":"https://github.com/mythmon","followers_url":"https://api.github.com/users/mythmon/followers","following_url":"https://api.github.com/users/mythmon/following{/other_user}","gists_url":"https://api.github.com/users/mythmon/gists{/gist_id}","starred_url":"https://api.github.com/users/mythmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythmon/subscriptions","organizations_url":"https://api.github.com/users/mythmon/orgs","repos_url":"https://api.github.com/users/mythmon/repos","events_url":"https://api.github.com/users/mythmon/events{/privacy}","received_events_url":"https://api.github.com/users/mythmon/received_events","type":"User","site_admin":false},"body":"f?","created_at":"2014-09-23T18:52:32Z","updated_at":"2014-10-03T01:24:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f879d0374c4500f2d142406c8715e6ad472cd0f7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/kitsune/pulls/2122/commits","review_comments_url":"https://api.github.com/repos/mozilla/kitsune/pulls/2122/comments","review_comment_url":"https://api.github.com/repos/mozilla/kitsune/pulls/comments/{number}","comments_url":"https://api.github.com/repos/mozilla/kitsune/issues/2122/comments","statuses_url":"https://api.github.com/repos/mozilla/kitsune/statuses/61f2d37a48730592a56179c127b4f039362fcc3b","head":{"label":"mythmon:api-question-rw-1062407","ref":"api-question-rw-1062407","sha":"61f2d37a48730592a56179c127b4f039362fcc3b","user":{"login":"mythmon","id":305049,"avatar_url":"https://avatars.githubusercontent.com/u/305049?v=2","gravatar_id":"","url":"https://api.github.com/users/mythmon","html_url":"https://github.com/mythmon","followers_url":"https://api.github.com/users/mythmon/followers","following_url":"https://api.github.com/users/mythmon/following{/other_user}","gists_url":"https://api.github.com/users/mythmon/gists{/gist_id}","starred_url":"https://api.github.com/users/mythmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythmon/subscriptions","organizations_url":"https://api.github.com/users/mythmon/orgs","repos_url":"https://api.github.com/users/mythmon/repos","events_url":"https://api.github.com/users/mythmon/events{/privacy}","received_events_url":"https://api.github.com/users/mythmon/received_events","type":"User","site_admin":false},"repo":{"id":4978152,"name":"kitsune","full_name":"mythmon/kitsune","owner":{"login":"mythmon","id":305049,"avatar_url":"https://avatars.githubusercontent.com/u/305049?v=2","gravatar_id":"","url":"https://api.github.com/users/mythmon","html_url":"https://github.com/mythmon","followers_url":"https://api.github.com/users/mythmon/followers","following_url":"https://api.github.com/users/mythmon/following{/other_user}","gists_url":"https://api.github.com/users/mythmon/gists{/gist_id}","starred_url":"https://api.github.com/users/mythmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythmon/subscriptions","organizations_url":"https://api.github.com/users/mythmon/orgs","repos_url":"https://api.github.com/users/mythmon/repos","events_url":"https://api.github.com/users/mythmon/events{/privacy}","received_events_url":"https://api.github.com/users/mythmon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mythmon/kitsune","description":"Platform for Firefox Help","fork":true,"url":"https://api.github.com/repos/mythmon/kitsune","forks_url":"https://api.github.com/repos/mythmon/kitsune/forks","keys_url":"https://api.github.com/repos/mythmon/kitsune/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mythmon/kitsune/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mythmon/kitsune/teams","hooks_url":"https://api.github.com/repos/mythmon/kitsune/hooks","issue_events_url":"https://api.github.com/repos/mythmon/kitsune/issues/events{/number}","events_url":"https://api.github.com/repos/mythmon/kitsune/events","assignees_url":"https://api.github.com/repos/mythmon/kitsune/assignees{/user}","branches_url":"https://api.github.com/repos/mythmon/kitsune/branches{/branch}","tags_url":"https://api.github.com/repos/mythmon/kitsune/tags","blobs_url":"https://api.github.com/repos/mythmon/kitsune/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mythmon/kitsune/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mythmon/kitsune/git/refs{/sha}","trees_url":"https://api.github.com/repos/mythmon/kitsune/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mythmon/kitsune/statuses/{sha}","languages_url":"https://api.github.com/repos/mythmon/kitsune/languages","stargazers_url":"https://api.github.com/repos/mythmon/kitsune/stargazers","contributors_url":"https://api.github.com/repos/mythmon/kitsune/contributors","subscribers_url":"https://api.github.com/repos/mythmon/kitsune/subscribers","subscription_url":"https://api.github.com/repos/mythmon/kitsune/subscription","commits_url":"https://api.github.com/repos/mythmon/kitsune/commits{/sha}","git_commits_url":"https://api.github.com/repos/mythmon/kitsune/git/commits{/sha}","comments_url":"https://api.github.com/repos/mythmon/kitsune/comments{/number}","issue_comment_url":"https://api.github.com/repos/mythmon/kitsune/issues/comments/{number}","contents_url":"https://api.github.com/repos/mythmon/kitsune/contents/{+path}","compare_url":"https://api.github.com/repos/mythmon/kitsune/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mythmon/kitsune/merges","archive_url":"https://api.github.com/repos/mythmon/kitsune/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mythmon/kitsune/downloads","issues_url":"https://api.github.com/repos/mythmon/kitsune/issues{/number}","pulls_url":"https://api.github.com/repos/mythmon/kitsune/pulls{/number}","milestones_url":"https://api.github.com/repos/mythmon/kitsune/milestones{/number}","notifications_url":"https://api.github.com/repos/mythmon/kitsune/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mythmon/kitsune/labels{/name}","releases_url":"https://api.github.com/repos/mythmon/kitsune/releases{/id}","created_at":"2012-07-10T18:09:51Z","updated_at":"2014-08-26T23:01:26Z","pushed_at":"2014-10-02T23:11:04Z","git_url":"git://github.com/mythmon/kitsune.git","ssh_url":"git@github.com:mythmon/kitsune.git","clone_url":"https://github.com/mythmon/kitsune.git","svn_url":"https://github.com/mythmon/kitsune","homepage":"http://support.mozilla.com/","size":93838,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"38b45a4489e605d6346574edd02361d5fc0b6ced","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=2","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":489645,"name":"kitsune","full_name":"mozilla/kitsune","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=2","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/kitsune","description":"Platform for Mozilla Support","fork":false,"url":"https://api.github.com/repos/mozilla/kitsune","forks_url":"https://api.github.com/repos/mozilla/kitsune/forks","keys_url":"https://api.github.com/repos/mozilla/kitsune/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/kitsune/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/kitsune/teams","hooks_url":"https://api.github.com/repos/mozilla/kitsune/hooks","issue_events_url":"https://api.github.com/repos/mozilla/kitsune/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/kitsune/events","assignees_url":"https://api.github.com/repos/mozilla/kitsune/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/kitsune/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/kitsune/tags","blobs_url":"https://api.github.com/repos/mozilla/kitsune/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/kitsune/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/kitsune/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/kitsune/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/kitsune/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/kitsune/languages","stargazers_url":"https://api.github.com/repos/mozilla/kitsune/stargazers","contributors_url":"https://api.github.com/repos/mozilla/kitsune/contributors","subscribers_url":"https://api.github.com/repos/mozilla/kitsune/subscribers","subscription_url":"https://api.github.com/repos/mozilla/kitsune/subscription","commits_url":"https://api.github.com/repos/mozilla/kitsune/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/kitsune/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/kitsune/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/kitsune/issues/comments/{number}","contents_url":"https://api.github.com/repos/mozilla/kitsune/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/kitsune/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/kitsune/merges","archive_url":"https://api.github.com/repos/mozilla/kitsune/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/kitsune/downloads","issues_url":"https://api.github.com/repos/mozilla/kitsune/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/kitsune/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/kitsune/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/kitsune/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/kitsune/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/kitsune/releases{/id}","created_at":"2010-01-26T18:53:57Z","updated_at":"2014-10-02T16:36:20Z","pushed_at":"2014-10-02T15:27:31Z","git_url":"git://github.com/mozilla/kitsune.git","ssh_url":"git@github.com:mozilla/kitsune.git","clone_url":"https://github.com/mozilla/kitsune.git","svn_url":"https://github.com/mozilla/kitsune","homepage":"http://support.mozilla.com/","size":157179,"stargazers_count":247,"watchers_count":247,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":224,"mirror_url":null,"open_issues_count":8,"forks":224,"open_issues":8,"watchers":247,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/kitsune/pulls/2122"},"html":{"href":"https://github.com/mozilla/kitsune/pull/2122"},"issue":{"href":"https://api.github.com/repos/mozilla/kitsune/issues/2122"},"comments":{"href":"https://api.github.com/repos/mozilla/kitsune/issues/2122/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/kitsune/pulls/2122/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/kitsune/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/mozilla/kitsune/pulls/2122/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/kitsune/statuses/61f2d37a48730592a56179c127b4f039362fcc3b"}}}}