launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25826
[Merge] ~pappacena/launchpad:bugfix-email-change-error-msg-1907173 into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:bugfix-email-change-error-msg-1907173 into launchpad:master.
Commit message:
Preventing unicode decode error when setting existing email for a team
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1907173 in Launchpad itself: "Cannot change email address of a LoCo Team"
https://bugs.launchpad.net/launchpad/+bug/1907173
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/395036
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:bugfix-email-change-error-msg-1907173 into launchpad:master.
diff --git a/lib/lp/registry/browser/team.py b/lib/lp/registry/browser/team.py
index c309d57..d10af5a 100644
--- a/lib/lp/registry/browser/team.py
+++ b/lib/lp/registry/browser/team.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
__metaclass__ = type
@@ -43,6 +43,7 @@ from lazr.restful.interfaces import IJSONRequestCache
from lazr.restful.utils import smartquote
import pytz
import simplejson
+import six
from six.moves.urllib.parse import unquote
from zope.browserpage import ViewPageTemplateFile
from zope.component import getUtility
@@ -520,8 +521,10 @@ class TeamContactAddressView(MailingListTeamBaseView):
# We need to wrap this in structured, so that the
# markup is preserved. Note that this puts the
# responsibility for security on the exception thrower.
- self.setFieldError('contact_address',
- structured(str(error)))
+ msg = error.args[0]
+ if not isinstance(msg, structured):
+ msg = structured(six.text_type(msg))
+ self.setFieldError('contact_address', msg)
elif data['contact_method'] == TeamContactMethod.HOSTED_LIST:
mailing_list = getUtility(IMailingListSet).get(self.context.name)
if mailing_list is None or not mailing_list.is_usable:
diff --git a/lib/lp/registry/browser/tests/test_team.py b/lib/lp/registry/browser/tests/test_team.py
index 672c59d..44a1d63 100644
--- a/lib/lp/registry/browser/tests/test_team.py
+++ b/lib/lp/registry/browser/tests/test_team.py
@@ -1,6 +1,8 @@
-# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
import contextlib
@@ -39,6 +41,7 @@ from lp.services.webapp.escaping import html_escape
from lp.services.webapp.publisher import canonical_url
from lp.soyuz.enums import ArchiveStatus
from lp.testing import (
+ admin_logged_in,
ANONYMOUS,
login,
login_celebrity,
@@ -967,3 +970,28 @@ class TestPersonIndexVisibilityView(TestCaseWithFactory):
'private team link', 'a',
attrs={'href': '/~private-team', 'class': 'sprite team private'},
text='Private Team'))
+
+
+class TestTeamContactAddressView(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_team_change_contact_address_to_existing_address(self):
+ # Test that a team can change the contact address.
+ someone_email = "someone@xxxxxxxxxxxxx"
+ someone = self.factory.makePerson(
+ displayname="Unicode Person \xc9", email=someone_email)
+ someone_url = canonical_url(someone)
+ team = self.factory.makeTeam(email="team@xxxxxxxxxxxxx")
+ with admin_logged_in():
+ form = {
+ 'field.contact_method': 'EXTERNAL_ADDRESS',
+ 'field.contact_address': 'someone@xxxxxxxxxxxxx',
+ 'field.actions.change': 'Change',
+ }
+ view = create_initialized_view(team, '+contactaddress', form=form)
+ expected_msg = (
+ '%s is already registered in Launchpad and is associated '
+ 'with <a href="%s">Unicode Person \xc9</a>.')
+ expected_msg %= (someone_email, someone_url)
+ self.assertEqual([expected_msg], view.errors)
Follow ups