Permalink
Browse files

🚑 update binary_content method

  • Loading branch information...
trojikman committed Sep 23, 2018
1 parent 39bff34 commit 7a0fa63c488e397e4b7237f51cbac4b6ac49532e
Showing with 6 additions and 1 deletion.
  1. +6 −1 ir_attachment_url/models/ir_http.py
@@ -9,7 +9,7 @@
from odoo.tools.mimetypes import guess_mimetype
from odoo.http import request, STATIC_CACHE
from odoo.modules.module import get_resource_path, get_module_path
from odoo.tools import pycompat
from odoo.tools import pycompat, consteq
class IrHttp(models.AbstractModel):
@@ -37,6 +37,7 @@ def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas
:param str mimetype: mintype of the field (for headers)
:param str default_mimetype: default mintype if no mintype found
:param str access_token: optional token for unauthenticated access
only available for ir.attachment
:param Environment env: by default use request.env
:returns: (status, headers, content)
"""
@@ -45,6 +46,10 @@ def binary_content(cls, xmlid=None, model='ir.attachment', id=None, field='datas
obj = None
if xmlid:
obj = env.ref(xmlid, False)
elif id and model == 'ir.attachment' and access_token:
obj = env[model].sudo().browse(int(id))
if not consteq(obj.access_token, access_token):
return (403, [], None)
elif id and model in env.registry:
obj = env[model].browse(int(id))

0 comments on commit 7a0fa63

Please sign in to comment.