← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ilasc/launchpad/+git/security:bug-1944599 into launchpad:master

 

Ioana Lasc has proposed merging ~ilasc/launchpad/+git/security:bug-1944599 into launchpad:master.

Commit message:
Move addLanguage and removeLanguage to IPersonEditRestricted

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/security/+merge/409215
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad/+git/security:bug-1944599 into launchpad:master.
diff --git a/lib/lp/answers/browser/tests/test_questiontarget.py b/lib/lp/answers/browser/tests/test_questiontarget.py
index a1b29e8..d7805e7 100644
--- a/lib/lp/answers/browser/tests/test_questiontarget.py
+++ b/lib/lp/answers/browser/tests/test_questiontarget.py
@@ -283,8 +283,8 @@ class QuestionTargetPortletAnswerContactsWithDetailsTests(
         question = self.factory.makeQuestion()
         contact = self.factory.makePerson(
             name='user', displayname='Contact Name')
-        contact.addLanguage(getUtility(ILanguageSet)['en'])
         with person_logged_in(contact):
+            contact.addLanguage(getUtility(ILanguageSet)['en'])
             question.target.addAnswerContact(contact, contact)
         view = create_view(question.target, '+portlet-answercontacts-details')
         api_request = IWebServiceClientRequest(view.request)
@@ -310,8 +310,8 @@ class QuestionTargetPortletAnswerContactsWithDetailsTests(
             name="team-owner", displayname="Team Owner")
         contact = self.factory.makeTeam(
             name='team', displayname='Team Name', owner=teamowner)
-        contact.addLanguage(getUtility(ILanguageSet)['en'])
         with person_logged_in(contact.teamowner):
+            contact.addLanguage(getUtility(ILanguageSet)['en'])
             question.target.addAnswerContact(contact, contact)
         view = create_view(question.target, '+portlet-answercontacts-details')
         api_request = IWebServiceClientRequest(view.request)
@@ -337,8 +337,8 @@ class QuestionTargetPortletAnswerContactsWithDetailsTests(
             name="team-owner", displayname="Team Owner")
         contact = self.factory.makeTeam(
             name='team', displayname='Team Name', owner=teamowner)
-        contact.addLanguage(getUtility(ILanguageSet)['en'])
         with person_logged_in(contact.teamowner):
+            contact.addLanguage(getUtility(ILanguageSet)['en'])
             question.target.addAnswerContact(contact, contact.teamowner)
         view = create_view(question.target, '+portlet-answercontacts-details')
         api_request = IWebServiceClientRequest(view.request)
@@ -367,8 +367,8 @@ class QuestionTargetPortletAnswerContactsWithDetailsTests(
         contact = self.factory.makeTeam(
             name='team', displayname='Team Name', owner=teamowner,
             members=[member])
-        contact.addLanguage(getUtility(ILanguageSet)['en'])
         with person_logged_in(contact.teamowner):
+            contact.addLanguage(getUtility(ILanguageSet)['en'])
             question.target.addAnswerContact(contact, contact.teamowner)
         view = create_view(question.target, '+portlet-answercontacts-details')
         api_request = IWebServiceClientRequest(view.request)
@@ -393,8 +393,8 @@ class QuestionTargetPortletAnswerContactsWithDetailsTests(
         question = self.factory.makeQuestion(target=distro)
         contact = self.factory.makePerson(
             name='user', displayname='Contact Name')
-        contact.addLanguage(getUtility(ILanguageSet)['en'])
         with person_logged_in(contact):
+            contact.addLanguage(getUtility(ILanguageSet)['en'])
             question.target.addAnswerContact(contact, contact)
         view = create_view(question.target, '+portlet-answercontacts-details')
         api_request = IWebServiceClientRequest(view.request)
@@ -420,7 +420,8 @@ class QuestionTargetPortletAnswerContactsWithDetailsTests(
         member = self.factory.makePerson()
         contact = self.factory.makePerson(
             name='user', displayname='Contact Name')
-        contact.addLanguage(getUtility(ILanguageSet)['en'])
+        with person_logged_in(contact):
+            contact.addLanguage(getUtility(ILanguageSet)['en'])
         with person_logged_in(member):
             question.target.addAnswerContact(contact, contact)
         view = create_view(question.target, '+portlet-answercontacts-details')
diff --git a/lib/lp/answers/doc/notifications.txt b/lib/lp/answers/doc/notifications.txt
index c447754..ebbf81f 100644
--- a/lib/lp/answers/doc/notifications.txt
+++ b/lib/lp/answers/doc/notifications.txt
@@ -67,6 +67,7 @@ notified about the changes as well:
     >>> from lp.registry.interfaces.person import IPersonSet
     >>> from lp.services.worlddata.interfaces.language import ILanguageSet
     >>> ubuntu_team = getUtility(IPersonSet).getByName('ubuntu-team')
+    >>> login(ubuntu_team.teamowner.preferredemail.email)
     >>> ubuntu_team.addLanguage(getUtility(ILanguageSet)['en'])
     >>> ubuntu.addAnswerContact(ubuntu_team, ubuntu_team.teamowner)
     True
diff --git a/lib/lp/answers/doc/person.txt b/lib/lp/answers/doc/person.txt
index 41333cf..d908b02 100644
--- a/lib/lp/answers/doc/person.txt
+++ b/lib/lp/answers/doc/person.txt
@@ -332,6 +332,7 @@ IQuestionTargets.
     >>> no_priv_raw.hasParticipationEntryFor(translator_team)
     True
     >>> evolution_package = ubuntu.getSourcePackage('evolution')
+    >>> login('carlos@xxxxxxxx')
     >>> translator_team.addLanguage(english)
     >>> evolution_package.addAnswerContact(
     ...     translator_team, translator_team.teamowner)
diff --git a/lib/lp/answers/doc/question.txt b/lib/lp/answers/doc/question.txt
index cb1b002..8aa8ea4 100644
--- a/lib/lp/answers/doc/question.txt
+++ b/lib/lp/answers/doc/question.txt
@@ -230,6 +230,7 @@ part of the indirect subscribers list.
 
     >>> from lp.services.worlddata.interfaces.language import ILanguageSet
     >>> english = getUtility(ILanguageSet)['en']
+    >>> login('no-priv@xxxxxxxxxxxxx')
     >>> no_priv.addLanguage(english)
     >>> firefox.addAnswerContact(no_priv, no_priv)
     True
@@ -255,6 +256,7 @@ are part of the indirect subscribers list.
     >>> list(evolution_in_ubuntu.answer_contacts)
     []
     >>> ubuntu_team = getUtility(IPersonSet).getByName('ubuntu-team')
+    >>> login(ubuntu_team.teamowner.preferredemail.email)
     >>> ubuntu_team.addLanguage(english)
     >>> ubuntu.addAnswerContact(ubuntu_team, ubuntu_team.teamowner)
     True
diff --git a/lib/lp/answers/doc/workflow.txt b/lib/lp/answers/doc/workflow.txt
index 33ecd85..e6942fd 100644
--- a/lib/lp/answers/doc/workflow.txt
+++ b/lib/lp/answers/doc/workflow.txt
@@ -52,6 +52,7 @@ Ubuntu Team owning the distribution.
 
     >>> ubuntu = getUtility(IDistributionSet)['ubuntu']
     >>> english = getUtility(ILanguageSet)['en']
+    >>> login('test@xxxxxxxxxxxxx')
     >>> sample_person.addLanguage(english)
     >>> ubuntu.addAnswerContact(sample_person, sample_person)
     True
diff --git a/lib/lp/answers/model/tests/test_question.py b/lib/lp/answers/model/tests/test_question.py
index 28e980f..0883f46 100644
--- a/lib/lp/answers/model/tests/test_question.py
+++ b/lib/lp/answers/model/tests/test_question.py
@@ -74,7 +74,8 @@ class TestQuestionInDirectSubscribers(TestCaseWithFactory):
     def test_answerContactIsIndirectSubscriber(self):
         # Question answer contacts are indirect subscribers to questions.
         person = self.factory.makePerson()
-        person.addLanguage(getUtility(ILanguageSet)['en'])
+        with person_logged_in(person):
+            person.addLanguage(getUtility(ILanguageSet)['en'])
         question = self.factory.makeQuestion()
         with person_logged_in(question.owner):
             question.target.addAnswerContact(person, person)
@@ -96,10 +97,12 @@ class TestQuestionInDirectSubscribers(TestCaseWithFactory):
         # Question answer contacts are indirect subscribers to questions and
         # are filtered according to the question's language.
         english_person = self.factory.makePerson()
-        english_person.addLanguage(getUtility(ILanguageSet)['en'])
+        with person_logged_in(english_person):
+            english_person.addLanguage(getUtility(ILanguageSet)['en'])
         spanish = getUtility(ILanguageSet)['es']
         spanish_person = self.factory.makePerson()
-        spanish_person.addLanguage(spanish)
+        with person_logged_in((spanish_person)):
+            spanish_person.addLanguage(spanish)
         question = self.factory.makeQuestion(language=spanish)
         with person_logged_in(question.owner):
             question.target.addAnswerContact(english_person, english_person)
diff --git a/lib/lp/answers/model/tests/test_questionsubscription.py b/lib/lp/answers/model/tests/test_questionsubscription.py
index 1275905..31a2fe6 100644
--- a/lib/lp/answers/model/tests/test_questionsubscription.py
+++ b/lib/lp/answers/model/tests/test_questionsubscription.py
@@ -128,7 +128,8 @@ class TestQuestionSubscriptionCanBeUnsubscribedbyUser(TestCaseWithFactory):
         """Question target answer contact can unsubscribe someone."""
         answer_contact = self.factory.makePerson()
         english = getUtility(ILanguageSet)['en']
-        answer_contact.addLanguage(english)
+        with person_logged_in((answer_contact)):
+            answer_contact.addLanguage(english)
         distro_owner = self.factory.makePerson()
         distro = self.factory.makeDistribution(owner=distro_owner)
         with person_logged_in(distro_owner):
diff --git a/lib/lp/answers/tests/test_question_workflow.py b/lib/lp/answers/tests/test_question_workflow.py
index d458f68..582bb6b 100644
--- a/lib/lp/answers/tests/test_question_workflow.py
+++ b/lib/lp/answers/tests/test_question_workflow.py
@@ -865,7 +865,8 @@ class RejectTestCase(BaseAnswerTrackerWorkflowTestCase):
                           if status.name != 'INVALID']
         # Reject user must be an answer contact, (or admin, or product owner).
         # Answer contacts must speak a language
-        self.answerer.addLanguage(getUtility(ILanguageSet)['en'])
+        with person_logged_in(self.answerer):
+            self.answerer.addLanguage(getUtility(ILanguageSet)['en'])
         self.ubuntu.addAnswerContact(self.answerer, self.answerer)
         login_person(self.answerer)
         self._testInvalidTransition(
diff --git a/lib/lp/archiveuploader/tests/test_snapupload.py b/lib/lp/archiveuploader/tests/test_snapupload.py
index 0f216b4..51f6a50 100644
--- a/lib/lp/archiveuploader/tests/test_snapupload.py
+++ b/lib/lp/archiveuploader/tests/test_snapupload.py
@@ -114,4 +114,3 @@ class TestSnapBuildUploads(TestUploadProcessorBase):
         self.assertTrue(self.build.verifySuccessfulUpload())
         self.assertEqual(1, len(list(self.build.store_upload_jobs)))
         self.assertEqual(2, len(list(self.build.getFiles())))
-
diff --git a/lib/lp/coop/answersbugs/tests/test_doc.py b/lib/lp/coop/answersbugs/tests/test_doc.py
index 21886f3..a917db1 100644
--- a/lib/lp/coop/answersbugs/tests/test_doc.py
+++ b/lib/lp/coop/answersbugs/tests/test_doc.py
@@ -22,6 +22,7 @@ from lp.soyuz.tests.test_doc import (
 from lp.testing import (
     ANONYMOUS,
     login,
+    person_logged_in,
     )
 from lp.testing.dbuser import switch_dbuser
 from lp.testing.layers import (
@@ -48,7 +49,8 @@ def _createUbuntuBugTaskLinkedToQuestion():
     login('test@xxxxxxxxxxxxx')
     sample_person = getUtility(IPersonSet).getByEmail('test@xxxxxxxxxxxxx')
     ubuntu_team = getUtility(IPersonSet).getByName('ubuntu-team')
-    ubuntu_team.addLanguage(getUtility(ILanguageSet)['en'])
+    with person_logged_in(ubuntu_team.teamowner):
+        ubuntu_team.addLanguage(getUtility(ILanguageSet)['en'])
     ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
     ubuntu.addAnswerContact(ubuntu_team, ubuntu_team.teamowner)
     ubuntu_question = ubuntu.newQuestion(
diff --git a/lib/lp/registry/browser/tests/person-views.txt b/lib/lp/registry/browser/tests/person-views.txt
index 2f5e353..e8f7831 100644
--- a/lib/lp/registry/browser/tests/person-views.txt
+++ b/lib/lp/registry/browser/tests/person-views.txt
@@ -197,9 +197,11 @@ correction. The list of languages is alphabetized.
     >>> from lp.services.worlddata.interfaces.language import ILanguageSet
 
     >>> languageset = getUtility(ILanguageSet)
+    >>> login('test@xxxxxxxxxxxxx')
     >>> sample_person.addLanguage(languageset.getLanguageByCode('so'))
     >>> sample_person.addLanguage(languageset.getLanguageByCode('fr'))
 
+    >>> login(ANONYMOUS)
     >>> view = create_view(sample_person, '+portlet-contact-details')
     >>> print(view.languages)
     French, Somali
@@ -217,14 +219,13 @@ set a language.
 Teams most often set just one language that is used for the Answers
 application. If the language is a variant, the variation is shown in
 parenthesis.
-
+    >>> login('test@xxxxxxxxxxxxx')
     >>> landscape_developers.addLanguage(
     ...     languageset.getLanguageByCode('pt_BR'))
     >>> view = create_view(landscape_developers, '+portlet-contact-details')
     >>> print(view.languages)
     Portuguese (Brazil)
 
-
 Things a person is working on
 -----------------------------
 
diff --git a/lib/lp/registry/doc/person.txt b/lib/lp/registry/doc/person.txt
index ecbb0f7..0d29658 100644
--- a/lib/lp/registry/doc/person.txt
+++ b/lib/lp/registry/doc/person.txt
@@ -1171,6 +1171,7 @@ To add new languages we use Person.addLanguage().
 
     >>> from lp.services.worlddata.interfaces.language import ILanguageSet
     >>> languageset = getUtility(ILanguageSet)
+    >>> login('carlos@xxxxxxxx')
     >>> carlos.addLanguage(languageset['pt_BR'])
     >>> for lang in carlos.languages:
     ...     print(lang.code)
diff --git a/lib/lp/registry/interfaces/person.py b/lib/lp/registry/interfaces/person.py
index 21094fa..173fb49 100644
--- a/lib/lp/registry/interfaces/person.py
+++ b/lib/lp/registry/interfaces/person.py
@@ -1359,31 +1359,6 @@ class IPersonViewRestricted(IHasBranches, IHasSpecifications,
     def getPathsToTeams():
         """Return the paths to all teams related to this person."""
 
-    @operation_parameters(
-        language=Reference(schema=ILanguage))
-    @export_write_operation()
-    @operation_for_version("devel")
-    def addLanguage(language):
-        """Add a language to this person's preferences.
-
-        :param language: An object providing ILanguage.
-
-        If the given language is one of the user's preferred languages
-        already, nothing will happen.
-        """
-
-    @operation_parameters(
-        language=Reference(schema=ILanguage))
-    @export_write_operation()
-    @operation_for_version("devel")
-    def removeLanguage(language):
-        """Remove a language from this person's preferences.
-
-        :param language: An object providing ILanguage.
-
-        If the given language is not present, nothing  will happen.
-        """
-
     def isBugContributor(user):
         """Is the person a contributer to bugs in Launchpad?
 
@@ -1794,6 +1769,31 @@ class IPersonEditRestricted(Interface):
         :return: a PPA `IArchive` record.
         """
 
+    @operation_parameters(
+        language=Reference(schema=ILanguage))
+    @export_write_operation()
+    @operation_for_version("devel")
+    def addLanguage(language):
+        """Add a language to this person's preferences.
+
+        :param language: An object providing ILanguage.
+
+        If the given language is one of the user's preferred languages
+        already, nothing will happen.
+        """
+
+    @operation_parameters(
+        language=Reference(schema=ILanguage))
+    @export_write_operation()
+    @operation_for_version("devel")
+    def removeLanguage(language):
+        """Remove a language from this person's preferences.
+
+        :param language: An object providing ILanguage.
+
+        If the given language is not present, nothing  will happen.
+        """
+
 
 class IPersonSpecialRestricted(Interface):
     """IPerson methods that require launchpad.Special permission to use."""
diff --git a/lib/lp/registry/tests/test_pillaraffiliation.py b/lib/lp/registry/tests/test_pillaraffiliation.py
index fa20d2b..47e49e2 100644
--- a/lib/lp/registry/tests/test_pillaraffiliation.py
+++ b/lib/lp/registry/tests/test_pillaraffiliation.py
@@ -443,9 +443,9 @@ class TestQuestionPillarAffiliation(TestCaseWithFactory):
         # target.
         answer_contact = self.factory.makePerson()
         english = getUtility(ILanguageSet)['en']
-        answer_contact.addLanguage(english)
         distro = self.factory.makeDistribution(owner=answer_contact)
         with person_logged_in(answer_contact):
+            answer_contact.addLanguage(english)
             distro.addAnswerContact(answer_contact, answer_contact)
         question = self.factory.makeQuestion(target=distro)
         [badges] = (
@@ -465,11 +465,11 @@ class TestQuestionPillarAffiliation(TestCaseWithFactory):
         # target.
         answer_contact = self.factory.makePerson()
         english = getUtility(ILanguageSet)['en']
-        answer_contact.addLanguage(english)
         distribution = self.factory.makeDistribution(owner=answer_contact)
         distro_sourcepackage = self.factory.makeDistributionSourcePackage(
             distribution=distribution)
         with person_logged_in(answer_contact):
+            answer_contact.addLanguage(english)
             distro_sourcepackage.addAnswerContact(
                 answer_contact, answer_contact)
         question = self.factory.makeQuestion(
@@ -491,11 +491,11 @@ class TestQuestionPillarAffiliation(TestCaseWithFactory):
         # target's distro.
         answer_contact = self.factory.makePerson()
         english = getUtility(ILanguageSet)['en']
-        answer_contact.addLanguage(english)
         distribution = self.factory.makeDistribution(owner=answer_contact)
         distro_sourcepackage = self.factory.makeDistributionSourcePackage(
             distribution=distribution)
         with person_logged_in(answer_contact):
+            answer_contact.addLanguage(english)
             distribution.addAnswerContact(answer_contact, answer_contact)
         question = self.factory.makeQuestion(
             target=distro_sourcepackage, owner=answer_contact)
diff --git a/lib/lp/translations/browser/tests/test_persontranslationview.py b/lib/lp/translations/browser/tests/test_persontranslationview.py
index 33abcbc..456ba07 100644
--- a/lib/lp/translations/browser/tests/test_persontranslationview.py
+++ b/lib/lp/translations/browser/tests/test_persontranslationview.py
@@ -11,6 +11,7 @@ from lp.services.webapp import canonical_url
 from lp.services.webapp.servers import LaunchpadTestRequest
 from lp.testing import (
     BrowserTestCase,
+    person_logged_in,
     TestCaseWithFactory,
     )
 from lp.testing.layers import (
@@ -392,7 +393,8 @@ class TestPersonTranslationViewPermissions(BrowserTestCase):
         super(TestPersonTranslationViewPermissions, self).setUp()
         self.context = self.factory.makePerson()
         self.language = self.factory.makeLanguage()
-        self.context.addLanguage(self.language)
+        with person_logged_in(self.context):
+            self.context.addLanguage(self.language)
         owner = self.factory.makePerson()
         self.translationgroup = self.factory.makeTranslationGroup(owner=owner)
         TranslatorSet().new(
diff --git a/lib/lp/translations/doc/language.txt b/lib/lp/translations/doc/language.txt
index 309b92d..91eb560 100644
--- a/lib/lp/translations/doc/language.txt
+++ b/lib/lp/translations/doc/language.txt
@@ -16,6 +16,7 @@ concrete language.
 
     >>> from lp.services.worlddata.interfaces.language import ILanguageSet
     >>> spanish = getUtility(ILanguageSet).getLanguageByCode('es')
+    >>> login('foo.bar@xxxxxxxxxxxxx')
     >>> foo_bar.addLanguage(spanish)
     >>> for translator in spanish.translators:
     ...     karma = 0
diff --git a/lib/lp/translations/stories/standalone/xx-person-editlanguages.txt b/lib/lp/translations/stories/standalone/xx-person-editlanguages.txt
index d552f30..e9bb6b2 100644
--- a/lib/lp/translations/stories/standalone/xx-person-editlanguages.txt
+++ b/lib/lp/translations/stories/standalone/xx-person-editlanguages.txt
@@ -237,7 +237,7 @@ The nag message links to the languages editing page.
 Once Noi has set one or more preferred languages, the nag message goes
 away.
 
-    >>> login(ANONYMOUS)
+    >>> login('noi@xxxxxxxxxxx')
     >>> from lp.services.worlddata.model.language import LanguageSet
     >>> noi.addLanguage(LanguageSet().getLanguageByCode('lo'))
     >>> logout()

Follow ups