From 38d7e563aa7181947e66432558d358f199fc8693 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 27 Aug 2015 16:09:02 +0200 Subject: [PATCH] [IMP] base: add `public` field on attachment --- addons/web_editor/controllers/main.py | 2 ++ openerp/addons/base/ir/ir_attachment.py | 11 +++++++---- openerp/addons/base/ir/ir_attachment_view.xml | 1 + openerp/addons/base/ir/ir_qweb.py | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/controllers/main.py b/addons/web_editor/controllers/main.py index 2a9503db2d0..24fb6064dcb 100644 --- a/addons/web_editor/controllers/main.py +++ b/addons/web_editor/controllers/main.py @@ -145,6 +145,7 @@ class Web_Editor(http.Controller): 'name': name, 'type': 'url', 'url': url, + 'public': True, 'res_model': 'ir.ui.view', }, request.context) uploads += Attachments.read(request.cr, request.uid, [attachment_id], ['name', 'mimetype', 'checksum', 'url'], request.context) @@ -169,6 +170,7 @@ class Web_Editor(http.Controller): 'name': c_file.filename, 'datas': data.encode('base64'), 'datas_fname': c_file.filename, + 'public': True, 'res_model': 'ir.ui.view', }, request.context) attachment_ids.append(attachment_id) diff --git a/openerp/addons/base/ir/ir_attachment.py b/openerp/addons/base/ir/ir_attachment.py index c3922392899..804fdb218bc 100644 --- a/openerp/addons/base/ir/ir_attachment.py +++ b/openerp/addons/base/ir/ir_attachment.py @@ -290,6 +290,7 @@ class ir_attachment(osv.osv): 'checksum': fields.char("Checksum/SHA1", size=40, select=True, readonly=True), 'mimetype': fields.char('Mime Type', readonly=True), 'index_content': fields.text('Indexed Content', readonly=True), + 'public': fields.boolean('Is public document'), } _defaults = { @@ -316,8 +317,10 @@ class ir_attachment(osv.osv): if ids: if isinstance(ids, (int, long)): ids = [ids] - cr.execute('SELECT DISTINCT res_model, res_id, create_uid FROM ir_attachment WHERE id = ANY (%s)', (ids,)) - for rmod, rid, create_uid in cr.fetchall(): + cr.execute('SELECT res_model, res_id, create_uid, public FROM ir_attachment WHERE id = ANY (%s)', (ids,)) + for rmod, rid, create_uid, public in cr.fetchall(): + if public and mode == 'read': + continue if not (rmod and rid): if create_uid != uid: require_employee = True @@ -368,11 +371,11 @@ class ir_attachment(osv.osv): # the linked document. # Use pure SQL rather than read() as it is about 50% faster for large dbs (100k+ docs), # and the permissions are checked in super() and below anyway. - cr.execute("""SELECT id, res_model, res_id FROM ir_attachment WHERE id = ANY(%s)""", (list(ids),)) + cr.execute("""SELECT id, res_model, res_id, public FROM ir_attachment WHERE id = ANY(%s)""", (list(ids),)) targets = cr.dictfetchall() model_attachments = {} for target_dict in targets: - if not target_dict['res_model']: + if not target_dict['res_model'] or target_dict['public']: continue # model_attachments = { 'model': { 'res_id': [id1,id2] } } model_attachments.setdefault(target_dict['res_model'],{}).setdefault(target_dict['res_id'] or 0, set()).add(target_dict['id']) diff --git a/openerp/addons/base/ir/ir_attachment_view.xml b/openerp/addons/base/ir/ir_attachment_view.xml index 3cfa52da858..35b3f806695 100644 --- a/openerp/addons/base/ir/ir_attachment_view.xml +++ b/openerp/addons/base/ir/ir_attachment_view.xml @@ -24,6 +24,7 @@ +