From b1f88d634d603b74a62d051032e4003fc6f7a3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 27 Feb 2014 14:48:29 +0100 Subject: [PATCH 01/23] [IMP] [FIX] email_template: do not sanitize the template content. Indeed its content may contain invalid html that could be stripped by the sanitizer. The content generated based on the template will be sanitized when stored in the mail_mail or mail_message body field, thus after rendering. The template therefore holds html, but that is not sanitized. But that's still html, therefore using an html field. bzr revid: tde@openerp.com-20140227134829-te8mxeakc3s96fun --- addons/email_template/email_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py index fcfe869da90..0b5945c1f0b 100644 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@ -183,7 +183,7 @@ class email_template(osv.osv): 'mail_server_id': fields.many2one('ir.mail_server', 'Outgoing Mail Server', readonly=False, help="Optional preferred server for outgoing mails. If not set, the highest " "priority one will be used."), - 'body_html': fields.html('Body', translate=True, help="Rich-text/HTML version of the message (placeholders may be used here)"), + 'body_html': fields.html('Body', translate=True, sanitize=False, help="Rich-text/HTML version of the message (placeholders may be used here)"), 'report_name': fields.char('Report Filename', translate=True, help="Name to use for the generated report file (may contain placeholders)\n" "The extension can be omitted and will then come from the report type."), From a9a4767d17650320cba710ce99b6c737419df7c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 27 Feb 2014 16:38:35 +0100 Subject: [PATCH 02/23] [FIX] email_template : - fixed composer using template that were rendering the body twice, once form the template and once from the composer body. Only the latter one is used, so avoid generating the template body that is not necessary - fixed email_template generating values for a set of given fields, ignoring the field list given into parameter - fixed post processing of templates to transform local urls into absolute urls; now urls are transformed after body generation, when sending email based on templates , or when generating the content when using the composer. bzr revid: tde@openerp.com-20140227153835-gmqnxrzed9fnbxhm --- addons/email_template/email_template.py | 6 ++-- .../wizard/mail_compose_message.py | 15 +++++--- addons/website_mail/models/__init__.py | 1 + addons/website_mail/models/email_template.py | 16 ++++----- .../models/mail_compose_message.py | 34 +++++++++++++++++++ 5 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 addons/website_mail/models/mail_compose_message.py diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py index 0b5945c1f0b..d9b65849fae 100644 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@ -356,17 +356,17 @@ class email_template(osv.osv): results = dict() for template, template_res_ids in templates_to_res_ids.iteritems(): # generate fields value for all res_ids linked to the current template - for field in ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to']: + for field in fields: generated_field_values = self.render_template_batch(cr, uid, getattr(template, field), template.model, template_res_ids, context=context) for res_id, field_value in generated_field_values.iteritems(): results.setdefault(res_id, dict())[field] = field_value # update values for all res_ids for res_id in template_res_ids: values = results[res_id] - if template.user_signature: + if 'body_html' in fields and template.user_signature: signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature values['body_html'] = tools.append_content_to_html(values['body_html'], signature) - if values['body_html']: + if values.get('body_html'): values['body'] = tools.html_sanitize(values['body_html']) values.update( mail_server_id=template.mail_server_id.id or False, diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py index beede1122dc..3f926439d08 100644 --- a/addons/email_template/wizard/mail_compose_message.py +++ b/addons/email_template/wizard/mail_compose_message.py @@ -162,16 +162,18 @@ class mail_compose_message(osv.TransientModel): partner_ids += self.pool['res.partner'].exists(cr, SUPERUSER_ID, tpl_partner_ids, context=context) return partner_ids - def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None): + def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None, fields=None): """ Call email_template.generate_email(), get fields relevant for mail.compose.message, transform email_cc and email_to into partner_ids """ # filter template values - fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'attachments', 'mail_server_id'] + if fields is None: + fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'mail_server_id'] + returned_fields = fields + ['attachments'] values = dict.fromkeys(res_ids, False) - template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, context=context) + template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, fields=fields, context=context) for res_id in res_ids: - res_id_values = dict((field, template_values[res_id][field]) for field in fields if template_values[res_id].get(field)) + res_id_values = dict((field, template_values[res_id][field]) for field in returned_fields if template_values[res_id].get(field)) res_id_values['body'] = res_id_values.pop('body_html', '') # transform email_to, email_cc into partner_ids @@ -189,7 +191,10 @@ class mail_compose_message(osv.TransientModel): """ Override to handle templates. """ # generate template-based values if wizard.template_id: - template_values = self.generate_email_for_composer_batch(cr, uid, wizard.template_id.id, res_ids, context=context) + template_values = self.generate_email_for_composer_batch( + cr, uid, wizard.template_id.id, res_ids, + fields=['email_to', 'partner_to', 'email_cc', 'attachment_ids', 'mail_server_id'], + context=context) else: template_values = dict.fromkeys(res_ids, dict()) # generate composer values diff --git a/addons/website_mail/models/__init__.py b/addons/website_mail/models/__init__.py index e60de014149..3e374ccddd2 100644 --- a/addons/website_mail/models/__init__.py +++ b/addons/website_mail/models/__init__.py @@ -1,3 +1,4 @@ import mail_message import mail_thread import email_template +import mail_compose_message \ No newline at end of file diff --git a/addons/website_mail/models/email_template.py b/addons/website_mail/models/email_template.py index aed01c179f7..105fcff4428 100644 --- a/addons/website_mail/models/email_template.py +++ b/addons/website_mail/models/email_template.py @@ -79,12 +79,10 @@ class EmailTemplate(osv.Model): html = html[5:-6] return html - def create(self, cr, uid, values, context=None): - if 'body_html' in values: - values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context) - return super(EmailTemplate, self).create(cr, uid, values, context=context) - - def write(self, cr, uid, ids, values, context=None): - if 'body_html' in values: - values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context) - return super(EmailTemplate, self).write(cr, uid, ids, values, context=context) + def generate_email_batch(self, cr, uid, template_id, res_ids, context=None, fields=None): + """ Add a post processing after rendering, aka replace local URLs to absolute URLs. """ + results = super(EmailTemplate, self).generate_email_batch(cr, uid, template_id, res_ids, context=context, fields=fields) + for res_id, value in results.iteritems(): + if 'body_html' in value: + results[res_id]['body_html'] = self._postprocess_html_replace_links(cr, uid, value['body_html'], context=context) + return results diff --git a/addons/website_mail/models/mail_compose_message.py b/addons/website_mail/models/mail_compose_message.py new file mode 100644 index 00000000000..bc8258bbb6f --- /dev/null +++ b/addons/website_mail/models/mail_compose_message.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014-Today OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import osv + + +class MailComposeMessage(osv.Model): + _inherit = 'mail.compose.message' + + def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None, fields=None): + """ Add a post processing after rendering, aka replace local URLs to absolute URLs. """ + results = super(MailComposeMessage, self).generate_email_for_composer_batch(cr, uid, template_id, res_ids, context=context, fields=fields) + for res_id, value in results.iteritems(): + if 'body' in value: + results[res_id]['body'] = self.pool['email.template']._postprocess_html_replace_links(cr, uid, value['body'], context=context) + return results From 015083df092fde1fa55a0efe0631da907f288471 Mon Sep 17 00:00:00 2001 From: Kersten Jeremy Date: Fri, 28 Feb 2014 15:00:53 +0100 Subject: [PATCH 03/23] [FIX] Calendar - Tempalte Mail - Move the if condition who vas between table and tr into td, else wysiwig and some other sanitizers will move the if condition outside the table bzr revid: jke@openerp.com-20140228140053-02952ews6aadfcjf --- addons/calendar/calendar_data.xml | 238 ++++++++++++++++-------------- 1 file changed, 131 insertions(+), 107 deletions(-) diff --git a/addons/calendar/calendar_data.xml b/addons/calendar/calendar_data.xml index 4426014e509..9171bc435e0 100644 --- a/addons/calendar/calendar_data.xml +++ b/addons/calendar/calendar_data.xml @@ -151,50 +151,58 @@ - % if object.event_id.location: - + - + - % endif - % if object.event_id.description : - + + - - % endif - % if not object.event_id.allday and object.event_id.duration: - + + - - % endif +
-
- Where -
-
-
- : ${object.event_id.location} - (View Map) - -
+ % if object.event_id.location: +
+ Where +
+ % endif
+ % if object.event_id.location: +
+ : ${object.event_id.location} + (View Map) + +
+ % endif +
-
- What -
+ % if object.event_id.description : +
+ What +
+ % endif
-
- : ${object.event_id.description} -
+
+ % if object.event_id.description : +
+ : ${object.event_id.description} +
+ % endif
-
- Duration -
+ % if not object.event_id.allday and object.event_id.duration: +
+ Duration +
+ % endif
-
- : ${('%dH%02d' % (object.event_id.duration,(object.event_id.duration*60)%60))} -
+ % if not object.event_id.allday and object.event_id.duration: +
+ : ${('%dH%02d' % (object.event_id.duration,(object.event_id.duration*60)%60))} +
+ % endif
@@ -219,9 +227,9 @@
@@ -265,7 +273,7 @@
- + -
${object.event_id.get_interval(object.event_id.date, 'dayname')}
@@ -276,50 +284,58 @@
- % if object.event_id.location: - + - + - % endif - % if object.event_id.description : - + + - - % endif - % if not object.event_id.allday and object.event_id.duration: - + + - - % endif +
-
- Where -
-
-
- : ${object.event_id.location} - (View Map) - -
+ % if object.event_id.location: +
+ Where +
+ % endif
+ % if object.event_id.location: +
+ : ${object.event_id.location} + (View Map) + +
+ % endif +
-
- What -
+ % if object.event_id.description : +
+ What +
+ % endif
-
- : ${object.event_id.description} -
+
+ % if object.event_id.description : +
+ : ${object.event_id.description} +
+ % endif
-
- Duration -
+ % if not object.event_id.allday and object.event_id.duration: +
+ Duration +
+ % endif
-
- : ${('%dH%02d' % (object.event_id.duration,(object.event_id.duration*60)%60))} -
+ % if not object.event_id.allday and object.event_id.duration: +
+ : ${('%dH%02d' % (object.event_id.duration,(object.event_id.duration*60)%60))} +
+ % endif
@@ -341,12 +357,12 @@
+
@@ -400,50 +416,58 @@ - % if object.event_id.location: - + - + - % endif - % if object.event_id.description : - + + - - % endif - % if not object.event_id.allday and object.event_id.duration: - + + - - % endif +
-
- Where -
-
-
- : ${object.event_id.location} - (View Map) - -
+ % if object.event_id.location: +
+ Where +
+ % endif
+ % if object.event_id.location: +
+ : ${object.event_id.location} + (View Map) + +
+ % endif +
-
- What -
+ % if object.event_id.description : +
+ What +
+ % endif
-
- : ${object.event_id.description} -
+
+ % if object.event_id.description : +
+ : ${object.event_id.description} +
+ % endif
-
- Duration -
+ % if not object.event_id.allday and object.event_id.duration: +
+ Duration +
+ % endif
-
- : ${('%dH%02d' % (object.event_id.duration,(object.event_id.duration*60)%60))} -
+ % if not object.event_id.allday and object.event_id.duration: +
+ : ${('%dH%02d' % (object.event_id.duration,(object.event_id.duration*60)%60))} +
+ % endif
From 4954c0fa39e947c8ac77d595bbd49a2437ad1098 Mon Sep 17 00:00:00 2001 From: Kersten Jeremy Date: Fri, 28 Feb 2014 15:39:30 +0100 Subject: [PATCH 04/23] [FIX] Allow other users to read field recurrent_id_date from private event, else we cannot see that this event is excluded from a recurrence bzr revid: jke@openerp.com-20140228143930-3eeam1a3676kgv4i --- addons/calendar/calendar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index e25f75d803a..c5f2a1e9af8 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -1515,7 +1515,7 @@ class calendar_event(osv.Model): continue if r['class'] == 'private': for f in r.keys(): - if f not in ('id', 'date', 'date_deadline', 'duration', 'user_id', 'state', 'interval', 'count'): + if f not in ('id', 'date', 'date_deadline', 'duration', 'user_id', 'state', 'interval', 'count', 'recurrent_id_date'): if isinstance(r[f], list): r[f] = [] else: From 47c4728f4334756da052f92e974bf7751db4f629 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 28 Feb 2014 15:22:33 +0100 Subject: [PATCH 05/23] [FIX] mail,website_sale: rename file_type to file_type_icon to avoid name conflict with file_type field added by document module bzr revid: chs@openerp.com-20140228142233-i0mm9lav0czbydkk --- addons/mail/ir_attachment.py | 9 ++++----- addons/mail/mail_message.py | 4 ++-- addons/mail/static/src/xml/mail.xml | 6 +++--- addons/website_sale/views/website_sale.xml | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/addons/mail/ir_attachment.py b/addons/mail/ir_attachment.py index 99c5a9e054e..a5d8705c0fb 100644 --- a/addons/mail/ir_attachment.py +++ b/addons/mail/ir_attachment.py @@ -186,12 +186,11 @@ class IrAttachment(osv.Model): def get_attachment_type(self, cr, uid, ids, name, args, context=None): result = {} for attachment in self.browse(cr, uid, ids, context=context): - fileext = os.path.splitext(attachment.datas_fname)[1].lower() - if not fileext or not fileext[1:] in self._fileext_to_type: - return 'unknown' - result[attachment.id] = self._fileext_to_type[fileext[1:]] + fileext = os.path.splitext(attachment.datas_fname or '')[1].lower()[1:] + result[attachment.id] = self._fileext_to_type.get(fileext, 'unknown') return result _columns = { - 'file_type': fields.function(get_attachment_type, type='char', string='File Type'), + 'file_type_icon': fields.function(get_attachment_type, type='char', string='File Type Icon'), + 'file_type': fields.related('file_type_icon', type='char'), # FIXME remove in trunk } diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 40a51df91d2..4c05d7a6d1f 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -351,12 +351,12 @@ class mail_message(osv.Model): partner_tree = dict((partner[0], partner) for partner in partners) # 2. Attachments as SUPERUSER, because could receive msg and attachments for doc uid cannot see - attachments = ir_attachment_obj.read(cr, SUPERUSER_ID, list(attachment_ids), ['id', 'datas_fname', 'name', 'file_type'], context=context) + attachments = ir_attachment_obj.read(cr, SUPERUSER_ID, list(attachment_ids), ['id', 'datas_fname', 'name', 'file_type_icon'], context=context) attachments_tree = dict((attachment['id'], { 'id': attachment['id'], 'filename': attachment['datas_fname'], 'name': attachment['name'], - 'file_type': attachment['file_type'], + 'file_type_icon': attachment['file_type_icon'], }) for attachment in attachments) # 3. Update message dictionaries diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index 6ce588e82a2..28cbbca1f2c 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -88,10 +88,10 @@ --> - +
- +
[
@@ -100,7 +100,7 @@
- +
diff --git a/addons/website_sale/views/website_sale.xml b/addons/website_sale/views/website_sale.xml index 4f8a5404d74..a1b21137d94 100644 --- a/addons/website_sale/views/website_sale.xml +++ b/addons/website_sale/views/website_sale.xml @@ -419,11 +419,11 @@
- + - + From a5fc14193de543b71d4e7968d7692756605876fe Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 28 Feb 2014 16:15:44 +0100 Subject: [PATCH 06/23] [FIX] website_mail: forbid access to email_designer routes to public user bzr revid: chs@openerp.com-20140228151544-ipoih9c924rsbqi1 --- addons/website_mail/controllers/email_designer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website_mail/controllers/email_designer.py b/addons/website_mail/controllers/email_designer.py index 81bc703b702..3eb3c32ac96 100644 --- a/addons/website_mail/controllers/email_designer.py +++ b/addons/website_mail/controllers/email_designer.py @@ -7,7 +7,7 @@ from openerp.addons.web.http import request class WebsiteEmailDesigner(http.Controller): - @http.route('/website_mail/email_designer//', type='http', auth="public", website=True, multilang=True) + @http.route('/website_mail/email_designer//', type='http', auth="user", website=True, multilang=True) def index(self, template, **kw): values = { 'template': template, @@ -15,6 +15,6 @@ class WebsiteEmailDesigner(http.Controller): print template return request.website.render("website_mail.designer_index", values) - @http.route(['/website_mail/snippets'], type='json', auth="public", website=True) + @http.route(['/website_mail/snippets'], type='json', auth="user", website=True) def snippets(self): return request.website._render('website_mail.email_designer_snippets') From 57c469123656c4238f8e20a640916d4fc56b0566 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 28 Feb 2014 16:16:48 +0100 Subject: [PATCH 07/23] [TYPO] website_hr_recruitment: s/Kraigslist/Craigslist/g bzr revid: chs@openerp.com-20140228151648-2f33zqeffg8ipcyg --- addons/website_hr_recruitment/static/description/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website_hr_recruitment/static/description/index.html b/addons/website_hr_recruitment/static/description/index.html index 1a56da0e82c..7af603b64dc 100644 --- a/addons/website_hr_recruitment/static/description/index.html +++ b/addons/website_hr_recruitment/static/description/index.html @@ -51,14 +51,14 @@

Post Your Jobs on Best Job Boards

-

LinkedIn, Monster, Kraigslist, Careerbuilder,...

+

LinkedIn, Monster, Craigslist, Careerbuilder,...

From 2d903bcbb80f1b97e3c34c57e8792cc27dc14802 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 28 Feb 2014 17:31:12 +0100 Subject: [PATCH 09/23] [FIX]website: stop animation on focus (clean fix) bzr revid: dle@openerp.com-20140228163112-hru06zno1sl919uq --- .../static/src/js/website.snippets.editor.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js index 491c0a2aba6..adb0c704227 100644 --- a/addons/website/static/src/js/website.snippets.editor.js +++ b/addons/website/static/src/js/website.snippets.editor.js @@ -25,8 +25,17 @@ this.on('rte:ready', this, function () { self.snippets.$button.removeClass("hidden"); website.snippet.start_animation(); - // force to unactive slider cycling - setInterval(function () {$(".carousel").carousel("pause");},3000); + $(website.snippet.readyAnimation).each(function() { + var animation = $(this).data("snippet-view"); + if (animation) { + animation.$target.on('focus', '*', function(){ + animation.stop(); + }); + animation.$target.on('blur', '*', function(){ + animation.start(); + }); + } + }); }); return this._super.apply(this, arguments); From 55270edc3c948d79d55a9697a55b65401e78234a Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 28 Feb 2014 18:07:12 +0100 Subject: [PATCH 10/23] [FIX] ir.http.authenticate: avoid discarding sessions when authentication status is unknown In some cases the authentication check can fail for an unknown reason (e.g. connection pool is temporarily full). This should not be treated as an authentication failure, as the status is really unknown. Let those exceptions bubble up instead. bzr revid: odo@openerp.com-20140228170712-l8smq6u3cmvjtd5e --- openerp/addons/base/ir/ir_http.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_http.py b/openerp/addons/base/ir/ir_http.py index 18699110605..93dc4d84e76 100644 --- a/openerp/addons/base/ir/ir_http.py +++ b/openerp/addons/base/ir/ir_http.py @@ -77,7 +77,9 @@ class ir_http(osv.AbstractModel): # what if error in security.check() # -> res_users.check() # -> res_users.check_credentials() - except Exception: + except (openerp.exceptions.AccessDenied, openerp.http.SessionExpiredException): + # All other exceptions mean undetermined status (e.g. connection pool full), + # let them bubble up request.session.logout() getattr(self, "_auth_method_%s" % auth_method)() return auth_method From 70d3570846a9786204996e71274967cc31c7fbd6 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 28 Feb 2014 18:09:00 +0100 Subject: [PATCH 11/23] [FIX]website: do not send False value to google map api to retrieve the image. Otherwise, you are in the middle of the ocean. bzr revid: dle@openerp.com-20140228170900-lagmopkmkb58exqr --- addons/website/models/website.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 99187fc7bad..8f95a4a6123 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -572,7 +572,7 @@ class res_partner(osv.osv): def google_map_img(self, cr, uid, ids, zoom=8, width=298, height=298, context=None): partner = self.browse(cr, uid, ids[0], context=context) params = { - 'center': '%s, %s %s, %s' % (partner.street, partner.city, partner.zip, partner.country_id and partner.country_id.name_get()[0][1] or ''), + 'center': '%s, %s %s, %s' % (partner.street or '', partner.city or '', partner.zip or '', partner.country_id and partner.country_id.name_get()[0][1] or ''), 'size': "%sx%s" % (height, width), 'zoom': zoom, 'sensor': 'false', From a94df36bdb33889723c6fd7e1d78d1511352ab03 Mon Sep 17 00:00:00 2001 From: Kersten Jeremy Date: Mon, 3 Mar 2014 10:41:59 +0100 Subject: [PATCH 12/23] [FIX] Remove default tz from context, to allow website (Public user) to usecorrect timeZone. Now event (eg) will be displayed with the TimeZone of "Public User" by default bzr revid: jke@openerp.com-20140303094159-sh4ixlr6f7uojlft --- openerp/http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/http.py b/openerp/http.py index c8c1bed24eb..37017751b95 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -692,7 +692,7 @@ class OpenERPSession(werkzeug.contrib.sessions.Session): self.setdefault("uid", None) self.setdefault("login", None) self.setdefault("password", None) - self.setdefault("context", {'tz': "UTC", "uid": None}) + self.setdefault("context", {}) def get_context(self): """ From 05fdc2290a2c8ef31f8a0df393cba29b196f6e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 3 Mar 2014 11:40:44 +0100 Subject: [PATCH 13/23] [IMP] email_template: relocate url rewritign stuff directly into the rendering method. bzr revid: tde@openerp.com-20140303104044-hgmii31ga6msf72z --- addons/email_template/email_template.py | 55 ++++++++++++++++++- addons/website_mail/models/__init__.py | 3 +- addons/website_mail/models/email_template.py | 50 ----------------- .../models/mail_compose_message.py | 34 ------------ 4 files changed, 54 insertions(+), 88 deletions(-) delete mode 100644 addons/website_mail/models/mail_compose_message.py diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py index d9b65849fae..4a8e6f51706 100644 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@ -24,6 +24,8 @@ import base64 import datetime import dateutil.relativedelta as relativedelta import logging +import lxml +import urlparse import openerp from openerp import SUPERUSER_ID @@ -70,6 +72,7 @@ try: except ImportError: _logger.warning("jinja2 not available, templating features will not work!") + class email_template(osv.osv): "Templates for sending email" _name = "email.template" @@ -82,7 +85,48 @@ class email_template(osv.osv): res['model_id'] = self.pool['ir.model'].search(cr, uid, [('model', '=', res.pop('model'))], context=context)[0] return res - def render_template_batch(self, cr, uid, template, model, res_ids, context=None): + def _replace_local_links(self, cr, uid, html, context=None): + """ Post-processing of html content to replace local links to absolute + links, using web.base.url as base url. """ + if not html: + return html + + # form a tree + root = lxml.html.fromstring(html) + if not len(root) and root.text is None and root.tail is None: + html = '
%s
' % html + root = lxml.html.fromstring(html) + + base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') + (base_scheme, base_netloc, bpath, bparams, bquery, bfragment) = urlparse.urlparse(base_url) + + def _process_link(url): + new_url = url + (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url) + if not scheme and not netloc: + new_url = urlparse.urlunparse((base_scheme, base_netloc, path, params, query, fragment)) + return new_url + + # check all nodes, replace : + # - img src -> check URL + # - a href -> check URL + for node in root.iter(): + if node.tag == 'a': + node.set('href', _process_link(node.get('href'))) + elif node.tag == 'img' and not node.get('src', 'data').startswith('data'): + node.set('src', _process_link(node.get('src'))) + + html = lxml.html.tostring(root, pretty_print=False, method='html') + # this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that + if html.startswith('
') and html.endswith('
'): + html = html[5:-6] + return html + + def render_post_process(self, cr, uid, html, context=None): + html = self._replace_local_links(cr, uid, html, context=context) + return html + + def render_template_batch(self, cr, uid, template, model, res_ids, context=None, post_processing=None): """Render the given template text, replace mako expressions ``${expr}`` with the result of evaluating these expressions with an evaluation context containing: @@ -125,6 +169,10 @@ class email_template(osv.osv): if render_result == u"False": render_result = u"" results[res_id] = render_result + + if post_processing: + for res_id, result in results.iteritems(): + results[res_id] = self.render_post_process(cr, uid, result, context=context) return results def get_email_template_batch(self, cr, uid, template_id=False, res_ids=None, context=None): @@ -357,7 +405,10 @@ class email_template(osv.osv): for template, template_res_ids in templates_to_res_ids.iteritems(): # generate fields value for all res_ids linked to the current template for field in fields: - generated_field_values = self.render_template_batch(cr, uid, getattr(template, field), template.model, template_res_ids, context=context) + generated_field_values = self.render_template_batch( + cr, uid, getattr(template, field), template.model, template_res_ids, + post_processing=(field == 'body_html'), + context=context) for res_id, field_value in generated_field_values.iteritems(): results.setdefault(res_id, dict())[field] = field_value # update values for all res_ids diff --git a/addons/website_mail/models/__init__.py b/addons/website_mail/models/__init__.py index 3e374ccddd2..fc2ecbbc9bb 100644 --- a/addons/website_mail/models/__init__.py +++ b/addons/website_mail/models/__init__.py @@ -1,4 +1,3 @@ import mail_message import mail_thread -import email_template -import mail_compose_message \ No newline at end of file +import email_template \ No newline at end of file diff --git a/addons/website_mail/models/email_template.py b/addons/website_mail/models/email_template.py index 105fcff4428..beb02739f29 100644 --- a/addons/website_mail/models/email_template.py +++ b/addons/website_mail/models/email_template.py @@ -19,9 +19,6 @@ # ############################################################################## -import lxml -import urlparse - from openerp.osv import osv, fields from openerp.tools.translate import _ @@ -39,50 +36,3 @@ class EmailTemplate(osv.Model): help='Link to the website', ), } - - def _postprocess_html_replace_links(self, cr, uid, body_html, context=None): - """ Post-processing of body_html. Indeed the content generated by the - website builder contains references to local addresses, for example - for images. This method changes those addresses to absolute addresses. """ - html = body_html - if not body_html: - return html - - # form a tree - root = lxml.html.fromstring(html) - if not len(root) and root.text is None and root.tail is None: - html = '
%s
' % html - root = lxml.html.fromstring(html) - - base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') - (base_scheme, base_netloc, bpath, bparams, bquery, bfragment) = urlparse.urlparse(base_url) - - def _process_link(url): - new_url = url - (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url) - if not scheme and not netloc: - new_url = urlparse.urlunparse((base_scheme, base_netloc, path, params, query, fragment)) - return new_url - - # check all nodes, replace : - # - img src -> check URL - # - a href -> check URL - for node in root.iter(): - if node.tag == 'a': - node.set('href', _process_link(node.get('href'))) - elif node.tag == 'img' and not node.get('src', 'data').startswith('data'): - node.set('src', _process_link(node.get('src'))) - - html = lxml.html.tostring(root, pretty_print=False, method='html') - # this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that - if html.startswith('
') and html.endswith('
'): - html = html[5:-6] - return html - - def generate_email_batch(self, cr, uid, template_id, res_ids, context=None, fields=None): - """ Add a post processing after rendering, aka replace local URLs to absolute URLs. """ - results = super(EmailTemplate, self).generate_email_batch(cr, uid, template_id, res_ids, context=context, fields=fields) - for res_id, value in results.iteritems(): - if 'body_html' in value: - results[res_id]['body_html'] = self._postprocess_html_replace_links(cr, uid, value['body_html'], context=context) - return results diff --git a/addons/website_mail/models/mail_compose_message.py b/addons/website_mail/models/mail_compose_message.py deleted file mode 100644 index bc8258bbb6f..00000000000 --- a/addons/website_mail/models/mail_compose_message.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2014-Today OpenERP SA (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp.osv import osv - - -class MailComposeMessage(osv.Model): - _inherit = 'mail.compose.message' - - def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None, fields=None): - """ Add a post processing after rendering, aka replace local URLs to absolute URLs. """ - results = super(MailComposeMessage, self).generate_email_for_composer_batch(cr, uid, template_id, res_ids, context=context, fields=fields) - for res_id, value in results.iteritems(): - if 'body' in value: - results[res_id]['body'] = self.pool['email.template']._postprocess_html_replace_links(cr, uid, value['body'], context=context) - return results From 9d00835b2c7ea32441097318bf9c78ef48373118 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 3 Mar 2014 14:54:26 +0100 Subject: [PATCH 14/23] [FIX] order of attachments in 'existing images' sub-dialog: put last uploaded first bzr revid: xmo@openerp.com-20140303135426-evouhwgjtwku3v2b --- addons/website/static/src/js/website.editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index 303a7ee79d4..f7e3255de24 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -1463,7 +1463,7 @@ kwargs: { fields: ['name', 'website_url'], domain: [['res_model', '=', 'ir.ui.view']], - order: 'name', + order: 'id desc', context: website.get_context(), } }); From ec68d3d8bd13e84cd742e849c4ac602805a5d4c3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 3 Mar 2014 15:24:01 +0100 Subject: [PATCH 15/23] [IMP] don't duplicate website_url function field of attachments bzr revid: xmo@openerp.com-20140303142401-2jaxc3m31tmqw9qa --- addons/website/controllers/main.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 605315050c6..856ab6ecffc 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -259,20 +259,18 @@ class Website(openerp.addons.web.controllers.main.Home): u"Image size excessive, uploaded images must be smaller " u"than 42 million pixel") - attachment_id = request.registry['ir.attachment'].create(request.cr, request.uid, { + Attachments = request.registry['ir.attachment'] + attachment_id = Attachments.create(request.cr, request.uid, { 'name': upload.filename, 'datas': image_data.encode('base64'), 'datas_fname': upload.filename, 'res_model': 'ir.ui.view', }, request.context) - url = website.urlplus('/website/image', { - 'model': 'ir.attachment', - 'id': attachment_id, - 'field': 'datas', - 'max_height': MAX_IMAGE_HEIGHT, - 'max_width': MAX_IMAGE_WIDTH, - }) + [attachment] = Attachments.read( + request.cr, request.uid, [attachment_id], ['website_url'], + context=request.context) + url = attachment['website_url'] except Exception, e: logger.exception("Failed to upload image to attachment") message = unicode(e) From a99a15c9607cfede384a86736cc4f81ab24e841a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 3 Mar 2014 16:38:55 +0100 Subject: [PATCH 16/23] [ADD] deduplication of website images being uploaded There is a deduplication in ir.attachment, but it's only for FS-stored content *and* it only deduplicates storage not models (as there are access rights issues involved). The goal here is to always return the same attachment when a user uploads the exact same image multiple times (because it's simpler or whatever). Initially tried to use a binary field & digest(), but search() blows up because it tries to utf-8 encode raw binary data. So use char & hexdigest instead. _compute_checksum returns None if the provided attachment data does not look like a website image attachment. Unhandled: multiple existing matches, maybe a UNIQUE constraint on the checksum field would be a good idea just in case. bzr revid: xmo@openerp.com-20140303153855-5f2l8v0jq2mgb26f --- addons/website/models/website.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 8f95a4a6123..4e39f291df2 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import hashlib import inspect import itertools import logging @@ -562,10 +563,37 @@ class ir_attachment(osv.osv): 'max_height': 768, }) return result + def _datas_checksum(self, cr, uid, ids, name, arg, context=None): + return dict( + (attach['id'], self._compute_checksum(attach)) + for attach in self.read( + cr, uid, ids, ['res_model', 'res_id', 'type', 'datas'], + context=context) + ) + + def _compute_checksum(self, attachment_dict): + if attachment_dict.get('res_model') == 'ir.ui.view'\ + and not attachment_dict.get('res_id')\ + and attachment_dict.get('type', 'binary') == 'binary'\ + and attachment_dict.get('datas'): + return hashlib.new('sha1', attachment_dict['datas']).hexdigest() + return None + _columns = { + 'datas_checksum': fields.function(_datas_checksum, size=40, + string="Datas checksum", type='char', store=True, select=True), 'website_url': fields.function(_website_url_get, string="Attachment URL", type='char') } + def create(self, cr, uid, values, context=None): + chk = self._compute_checksum(values) + if chk: + match = self.search(cr, uid, [('datas_checksum', '=', chk)], context=context) + if match: + return match[0] + return super(ir_attachment, self).create( + cr, uid, values, context=context) + class res_partner(osv.osv): _inherit = "res.partner" From f3638567738cdc242fa43dc0a1770ea7bd4b4b6e Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 3 Mar 2014 18:44:45 +0100 Subject: [PATCH 17/23] [FIX] website_hr_recruitment: missing required 'name', which leaded to crash, and the phone field is partner_phone, not just phone. Do you even test what you do ? bzr revid: dle@openerp.com-20140303174445-j733tpmccc9x855u --- addons/website_hr_recruitment/controllers/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/website_hr_recruitment/controllers/main.py b/addons/website_hr_recruitment/controllers/main.py index a3cbbe3cbc4..8140a39dc9b 100644 --- a/addons/website_hr_recruitment/controllers/main.py +++ b/addons/website_hr_recruitment/controllers/main.py @@ -86,11 +86,14 @@ class website_hr_recruitment(http.Controller): value = { 'source_id' : imd.xmlid_to_res_id(cr, SUPERUSER_ID, 'hr_recruitment.source_website_company'), + 'name': '%s\'s Application' % post.get('partner_name'), } - for f in ['phone', 'email_from', 'partner_name', 'description']: + for f in ['email_from', 'partner_name', 'description']: value[f] = post.get(f) for f in ['department_id', 'job_id']: value[f] = int(post.get(f) or 0) + # Retro-compatibility for saas-3. "phone" field should be replace by "partner_phone" in the template in trunk. + value['partner_phone'] = post.pop('phone', False) applicant_id = request.registry['hr.applicant'].create(cr, SUPERUSER_ID, value, context=context) if post['ufile']: From e78a3b18cc6c049a712d594ab70287c486447f0a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 4 Mar 2014 12:07:16 +0100 Subject: [PATCH 18/23] [ADD] tentative removal of attachments Attachments ought be removed only if they are not used in an existing page/web view. Theoretically this could be set directly in unlink(), but: * that would make a nice error message significantly harder * the expenses of performing a text search in all view archs would be a bit expensive Notes: * the views set could be reduced to only "web" views * the search is likely sensible to false negatives e.g. different order of query parameters. It *will* remove images still being used. bzr revid: xmo@openerp.com-20140304110716-u14w6uo8fbkfa42i --- addons/website/models/website.py | 28 +++++++++++++++++ addons/website/static/src/css/editor.css | 20 +++++++++++++ addons/website/static/src/css/editor.sass | 22 ++++++++++++-- .../website/static/src/js/website.editor.js | 30 +++++++++++++++++++ .../website/static/src/xml/website.editor.xml | 20 +++++++++++-- 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 4e39f291df2..5da633a27a6 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -9,6 +9,7 @@ import urlparse import werkzeug import werkzeug.exceptions +import werkzeug.utils import werkzeug.wrappers # optional python-slugify import (https://github.com/un33k/python-slugify) try: @@ -594,6 +595,33 @@ class ir_attachment(osv.osv): return super(ir_attachment, self).create( cr, uid, values, context=context) + def try_remove(self, cr, uid, ids, context=None): + """ Removes a web-based image attachment if it is used by no view + (template) + + Returns a dict mapping attachments which would not be removed (if any) + mapped to the views preventing their removal + """ + Views = self.pool['ir.ui.view'] + attachments_to_remove = [] + # views blocking removal of the attachment + removal_blocked_by = {} + + for attachment in self.browse(cr, uid, ids, context=context): + # in-document URLs are html-escaped, a straight search will not + # find them + url = werkzeug.utils.escape(attachment.website_url) + ids = Views.search(cr, uid, [('arch', 'like', url)], context=context) + + if ids: + removal_blocked_by[attachment.id] = Views.read( + cr, uid, ids, ['name'], context=context) + else: + attachments_to_remove.append(attachment.id) + if attachments_to_remove: + self.unlink(cr, uid, attachments_to_remove, context=context) + return removal_blocked_by + class res_partner(osv.osv): _inherit = "res.partner" diff --git a/addons/website/static/src/css/editor.css b/addons/website/static/src/css/editor.css index df2188e794d..da0fad43caf 100644 --- a/addons/website/static/src/css/editor.css +++ b/addons/website/static/src/css/editor.css @@ -251,6 +251,26 @@ ul.oe_menu_editor .disclose { .existing-attachments .pager .disabled { display: none; } +.existing-attachments .existing-attachment-cell { + position: relative; +} +.existing-attachments .existing-attachment-cell .img { + border: 1px solid #848490; +} +.existing-attachments .existing-attachment-cell .existing-attachment-remove { + position: absolute; + top: 0; + left: 15px; + cursor: pointer; + background: white; + padding: 2px; + border: 1px solid #848490; + border-top: none; + border-left: none; + -moz-border-radius-bottomright: 8px; + -webkit-border-bottom-right-radius: 8px; + border-bottom-right-radius: 8px; +} .cke_widget_wrapper { position: static !important; diff --git a/addons/website/static/src/css/editor.sass b/addons/website/static/src/css/editor.sass index 49b71ffefdf..4571dcd257e 100644 --- a/addons/website/static/src/css/editor.sass +++ b/addons/website/static/src/css/editor.sass @@ -211,9 +211,27 @@ ul.oe_menu_editor .font-icons-selected background-color: #ddd +$attachment-border-color: #848490 +.existing-attachments + .pager .disabled + display: none -.existing-attachments .pager .disabled - display: none + .existing-attachment-cell + position: relative + .img + border: 1px solid $attachment-border-color + .existing-attachment-remove + position: absolute + top: 0 + left: 15px // padding-left on col-* + + cursor: pointer + background: white + padding: 2px + border: 1px solid $attachment-border-color + border-top: none + border-left: none + +border-bottom-right-radius(8px) // wrapper positioned relatively for drag&drop widget which is disabled below. // Breaks completely horribly crazy products listing page, so take it out. diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index f7e3255de24..3915c3daaeb 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -1441,6 +1441,7 @@ this.page += $target.hasClass('previous') ? -1 : 1; this.display_attachments(); }, + 'click .existing-attachment-remove': 'try_remove', }), init: function (parent) { this.image = null; @@ -1473,6 +1474,7 @@ this.display_attachments(); }, display_attachments: function () { + this.$('.help-block').empty(); var per_screen = IMAGES_PER_ROW * IMAGES_ROWS; var from = this.page * per_screen; @@ -1500,6 +1502,34 @@ } this.close() }, + + try_remove: function (e) { + var $help_block = this.$('.help-block').empty(); + var self = this; + var id = parseInt($(e.target).data('id'), 10); + var attachment = _.findWhere(this.records, {id: id}); + + return openerp.jsonRpc('/web/dataset/call_kw', 'call', { + model: 'ir.attachment', + method: 'try_remove', + args: [], + kwargs: { + ids: [id], + context: website.get_context() + } + }).then(function (prevented) { + if (_.isEmpty(prevented)) { + self.records = _.without(self.records, attachment); + self.display_attachments(); + return; + } + $help_block.replaceWith(openerp.qweb.render( + 'website.editor.dialog.image.existing.error', { + views: prevented[id] + } + )); + }); + }, }); function get_selected_link(editor) { diff --git a/addons/website/static/src/xml/website.editor.xml b/addons/website/static/src/xml/website.editor.xml index 6c1e387c958..1010ec05127 100644 --- a/addons/website/static/src/xml/website.editor.xml +++ b/addons/website/static/src/xml/website.editor.xml @@ -140,8 +140,9 @@
-