summaryrefslogtreecommitdiff
path: root/addons/document/document.py
diff options
context:
space:
mode:
Diffstat (limited to 'addons/document/document.py')
-rw-r--r--addons/document/document.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/addons/document/document.py b/addons/document/document.py
index 7e575f38a37..79fb83b5b1f 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -35,6 +35,36 @@ 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=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)
+ 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):
return os.path.join(DMS_ROOT_PATH, cr.dbname)
@@ -135,6 +165,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 = {}
@@ -168,7 +207,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']) :
+ and ('name' not in vals or fbro.name == vals['name']):
ids2.append(fbro.id)
continue
fnode = nctx.get_file_node(cr, fbro)