From 2aa5d026d1b2c562fef370c37604a7378788b4a3 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 23 Nov 2010 20:49:38 +0200 Subject: document: fix access of res.users folders We need to relax the rule of ir.attachment. Needs server patch, see commit message there. bzr revid: p_christ@hol.gr-20101123184938-jklijdqt0xx5u6cs --- addons/document/document.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index e3d810668b4..790b650d4f5 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -133,6 +133,15 @@ class document_file(osv.osv): return False return True + def check(self, cr, uid, ids, mode, context=None, values=None): + """Check access wrt. res_model, relax the rule of ir.attachment parent + + With 'document' installed, everybody will have access to attachments of + any resources they can *read*. + """ + return super(document_file, self).check(cr, uid, ids, mode='read', + context=context, values=values) + def copy(self, cr, uid, id, default=None, context=None): if not default: default = {} -- cgit v1.2.3 From ebd5c62dbc6ffa689ea36b85951c4202e1317dac Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Mon, 20 Dec 2010 18:24:19 +0530 Subject: [FIX]: solved Problem of after install document module, documents are lost which are added before installed document module bzr revid: atp@tinyerp.co.in-20101220125419-y99i8aqw3y1s00by --- addons/document/document.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 7e575f38a37..c1c06711faa 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -46,15 +46,25 @@ class document_file(osv.osv): # nctx will /not/ inherit the caller's context. Most of # it would be useless, anyway (like active_id, active_model, # bin_size etc.) + result = {} bin_size = context.get('bin_size', False) for fbro in fbrl: - fnode = nodes.node_file(None, None, nctx, fbro) + if not fbro.parent_id: + cr.execute("select db_datas from ir_attachment where id = %s" ,(fbro.id,)) + res = cr.fetchone() + datas = res[0] or '' + size = len(datas) + else: + fnode = nodes.node_file(None, None, nctx, fbro) + datas = fnode.get_data(cr, fbro) + datas = base64.encodestring(datas or '') + size = fnode.get_data_len(cr, fbro) + if not bin_size: - data = fnode.get_data(cr, fbro) - result[fbro.id] = base64.encodestring(data or '') + result[fbro.id] = datas else: - result[fbro.id] = fnode.get_data_len(cr, fbro) + result[fbro.id] = size return result -- cgit v1.2.3 From 5633f1b6ba9f9f5bc1416bf023638a611c3f87f1 Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Thu, 23 Dec 2010 15:21:09 +0530 Subject: [Fix]: Fixed documents lost problem which are added before installed document module. bzr revid: atp@tinyerp.co.in-20101223095109-ntp3hrl30xb82pya --- addons/document/document.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index c1c06711faa..98257a4deb8 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -35,6 +35,17 @@ DMS_ROOT_PATH = tools.config.get('document_path', os.path.join(tools.config['roo class document_file(osv.osv): _inherit = 'ir.attachment' _rec_name = 'datas_fname' + + def attach_parent_id(self, cr, uid, ids=[], context=None): + """Attach Parent id For document""" + + parent_id = self.pool.get('document.directory')._get_root_directory(cr,uid) + ids = self.search(cr, uid, [('parent_id', '=', False)]) + attach_doc = self.browse(cr, uid, ids, context=context) + for attach in attach_doc: + cr.execute("UPDATE ir_attachment SET parent_id = %s,db_datas = decode(encode(%s,'escape'), 'base64') WHERE id = %s", (parent_id, attach.db_datas, attach.id)) + return True + def _get_filestore(self, cr): return os.path.join(DMS_ROOT_PATH, cr.dbname) @@ -42,32 +53,21 @@ class document_file(osv.osv): if context is None: context = {} fbrl = self.browse(cr, uid, ids, context=context) - nctx = nodes.get_node_context(cr, uid, context={}) + + nctx = nodes.get_node_context(cr, uid, context=context) # nctx will /not/ inherit the caller's context. Most of # it would be useless, anyway (like active_id, active_model, # bin_size etc.) - result = {} bin_size = context.get('bin_size', False) for fbro in fbrl: - if not fbro.parent_id: - cr.execute("select db_datas from ir_attachment where id = %s" ,(fbro.id,)) - res = cr.fetchone() - datas = res[0] or '' - size = len(datas) - else: - fnode = nodes.node_file(None, None, nctx, fbro) - datas = fnode.get_data(cr, fbro) - datas = base64.encodestring(datas or '') - size = fnode.get_data_len(cr, fbro) - + fnode = nodes.node_file(None, None, nctx, fbro) if not bin_size: - result[fbro.id] = datas + data = fnode.get_data(cr, fbro) + result[fbro.id] = base64.encodestring(data or '') else: - result[fbro.id] = size - + result[fbro.id] = fnode.get_data_len(cr, fbro) return result - # # This code can be improved # @@ -178,10 +178,11 @@ class document_file(osv.osv): ids2 = [] for fbro in self.browse(cr, uid, ids, context=context): if ('parent_id' not in vals or fbro.parent_id.id == vals['parent_id']) \ - and ('name' not in vals or fbro.name == vals['name']) : + and ('name' not in vals or fbro.name == vals['name']) or not fbro.parent_id: ids2.append(fbro.id) continue fnode = nctx.get_file_node(cr, fbro) + print "fnode",fnode res = fnode.move_to(cr, dnode or fnode.parent, vals.get('name', fbro.name), fbro, dbro, True) if isinstance(res, dict): vals2 = vals.copy() -- cgit v1.2.3 From ffa6d2dda7b51660f0c647a4598090149c34c72a Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Thu, 23 Dec 2010 15:41:18 +0530 Subject: [IMP] bzr revid: atp@tinyerp.co.in-20101223101118-el1zl830r8yj36h2 --- addons/document/document.py | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 98257a4deb8..5e6fb4646ec 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -182,7 +182,6 @@ class document_file(osv.osv): ids2.append(fbro.id) continue fnode = nctx.get_file_node(cr, fbro) - print "fnode",fnode res = fnode.move_to(cr, dnode or fnode.parent, vals.get('name', fbro.name), fbro, dbro, True) if isinstance(res, dict): vals2 = vals.copy() -- cgit v1.2.3 From 8e8803e9df4067d2c04d37e603bae76b40ecb17d Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 23 Dec 2010 16:16:39 +0200 Subject: document, caldav: revert changes that are not needed and spacing Let's keep the diff against trunk-dev-addons1 only to things that make sense. bzr revid: p_christ@hol.gr-20101223141639-o13v6llljplpgl7s --- addons/document/document.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 5e6fb4646ec..874fc8b8888 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -53,8 +53,7 @@ class document_file(osv.osv): if context is None: context = {} fbrl = self.browse(cr, uid, ids, context=context) - - nctx = nodes.get_node_context(cr, uid, context=context) + nctx = nodes.get_node_context(cr, uid, context={}) # nctx will /not/ inherit the caller's context. Most of # it would be useless, anyway (like active_id, active_model, # bin_size etc.) @@ -67,7 +66,9 @@ class document_file(osv.osv): result[fbro.id] = base64.encodestring(data or '') else: result[fbro.id] = fnode.get_data_len(cr, fbro) + return result + # # This code can be improved # @@ -178,7 +179,7 @@ class document_file(osv.osv): ids2 = [] for fbro in self.browse(cr, uid, ids, context=context): if ('parent_id' not in vals or fbro.parent_id.id == vals['parent_id']) \ - and ('name' not in vals or fbro.name == vals['name']) or not fbro.parent_id: + and ('name' not in vals or fbro.name == vals['name']): ids2.append(fbro.id) continue fnode = nctx.get_file_node(cr, fbro) -- cgit v1.2.3 From 43387c7f430a5109a5f2fcef9dd9c94594c788ff Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 23 Dec 2010 16:25:29 +0200 Subject: document: improve the attach_parent_id() function. No need to call an SQL command in iteration! No need to transfer the db_datas back and forth from Postgres! Also, prepended an underscore, so that the function is never exported through RPC. bzr revid: p_christ@hol.gr-20101223142529-hgudbfj54p4d2e34 --- addons/document/document.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 874fc8b8888..dd34dd4295c 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -36,14 +36,33 @@ class document_file(osv.osv): _inherit = 'ir.attachment' _rec_name = 'datas_fname' - def attach_parent_id(self, cr, uid, ids=[], context=None): - """Attach Parent id For document""" + def _attach_parent_id(self, cr, uid, ids=None, context=None): + """Migrate ir.attachments to the document module. + + When the 'document' module is loaded on a db that has had plain attachments, + they will need to be attached to some parent folder, and be converted from + base64-in-bytea to raw-in-bytea format. + This function performs the internal migration, once and forever, for these + attachments. It cannot be done through the nominal ORM maintenance code, + because the root folder is only created after the document_data.xml file + is loaded. + It also establishes the parent_id NOT NULL constraint that ir.attachment + should have had (but would have failed if plain attachments contained null + values). + """ parent_id = self.pool.get('document.directory')._get_root_directory(cr,uid) - ids = self.search(cr, uid, [('parent_id', '=', False)]) - attach_doc = self.browse(cr, uid, ids, context=context) - for attach in attach_doc: - cr.execute("UPDATE ir_attachment SET parent_id = %s,db_datas = decode(encode(%s,'escape'), 'base64') WHERE id = %s", (parent_id, attach.db_datas, attach.id)) + if not parent_id: + logging.getLogger('document').warning("at _attach_parent_id(), still not able to set the parent!") + return False + + if ids is not None: + raise NotImplementedError("Ids is just there by convention! Don't use it yet, please.") + + cr.execute("UPDATE ir_attachment " \ + "SET parent_id = %s, db_datas = decode(encode(db_datas,'escape'), 'base64') " \ + "WHERE parent_id IS NULL", (parent_id,)) + cr.execute("ALTER TABLE ir_attachment ALTER parent_id SET NOT NULL") return True def _get_filestore(self, cr): -- cgit v1.2.3