Added local user mail adapter
authorThierry Florac <thierry.florac@onf.fr>
Mon, 02 Oct 2017 14:44:42 +0200
changeset 98 39b5457b87f2
parent 97 e3f804db3e6f
child 99 14805c882758
Added local user mail adapter
src/pyams_security/plugin/userfolder.py
--- a/src/pyams_security/plugin/userfolder.py	Thu Sep 28 15:02:44 2017 +0200
+++ b/src/pyams_security/plugin/userfolder.py	Mon Oct 02 14:44:42 2017 +0200
@@ -36,7 +36,7 @@
 from chameleon.zpt.template import PageTemplateFile
 from persistent import Persistent
 from pyams_security.principal import PrincipalInfo
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.html import html_to_text
 from pyams_utils.registry import query_utility, get_utility
 from pyams_utils.request import check_request
@@ -133,6 +133,19 @@
                          title=user.title)
 
 
+try:
+    from pyams_mail.interfaces import IPrincipalMailInfo
+except ImportError:
+    pass
+else:
+    @adapter_config(context=ILocalUser, provides=IPrincipalMailInfo)
+    class UserPrincipalMailInfoAdapter(ContextAdapter):
+        """User principal mail info adapter"""
+
+        def get_addresses(self):
+            yield ('{0} {1}'.format(self.context.firstname, self.context.lastname), self.context.email)
+
+
 @implementer(IUsersFolderPlugin)
 class UsersFolder(Folder):
     """Local users folder"""