[PATCH saem] [ui] Fix crash when displaying an email address

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Oct 5 11:00:49 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507124081 -7200
#      Wed Oct 04 15:34:41 2017 +0200
# Node ID 976da31e4753197f8821706f065b2b145f90a822
# Parent  dceca66da16ecdd0d891f3aeaddde08c02b485a7
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 976da31e4753
[ui] Fix crash when displaying an email address

In 5de93fa17e61 we dropped the "alias" attribute of email address, but the
default dc_title implementation will attempt to access it, leading to an
attribute error. Override it to avoid this.

Closes extranet #36119710

diff --git a/cubicweb_saem_ref/entities/__init__.py b/cubicweb_saem_ref/entities/__init__.py
--- a/cubicweb_saem_ref/entities/__init__.py
+++ b/cubicweb_saem_ref/entities/__init__.py
@@ -17,11 +17,11 @@
 
 from logilab.common.decorators import monkeypatch
 
 from cubicweb.view import Adapter, EntityAdapter
 from cubicweb.predicates import match_kwargs, relation_possible, is_instance
-from cubicweb.entities import AnyEntity, fetch_config, authobjs
+from cubicweb.entities import AnyEntity, fetch_config, authobjs, lib
 
 
 class ARKGeneratorMixIn(object):
     """Entity adapter for ARK unique identifier generation"""
     __abstract__ = True
@@ -126,10 +126,17 @@ class ConceptArkNAALocator(ArkNAALocator
 class ExternalUri(AnyEntity):
     __regid__ = 'ExternalUri'
     fetch_attrs, cw_fetch_order = fetch_config(('uri',))
 
 
+class EmailAddress(lib.EmailAddress):
+    fetch_attrs, cw_fetch_order = fetch_config(['address'])
+
+    def dc_title(self):
+        return self.display_address()
+
+
 @monkeypatch(authobjs.CWUser, methodname='naa')
 @property
 def naa(self):
     if self.authority and self.authority[0].ark_naa:
         return self.authority[0].ark_naa[0]
diff --git a/test/test_views.py b/test/test_views.py
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -231,10 +231,15 @@ class FuncViewsTC(CubicWebTC):
             self.assertEqual(params,
                              {'divid': expected_divid,
                               'vid': vid,
                               'rql': u'Any X WHERE X eid {}'.format(ou.eid)})
 
+    def test_email_address(self):
+        with self.admin_access.cnx() as cnx:
+            address = cnx.create_entity('EmailAddress', address=u'admin at cubicweb.org')
+            self.assertEqual(address.dc_title(), u'admin at cubicweb.org')
+
 
 class SEDAViewsTC(CubicWebTC):
 
     def test_seda_get_related_version(self):
         """Check that we get correct results when asking for `draft`, `published`, `replaced`


More information about the saem-devel mailing list