Skip to content

Commit

Permalink
[MOV] mass_mailing_sms,link_tracker: Move convert_links_text to link_…
Browse files Browse the repository at this point in the history
…tracker

This method being needed in the new social app, it made sense to move it to
the link_tracker module to make it available for mass_mailing_sms and social
to avoid unnecessary duplicated code.

LINKS:

closes #34973

Taskid: 2045210
Pr: 37143
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
  • Loading branch information
qmo-odoo authored and awa-odoo committed Sep 20, 2019
1 parent 6c531b3 commit 79bfdbf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
22 changes: 22 additions & 0 deletions addons/link_tracker/models/link_tracker.py
Expand Up @@ -15,6 +15,7 @@


URL_REGEX = r'(\bhref=[\'"](?!mailto:|tel:|sms:)([^\'"]+)[\'"])'
TEXT_URL_REGEX = r'(https?:\/\/(www\.)?[a-zA-Z0-9@:%._\+~#=/-]{1,64})'


def VALIDATE_URL(url):
Expand Down Expand Up @@ -164,6 +165,27 @@ def convert_links(self, html, vals, blacklist=None):

return html

def _convert_links_text(self, body, vals, blacklist=None):
shortened_schema = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + '/r/'
unsubscribe_schema = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + '/sms/'
for match in re.findall(TEXT_URL_REGEX, body):
original_url = match[0]
# don't shorten already-shortened links or links towards unsubscribe page
if original_url.startswith(shortened_schema) or original_url.startswith(unsubscribe_schema):
continue
# support blacklist items in path, like /u/
parsed = urls.url_parse(original_url, scheme='http')
if blacklist and any(item in parsed.path for item in blacklist):
continue

vals['url'] = utils.unescape(original_url)
link = self.create(vals)
shortened_url = link.short_url
if shortened_url:
body = body.replace(original_url, shortened_url, 1)

return body

def action_view_statistics(self):
action = self.env['ir.actions.act_window'].for_xml_id('link_tracker', 'link_tracker_click_action_statistics')
action['domain'] = [('link_id', '=', self.id)]
Expand Down
1 change: 0 additions & 1 deletion addons/mass_mailing_sms/models/__init__.py
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import link_tracker
from . import mailing_contact
from . import mailing_list
from . import mailing_mailing
Expand Down
33 changes: 0 additions & 33 deletions addons/mass_mailing_sms/models/link_tracker.py

This file was deleted.

0 comments on commit 79bfdbf

Please sign in to comment.