[notification] avoid using InternalManager when we've got a CWUser

This will avoid potential information leak due to missed security restriction and is more compatible with legacy code (pb encountered in some client code).

Closes #10294761

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset499410b147d6
branchdefault
phasedraft
hiddenyes
parent revision#2dafcdd19c99 pep8 bits
child revision<not specified>
files modified by this revision
cubicweb/sobjects/notification.py
cubicweb/sobjects/test/unittest_notification.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1453827840 -3600
# Tue Jan 26 18:04:00 2016 +0100
# Node ID 499410b147d6d1bcab726e881607bb8e369c0f3a
# Parent 2dafcdd19c9918f6d0bde86b6afdcaf07c1722b3
[notification] avoid using InternalManager when we've got a CWUser

This will avoid potential information leak due to missed security restriction
and is more compatible with legacy code (pb encountered in some client code).

Closes #10294761

diff --git a/cubicweb/sobjects/notification.py b/cubicweb/sobjects/notification.py
@@ -48,13 +48,11 @@
1 
2      def recipients(self):
3          mode = self._cw.vreg.config['default-recipients-mode']
4          if mode == 'users':
5              execute = self._cw.execute
6 -            dests = [(u.cw_adapt_to('IEmailable').get_email(),
7 -                      u.property_value('ui.language'))
8 -                     for u in execute(self.user_rql, build_descr=True).entities()]
9 +            dests = list(execute(self.user_rql, build_descr=True).entities())
10          elif mode == 'default-dest-addrs':
11              lang = self._cw.vreg.property_value('ui.language')
12              dests = zip(self._cw.vreg.config['default-dest-addrs'], repeat(lang))
13          else: # mode == 'none'
14              dests = []
diff --git a/cubicweb/sobjects/test/unittest_notification.py b/cubicweb/sobjects/test/unittest_notification.py
@@ -33,11 +33,11 @@
15              finder = self.vreg['components'].select('recipients_finder',
16                                                      req, rset=urset)
17              self.set_option('default-recipients-mode', 'none')
18              self.assertEqual(finder.recipients(), [])
19              self.set_option('default-recipients-mode', 'users')
20 -            self.assertEqual(finder.recipients(), [(u'admin@logilab.fr', 'fr')])
21 +            self.assertEqual(finder.recipients(), [req.user])
22              self.set_option('default-recipients-mode', 'default-dest-addrs')
23              self.set_option('default-dest-addrs', 'abcd@logilab.fr, efgh@logilab.fr')
24              self.assertEqual(list(finder.recipients()),
25                               [('abcd@logilab.fr', 'en'), ('efgh@logilab.fr', 'en')])
26