Commit 406819c6 authored by Julien Cristau's avatar Julien Cristau
Browse files

[hooks] update to cw 3.19

Operations get a cnx instead of a session.
parent 8b53e5b9723f
......@@ -20,7 +20,7 @@ classifiers = [
]
# used packages
__depends__ = {'cubicweb': '>= 3.16.0',
__depends__ = {'cubicweb': '>= 3.19.0',
'cubicweb-file': '>= 1.9.0',
'logilab-common': '>= 0.58.3',
}
......
......@@ -20,7 +20,7 @@ BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
BuildRequires: %{python} %{python}-setuptools
Requires: cubicweb >= 3.16.0
Requires: cubicweb >= 3.19.0
Requires: cubicweb-file >= 1.9.0
Requires: logilab-common >= 0.58.3
......
......@@ -9,7 +9,7 @@ Homepage: http://www.cubicweb.org/project/cubicweb-email
Package: cubicweb-email
Architecture: all
Depends: cubicweb-common (>= 3.16.0), cubicweb-file (>= 1.9.0)
Depends: cubicweb-common (>= 3.19.0), cubicweb-file (>= 1.9.0)
Description: email component for the CubicWeb framework
This CubicWeb component models email messages.
.
......
......@@ -18,13 +18,13 @@ from cubicweb.predicates import is_instance
from cubicweb.server import hook
def fix_ownership(session, eid, email):
def fix_ownership(cnx, eid, email):
sender = email.senderaddr.email_of
if sender and sender.e_schema == 'CWUser' and sender.eid != session.user.eid:
# match a user which is not the session's user, set owned_by / created_by
session.execute('SET X owned_by U WHERE X eid %(x)s, U eid %(u)s',
if sender and sender.e_schema == 'CWUser' and sender.eid != cnx.user.eid:
# match a user which is not the connection's user, set owned_by / created_by
cnx.execute('SET X owned_by U WHERE X eid %(x)s, U eid %(u)s',
{'x': eid, 'u': sender.eid})
session.execute('SET X created_by U WHERE X eid %(x)s, U eid %(u)s',
cnx.execute('SET X created_by U WHERE X eid %(x)s, U eid %(u)s',
{'x': eid, 'u': sender.eid})
......@@ -37,12 +37,12 @@ class ExtractEmailInformation(hook.Operation):
info = self.info
origeid = int(info['eid'])
try:
origetype = self.session.describe(origeid)[0]
origetype = self.cnx.entity_metas(origeid)['type']
except UnknownEid:
self.error('email %s is referencing an unknown eid %s',
email.messageid, origeid)
return
if origetype in self.session.vreg.schema['comments'].objects('Comment'):
if origetype in self.cnx.vreg.schema['comments'].objects('Comment'):
try:
part = email.parts_in_order(prefered_mime_type='text/plain')[0]
except IndexError:
......@@ -55,13 +55,13 @@ class ExtractEmailInformation(hook.Operation):
origeid, email)
def insert_comment(self, eid, emailpart):
com = self.session.execute(
com = self.cnx.execute(
'INSERT Comment C: C content %(content)s, '
'C content_format %(format)s, C comments X, C generated_by E '
'WHERE X eid %(x)s, E eid %(e)s',
{'x': eid, 'e': self.email.eid, 'format': u'text/plain',
'content': emailpart.actual_content()})
fix_ownership(self.session, com[0][0], self.email)
fix_ownership(self.cnx, com[0][0], self.email)
class AnalyzeEmailText(hook.Operation):
......@@ -75,13 +75,13 @@ class AnalyzeEmailText(hook.Operation):
except TransformError:
continue
# XXX use user session if gpg signature validated
parser = self.session.vreg['components'].select('textanalyzer', self.session)
parser = self.cnx.vreg['components'].select('textanalyzer', self.cnx)
parser.parse(self, text)
def fire_event(self, event, evargs):
if event == 'state-changed':
evargs['trinfo'].cw_set(generated_by=self.email)
fix_ownership(self.session, evargs['trinfo'].eid, self.email)
fix_ownership(self.cnx, evargs['trinfo'].eid, self.email)
class AddEmailHook(hook.Hook):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment