[FIX] base, website: make attachment serving multi-website

- Reaching an attachment datas thanks to its URL was not multi-website
- Compiling assets with URLs to attachment datas was not multi-website
This commit is contained in:
qsm-odoo
2018-10-01 21:33:32 +02:00
parent 03a93f0968
commit 89678c6041
5 changed files with 27 additions and 2 deletions
+1
View File
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import assetsbundle
from . import ir_actions
from . import ir_attachment
from . import ir_http
+11
View File
@@ -0,0 +1,11 @@
from odoo.addons.base.models.assetsbundle import WebAsset
_old_get_stat_attachment_domain = WebAsset._get_stat_attachment_domain
def _new_get_stat_attachment_domain(self):
domain = _old_get_stat_attachment_domain(self)
website = self.bundle.env['website'].get_current_website()
return domain + website.website_domain()
WebAsset._get_stat_attachment_domain = _new_get_stat_attachment_domain
+6
View File
@@ -149,6 +149,12 @@ class Http(models.AbstractModel):
domain = [('url_from', '=', req_page)] + request.website.website_domain()
return request.env['website.redirect'].search(domain, limit=1)
@classmethod
def _get_serve_attachment_domain(cls):
domain = super(Http, cls)._get_serve_attachment_domain()
website = request.env['website'].get_current_website()
return domain + website.website_domain()
@classmethod
def _serve_fallback(cls, exception):
# serve attachment before
+4 -1
View File
@@ -615,12 +615,15 @@ class WebAsset(object):
try:
# Test url against ir.attachments
fields = ['__last_update', 'datas', 'mimetype']
domain = [('type', '=', 'binary'), ('url', '=', self.url)]
domain = self._get_stat_attachment_domain()
attach = self.bundle.env['ir.attachment'].sudo().search_read(domain, fields)
self._ir_attach = attach[0]
except Exception:
raise AssetNotFound("Could not find %s" % self.name)
def _get_stat_attachment_domain(self):
return [('type', '=', 'binary'), ('url', '=', self.url)]
# depreciated and will remove after v11
def to_html(self):
tagName, attributes, content = self.to_node()
+5 -1
View File
@@ -126,7 +126,7 @@ class IrHttp(models.AbstractModel):
@classmethod
def _serve_attachment(cls):
env = api.Environment(request.cr, SUPERUSER_ID, request.context)
domain = [('type', '=', 'binary'), ('url', '=', request.httprequest.path)]
domain = cls._get_serve_attachment_domain()
fields = ['__last_update', 'datas', 'name', 'mimetype', 'checksum']
attach = env['ir.attachment'].search_read(domain, fields)
if attach:
@@ -152,6 +152,10 @@ class IrHttp(models.AbstractModel):
response.data = base64.b64decode(datas)
return response
@classmethod
def _get_serve_attachment_domain(cls):
return [('type', '=', 'binary'), ('url', '=', request.httprequest.path)]
@classmethod
def _serve_fallback(cls, exception):
# serve attachment