← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/export-reject-question into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/export-reject-question into lp:launchpad.

Commit message:
Export IQuestion.reject on the webservice, as an affordance for handling spam.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/export-reject-question/+merge/293673

Export IQuestion.reject on the webservice, as an affordance for handling spam.

I seem to have pushed this branch in January and forgotten to propose it for merging.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/export-reject-question into lp:launchpad.
=== modified file 'lib/lp/answers/interfaces/question.py'
--- lib/lp/answers/interfaces/question.py	2016-01-26 15:47:37 +0000
+++ lib/lp/answers/interfaces/question.py	2016-05-03 21:06:32 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Interfaces for a Question."""
@@ -16,6 +16,7 @@
 from lazr.restful.declarations import (
     call_with,
     export_as_webservice_entry,
+    export_factory_operation,
     export_write_operation,
     exported,
     operation_for_version,
@@ -345,6 +346,11 @@
         the question target owner or part of the administration team.
         """
 
+    @operation_parameters(
+        comment=Text(title=_("An explanation of the rejection")))
+    @call_with(user=REQUEST_USER)
+    @export_factory_operation(IQuestionMessage, [])
+    @operation_for_version("devel")
     def reject(user, comment, datecreated=None):
         """Mark this question as INVALID.
 

=== modified file 'lib/lp/answers/tests/test_question_webservice.py'
--- lib/lp/answers/tests/test_question_webservice.py	2016-02-05 16:51:12 +0000
+++ lib/lp/answers/tests/test_question_webservice.py	2016-05-03 21:06:32 +0000
@@ -14,9 +14,11 @@
 from lazr.restfulclient.errors import HTTPError
 import pytz
 from simplejson import dumps
+from testtools.matchers import EndsWith
 import transaction
 from zope.security.proxy import removeSecurityProxy
 
+from lp.answers.enums import QuestionStatus
 from lp.answers.errors import (
     AddAnswerContactError,
     FAQTargetError,
@@ -26,6 +28,7 @@
     NotQuestionOwnerError,
     QuestionTargetError,
     )
+from lp.services.webapp.interfaces import OAuthPermission
 from lp.testing import (
     admin_logged_in,
     celebrity_logged_in,
@@ -147,6 +150,31 @@
             self.findQuestionTitle(response),
             "<p>No, this is a question</p>")
 
+    def test_reject(self):
+        # A question can be rejected via the API.
+        question_url = '/%s/+question/%d' % (
+            self.target_name, self.question.id)
+        response = self.webservice.named_post(
+            question_url, 'reject', comment='A rejection message')
+        self.assertEqual(201, response.status)
+        self.assertThat(
+            response.getheader('location'),
+            EndsWith('%s/messages/1' % question_url))
+        self.assertEqual(QuestionStatus.INVALID, self.question.status)
+
+    def test_reject_not_answer_contact(self):
+        # If the requesting user is not an answer contact, the API returns a
+        # suitable error.
+        with celebrity_logged_in('admin'):
+            random_person = self.factory.makePerson()
+        webservice = webservice_for_person(
+            random_person, permission=OAuthPermission.WRITE_PUBLIC)
+        webservice.default_api_version = 'devel'
+        response = webservice.named_post(
+            '/%s/+question/%d' % (self.target_name, self.question.id),
+            'reject', comment='A rejection message')
+        self.assertEqual(401, response.status)
+
 
 class TestSetCommentVisibility(TestCaseWithFactory):
     """Tests who can successfully set comment visibility."""


Follow ups