Browse Source

Add access to portal/public user to his own email trackings

pull/269/head
Antonio Espinosa 8 years ago
committed by Jairo Llopis
parent
commit
83242949d7
  1. 1
      mail_tracking/__manifest__.py
  2. 29
      mail_tracking/models/mail_tracking_email.py
  3. 9
      mail_tracking/models/res_partner.py
  4. 2
      mail_tracking/security/ir.model.access.csv
  5. 16
      mail_tracking/security/mail_tracking_email_security.xml
  6. 25
      mail_tracking/tests/test_mail_tracking.py

1
mail_tracking/__manifest__.py

@ -19,6 +19,7 @@
], ],
"data": [ "data": [
"data/tracking_data.xml", "data/tracking_data.xml",
"security/mail_tracking_email_security.xml",
"security/ir.model.access.csv", "security/ir.model.access.csv",
"views/assets.xml", "views/assets.xml",
"views/mail_tracking_email_view.xml", "views/mail_tracking_email_view.xml",

29
mail_tracking/models/mail_tracking_email.py

@ -100,16 +100,20 @@ class MailTrackingEmail(models.Model):
@api.model @api.model
def email_is_bounced(self, email): def email_is_bounced(self, email):
return len(self._email_score_tracking_filter([
('recipient_address', '=ilike', email),
('state', 'in', ('error', 'rejected', 'spam', 'bounced')),
])) > 0
if email:
return len(self._email_score_tracking_filter([
('recipient_address', '=', email.lower()),
('state', 'in', ('error', 'rejected', 'spam', 'bounced')),
])) > 0
return False
@api.model @api.model
def email_score_from_email(self, email): def email_score_from_email(self, email):
return self._email_score_tracking_filter([
('recipient_address', '=ilike', email)
]).email_score()
if email:
return self._email_score_tracking_filter([
('recipient_address', '=', email.lower())
]).email_score()
return 0.
@api.model @api.model
def _email_score_weights(self): def _email_score_weights(self):
@ -146,11 +150,14 @@ class MailTrackingEmail(models.Model):
@api.depends('recipient') @api.depends('recipient')
def _compute_recipient_address(self): def _compute_recipient_address(self):
for email in self: for email in self:
matches = re.search(r'<(.*@.*)>', email.recipient)
if matches:
email.recipient_address = matches.group(1)
if email.recipient:
matches = re.search(r'<(.*@.*)>', email.recipient)
if matches:
email.recipient_address = matches.group(1).lower()
else:
email.recipient_address = email.recipient.lower()
else: else:
email.recipient_address = email.recipient
email.recipient_address = False
@api.depends('name', 'recipient') @api.depends('name', 'recipient')
def _compute_tracking_display_name(self): def _compute_tracking_display_name(self):

9
mail_tracking/models/res_partner.py

@ -27,10 +27,12 @@ class ResPartner(models.Model):
@api.depends('email') @api.depends('email')
def _compute_tracking_emails_count(self): def _compute_tracking_emails_count(self):
for partner in self: for partner in self:
partner.tracking_emails_count = self.env['mail.tracking.email'].\
search_count([
('recipient_address', '=ilike', partner.email)
count = 0
if partner.email:
count = self.env['mail.tracking.email'].search_count([
('recipient_address', '=', partner.email.lower())
]) ])
partner.tracking_emails_count = count
@api.multi @api.multi
def email_bounced_set(self, tracking_email, reason): def email_bounced_set(self, tracking_email, reason):
@ -41,6 +43,7 @@ class ResPartner(models.Model):
def write(self, vals): def write(self, vals):
email = vals.get('email') email = vals.get('email')
if email is not None: if email is not None:
vals['email'] = email.lower() if email else False
vals['email_bounced'] = ( vals['email_bounced'] = (
bool(email) and bool(email) and
self.env['mail.tracking.email'].email_is_bounced(email)) self.env['mail.tracking.email'].email_is_bounced(email))

2
mail_tracking/security/ir.model.access.csv

@ -1,4 +1,6 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_mail_tracking_email_group_public","mail_tracking_email group_public","model_mail_tracking_email","base.group_public",1,0,0,0
"access_mail_tracking_email_group_portal","mail_tracking_email group_portal","model_mail_tracking_email","base.group_portal",1,0,0,0
"access_mail_tracking_email_group_user","mail_tracking_email group_user","model_mail_tracking_email","base.group_user",1,0,0,0 "access_mail_tracking_email_group_user","mail_tracking_email group_user","model_mail_tracking_email","base.group_user",1,0,0,0
"access_mail_tracking_event_group_user","mail_tracking_event group_user","model_mail_tracking_event","base.group_user",1,0,0,0 "access_mail_tracking_event_group_user","mail_tracking_event group_user","model_mail_tracking_event","base.group_user",1,0,0,0
"access_mail_tracking_email_group_system","mail_tracking_email group_system","model_mail_tracking_email","base.group_system",1,1,1,1 "access_mail_tracking_email_group_system","mail_tracking_email group_system","model_mail_tracking_email","base.group_system",1,1,1,1

16
mail_tracking/security/mail_tracking_email_security.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Antonio Espinosa - <antonio.espinosa@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record model="ir.rule" id="mail_tracking_email_portal_public_rule">
<field name="name">mail_tracking_email: portal/public: read access on my email trackings</field>
<field name="model_id" ref="model_mail_tracking_email"/>
<field name="domain_force">[('partner_id', '=', user.partner_id.id)]</field>
<field name="groups" eval="[(4, ref('base.group_portal')), (4, ref('base.group_public'))]"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
<field name="perm_write" eval="False"/>
</record>
</odoo>

25
mail_tracking/tests/test_mail_tracking.py

@ -52,6 +52,31 @@ class TestMailTracking(TransactionCase):
http.request = self.last_request http.request = self.last_request
return super(TestMailTracking, self).tearDown(*args, **kwargs) return super(TestMailTracking, self).tearDown(*args, **kwargs)
def test_email_lower(self):
self.recipient.write({'email': 'UPPER@example.com'})
self.assertEqual('upper@example.com', self.recipient.email)
def test_empty_email(self):
self.recipient.write({'email_bounced': True})
self.recipient.write({'email': False})
self.assertEqual(False, self.recipient.email)
self.assertEqual(False, self.recipient.email_bounced)
self.recipient.write({'email_bounced': True})
self.recipient.write({'email': ''})
self.assertEqual(False, self.recipient.email)
self.assertEqual(False, self.recipient.email_bounced)
self.assertEqual(
False,
self.env['mail.tracking.email'].email_is_bounced(False))
self.assertEqual(
0.,
self.env['mail.tracking.email'].email_score_from_email(False))
def test_recipient_address_compute(self):
mail, tracking = self.mail_send(self.recipient.email)
tracking.write({'recipient': False})
self.assertEqual(False, tracking.recipient_address)
def test_message_post(self): def test_message_post(self):
# This message will generate a notification for recipient # This message will generate a notification for recipient
message = self.env['mail.message'].create({ message = self.env['mail.message'].create({

Loading…
Cancel
Save