From 37e0ea5d6a4c2cbdc8755325ac8aa6835f597fe1 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 11:02:48 +0100 Subject: [PATCH 01/46] [MIG] Make modules installable --- cmis/__openerp__.py | 4 ++-- cmis_read/__openerp__.py | 4 ++-- cmis_write/__openerp__.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmis/__openerp__.py b/cmis/__openerp__.py index 0d67ad9..a4026b2 100644 --- a/cmis/__openerp__.py +++ b/cmis/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'CMIS', - 'version': '7.0.1.1.0', + 'version': '9.0.1.0.0', 'category': 'Connector', 'summary': 'Connect OpenERP with a CMIS server', 'description': """ @@ -56,6 +56,6 @@ 'views/cmis_backend_view.xml', 'views/cmis_menu.xml', ], - 'installable': False, + 'installable': True, 'auto_install': False, } diff --git a/cmis_read/__openerp__.py b/cmis_read/__openerp__.py index e7d6c33..d57a48c 100644 --- a/cmis_read/__openerp__.py +++ b/cmis_read/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'CMIS Read', - 'version': '7.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Knowledge Management', 'summary': 'Store Document File from a Remote CMIS Server', 'description': """ @@ -80,6 +80,6 @@ 'test': [], 'demo': [ ], - 'installable': False, + 'installable': True, 'auto_install': False, } diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index e5063d8..4cec5b1 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'CMIS Write', - 'version': '7.0.0.1.0', + 'version': '9.0.1.0.0', 'category': 'Knowledge Management', 'summary': 'Create Document in DMS from Odoo/OpenERP', 'description': """ @@ -83,6 +83,6 @@ 'qweb': [], 'test': [], 'demo': [], - 'installable': False, + 'installable': True, 'auto_install': False, } From 36bb19363332f3baaf13daa89a8baa98455488db Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 12:18:39 +0100 Subject: [PATCH 02/46] [MIG] Remove deprecated checks attribute in test module --- cmis/tests/__init__.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cmis/tests/__init__.py b/cmis/tests/__init__.py index be75a74..48a3d38 100644 --- a/cmis/tests/__init__.py +++ b/cmis/tests/__init__.py @@ -20,10 +20,4 @@ # ############################################################################## -from . import ( - test_model, -) - -checks = [ - test_model, -] +from . import test_model From 884a861514abde5cb4d0cea431b4e7fc723d9757 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 12:20:58 +0100 Subject: [PATCH 03/46] [MIG] Remove deprecated call to install_in_connector() --- cmis/connector.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmis/connector.py b/cmis/connector.py index c030194..bad0584 100644 --- a/cmis/connector.py +++ b/cmis/connector.py @@ -20,12 +20,9 @@ # ############################################################################## -from openerp.addons.connector.connector import ( - Environment, install_in_connector) +from openerp.addons.connector.connector import Environment from openerp.addons.connector.checkpoint import checkpoint -install_in_connector() - def get_environment(session, model_name, backend_id): """ Create an environment to work with. """ From 65ff8cdad283f75fe63a5f96161aad3c60bf994f Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 12:31:58 +0100 Subject: [PATCH 04/46] [MIG] Move description to README.rst --- cmis/README.rst | 70 +++++++++++++++++++++++++++++++++++++++++++++ cmis/__openerp__.py | 20 +------------ 2 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 cmis/README.rst diff --git a/cmis/README.rst b/cmis/README.rst new file mode 100644 index 0000000..b7f492a --- /dev/null +++ b/cmis/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============== +CMIS Connector +============== + +This module is the base for Odoo modules implementing different integration +scenario with a CMIS server. +It allows you to configure a CMIS backend in Odoo. + +Installation +============ + +No installation required: + +Configuration +============= + +Create a new CMIS backend with the host, login and password. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/104/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* El Hadji Dem +* Maxime Chambreuil +* Laurent Mignon + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/cmis/__openerp__.py b/cmis/__openerp__.py index a4026b2..3e6c080 100644 --- a/cmis/__openerp__.py +++ b/cmis/__openerp__.py @@ -25,26 +25,8 @@ 'version': '9.0.1.0.0', 'category': 'Connector', 'summary': 'Connect OpenERP with a CMIS server', - 'description': """ -CMIS Connector -============== - -This module is the base for OpenERP modules implementing different integration -scenario with a CMIS server. -It allows you to configure a CMIS backend in OpenERP. - -Configuration -============= - -Create a new CMIS backend with the host, login and password. - -Contributors ------------- -* El Hadji Dem (elhadji.dem@savoirfairelinux.com) -* Maxime Chambreuil (maxime.chambreuil@savoirfairelinux.com) -""", 'author': "Savoir-faire Linux, Odoo Community Association (OCA)", - 'website': 'www.savoirfairelinux.com', + 'website': 'https://odoo-community.org/', 'license': 'AGPL-3', 'depends': [ 'connector', From 451eb9edd4aa37faa97734814dd9829d2394b612 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 12:38:00 +0100 Subject: [PATCH 05/46] [MIG] Use shortened licence --- cmis/__init__.py | 22 ++-------------------- cmis/__openerp__.py | 22 ++-------------------- cmis/backend.py | 22 ++-------------------- cmis/cmis_backend.py | 22 ++-------------------- cmis/cmis_binding.py | 22 ++-------------------- cmis/connector.py | 22 ++-------------------- cmis/tests/__init__.py | 24 +++--------------------- cmis/tests/test_model.py | 22 ++-------------------- cmis/unit/__init__.py | 22 ++-------------------- cmis/unit/backend_adapter.py | 22 ++-------------------- cmis/unit/binder.py | 22 ++-------------------- cmis/unit/import_synchronizer.py | 22 ++-------------------- cmis/unit/mapper.py | 22 ++-------------------- 13 files changed, 27 insertions(+), 261 deletions(-) diff --git a/cmis/__init__.py b/cmis/__init__.py index d737c16..6d5393c 100644 --- a/cmis/__init__.py +++ b/cmis/__init__.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import ( cmis_backend, diff --git a/cmis/__openerp__.py b/cmis/__openerp__.py index 3e6c080..a7db4e2 100644 --- a/cmis/__openerp__.py +++ b/cmis/__openerp__.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'CMIS', diff --git a/cmis/backend.py b/cmis/backend.py index 3c0e4b6..21d37b0 100644 --- a/cmis/backend.py +++ b/cmis/backend.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import openerp.addons.connector.backend as backend diff --git a/cmis/cmis_backend.py b/cmis/cmis_backend.py index 8f8156a..b8ac6fd 100644 --- a/cmis/cmis_backend.py +++ b/cmis/cmis_backend.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm, fields from openerp.tools.translate import _ diff --git a/cmis/cmis_binding.py b/cmis/cmis_binding.py index a1e8463..adc91e9 100644 --- a/cmis/cmis_binding.py +++ b/cmis/cmis_binding.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm, fields diff --git a/cmis/connector.py b/cmis/connector.py index bad0584..5a66058 100644 --- a/cmis/connector.py +++ b/cmis/connector.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.addons.connector.connector import Environment from openerp.addons.connector.checkpoint import checkpoint diff --git a/cmis/tests/__init__.py b/cmis/tests/__init__.py index 48a3d38..3265cca 100644 --- a/cmis/tests/__init__.py +++ b/cmis/tests/__init__.py @@ -1,23 +1,5 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2013-2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import test_model diff --git a/cmis/tests/test_model.py b/cmis/tests/test_model.py index 4291919..6d60852 100644 --- a/cmis/tests/test_model.py +++ b/cmis/tests/test_model.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################### -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2010 - 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################### +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.tests.common import TransactionCase diff --git a/cmis/unit/__init__.py b/cmis/unit/__init__.py index c239f82..2570fc0 100644 --- a/cmis/unit/__init__.py +++ b/cmis/unit/__init__.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import backend_adapter from . import binder diff --git a/cmis/unit/backend_adapter.py b/cmis/unit/backend_adapter.py index a7f4252..f4d75aa 100644 --- a/cmis/unit/backend_adapter.py +++ b/cmis/unit/backend_adapter.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm from openerp.tools.translate import _ diff --git a/cmis/unit/binder.py b/cmis/unit/binder.py index bba4907..c03bdc7 100644 --- a/cmis/unit/binder.py +++ b/cmis/unit/binder.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.addons.connector.connector import Binder diff --git a/cmis/unit/import_synchronizer.py b/cmis/unit/import_synchronizer.py index d46be6f..dc49bd3 100644 --- a/cmis/unit/import_synchronizer.py +++ b/cmis/unit/import_synchronizer.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging from openerp.addons.connector.unit.synchronizer import ImportSynchronizer diff --git a/cmis/unit/mapper.py b/cmis/unit/mapper.py index 7e233e8..f017178 100644 --- a/cmis/unit/mapper.py +++ b/cmis/unit/mapper.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.addons.connector.unit.mapper import ImportMapper, mapping from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT From a221fa22f2b20602b60a114718d932eb0f2acf4b Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 14:45:14 +0100 Subject: [PATCH 06/46] [MIG] Use new API --- cmis/cmis_backend.py | 180 ++++++++++++++--------------------- cmis/cmis_binding.py | 22 ++--- cmis/exceptions.py | 18 ++++ cmis/unit/backend_adapter.py | 43 ++++----- cmis/unit/binder.py | 102 +------------------- 5 files changed, 115 insertions(+), 250 deletions(-) create mode 100644 cmis/exceptions.py diff --git a/cmis/cmis_backend.py b/cmis/cmis_backend.py index b8ac6fd..3502a91 100644 --- a/cmis/cmis_backend.py +++ b/cmis/cmis_backend.py @@ -1,138 +1,98 @@ # -*- coding: utf-8 -*- # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import cmislib.exceptions -from openerp.osv import orm, fields +from openerp import api, fields, models +from openerp.exceptions import Warning from openerp.tools.translate import _ from openerp.addons.connector.connector import Environment from openerp.addons.connector.session import ConnectorSession from .unit.backend_adapter import CmisAdapter -import cmislib.exceptions +from .exceptions import CMISError -class cmis_backend(orm.Model): +class CmisBackend(models.Model): _name = 'cmis.backend' _description = 'CMIS Backend' _inherit = 'connector.backend' + _backend_type = 'cmis' - _columns = { - 'version': fields.selection( - lambda self, *a, **kw: self._select_versions(*a, **kw), - 'Version', - required=True, - ), - 'location': fields.char( - 'Location', - required=True, - ), - 'username': fields.char( - 'Username', - required=True, - ), - 'password': fields.char( - 'Password', - required=True, - ), - 'initial_directory_read': fields.char( - 'Initial directory for reading', - required=True, - ), - 'initial_directory_write': fields.char( - 'Initial directory for writing', - required=True, - ), - 'browsing_ok': fields.boolean( - 'Allow browsing this backend', - ), - 'storing_ok': fields.boolean( - 'Allow storing in this backend', - ), - } - _defaults = { - 'initial_directory_read': '/', - 'initial_directory_write': '/', - } - def select_versions(self, cr, uid, context=None): - """ Available versions in the backend. - Can be inherited to add custom versions. Using this method - to add a version from an ``_inherit`` does not constrain - to redefine the ``version`` field in the ``_inherit`` model. - """ - return [('1.0', '1.0')] - def _select_versions(self, cr, uid, context=None): - """ Available versions in the backend. - If you want to add a version, do not override this - method, but ``select_version``. - """ - return self.select_versions(cr, uid, context=context) + version = fields.Selection( + selection=[('1.0', '1.0')], required=True) + location = fields.Char( + required=True) + username = fields.Char( + required=True) + password = fields.Char( + required=True) + initial_directory_read = fields.Char( + 'Initial directory for reading', required=True, default='/') + initial_directory_write = fields.Char( + 'Initial directory for writing', required=True, default='/') + browsing_ok = fields.Boolean( + 'Allow browsing this backend') + storing_ok = fields.Boolean( + 'Allow storing in this backend') - def _get_base_adapter(self, cr, uid, ids, context=None): + @api.multi + def _get_base_adapter(self): """ Get an adapter to test the backend connection """ - backend = self.browse(cr, uid, ids[0], context=context) - session = ConnectorSession(cr, uid, context=context) - environment = Environment(backend, session, None) - + self.ensure_one() + session = ConnectorSession.from_env(self.env) + environment = Environment(self, session, None) return CmisAdapter(environment) - def check_auth(self, cr, uid, ids, context=None): + @api.multi + def check_auth(self): """ Check the authentication with DMS """ + self.ensure_one() + adapter = self._get_base_adapter() + return adapter._auth(self) - adapter = self._get_base_adapter(cr, uid, ids, context=context) - return adapter._auth(ids) - - def check_directory_of_write(self, cr, uid, ids, context=None): + @api.multi + def check_directory_of_write(self): """Check access right to write from the path""" - if context is None: - context = self.pool['res.users'].context_get(cr, uid) - cmis_backend_obj = self.pool.get('cmis.backend') datas_fname = 'testdoc' - # login with the cmis account - repo = self.check_auth(cr, uid, ids, context=context) - cmis_backend_rec = cmis_backend_obj.read( - cr, uid, ids, ['initial_directory_write'], - context=context)[0] - folder_path_write = cmis_backend_rec['initial_directory_write'] - # Testing the path - rs = repo.query("SELECT cmis:path FROM cmis:folder") - bool_path_write = self.check_existing_path(rs, folder_path_write) - # Check if we can create a doc from OE to EDM - # Document properties - if bool_path_write: - sub = repo.getObjectByPath(folder_path_write) - try: - sub.createDocumentFromString( - datas_fname, - contentString='hello, world', - contentType='text/plain') - except cmislib.exceptions.UpdateConflictException: - raise orm.except_orm( - _('Cmis Error!'), - _("The test file already exists in the DMS. " - "Please remove it and try again.")) - except cmislib.exceptions.RuntimeException: - raise orm.except_orm( - _('Cmis access right Error!'), - ("Please check your access right.")) - self.get_error_for_path(bool_path_write, folder_path_write) + for this in self: + # login with the cmis account + repo = this.check_auth() + folder_path_write = this.initial_directory_write + # Testing the path + rs = repo.query("SELECT cmis:path FROM cmis:folder") + bool_path_write = self.check_existing_path(rs, folder_path_write) + # Check if we can create a doc from OE to EDM + # Document properties + if bool_path_write: + sub = repo.getObjectByPath(folder_path_write) + try: + sub.createDocumentFromString( + datas_fname, + contentString='hello, world', + contentType='text/plain') + except cmislib.exceptions.UpdateConflictException: + raise CMISError( + _("The test file already exists in the DMS. " + "Please remove it and try again.")) + except cmislib.exceptions.RuntimeException: + raise CMISError( + ("Please check your access right.")) + self.get_error_for_path(bool_path_write, folder_path_write) - def check_directory_of_read(self, cr, uid, ids, context=None): + @api.multi + def check_directory_of_read(self): """Check access right to read from the path""" - if context is None: - context = self.pool['res.users'].context_get(cr, uid) - cmis_backend_rec = self.read( - cr, uid, ids, ['initial_directory_read'], - context=context)[0] - # Login with the cmis account - repo = self.check_auth(cr, uid, ids, context=context) - folder_path_read = cmis_backend_rec['initial_directory_read'] - # Testing the path - rs = repo.query("SELECT cmis:path FROM cmis:folder ") - bool_path_read = self.check_existing_path(rs, folder_path_read) - self.get_error_for_path(bool_path_read, folder_path_read) + for this in self: + repo = this.check_auth() + folder_path_read = this.initial_directory_read + # Testing the path + rs = repo.query("SELECT cmis:path FROM cmis:folder ") + bool_path_read = self.check_existing_path(rs, folder_path_read) + self.get_error_for_path(bool_path_read, folder_path_read) def check_existing_path(self, rs, folder_path): """Function to check if the path is correct""" @@ -146,11 +106,9 @@ def check_existing_path(self, rs, folder_path): def get_error_for_path(self, is_valid, path): """Return following the boolean the right error message""" if is_valid: - raise orm.except_orm(_('Cmis Message'), - _("Path is correct for : %s") % path) + raise Warning(_("Path is correct for : %s") % path) else: - raise orm.except_orm(_('Cmis Error!'), - _("Error path for : %s") % path) + raise CMISError( _("Error path for : %s") % path) def sanitize_input(self, file_name): """Prevent injection by escaping: '%_""" diff --git a/cmis/cmis_binding.py b/cmis/cmis_binding.py index adc91e9..60a3ac8 100644 --- a/cmis/cmis_binding.py +++ b/cmis/cmis_binding.py @@ -2,22 +2,18 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm, fields +from openerp import fields, models -class CmisBinding(orm.AbstractModel): +class CmisBinding(models.AbstractModel): _name = 'cmis.binding' _inherit = 'external.binding' _description = 'DMS Binding (Abstract)' - _columns = { - 'backend_id': fields.many2one( - 'cmis.backend', 'CMIS Backend', required=True, - ondelete='restrict' - ), - 'dms_id': fields.integer('ID in Dms', required=True), - 'sync_date': fields.datetime( - 'Last Synchronization Date', required=True), - 'updated_on': fields.datetime('Last Update in Dms') - - } + backend_id = fields.Many2one( + 'cmis.backend', 'CMIS Backend', required=True, + ondelete='restrict') + dms_id = fields.Integer('ID in Dms', required=True) + sync_date = fields.Datetime( + 'Last Synchronization Date', required=True) + updated_on = fields.Datetime('Last Update in Dms') diff --git a/cmis/exceptions.py b/cmis/exceptions.py new file mode 100644 index 0000000..b185429 --- /dev/null +++ b/cmis/exceptions.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.exceptions import UserError +from openerp.tools.translate import _ + + +class CMISError(UserError): + """CMIS Error!""" + def __init__(self, value): + super(CMISError, self).__init__(value) + + +class CMISConnectionError(CMISError): + """CMIS connection Error!""" + def __init__(self, value): + super(CMISConnectionError, self).__init__(value) \ No newline at end of file diff --git a/cmis/unit/backend_adapter.py b/cmis/unit/backend_adapter.py index f4d75aa..daa5c29 100644 --- a/cmis/unit/backend_adapter.py +++ b/cmis/unit/backend_adapter.py @@ -2,42 +2,33 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm -from openerp.tools.translate import _ -from openerp.addons.connector.unit.backend_adapter import CRUDAdapter -import cmislib.exceptions from cmislib.model import CmisClient +import cmislib.exceptions import urllib2 +from openerp.tools.translate import _ +from openerp.addons.connector.unit.backend_adapter import CRUDAdapter +from openerp.addons.cmis.exceptions import CMISConnectionError + class CmisAdapter(CRUDAdapter): - def _auth(self, ids): + def _auth(self, cmis_backend): """Test connection with CMIS""" - if type(ids) is not list: - ids = [ids] - # Get the url, user and password for CMIS - # ids = self.search(cr, uid, []) - if not ids: - raise orm.except_orm( - _('Internal Error'), - _('Something very wrong happened. _auth() ' - 'called without any ids.') - ) - res = self.backend_record.read(['location', 'username', 'password'])[0] - url = res['location'] - user_name = res['username'] - user_password = res['password'] - client = CmisClient(url, user_name, user_password) + cmis_backend.ensure_one() + client = CmisClient( + cmis_backend.location, + cmis_backend.username, + cmis_backend.password) try: return client.defaultRepository except cmislib.exceptions.ObjectNotFoundException: - raise orm.except_orm(_('CMIS connection Error!'), - _("Check your CMIS account configuration.")) + raise CMISConnectionError( + _("Check your CMIS account configuration.")) except cmislib.exceptions.PermissionDeniedException: - raise orm.except_orm(_('CMIS connection Error!'), - _("Check your CMIS account configuration.")) + raise CMISConnectionError( + _("Check your CMIS account configuration.")) except urllib2.URLError: - raise orm.except_orm(_('CMIS connection Error!'), - _("SERVER is down.")) + raise CMISConnectionError( + _("SERVER is down.")) diff --git a/cmis/unit/binder.py b/cmis/unit/binder.py index c03bdc7..932656e 100644 --- a/cmis/unit/binder.py +++ b/cmis/unit/binder.py @@ -2,111 +2,13 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.addons.connector.connector import Binder from ..backend import cmis -from datetime import datetime -from openerp.tools import ustr - @cmis class CmisModelBinder(Binder): _model_name = [] - - def to_openerp(self, external_id, unwrap=False): - """ Give the OpenERP ID for an external ID - - :param external_id: external ID for which we want the OpenERP ID - :param unwrap: if True, returns the openerp_id of the dms_xxxx - record, else return the id (binding id) of that record - :return: a record ID, depending on the value of unwrap, - or None if the external_id is not mapped - :rtype: int - """ - with self.session.change_context({'active_test': False}): - binding_ids = self.session.search(self.model._name, [ - ('dms_id', '=', ustr(external_id)), - ('backend_id', '=', self.backend_record.id) - ]) - - if not binding_ids: - return None - - binding_id = binding_ids[0] - - if unwrap: - return self.session.read( - self.model._name, binding_id, ['openerp_id'])['openerp_id'][0] - else: - return binding_id - - def to_backend(self, record_id, wrap=False): - """ Give the external ID for an OpenERP ID - - :param record_id: OpenERP ID for which we want the external id - :param wrap: if False, record_id is the ID of the binding, - if True, record_id is the ID of the normal record, the - method will search the corresponding binding and returns - the backend id of the binding - :return: backend identifier of the record - """ - if wrap: - with self.session.change_context({'active_test': False}): - erp_id = self.session.search( - self.model._name, - [('openerp_id', '=', record_id), - ('backend_id', '=', self.backend_record.id) - ]) - if erp_id: - record_id = erp_id[0] - else: - return None - - dms_record = self.session.read( - self.model._name, record_id, ['dms_id']) - - return dms_record['dms_id'] - - def bind(self, external_id, binding_id): - """ Create the link between an external ID and an OpenERP ID and - update the last synchronization date. - - :param external_id: External ID to bind - :param binding_id: OpenERP ID to bind - :type binding_id: int - """ - # avoid to trigger the export when we modify the `dms_id` - context = self.session.context.copy() - context['connector_no_export'] = True - now_fmt = datetime.now().strftime(DEFAULT_SERVER_DATETIME_FORMAT) - - self.environment.model.write( - self.session.cr, self.session.uid, binding_id, { - 'dms_id': ustr(external_id), - 'sync_date': now_fmt - }, context=context) - - def unwrap_binding(self, binding_id, browse=False): - binding = self.session.read( - self.model._name, binding_id, ['openerp_id']) - - openerp_id = binding['openerp_id'][0] - - if browse: - return self.session.browse(self.unwrap_model(), openerp_id) - - return openerp_id - - def unwrap_model(self): - """ This binder assumes that the normal model - lays in ``openerp_id`` since - this is the field we use in the ``_inherits`` bindings. - """ - try: - column = self.model._columns['openerp_id'] - except KeyError: - raise ValueError('Cannot unwrap model %s, because it has ' - 'no openerp_id field' % self.model._name) - return column._obj + _external_field = 'dms_id' + _backend_field = 'backend_id' From 08ba662de48b49ed289f02720bae91c23448563a Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 14:50:40 +0100 Subject: [PATCH 07/46] [MIG] Move Odoo models to module 'models' --- cmis/exceptions.py | 2 +- cmis/models/__init__.py | 8 ++++++++ cmis/{ => models}/cmis_backend.py | 0 cmis/{ => models}/cmis_binding.py | 0 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 cmis/models/__init__.py rename cmis/{ => models}/cmis_backend.py (100%) rename cmis/{ => models}/cmis_binding.py (100%) diff --git a/cmis/exceptions.py b/cmis/exceptions.py index b185429..17fcaa5 100644 --- a/cmis/exceptions.py +++ b/cmis/exceptions.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © 2014-2015 Savoir-faire Linux (). +# © 2016 ACSONE SA/NV (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.exceptions import UserError diff --git a/cmis/models/__init__.py b/cmis/models/__init__.py new file mode 100644 index 0000000..088724c --- /dev/null +++ b/cmis/models/__init__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import ( + cmis_backend, + cmis_binding, +) diff --git a/cmis/cmis_backend.py b/cmis/models/cmis_backend.py similarity index 100% rename from cmis/cmis_backend.py rename to cmis/models/cmis_backend.py diff --git a/cmis/cmis_binding.py b/cmis/models/cmis_binding.py similarity index 100% rename from cmis/cmis_binding.py rename to cmis/models/cmis_binding.py From 7b5d6102ab0e2e9cacf197eb273625b852be9790 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 14:51:33 +0100 Subject: [PATCH 08/46] [MIG] Fix import after move of Odoo models to module models --- cmis/__init__.py | 3 +-- cmis/models/cmis_backend.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cmis/__init__.py b/cmis/__init__.py index 6d5393c..c30a784 100644 --- a/cmis/__init__.py +++ b/cmis/__init__.py @@ -3,7 +3,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import ( - cmis_backend, backend, - cmis_binding, + models, ) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 3502a91..cd871ba 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -8,8 +8,8 @@ from openerp.tools.translate import _ from openerp.addons.connector.connector import Environment from openerp.addons.connector.session import ConnectorSession -from .unit.backend_adapter import CmisAdapter -from .exceptions import CMISError +from ..unit.backend_adapter import CmisAdapter +from ..exceptions import CMISError class CmisBackend(models.Model): From 1039035a98951f3e0deff1127efb1f60edb0e601 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Tue, 16 Feb 2016 15:01:59 +0100 Subject: [PATCH 09/46] [PEP8] --- cmis/exceptions.py | 5 ++--- cmis/models/cmis_backend.py | 3 +-- cmis/unit/backend_adapter.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cmis/exceptions.py b/cmis/exceptions.py index 17fcaa5..8da63e8 100644 --- a/cmis/exceptions.py +++ b/cmis/exceptions.py @@ -3,16 +3,15 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.exceptions import UserError -from openerp.tools.translate import _ class CMISError(UserError): """CMIS Error!""" def __init__(self, value): - super(CMISError, self).__init__(value) + super(CMISError, self).__init__(value) class CMISConnectionError(CMISError): """CMIS connection Error!""" def __init__(self, value): - super(CMISConnectionError, self).__init__(value) \ No newline at end of file + super(CMISConnectionError, self).__init__(value) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index cd871ba..69d8546 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -19,7 +19,6 @@ class CmisBackend(models.Model): _backend_type = 'cmis' - version = fields.Selection( selection=[('1.0', '1.0')], required=True) location = fields.Char( @@ -108,7 +107,7 @@ def get_error_for_path(self, is_valid, path): if is_valid: raise Warning(_("Path is correct for : %s") % path) else: - raise CMISError( _("Error path for : %s") % path) + raise CMISError(_("Error path for : %s") % path) def sanitize_input(self, file_name): """Prevent injection by escaping: '%_""" diff --git a/cmis/unit/backend_adapter.py b/cmis/unit/backend_adapter.py index daa5c29..df30e89 100644 --- a/cmis/unit/backend_adapter.py +++ b/cmis/unit/backend_adapter.py @@ -18,7 +18,7 @@ def _auth(self, cmis_backend): cmis_backend.ensure_one() client = CmisClient( cmis_backend.location, - cmis_backend.username, + cmis_backend.username, cmis_backend.password) try: From 8c3692d5644a7e99bff1176e0d88d78be978ecb2 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 29 Feb 2016 11:26:02 +0100 Subject: [PATCH 10/46] [FIX] connector.Environment replaced by connector.ConnectoEnvironment in 9.0 --- cmis/models/cmis_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 69d8546..7fd0b9e 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -6,7 +6,7 @@ from openerp import api, fields, models from openerp.exceptions import Warning from openerp.tools.translate import _ -from openerp.addons.connector.connector import Environment +from openerp.addons.connector.connector import ConnectorEnvironment from openerp.addons.connector.session import ConnectorSession from ..unit.backend_adapter import CmisAdapter from ..exceptions import CMISError @@ -43,7 +43,7 @@ def _get_base_adapter(self): """ self.ensure_one() session = ConnectorSession.from_env(self.env) - environment = Environment(self, session, None) + environment = ConnectorEnvironment(self, session, None) return CmisAdapter(environment) @api.multi From 147d9a5c752e776cfaee0501639fe58520dd9aba Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 29 Feb 2016 12:03:26 +0100 Subject: [PATCH 11/46] [FIX] ImportSynchonizer renamed to Importer in 9.0 --- cmis/unit/import_synchronizer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmis/unit/import_synchronizer.py b/cmis/unit/import_synchronizer.py index dc49bd3..8feae1e 100644 --- a/cmis/unit/import_synchronizer.py +++ b/cmis/unit/import_synchronizer.py @@ -3,11 +3,11 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging -from openerp.addons.connector.unit.synchronizer import ImportSynchronizer +from openerp.addons.connector.unit.synchronizer import Importer _logger = logging.getLogger(__name__) -class CmisImportSynchronizer(ImportSynchronizer): +class CmisImportSynchronizer(Importer): """ Base importer for Dms """ def __init__(self, environment): @@ -82,6 +82,6 @@ def run(self, dms_id, options=None): self.binder.bind(self.dms_id, binding_id) -class CmisBatchImportSynchronizer(ImportSynchronizer): +class CmisBatchImportSynchronizer(Importer): def run(self, filters=None, options=None): raise NotImplementedError From 7b3af9463f46147dba9c07ee1b545cbc2f85e8ff Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 7 Apr 2016 16:43:16 +0200 Subject: [PATCH 12/46] [FIX] Import ACLs --- cmis/__openerp__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cmis/__openerp__.py b/cmis/__openerp__.py index a7db4e2..bb0ea45 100644 --- a/cmis/__openerp__.py +++ b/cmis/__openerp__.py @@ -19,6 +19,7 @@ 'data': [ 'views/cmis_backend_view.xml', 'views/cmis_menu.xml', + 'security/ir.model.access.csv', ], 'installable': True, 'auto_install': False, From 7e353f1ae8049d2bc0f7c0911cf6dbe5dad6d4ec Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 08:56:21 +0200 Subject: [PATCH 13/46] [IMP] Rename backend_id to cmis_backend_id:wq --- cmis/connector.py | 12 ++++++------ cmis/i18n/fr.po | 2 +- cmis/models/cmis_binding.py | 4 ++-- cmis/unit/binder.py | 2 +- cmis/unit/mapper.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmis/connector.py b/cmis/connector.py index 5a66058..21aa2dc 100644 --- a/cmis/connector.py +++ b/cmis/connector.py @@ -6,9 +6,9 @@ from openerp.addons.connector.checkpoint import checkpoint -def get_environment(session, model_name, backend_id): +def get_environment(session, model_name, cmis_backend_id): """ Create an environment to work with. """ - backend_record = session.browse('cmis.backend', backend_id) + backend_record = session.browse('cmis.backend', cmis_backend_id) env = Environment(backend_record, session, model_name) lang = backend_record.default_lang_id lang_code = lang.code if lang else 'en_US' @@ -16,7 +16,7 @@ def get_environment(session, model_name, backend_id): return env -def add_checkpoint(session, model_name, record_id, backend_id): +def add_checkpoint(session, model_name, record_id, cmis_backend_id): """ Add a row in the model ``connector.checkpoint`` for a record, meaning it has to be reviewed by a user. :param session: current session @@ -25,8 +25,8 @@ def add_checkpoint(session, model_name, record_id, backend_id): :type model_name: str :param record_id: ID of the record to be reviewed :type record_id: int - :param backend_id: ID of the Cmis Backend - :type backend_id: int + :param cmis_backend_id: ID of the Cmis Backend + :type cmis_backend_id: int """ return checkpoint.add_checkpoint( - session, model_name, record_id, 'cmis.backend', backend_id) + session, model_name, record_id, 'cmis.backend', cmis_backend_id) diff --git a/cmis/i18n/fr.po b/cmis/i18n/fr.po index ea3223f..3b315bc 100644 --- a/cmis/i18n/fr.po +++ b/cmis/i18n/fr.po @@ -19,7 +19,7 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n > 1);\n" #. module: cmis -#: view:cmis.backend:0 field:cmis.binding,backend_id:0 +#: view:cmis.backend:0 field:cmis.binding,cmis_backend_id:0 #: model:ir.model,name:cmis.model_cmis_backend msgid "CMIS Backend" msgstr "Backend CMIS" diff --git a/cmis/models/cmis_binding.py b/cmis/models/cmis_binding.py index 60a3ac8..3b775a9 100644 --- a/cmis/models/cmis_binding.py +++ b/cmis/models/cmis_binding.py @@ -10,9 +10,9 @@ class CmisBinding(models.AbstractModel): _inherit = 'external.binding' _description = 'DMS Binding (Abstract)' - backend_id = fields.Many2one( + cmis_backend_id = fields.Many2one( 'cmis.backend', 'CMIS Backend', required=True, - ondelete='restrict') + ondelete='restrict', oldname='backend_id') dms_id = fields.Integer('ID in Dms', required=True) sync_date = fields.Datetime( 'Last Synchronization Date', required=True) diff --git a/cmis/unit/binder.py b/cmis/unit/binder.py index 932656e..c6713d9 100644 --- a/cmis/unit/binder.py +++ b/cmis/unit/binder.py @@ -11,4 +11,4 @@ class CmisModelBinder(Binder): _model_name = [] _external_field = 'dms_id' - _backend_field = 'backend_id' + _backend_field = 'cmis_backend_id' diff --git a/cmis/unit/mapper.py b/cmis/unit/mapper.py index f017178..ceebc62 100644 --- a/cmis/unit/mapper.py +++ b/cmis/unit/mapper.py @@ -10,8 +10,8 @@ class CmisImportMapper(ImportMapper): @mapping - def backend_id(self, record): - return {'backend_id': self.backend_record.id} + def cmis_backend_id(self, record): + return {'cmis_backend_id': self.backend_record.id} @mapping def updated_on(self, record): From 6afb766ab4074ac98082499e8f383b8098e3061d Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 10:49:08 +0200 Subject: [PATCH 14/46] [IMP] Use enhanced version of cmislib --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 42a17a2..3121edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - travis_install_nightly - - pip install cmislib + - pip install git+https://github.com/lmignon/python-cmislib.git@6.0.dev#egg=cmislib script: - travis_run_tests From 22cfcb49dc3db40316a05c350cebc24d4ff04159 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 10:58:47 +0200 Subject: [PATCH 15/46] [FIX] base.group_document_user no more exists in V9 use base.group_user --- cmis_read/security/ir.model.access.csv | 2 +- cmis_write/security/ir.model.access.csv | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmis_read/security/ir.model.access.csv b/cmis_read/security/ir.model.access.csv index ac92b9a..5c766bd 100644 --- a/cmis_read/security/ir.model.access.csv +++ b/cmis_read/security/ir.model.access.csv @@ -1,2 +1,2 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_ir_attachment_dms_wizard,access_ir_attachment_dms_wizard,model_ir_attachment_dms_wizard,base.group_document_user,1,1,1,1 +access_ir_attachment_dms_wizard,access_ir_attachment_dms_wizard,model_ir_attachment_dms_wizard,base.group_user,1,1,1,1 diff --git a/cmis_write/security/ir.model.access.csv b/cmis_write/security/ir.model.access.csv index 6878ffb..0d36625 100644 --- a/cmis_write/security/ir.model.access.csv +++ b/cmis_write/security/ir.model.access.csv @@ -1,4 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_metadata_list_group_user,metadata.list user,model_metadata_list,base.group_document_user,1,1,1,1 -access_metadata,access_metadata,model_metadata,base.group_document_user,1,1,1,1 -access_ir_attachment_doc_backend,access_ir_attachment_doc_backend,model_ir_attachment_doc_backend,base.group_document_user,1,1,1,1 +access_metadata_list_group_user,metadata.list user,model_metadata_list,base.group_user,1,1,1,1 +access_metadata,access_metadata,model_metadata,base.group_user,1,1,1,1 +access_ir_attachment_doc_backend,access_ir_attachment_doc_backend,model_ir_attachment_doc_backend,base.group_user,1,1,1,1 From d6139b7596f41991415f38d423d70bbe71a56b4d Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 11:10:46 +0200 Subject: [PATCH 16/46] [FIX] cmis_write is not migrated --- cmis_write/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index 4cec5b1..1b319bd 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -83,6 +83,6 @@ 'qweb': [], 'test': [], 'demo': [], - 'installable': True, + 'installable': False, 'auto_install': False, } From 6e1b4f7dffb7c65829ca64252c6ed64a00c7b7a7 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 25 May 2016 10:28:39 +0200 Subject: [PATCH 17/46] [FIX] In alfresco 5.1, cmis:path is a list https://github.com/OCA/connector-cmis/issues/13 --- cmis/models/cmis_backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 7fd0b9e..0e3332f 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -97,8 +97,8 @@ def check_existing_path(self, rs, folder_path): """Function to check if the path is correct""" for one_rs in rs: # Print name of files - props = one_rs.getProperties() - if props['cmis:path'] == folder_path: + cmis_path = one_rs.getProperties()['cmis:path'] + if folder_path == cmis_path or folder_path in cmis_path: return True return False From ad102d9e0752f9c20f37cc94222ca153b837614d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 13:29:42 +0100 Subject: [PATCH 18/46] [MIG] Make module installable --- cmis_write/document_view.xml | 8 ++++---- cmis_write/ir_attachment.py | 22 +++++++++++----------- cmis_write/metadata_view.xml | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cmis_write/document_view.xml b/cmis_write/document_view.xml index a78325a..63e396e 100644 --- a/cmis_write/document_view.xml +++ b/cmis_write/document_view.xml @@ -3,12 +3,12 @@ - + ir.attachment.doc.backend ir.attachment - + - + @@ -21,7 +21,7 @@ - + diff --git a/cmis_write/ir_attachment.py b/cmis_write/ir_attachment.py index 31f8a9c..0a6adce 100644 --- a/cmis_write/ir_attachment.py +++ b/cmis_write/ir_attachment.py @@ -32,7 +32,7 @@ class ir_attachment(orm.Model): _inherit = 'ir.attachment' - def create(self, cr, uid, values, context=None): + def __create(self, cr, uid, values, context=None): if context is None: context = {} metadata_obj = self.pool['metadata'] @@ -41,12 +41,12 @@ def create(self, cr, uid, values, context=None): session = ConnectorSession(cr, uid, context=context) value = {} if values.get('datas'): - values['file_type'], values['index_content'] = self._index( + values['index_content'] = self._index( cr, uid, values['datas'], values.get('datas_fname', False), None) # Get the extension file ext = '' - if values['file_type']: + if values.get('file_type'): ext = '.' + values['file_type'][values['file_type']. find('/') + 1:] if not values.get('datas_fname'): @@ -130,7 +130,7 @@ def action_download(self, cr, uid, ids, context=None): return ir.db_datas return datas - def _data_set(self, cr, uid, id, name, value, arg, context=None): + def __data_set(self, cr, uid, id, name, value, arg, context=None): # We don't handle setting data to null if not value: return True @@ -196,13 +196,13 @@ def _data_get(self, cr, uid, ids, name, arg, context=None): 'Attachment download', help="Attachment download" ), - 'datas': fields.function( - _data_get, - fnct_inv=_data_set, - string='File Content', - type="binary", - nodrop=True - ), + #'datas': fields.function( + # _data_get, + # fnct_inv=_data_set, + # string='File Content', + # type="binary", + # nodrop=True + #), 'attachment_document_ids': fields.one2many( 'ir.attachment.doc.backend', 'attachment_id', diff --git a/cmis_write/metadata_view.xml b/cmis_write/metadata_view.xml index fb25785..fba950d 100644 --- a/cmis_write/metadata_view.xml +++ b/cmis_write/metadata_view.xml @@ -46,7 +46,7 @@ From 594972ac905303aee04485791d45452ea631a8f4 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 13:42:41 +0100 Subject: [PATCH 19/46] [MIG] Move Odoo models to module 'models' and views to to folder 'views' --- cmis_write/{ => models}/ir_attachment.py | 0 cmis_write/{ => models}/ir_attachment_doc_backend.py | 0 cmis_write/{ => models}/ir_attachment_download.py | 0 cmis_write/{ => models}/metadata.py | 0 cmis_write/{ => models}/metadata_list.py | 0 cmis_write/{ => views}/document_view.xml | 0 cmis_write/{ => views}/metadata_view.xml | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename cmis_write/{ => models}/ir_attachment.py (100%) rename cmis_write/{ => models}/ir_attachment_doc_backend.py (100%) rename cmis_write/{ => models}/ir_attachment_download.py (100%) rename cmis_write/{ => models}/metadata.py (100%) rename cmis_write/{ => models}/metadata_list.py (100%) rename cmis_write/{ => views}/document_view.xml (100%) rename cmis_write/{ => views}/metadata_view.xml (100%) diff --git a/cmis_write/ir_attachment.py b/cmis_write/models/ir_attachment.py similarity index 100% rename from cmis_write/ir_attachment.py rename to cmis_write/models/ir_attachment.py diff --git a/cmis_write/ir_attachment_doc_backend.py b/cmis_write/models/ir_attachment_doc_backend.py similarity index 100% rename from cmis_write/ir_attachment_doc_backend.py rename to cmis_write/models/ir_attachment_doc_backend.py diff --git a/cmis_write/ir_attachment_download.py b/cmis_write/models/ir_attachment_download.py similarity index 100% rename from cmis_write/ir_attachment_download.py rename to cmis_write/models/ir_attachment_download.py diff --git a/cmis_write/metadata.py b/cmis_write/models/metadata.py similarity index 100% rename from cmis_write/metadata.py rename to cmis_write/models/metadata.py diff --git a/cmis_write/metadata_list.py b/cmis_write/models/metadata_list.py similarity index 100% rename from cmis_write/metadata_list.py rename to cmis_write/models/metadata_list.py diff --git a/cmis_write/document_view.xml b/cmis_write/views/document_view.xml similarity index 100% rename from cmis_write/document_view.xml rename to cmis_write/views/document_view.xml diff --git a/cmis_write/metadata_view.xml b/cmis_write/views/metadata_view.xml similarity index 100% rename from cmis_write/metadata_view.xml rename to cmis_write/views/metadata_view.xml From 5b734a1487e75b4ffad290076a26667a763cc777 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 13:44:16 +0100 Subject: [PATCH 20/46] [MIG]Fix import after move --- cmis_write/__init__.py | 9 ++------- cmis_write/__openerp__.py | 4 ++-- cmis_write/models/__init__.py | 9 +++++++++ cmis_write/models/ir_attachment.py | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 cmis_write/models/__init__.py diff --git a/cmis_write/__init__.py b/cmis_write/__init__.py index edaf793..f0a949d 100644 --- a/cmis_write/__init__.py +++ b/cmis_write/__init__.py @@ -20,10 +20,5 @@ # ############################################################################## -from . import ( - ir_attachment, - ir_attachment_doc_backend, - metadata, - metadata_list, - ir_attachment_download -) +from . import models + diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index 1b319bd..fc9dfe0 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -73,8 +73,8 @@ 'cmis', ], 'data': [ - 'document_view.xml', - 'metadata_view.xml', + 'views/document_view.xml', + 'views/metadata_view.xml', 'security/ir.model.access.csv', ], 'js': [ diff --git a/cmis_write/models/__init__.py b/cmis_write/models/__init__.py new file mode 100644 index 0000000..3d7c0e5 --- /dev/null +++ b/cmis_write/models/__init__.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import ir_attachment_doc_backend +from . import ir_attachment_download +from . import ir_attachment +from . import metadata_list +from . import metadata diff --git a/cmis_write/models/ir_attachment.py b/cmis_write/models/ir_attachment.py index 0a6adce..1beca33 100644 --- a/cmis_write/models/ir_attachment.py +++ b/cmis_write/models/ir_attachment.py @@ -22,7 +22,7 @@ from openerp.osv import orm, fields from openerp.addons.connector.session import ConnectorSession -from .unit.import_synchronizer import create_doc_in_edm +from ..unit.import_synchronizer import create_doc_in_edm from openerp import SUPERUSER_ID import logging From 4a21856e2fb0ff19abf9b69652d9c1e443ad8c9f Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 14:43:38 +0100 Subject: [PATCH 21/46] [MIG] Use shortened licence --- cmis_write/__init__.py | 25 +++---------------- cmis_write/__openerp__.py | 24 +++--------------- cmis_write/models/ir_attachment.py | 23 +++-------------- .../models/ir_attachment_doc_backend.py | 24 +++--------------- cmis_write/models/ir_attachment_download.py | 24 +++--------------- cmis_write/models/metadata.py | 24 +++--------------- cmis_write/models/metadata_list.py | 24 +++--------------- cmis_write/tests/__init__.py | 22 ++-------------- cmis_write/tests/test_ir_attachment.py | 23 +++-------------- cmis_write/tests/test_metadata.py | 24 +++--------------- cmis_write/unit/__init__.py | 24 +++--------------- cmis_write/unit/import_synchronizer.py | 24 +++--------------- 12 files changed, 35 insertions(+), 250 deletions(-) diff --git a/cmis_write/__init__.py b/cmis_write/__init__.py index f0a949d..8ba4c6d 100644 --- a/cmis_write/__init__.py +++ b/cmis_write/__init__.py @@ -1,24 +1,5 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models - diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index fc9dfe0..3a21423 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'CMIS Write', diff --git a/cmis_write/models/ir_attachment.py b/cmis_write/models/ir_attachment.py index 1beca33..f81c096 100644 --- a/cmis_write/models/ir_attachment.py +++ b/cmis_write/models/ir_attachment.py @@ -1,23 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). ############################################################################## from openerp.osv import orm, fields diff --git a/cmis_write/models/ir_attachment_doc_backend.py b/cmis_write/models/ir_attachment_doc_backend.py index 6d42014..85ca4c1 100644 --- a/cmis_write/models/ir_attachment_doc_backend.py +++ b/cmis_write/models/ir_attachment_doc_backend.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm, fields diff --git a/cmis_write/models/ir_attachment_download.py b/cmis_write/models/ir_attachment_download.py index f87ade4..1563123 100644 --- a/cmis_write/models/ir_attachment_download.py +++ b/cmis_write/models/ir_attachment_download.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm, fields diff --git a/cmis_write/models/metadata.py b/cmis_write/models/metadata.py index 8cea758..5cfdb49 100644 --- a/cmis_write/models/metadata.py +++ b/cmis_write/models/metadata.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm, fields diff --git a/cmis_write/models/metadata_list.py b/cmis_write/models/metadata_list.py index 3201ef4..99d979e 100644 --- a/cmis_write/models/metadata_list.py +++ b/cmis_write/models/metadata_list.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.osv import orm, fields diff --git a/cmis_write/tests/__init__.py b/cmis_write/tests/__init__.py index 4a51ae1..8348cb0 100644 --- a/cmis_write/tests/__init__.py +++ b/cmis_write/tests/__init__.py @@ -1,24 +1,6 @@ # -*- coding: utf-8 -*- - -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2014 Savoir-faire Linux (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import ( test_attachment, diff --git a/cmis_write/tests/test_ir_attachment.py b/cmis_write/tests/test_ir_attachment.py index 25f020b..45846ca 100644 --- a/cmis_write/tests/test_ir_attachment.py +++ b/cmis_write/tests/test_ir_attachment.py @@ -1,23 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################### -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2010 - 2014 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). ############################################################################### from openerp.tests.common import TransactionCase diff --git a/cmis_write/tests/test_metadata.py b/cmis_write/tests/test_metadata.py index aad7074..baff087 100644 --- a/cmis_write/tests/test_metadata.py +++ b/cmis_write/tests/test_metadata.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.tests.common import TransactionCase diff --git a/cmis_write/unit/__init__.py b/cmis_write/unit/__init__.py index 803d27a..c8551a6 100644 --- a/cmis_write/unit/__init__.py +++ b/cmis_write/unit/__init__.py @@ -1,23 +1,5 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import import_synchronizer diff --git a/cmis_write/unit/import_synchronizer.py b/cmis_write/unit/import_synchronizer.py index 9ee4d2b..b84f6fb 100644 --- a/cmis_write/unit/import_synchronizer.py +++ b/cmis_write/unit/import_synchronizer.py @@ -1,24 +1,6 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2015 - Present Savoir-faire Linux -# (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2015 Savoir-faire Linux (). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.addons.connector.queue.job import job import base64 From b06ccf0ea22002c99d30d8f479acf6fe51fec679 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 14:45:03 +0100 Subject: [PATCH 22/46] [MIG] remove deprecated checks attribute in test module --- cmis_write/tests/__init__.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmis_write/tests/__init__.py b/cmis_write/tests/__init__.py index 8348cb0..f40f4f4 100644 --- a/cmis_write/tests/__init__.py +++ b/cmis_write/tests/__init__.py @@ -3,11 +3,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import ( - test_attachment, + test_ir_attachment, test_metadata, ) - -checks = [ - test_attachment, - test_metadata, -] From a949883268341b3fc2e17f5a7c1de3093ce4ab7b Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 14:58:13 +0100 Subject: [PATCH 23/46] [MIG] import order --- cmis_write/unit/import_synchronizer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmis_write/unit/import_synchronizer.py b/cmis_write/unit/import_synchronizer.py index b84f6fb..a400946 100644 --- a/cmis_write/unit/import_synchronizer.py +++ b/cmis_write/unit/import_synchronizer.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from openerp.addons.connector.queue.job import job import base64 import logging +from openerp.addons.connector.queue.job import job + _logger = logging.getLogger(__name__) From 1d44535fb7daec4fe7e1371e46b7cf180cf56f2d Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 14:58:28 +0100 Subject: [PATCH 24/46] [MIG] move description to README.rst --- cmis_write/README.rst | 89 +++++++++++++++++++++++++++++++++++++++ cmis_write/__openerp__.py | 44 +------------------ 2 files changed, 91 insertions(+), 42 deletions(-) create mode 100644 cmis_write/README.rst diff --git a/cmis_write/README.rst b/cmis_write/README.rst new file mode 100644 index 0000000..2c45c09 --- /dev/null +++ b/cmis_write/README.rst @@ -0,0 +1,89 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=============================== +Add Documents from Odoo/OpenERP +=============================== + +This module allows you to store Odoo/OpenERP document in the DMS repository. + +Installation +============ + +No installation required: + +Configuration +============= + +* Create a new CMIS backend with the host, login and password. +* Configure the path in the repository where documents will be dropped. + By default, it uses the home directory of the user. + +Usage +===== + +* On one Odoo/OpenERP record, click "Add document". +* Upload your documents +* Uploaded documents will be enqueued for storage in the DMS + (Document Management System) + +Add Metadata +------------ + +To manage a custom aspect using CMIS (and all the other supported ways) +you have to: + +* Define a new custom model configuring Alfresco. To do this I suggest you +http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model. + +* Add the custom aspect to the document you upload or create in Alfresco. +Using CMIS I suggest you: +http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-adding.html. + +* Set the custom property in the way you probably know using CMIS. + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/104/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* El Hadji Dem +* Maxime Chambreuil +* Laurent Mignon + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index 3a21423..afcf918 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -7,48 +7,8 @@ 'version': '9.0.1.0.0', 'category': 'Knowledge Management', 'summary': 'Create Document in DMS from Odoo/OpenERP', - 'description': """ -Add Documents from Odoo/OpenERP -=============================== - -This module allows you to store Odoo/OpenERP document in the DMS repository. - -Configuration -============= - -* Create a new CMIS backend with the host, login and password. -* Configure the path in the repository where documents will be dropped. - By default, it uses the home directory of the user. - -Usage -===== - -* On one Odoo/OpenERP record, click "Add document". -* Upload your documents -* Uploaded documents will be enqueued for storage in the DMS - (Document Management System) - -Add Metadata -============ - -To manage a custom aspect using CMIS (and all the other supported ways) -you have to: - -* Define a new custom model configuring Alfresco. To do this I suggest you -http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model. - -* Add the custom aspect to the document you upload or create in Alfresco. -Using CMIS I suggest you: -http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-adding.html. - -* Set the custom property in the way you probably know using CMIS. - -Contributors ------------- -* El Hadji Dem (elhadji.dem@savoirfairelinux.com) -""", - 'author': 'Savoir-faire Linux', - 'website': 'www.savoirfairelinux.com', + 'author': 'Savoir-faire Linux, Odoo Community Association (OCA)', + 'website': 'https://odoo-community.org/', 'license': 'AGPL-3', 'depends': [ 'document', From 26bda641625603cc2687a5cdda7e578f56351537 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 17 Feb 2016 18:01:20 +0100 Subject: [PATCH 25/46] [MIG] Use new API --- cmis_write/models/ir_attachment.py | 224 +++++------------- .../models/ir_attachment_doc_backend.py | 38 ++- cmis_write/models/ir_attachment_download.py | 30 +-- cmis_write/models/metadata.py | 98 ++++---- cmis_write/models/metadata_list.py | 26 +- cmis_write/unit/import_synchronizer.py | 45 ++-- 6 files changed, 161 insertions(+), 300 deletions(-) diff --git a/cmis_write/models/ir_attachment.py b/cmis_write/models/ir_attachment.py index f81c096..6534fe4 100644 --- a/cmis_write/models/ir_attachment.py +++ b/cmis_write/models/ir_attachment.py @@ -2,194 +2,76 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). ############################################################################## - -from openerp.osv import orm, fields +import logging +from openerp import api, fields, models from openerp.addons.connector.session import ConnectorSession from ..unit.import_synchronizer import create_doc_in_edm -from openerp import SUPERUSER_ID -import logging _logger = logging.getLogger(__name__) -class ir_attachment(orm.Model): +class IrAttachment(models.Model): _inherit = 'ir.attachment' - def __create(self, cr, uid, values, context=None): - if context is None: - context = {} - metadata_obj = self.pool['metadata'] - user_obj = self.pool['res.users'] - user_login = user_obj.browse(cr, uid, uid, context=context).login - session = ConnectorSession(cr, uid, context=context) - value = {} - if values.get('datas'): - values['index_content'] = self._index( - cr, uid, values['datas'], - values.get('datas_fname', False), None) - # Get the extension file - ext = '' - if values.get('file_type'): - ext = '.' + values['file_type'][values['file_type']. - find('/') + 1:] - if not values.get('datas_fname'): - values['datas_fname'] = values.get('name') + ext - value = { - 'name': values.get('name'), - 'datas_fname': values.get('datas_fname'), - 'datas': values.get('datas'), - 'res_id': values.get('res_id'), - 'res_model': values.get('res_model'), - } - metadata_ids = metadata_obj.search(cr, SUPERUSER_ID, [], - context=context) - dict_metadata = {} - list_fields = [] - # Get list of metadata - if values.get('res_model'): - for line in metadata_obj.browse(cr, SUPERUSER_ID, metadata_ids, - context=context): - if line.model_id.model == values.get('res_model') and \ - line.metadata_list_ids: - list_fields += [one_field.field_id.name - for one_field in line.metadata_list_ids] - if list_fields: - result = self.pool.get(values.get('res_model')).read(cr, uid, [ - values.get('res_id')], list_fields, context=context)[0] - for one_field in list_fields: - dict_metadata['cmis:' + one_field] = result[one_field] - if not context.get('bool_testdoc'): - # Don't save the document in Odoo/OpenERP - values['datas'] = None - # Create an ir.attachment - res = super(ir_attachment, self).create( - cr, uid, values, context=context) + id_dms = fields.Char('Id of Dms', help="Id of Dms.") + download_id = fields.One2many( + 'ir.attachment.download', + 'attachment_id', + 'Attachment download', + help="Attachment download" + ) + datas = fields.Binary( + compute='_data_get', + inverse='_data_set') + + attachment_document_ids = fields.One2many( + 'ir.attachment.doc.backend', + 'attachment_id', + 'Records', + help="Records" + ) + + @api.model + def create(self, values): + res = super(IrAttachment, self).create(values) + session = ConnectorSession.from_env(self.env) # if bool_testdoc in context, we don't need to create # the doc in the DMS - if not context.get('bool_testdoc'): - create_doc_in_edm.delay( - session, 'ir.attachment', value, res, dict_metadata, - user_login) + if 'bool_testdoc' not in self.env.context: + metadata = {} + if res.res_model: + metadata = self.env['metadata'].extract_metadata( + self.env[res.res_model].browse(res.res_id)) + create_doc_in_edm.delay( + session, 'ir.attachment', res.id, metadata, + self.env.user.login) return res - def action_download(self, cr, uid, ids, context=None): + @api.multi + def action_download(self): """ Download document if it is available in one of backend """ - if context is None: - context = {} - if isinstance(ids, (int, long)): - ids = [ids] - cmis_backend_obj = self.pool['cmis.backend'] - datas = '' - for ir in self.browse(cr, uid, ids, context=context): - # Get the created document from cmis_write. - # Document is stored from DMS. - if len(ir.attachment_document_ids) != 0: - for doc in ir.attachment_document_ids: - try: - backend = cmis_backend_obj.search( - cr, uid, [ - ('id', '=', doc.backend_id.id), - ('storing_ok', '=', 'True') - ], context=context) - # Connect to the backend - repo = cmis_backend_obj.check_auth( - cr, uid, backend, context=context) - # Get the id of document - id_dms = doc.object_doc_id - # Get results from id of document - query = " SELECT * FROM cmis:document \ - WHERE cmis:objectId ='" + id_dms + "'" - results = repo.query(query) - datas = results[0].getContentStream().read().encode( - 'base64') - return datas - except: - continue - else: - # Get the created document from cmis_read. - # Document is directly stored in Odoo/OpenERP. - return ir.db_datas + self.ensure_one() + cmis_backend_obj = self.env['cmis.backend'] + backend = cmis_backend_obj.search(('storing_ok', '=', 'True')) + backend.ensure_one() + repo = cmis_backend_obj.check_auth() + # Get results from id of document + query = " SELECT * FROM cmis:document \ + WHERE cmis:objectId ='" + self.id_dms + "'" + results = repo.query(query) + datas = results[0].getContentStream().read().encode( + 'base64') return datas - def __data_set(self, cr, uid, id, name, value, arg, context=None): - # We don't handle setting data to null - if not value: - return True - if context is None: - context = {} - location = self.pool['ir.config_parameter'].get_param( - cr, uid, 'ir_attachment.location') - file_size = len(value.decode('base64')) - if location: - attach = self.browse(cr, uid, id, context=context) - if attach.store_fname: - self._file_delete(cr, uid, location, attach.store_fname) - fname = self._file_write(cr, uid, location, value) - # SUPERUSER_ID as probably don't have write access, - # trigger during create - super(ir_attachment, self).write( - cr, SUPERUSER_ID, [id], - {'store_fname': fname, 'file_size': file_size}, - context=context) - else: - # Don't save data if the document comes from DMS - if not context.get('bool_testdoc'): - value = None - super(ir_attachment, self).write( - cr, SUPERUSER_ID, [id], - {'db_datas': value, 'file_size': file_size}, context=context) - return True - - def _data_get(self, cr, uid, ids, name, arg, context=None): + @api.depends('id_dms') + @api.multi + def _data_get(self): """ Get data from DMS """ - if context is None: - context = {} - result = {} - location = self.pool['ir.config_parameter'].get_param( - cr, uid, 'ir_attachment.location') - bin_size = context.get('bin_size') - for attach in self.browse(cr, uid, ids, context=context): - datas = self.action_download(cr, uid, attach.id, context=context) - if location and attach.store_fname: - result[attach.id] = self._file_read( - cr, uid, location, attach.store_fname, bin_size) - elif len(attach.attachment_document_ids) == 0: - result[attach.id] = datas - else: - if attach.id_dms: - if datas: - result[attach.id] = datas - else: - result[attach.id] = '' - _logger.warn('Access error of DMS') - else: - result[attach.id] = '' - _logger.warn('Attachment %s has no id_dms', attach.name) - return result - - _columns = { - 'id_dms': fields.char('Id of Dms', help="Id of Dms."), - 'download_id': fields.one2many( - 'ir.attachment.download', - 'attachment_id', - 'Attachment download', - help="Attachment download" - ), - #'datas': fields.function( - # _data_get, - # fnct_inv=_data_set, - # string='File Content', - # type="binary", - # nodrop=True - #), - 'attachment_document_ids': fields.one2many( - 'ir.attachment.doc.backend', - 'attachment_id', - 'Records', - help="Records" - ), - } + self.ensure_one() + if self.id_dms: + self.datas = self.action_download() + super(IrAttachment, self)._data_get() diff --git a/cmis_write/models/ir_attachment_doc_backend.py b/cmis_write/models/ir_attachment_doc_backend.py index 85ca4c1..4234c25 100644 --- a/cmis_write/models/ir_attachment_doc_backend.py +++ b/cmis_write/models/ir_attachment_doc_backend.py @@ -2,28 +2,26 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm, fields +from openerp import fields, models -class ir_attachment_doc_backend(orm.Model): +class IrAttachmentDocBackend(models.Model): _description = "List of backend's document" _name = 'ir.attachment.doc.backend' - _columns = { - 'attachment_id': fields.many2one( - 'ir.model.fields', - 'Document', - ondelete='cascade', - help="Document" - ), - 'backend_id': fields.many2one( - 'cmis.backend', - 'Backend', - ondelete='cascade', - help="Backend" - ), - 'object_doc_id': fields.char( - "Id of document backend", - help="Id of document backend" - ), - } + attachment_id = fields.Many2one( + 'ir.model.fields', + 'Document', + ondelete='cascade', + help="Document" + ) + backend_id = fields.Many2one( + 'cmis.backend', + 'Backend', + ondelete='cascade', + help="Backend" + ) + object_doc_id = fields.Char( + "Id of document backend", + help="Id of document backend" + ) diff --git a/cmis_write/models/ir_attachment_download.py b/cmis_write/models/ir_attachment_download.py index 1563123..152981a 100644 --- a/cmis_write/models/ir_attachment_download.py +++ b/cmis_write/models/ir_attachment_download.py @@ -2,27 +2,17 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm, fields +from openerp import fields, models -class ir_attachment_download(orm.TransientModel): +class IrAttachmentDownload(models.TransientModel): _name = 'ir.attachment.download' - _columns = { - 'name': fields.char( - 'Attachment Name', - required=True, - help='Attachment Name' - ), - 'datas': fields.binary('File', readonly=True), - 'type': fields.char('Type', help='Type'), - 'file_type': fields.char('Content Type', help='Content Type'), - 'attachment_id': fields.many2one( - 'ir.attachment', - 'Attachment', - help="Attachment" - ), - } - _defaults = { - 'type': 'binary', - } + name = fields.Char( + 'Attachment Name', required=True, help='Attachment Name') + datas = fields.Binary('File', readonly=True) + type = fields.Char(default='binary') + file_type = fields.Char('Content Type', help='Content Type') + attachment_id = fields.Many2one( + 'ir.attachment', 'Attachment', help="Attachment" + ) diff --git a/cmis_write/models/metadata.py b/cmis_write/models/metadata.py index 5cfdb49..fbc642a 100644 --- a/cmis_write/models/metadata.py +++ b/cmis_write/models/metadata.py @@ -2,54 +2,60 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm, fields +from openerp import api, fields, models -class metadata(orm.Model): +class Metadata(models.Model): _name = "metadata" _description = "Metadata" - _columns = { - 'name': fields.char("Name", required=True, select=1, help="Name"), - 'model_id': fields.many2one( - 'ir.model', - 'Model', - required=True, - select=1, - help="Model" - ), - 'field_ids': fields.many2many( - 'ir.model.fields', - 'metadata_field_rel', - 'meta_id', 'field_id', - 'Fields', - help="Fields" - ), - 'metadata_list_ids': fields.one2many( - 'metadata.list', - 'metadata_id', - 'List of fields', - help="List of fields" - ), - 'model_ids': fields.many2many( - 'ir.model', - string='Model List', - help="Model List" - ), - } + name = fields.Char("Name", required=True, select=1, help="Name") + model_id = fields.Many2one( + 'ir.model', + 'Model', + required=True, + select=1, + ) + field_ids = fields.Many2many( + 'ir.model.fields', + 'metadata_field_rel', + 'meta_id', 'field_id', + 'Fields', + ) + metadata_list_ids = fields.One2many( + 'metadata.list', + 'metadata_id', + 'List of fields', + help="List of fields" + ) + model_ids = fields.Many2many( + 'ir.model', + string='Model List', + help="Model List" + ) - def onchange_model(self, cr, uid, ids, model_id, context=None): - if context is None: - context = {} - if not model_id: - return {'value': {'model_ids': [(6, 0, [])]}} - model_ids = [model_id] - model_obj = self.pool.get('ir.model') - active_model_obj = self.pool.get(model_obj.browse( - cr, uid, model_id, context=context).model) - if active_model_obj._inherits: - for key, val in active_model_obj._inherits.items(): - found_model_ids = model_obj.search(cr, - uid, [('model', '=', key)], - context=context) - model_ids += found_model_ids - return {'value': {'model_ids': [(6, 0, model_ids)]}} + @api.model + def extract_metadata(self, instance): + """Extract metadata for the given model instance + """ + metadata = {} + if not instance: + return metadata + # Get list of metadata + fields = self.env['metadata.list'].search([ + ('metadata_id.model_id.model', '=', instance._name)]) + list_fields = fields.mapped('field_id.name') + for attr in list_fields: + metadata['cmis:' + attr] = getattr(instance, attr) + return metadata + + @api.onchange('model_id') + def onchange_model(self): + if not self.model_id: + self.model_ids = [(6, 0, [])] + model_ids = [self.model_id.id] + if self.model_id._inherits: + for key in self.model_id._inherits.keys(): + found_model_ids = self.model_id.search( + [('model', '=', key)]) + model_ids += found_model_ids._ids + self.model_ids = [(6, 0, model_ids)] diff --git a/cmis_write/models/metadata_list.py b/cmis_write/models/metadata_list.py index 99d979e..bd50ab8 100644 --- a/cmis_write/models/metadata_list.py +++ b/cmis_write/models/metadata_list.py @@ -2,22 +2,20 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.osv import orm, fields +from openerp import fields, models -class metadata_list(orm.Model): +class MetadataList(models.Model): _description = 'List of Metadata' _name = 'metadata.list' - _columns = { - 'field_id': fields.many2one( - 'ir.model.fields', - 'Fields', - help="Fields" - ), - 'metadata_id': fields.many2one( - 'metadata', - 'Metadata', - help="Metadata" - ), - } + field_id = fields.Many2one( + 'ir.model.fields', + 'Fields', + help="Fields" + ) + metadata_id = fields.Many2one( + 'metadata', + 'Metadata', + help="Metadata" + ) diff --git a/cmis_write/unit/import_synchronizer.py b/cmis_write/unit/import_synchronizer.py index a400946..9c9c500 100644 --- a/cmis_write/unit/import_synchronizer.py +++ b/cmis_write/unit/import_synchronizer.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + import base64 import logging from openerp.addons.connector.queue.job import job @@ -9,40 +10,28 @@ @job -def create_doc_in_edm(session, model_name, value, res, +def create_doc_in_edm(session, model_name, res, dict_metadata, user_login, filters=None): """ This method allows to create a doc from Odoo to DMS """ - cr = session.cr - uid = session.uid - context = session.context - if context is None: - context = {} - ir_attach_obj = session.pool.get('ir.attachment') - ir_attach_doc_backend_obj = session.pool.get('ir.attachment.doc.backend') - cmis_backend_obj = session.pool.get('cmis.backend') + ir_attach = session.env['ir.attachment'].browse(res) + ir_attach_doc_backend_obj = session.env['ir.attachment.doc.backend'] # List of backend with storing_ok is True - ids = cmis_backend_obj.search( - cr, uid, [('storing_ok', '=', 'True')], context=context) + backends = session.env['cmis.backend'].search( + [('storing_ok', '=', 'True')]) - for backend in session.browse('cmis.backend', ids): + for backend in backends: try: - repo = cmis_backend_obj.check_auth( - cr, uid, [backend.id], context=context) + repo = backend.check_auth() root = repo.rootFolder folder_path = backend.initial_directory_write # Document properties - if value.get('name'): - file_name = value.get('name') - elif value.get('datas_fname'): - file_name = value.get('datas_fname') - else: - file_name = value.get('datas_fname') + file_name = ir_attach.name props = { - 'cmis:name': file_name, - 'cmis:description': value.get('description'), + 'cmis:name': ir_attach.name, + 'cmis:description': ir_attach.description, 'cmis:createdBy': user_login, } # Add list of metadata in props @@ -56,20 +45,18 @@ def create_doc_in_edm(session, model_name, value, res, someDoc = sub1.createDocumentFromString( file_name, contentString=base64.b64decode( - value.get('datas')), contentType=value.get('file_type') + ir_attach.datas), contentType=ir_attach.mimetype ) # TODO: create custom properties on a document (Alfresco) # someDoc.getProperties().update(props) # Updating ir.attachment object with the new id # of document generated by DMS - ir_attach_obj.write(cr, uid, res, { - 'id_dms': someDoc.getObjectId()}, context=context) - ir_attach_doc_backend_obj.create( - cr, uid, { + ir_attach.id_dms = someDoc.getObjectId() + ir_attach_doc_backend_obj.create({ 'attachment_id': res, 'backend_id': backend.id, - 'object_doc_id': someDoc.getObjectId(), - }, context=context) + 'object_doc_id': ir_attach.id_dms, + }) _logger.warn('Attachment saved in DMS %s', backend.name) except: _logger.warn('Cannot save the attachment in DMS %s', backend.name) From 447b36e4f03f891b7bd7fb83f3276cc156988d32 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 18 Feb 2016 12:09:28 +0100 Subject: [PATCH 26/46] [MIG] Use new API --- cmis_write/models/ir_attachment.py | 26 ++++++++--- cmis_write/tests/test_ir_attachment.py | 57 +++++++----------------- cmis_write/tests/test_metadata.py | 61 +++++++++++--------------- cmis_write/unit/import_synchronizer.py | 4 +- 4 files changed, 63 insertions(+), 85 deletions(-) diff --git a/cmis_write/models/ir_attachment.py b/cmis_write/models/ir_attachment.py index 6534fe4..6d1f758 100644 --- a/cmis_write/models/ir_attachment.py +++ b/cmis_write/models/ir_attachment.py @@ -20,6 +20,7 @@ class IrAttachment(models.Model): 'Attachment download', help="Attachment download" ) + datas = fields.Binary( compute='_data_get', inverse='_data_set') @@ -54,14 +55,18 @@ def action_download(self): """ self.ensure_one() cmis_backend_obj = self.env['cmis.backend'] - backend = cmis_backend_obj.search(('storing_ok', '=', 'True')) + backend = cmis_backend_obj.search([('storing_ok', '=', 'True')]) backend.ensure_one() - repo = cmis_backend_obj.check_auth() + repo = backend.check_auth() # Get results from id of document query = " SELECT * FROM cmis:document \ WHERE cmis:objectId ='" + self.id_dms + "'" results = repo.query(query) - datas = results[0].getContentStream().read().encode( + # workaround bug in cmislib 0.5.1 + # https://issues.apache.org/jira/browse/CMIS-701 + result = results[0] + result.reload() + datas = result.getContentStream().read().encode( 'base64') return datas @@ -71,7 +76,14 @@ def _data_get(self): """ Get data from DMS """ - self.ensure_one() - if self.id_dms: - self.datas = self.action_download() - super(IrAttachment, self)._data_get() + for rec in self: + if rec.id_dms: + rec.datas = rec.action_download() + else: + rec.datas = super(IrAttachment, rec)._data_get( + 'datas', None)[rec.id] + + @api.multi + def _data_set(self): + for rec in self: + super(IrAttachment, rec)._data_set('datas', rec.datas, None) diff --git a/cmis_write/tests/test_ir_attachment.py b/cmis_write/tests/test_ir_attachment.py index 45846ca..ecc9bc9 100644 --- a/cmis_write/tests/test_ir_attachment.py +++ b/cmis_write/tests/test_ir_attachment.py @@ -4,7 +4,6 @@ ############################################################################### from openerp.tests.common import TransactionCase -from openerp.osv.orm import except_orm class test_ir_attachment(TransactionCase): @@ -12,22 +11,18 @@ class test_ir_attachment(TransactionCase): def setUp(self): super(test_ir_attachment, self).setUp() # Clean up registries - self.registry('ir.model').clear_caches() - self.registry('ir.model.data').clear_caches() + self.env['ir.model'].clear_caches() + self.env['ir.model.data'].clear_caches() # Get registries - self.user_model = self.registry("res.users") - self.ir_attachment_model = self.registry("ir.attachment") - self.partner_model = self.registry('res.partner') - self.metadata_model = self.registry('metadata') - # Get context - self.context = self.user_model.context_get(self.cr, self.uid) - + self.user_model = self.env["res.users"] + self.ir_attachment_model = self.env["ir.attachment"] + self.partner_model = self.env['res.partner'] + self.metadata_model = self.env['metadata'] partner_id = self.partner_model.create( - self.cr, self.uid, {'name': 'Test Partner', 'email': 'test@localhost', 'is_company': True, - }, context=None) + }) blob1 = 'blob1' blob1_b64 = blob1.encode('base64') @@ -43,33 +38,13 @@ def setUp(self): } def test_create_ir_attachment(self): - cr, uid, vals, context = self.cr, self.uid, self.vals, self.context + vals = self.vals vals['datas'] = None - context['bool_testdoc'] = True - ir_attachment_id = self.ir_attachment_model.create( - cr, uid, vals, context=context) - ir_attachment_pool = self.ir_attachment_model.browse( - cr, uid, ir_attachment_id, context=context) - - self.assertEqual(ir_attachment_pool.name, vals['name']) - - def test_data_set(self): - cr, uid, vals = self.cr, self.uid, self.vals.copy() - context = self.context - ir_attachment_id = self.ir_attachment_model.create( - cr, uid, vals, context=context) - result = self.ir_attachment_model._data_set( - cr, uid, [], ir_attachment_id, '', - 'testdata'.encode('base64'), context=context) - self.assertEqual(result, True) - - def test_data_get(self): - cr, uid, vals = self.cr, self.uid, self.vals.copy() - context = self.context - vals['id_dms'] = '' - ir_attachment_id = self.ir_attachment_model.create( - cr, uid, vals, context=context) - self.assertRaises( - except_orm, self.ir_attachment_model._data_get, - cr, uid, [ir_attachment_id], None, None, context=self.context - ) + ir_attachment = self.ir_attachment_model.with_context( + bool_testdoc=True).create(vals) + self.assertEqual(ir_attachment.name, vals['name']) + + def test_data_get_set(self): + ir_attachment = self.ir_attachment_model.with_context( + bool_testdoc=True).create(self.vals) + self.assertTrue(ir_attachment.datas) diff --git a/cmis_write/tests/test_metadata.py b/cmis_write/tests/test_metadata.py index baff087..84ad131 100644 --- a/cmis_write/tests/test_metadata.py +++ b/cmis_write/tests/test_metadata.py @@ -10,53 +10,42 @@ class test_metadata(TransactionCase): def setUp(self): super(test_metadata, self).setUp() # Clean up registries - self.registry('ir.model').clear_caches() - self.registry('ir.model.data').clear_caches() + self.env['ir.model'].clear_caches() + self.env['ir.model.data'].clear_caches() # Get registries - self.user_model = self.registry("res.users") - self.ir_model_model = self.registry('ir.model') - self.fields_model = self.registry('ir.model.fields') - self.metadata_model = self.registry('metadata') + self.user_model = self.env["res.users"] + self.ir_model_model = self.env['ir.model'] + self.fields_model = self.env['ir.model.fields'] + self.metadata_model = self.env['metadata'] # Get context - self.context = self.user_model.context_get(self.cr, self.uid) - self.ir_model_id = self.ir_model_model.search( - self.cr, self.uid, [('model', '=', 'res.partner')], - context=self.context)[0] - - self.field_id = self.fields_model.create( - self.cr, self.uid, - {'name': 'test', + self.ir_model = self.ir_model_model.search( + [('model', '=', 'res.partner')])[0] + + self.field = self.fields_model.create( + {'name': 'x_test', 'field_description': 'test', - 'model_id': self.ir_model_id, + 'model_id': self.ir_model.id, 'ttype': 'char', - }, context=None) + }) self.vals = { 'name': 'Test', - 'model_id': self.ir_model_id, - 'field_ids': [(4, self.field_id)], + 'model_id': self.ir_model.id, + 'field_ids': [(4, self.field.id)], 'metadata_list_ids': [(0, 0, { - 'field_id': self.field_id, + 'field_id': self.field.id, })], - 'model_ids': [(4, self.ir_model_id)], + 'model_ids': [(4, self.ir_model.id)], } def test_create_metadata(self): - cr, uid, vals, context = self.cr, self.uid, self.vals, self.context - metadata_id = self.metadata_model.create( - cr, uid, vals, context=context) - metadata_pool = self.metadata_model.browse( - cr, uid, metadata_id, context=context) - self.assertEqual(metadata_pool.name, vals['name']) - self.assertEqual(metadata_pool.model_id.id, vals['model_id']) + metadata = self.metadata_model.create(self.vals) + self.assertEqual(metadata.name, self.vals['name']) + self.assertEqual(metadata.model_id.id, self.vals['model_id']) def test_onchange_model(self): - cr, uid, vals, context = self.cr, self.uid, self.vals, self.context - res = self.metadata_model.onchange_model( - cr, uid, [], vals['model_id'], context=context) - vals['model_ids'] = res['value']['model_ids'] - metadata_id = self.metadata_model.create( - cr, uid, vals, context=context) - metadata_pool = self.metadata_model.browse( - cr, uid, metadata_id, context=context) - self.assertEqual(metadata_pool.name, vals['name']) + metadata = self.metadata_model.create(self.vals) + self.assertEqual(metadata.name, self.vals['name']) + self.assertEqual(metadata.model_id.id, self.vals['model_id']) + self.assertEqual(len(metadata.model_ids), 1) + self.assertEqual(metadata.model_ids[0], self.ir_model) diff --git a/cmis_write/unit/import_synchronizer.py b/cmis_write/unit/import_synchronizer.py index 9c9c500..ae9e634 100644 --- a/cmis_write/unit/import_synchronizer.py +++ b/cmis_write/unit/import_synchronizer.py @@ -51,7 +51,9 @@ def create_doc_in_edm(session, model_name, res, # someDoc.getProperties().update(props) # Updating ir.attachment object with the new id # of document generated by DMS - ir_attach.id_dms = someDoc.getObjectId() + ir_attach.write({ + 'id_dms': someDoc.getObjectId(), + 'datas': None}) ir_attach_doc_backend_obj.create({ 'attachment_id': res, 'backend_id': backend.id, From 218261a14dd3a5916df64133ffafdbf3319fffff Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 18 Feb 2016 12:28:31 +0100 Subject: [PATCH 27/46] [IMP]Only store attachment linked to a model in cmis --- cmis_write/models/ir_attachment.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmis_write/models/ir_attachment.py b/cmis_write/models/ir_attachment.py index 6d1f758..c09dc0a 100644 --- a/cmis_write/models/ir_attachment.py +++ b/cmis_write/models/ir_attachment.py @@ -32,13 +32,24 @@ class IrAttachment(models.Model): help="Records" ) + @api.multi + def must_be_stored_in_cmis(self): + self.ensure_one() + if 'bool_testdoc' in self.env.context: + return False + if not self.res_model: + return False + return True + @api.model def create(self, values): res = super(IrAttachment, self).create(values) session = ConnectorSession.from_env(self.env) # if bool_testdoc in context, we don't need to create # the doc in the DMS - if 'bool_testdoc' not in self.env.context: + # if the attachment is not linked to a model, we dont create the doc + # in DMSt + if res.must_be_stored_in_cmis(): metadata = {} if res.res_model: metadata = self.env['metadata'].extract_metadata( From c630be1ee066dc7e698ce1bbfb709d961cd1352e Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 09:04:48 +0200 Subject: [PATCH 28/46] [IMP] Rename backend_id to cmis_backend_id --- cmis_write/i18n/fr.po | 4 ++-- cmis_write/models/ir_attachment_doc_backend.py | 6 ++++-- cmis_write/unit/import_synchronizer.py | 2 +- cmis_write/views/document_view.xml | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmis_write/i18n/fr.po b/cmis_write/i18n/fr.po index f6b7345..e0f43a9 100644 --- a/cmis_write/i18n/fr.po +++ b/cmis_write/i18n/fr.po @@ -203,7 +203,7 @@ msgid "File" msgstr "Fichier" #. module: cmis_write -#: field:ir.attachment.doc.backend,backend_id:0 -#: help:ir.attachment.doc.backend,backend_id:0 +#: field:ir.attachment.doc.backend,cmis_backend_id:0 +#: help:ir.attachment.doc.backend,cmis_backend_id:0 msgid "Backend" msgstr "Backend" diff --git a/cmis_write/models/ir_attachment_doc_backend.py b/cmis_write/models/ir_attachment_doc_backend.py index 4234c25..e1e1df9 100644 --- a/cmis_write/models/ir_attachment_doc_backend.py +++ b/cmis_write/models/ir_attachment_doc_backend.py @@ -15,11 +15,13 @@ class IrAttachmentDocBackend(models.Model): ondelete='cascade', help="Document" ) - backend_id = fields.Many2one( + cmis_backend_id = fields.Many2one( 'cmis.backend', 'Backend', ondelete='cascade', - help="Backend" + help="Backend", + oldname='backend_id' + ) object_doc_id = fields.Char( "Id of document backend", diff --git a/cmis_write/unit/import_synchronizer.py b/cmis_write/unit/import_synchronizer.py index ae9e634..d833158 100644 --- a/cmis_write/unit/import_synchronizer.py +++ b/cmis_write/unit/import_synchronizer.py @@ -56,7 +56,7 @@ def create_doc_in_edm(session, model_name, res, 'datas': None}) ir_attach_doc_backend_obj.create({ 'attachment_id': res, - 'backend_id': backend.id, + 'cmis_backend_id': backend.id, 'object_doc_id': ir_attach.id_dms, }) _logger.warn('Attachment saved in DMS %s', backend.name) diff --git a/cmis_write/views/document_view.xml b/cmis_write/views/document_view.xml index 63e396e..f7344b9 100644 --- a/cmis_write/views/document_view.xml +++ b/cmis_write/views/document_view.xml @@ -12,11 +12,11 @@ - +
- + From 11dc8780e9219ee7fdd50ededfef7f8f2b9d71bb Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 10:31:40 +0200 Subject: [PATCH 29/46] [PEP8] --- cmis_write/models/ir_attachment.py | 4 ++-- cmis_write/models/ir_attachment_doc_backend.py | 1 - cmis_write/unit/import_synchronizer.py | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmis_write/models/ir_attachment.py b/cmis_write/models/ir_attachment.py index c09dc0a..a6a76bb 100644 --- a/cmis_write/models/ir_attachment.py +++ b/cmis_write/models/ir_attachment.py @@ -47,7 +47,7 @@ def create(self, values): session = ConnectorSession.from_env(self.env) # if bool_testdoc in context, we don't need to create # the doc in the DMS - # if the attachment is not linked to a model, we dont create the doc + # if the attachment is not linked to a model, we dont create the doc # in DMSt if res.must_be_stored_in_cmis(): metadata = {} @@ -73,7 +73,7 @@ def action_download(self): query = " SELECT * FROM cmis:document \ WHERE cmis:objectId ='" + self.id_dms + "'" results = repo.query(query) - # workaround bug in cmislib 0.5.1 + # workaround bug in cmislib 0.5.1 # https://issues.apache.org/jira/browse/CMIS-701 result = results[0] result.reload() diff --git a/cmis_write/models/ir_attachment_doc_backend.py b/cmis_write/models/ir_attachment_doc_backend.py index e1e1df9..bc3e5d6 100644 --- a/cmis_write/models/ir_attachment_doc_backend.py +++ b/cmis_write/models/ir_attachment_doc_backend.py @@ -21,7 +21,6 @@ class IrAttachmentDocBackend(models.Model): ondelete='cascade', help="Backend", oldname='backend_id' - ) object_doc_id = fields.Char( "Id of document backend", diff --git a/cmis_write/unit/import_synchronizer.py b/cmis_write/unit/import_synchronizer.py index d833158..85f63a5 100644 --- a/cmis_write/unit/import_synchronizer.py +++ b/cmis_write/unit/import_synchronizer.py @@ -55,10 +55,10 @@ def create_doc_in_edm(session, model_name, res, 'id_dms': someDoc.getObjectId(), 'datas': None}) ir_attach_doc_backend_obj.create({ - 'attachment_id': res, - 'cmis_backend_id': backend.id, - 'object_doc_id': ir_attach.id_dms, - }) + 'attachment_id': res, + 'cmis_backend_id': backend.id, + 'object_doc_id': ir_attach.id_dms, + }) _logger.warn('Attachment saved in DMS %s', backend.name) except: _logger.warn('Cannot save the attachment in DMS %s', backend.name) From ce190b6a9e10eb083b01e8c6056541f8f966438f Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 11:14:39 +0200 Subject: [PATCH 30/46] [MIG] make cmis_write installable --- cmis_write/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmis_write/__openerp__.py b/cmis_write/__openerp__.py index afcf918..e81a152 100644 --- a/cmis_write/__openerp__.py +++ b/cmis_write/__openerp__.py @@ -25,6 +25,6 @@ 'qweb': [], 'test': [], 'demo': [], - 'installable': False, + 'installable': True, 'auto_install': False, } From 7b1686ae52e3b359f182030c2ae6774dd54ad799 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Fri, 19 Feb 2016 18:59:57 +0100 Subject: [PATCH 31/46] [IMP] Add abstract models for mixed content between Odoo and Alfresco --- cmis/README.rst | 6 +++- cmis/models/__init__.py | 2 ++ cmis/models/cmis_backend.py | 19 +++++++++++++ cmis/models/cmis_folder.py | 50 ++++++++++++++++++++++++++++++++++ cmis/models/cmis_object_ref.py | 25 +++++++++++++++++ cmis/unit/backend_adapter.py | 4 ++- 6 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 cmis/models/cmis_folder.py create mode 100644 cmis/models/cmis_object_ref.py diff --git a/cmis/README.rst b/cmis/README.rst index b7f492a..d877b60 100644 --- a/cmis/README.rst +++ b/cmis/README.rst @@ -13,7 +13,11 @@ It allows you to configure a CMIS backend in Odoo. Installation ============ -No installation required: +To be compliant with the latest version of CMIS (1.1), the connector use +the latest version of the python cmislib library not yet released at this +stage. The lib can be installed with: + +pip install svn+https://svn.apache.org/repos/asf/chemistry/cmislib/trunk#egg=cmislib Configuration ============= diff --git a/cmis/models/__init__.py b/cmis/models/__init__.py index 088724c..7ddb65e 100644 --- a/cmis/models/__init__.py +++ b/cmis/models/__init__.py @@ -5,4 +5,6 @@ from . import ( cmis_backend, cmis_binding, + cmis_object_ref, + cmis_folder, ) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 0e3332f..0e257a0 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -2,6 +2,7 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import cmislib.exceptions +from cmislib.exceptions import ObjectNotFoundException from openerp import api, fields, models from openerp.exceptions import Warning @@ -93,6 +94,24 @@ def check_directory_of_read(self): bool_path_read = self.check_existing_path(rs, folder_path_read) self.get_error_for_path(bool_path_read, folder_path_read) + @api.multi + def get_object_by_path(self, path, create_if_not_found=True): + self.ensure_one() + repo = self.check_auth() + traversed = [] + for part in path.split('/'): + try: + part = '%s' % part + traversed.append(part) + new_root = repo.getObjectByPath('/'.join(traversed)) + except ObjectNotFoundException: + if create_if_not_found: + new_root = repo.createFolder(root, part) + else: + return False + root = new_root + return root + def check_existing_path(self, rs, folder_path): """Function to check if the path is correct""" for one_rs in rs: diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py new file mode 100644 index 0000000..f327378 --- /dev/null +++ b/cmis/models/cmis_folder.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models +from openerp.exceptions import Warning +from openerp.tools.translate import _ + + +class CmisFolder(models.AbstractModel): + """A model linked to a folder into cmis + """ + _name = 'cmis.folder' + _inherit = 'cmis.object.ref' + + name = fields.Char() + + @api.model + def get_initial_directory_write(self, backend): + return '/'.join([backend.initial_directory_write, + self._name.replace('.', '_')]) + + @api.multi + def _create_cmis_content(self, backend, parent_cmis_object): + self.ensure_one() + repo = backend.check_auth() + new_folder = repo.createFolder(parent_cmis_object, self.name) + return new_folder.getProperties()['cmis:objectId'] + + @api.multi + def create_in_cmis(self, backend_id): + backend = self.env['cmis.backend'].browse(backend_id) + backend.ensure_one() + vals ={} + for rec in self: + if rec.cmis_objectid: + raise Warning( + _("Folder %s already exists in CMIS (backend: %s)" % ( + rec.name, rec.backend_id.name))) + parent_cmis_object = backend.get_object_by_path( + self.get_initial_directory_write(backend), + create_if_not_found=True) + cmis_objectid = rec._create_cmis_content( + backend, parent_cmis_object) + rec.write({ + 'cmis_objectid': cmis_objectid, + 'bakend_id': backend.id + }) + vals[rec.id] = cmis_objectid + return vals diff --git a/cmis/models/cmis_object_ref.py b/cmis/models/cmis_object_ref.py new file mode 100644 index 0000000..6f7c62f --- /dev/null +++ b/cmis/models/cmis_object_ref.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# © 2016 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models +from openerp.tools.translate import _ + + +class CmisObjectRef(models.AbstractModel): + """A technical model to hold a reference to an object into + a cmis container + """ + _name = 'cmis.object.ref' + + cmis_objectid = fields.Char( + string="CMIS ObjectId", requried=True, index=True) + backend_id = fields.Many2one( + comodel_name="cmis.backend", + string="Backend") + + _sql_constraints = [ + ('cmis_object_ref_uniq', + 'unique (objectid, backend_id)', + "Cmis object Id must be uniquein a given backend !"), + ] diff --git a/cmis/unit/backend_adapter.py b/cmis/unit/backend_adapter.py index df30e89..c0d42fe 100644 --- a/cmis/unit/backend_adapter.py +++ b/cmis/unit/backend_adapter.py @@ -4,6 +4,7 @@ from cmislib.model import CmisClient import cmislib.exceptions +from cmislib.browser.binding import BrowserBinding import urllib2 from openerp.tools.translate import _ @@ -19,7 +20,8 @@ def _auth(self, cmis_backend): client = CmisClient( cmis_backend.location, cmis_backend.username, - cmis_backend.password) + cmis_backend.password, + binding=BrowserBinding()) try: return client.defaultRepository From a4eca7343fd62f57bfc16e27b199c1c5e2c0d954 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Sun, 21 Feb 2016 22:44:10 +0100 Subject: [PATCH 32/46] [IMP] Better function naming --- cmis/models/cmis_backend.py | 5 ++++- cmis/models/cmis_folder.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 0e257a0..5e680f6 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -95,9 +95,12 @@ def check_directory_of_read(self): self.get_error_for_path(bool_path_read, folder_path_read) @api.multi - def get_object_by_path(self, path, create_if_not_found=True): + def get_folder_by_path(self, path, create_if_not_found=True, + cmis_parent_objectid=None): self.ensure_one() repo = self.check_auth() + if cmis_parent_objectid: + repo = repo.getObject(cmis_parent_objectid) traversed = [] for part in path.split('/'): try: diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py index f327378..37a6fc8 100644 --- a/cmis/models/cmis_folder.py +++ b/cmis/models/cmis_folder.py @@ -37,7 +37,7 @@ def create_in_cmis(self, backend_id): raise Warning( _("Folder %s already exists in CMIS (backend: %s)" % ( rec.name, rec.backend_id.name))) - parent_cmis_object = backend.get_object_by_path( + parent_cmis_object = backend.get_folder_by_path( self.get_initial_directory_write(backend), create_if_not_found=True) cmis_objectid = rec._create_cmis_content( From c10639193cab0b79625c8c85a454af97f9e0b185 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Fri, 26 Feb 2016 15:31:23 +0100 Subject: [PATCH 33/46] [FIX] Improve logic --- cmis/models/cmis_backend.py | 3 ++- cmis/models/cmis_folder.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 5e680f6..d1986de 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -100,7 +100,8 @@ def get_folder_by_path(self, path, create_if_not_found=True, self.ensure_one() repo = self.check_auth() if cmis_parent_objectid: - repo = repo.getObject(cmis_parent_objectid) + path = repo.getObject( + cmis_parent_objectid).getPaths()[0] + '/' + path traversed = [] for part in path.split('/'): try: diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py index 37a6fc8..d78fa99 100644 --- a/cmis/models/cmis_folder.py +++ b/cmis/models/cmis_folder.py @@ -44,7 +44,7 @@ def create_in_cmis(self, backend_id): backend, parent_cmis_object) rec.write({ 'cmis_objectid': cmis_objectid, - 'bakend_id': backend.id + 'backend_id': backend.id }) vals[rec.id] = cmis_objectid return vals From 68c1240eb7358571b5f8128e46830232c6c8b709 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 9 Mar 2016 12:58:34 +0100 Subject: [PATCH 34/46] [FIX] Disable SSL certificat validation --- cmis/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmis/__init__.py b/cmis/__init__.py index c30a784..62563c5 100644 --- a/cmis/__init__.py +++ b/cmis/__init__.py @@ -2,6 +2,14 @@ # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import httplib2 +import functools +logger = logging.getLogger(__name__) + +logger.warning('Disable SSL Certificate Validation by python code') +httplib2.Http = functools.partial( + httplib2.Http, disable_ssl_certificate_validation=True) + from . import ( backend, models, From b477fb6b71b92f74c031e311c78ef3b83ea68120 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 9 Mar 2016 13:05:31 +0100 Subject: [PATCH 35/46] FIX --- cmis/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmis/__init__.py b/cmis/__init__.py index 62563c5..a806aa9 100644 --- a/cmis/__init__.py +++ b/cmis/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2014-2015 Savoir-faire Linux (). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - +import logging import httplib2 import functools logger = logging.getLogger(__name__) From 640a8826d8c132f24cc4f753d01a31b67a6c9b84 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 10 Mar 2016 12:12:11 +0100 Subject: [PATCH 36/46] [IMP] Add a more explicit error message when checking the CMIS paramters and log the original exception --- cmis/i18n/fr.po | 17 +++++++++++++---- cmis/unit/backend_adapter.py | 12 ++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmis/i18n/fr.po b/cmis/i18n/fr.po index 3b315bc..0824870 100644 --- a/cmis/i18n/fr.po +++ b/cmis/i18n/fr.po @@ -25,11 +25,12 @@ msgid "CMIS Backend" msgstr "Backend CMIS" #. module: cmis -#: code:addons/cmis/unit/backend_adapter.py:55 -#: code:addons/cmis/unit/backend_adapter.py:58 +#: code:addons/cmis/unit/backend_adapter.py:34 #, python-format -msgid "Check your CMIS account configuration." -msgstr "Vérifier la configuration de compte CMIS" +msgid "CMIS backend not found.\n" +"Check your CMIS account configuration." +msgstr "Backend CMIS non trouvé.\n" +"Vérifier la configuration de compte CMIS." #. module: cmis #: code:addons/cmis/unit/backend_adapter.py:54 @@ -98,6 +99,14 @@ msgstr "Permettre le stockage dans ce backend" msgid "Path is correct for : %s" msgstr "Le chemin est correct pour : %s" +#. module: cmis +#: code:addons/cmis/unit/backend_adapter.py:39 +#, python-format +msgid "Permission denied.\n" +"Check your CMIS account configuration." +msgstr "Permission refusée.\n" +"Vérifier la configuration de compte CMIS." + #. module: cmis #: view:cmis.backend:0 msgid "Cmis Configuration" diff --git a/cmis/unit/backend_adapter.py b/cmis/unit/backend_adapter.py index c0d42fe..edd20fe 100644 --- a/cmis/unit/backend_adapter.py +++ b/cmis/unit/backend_adapter.py @@ -6,11 +6,14 @@ import cmislib.exceptions from cmislib.browser.binding import BrowserBinding import urllib2 +import logging from openerp.tools.translate import _ from openerp.addons.connector.unit.backend_adapter import CRUDAdapter from openerp.addons.cmis.exceptions import CMISConnectionError +logger = logging.getLogger(__name__) + class CmisAdapter(CRUDAdapter): @@ -26,11 +29,16 @@ def _auth(self, cmis_backend): try: return client.defaultRepository except cmislib.exceptions.ObjectNotFoundException: + logger.exception("CMIS backend not found") raise CMISConnectionError( - _("Check your CMIS account configuration.")) + _("CMIS backend not found.\n" + "Check your CMIS account configuration.")) except cmislib.exceptions.PermissionDeniedException: + logger.exception("Permission denied") raise CMISConnectionError( - _("Check your CMIS account configuration.")) + _("Permission denied.\n" + "Check your CMIS account configuration.")) except urllib2.URLError: + logger.exception("UrlError") raise CMISConnectionError( _("SERVER is down.")) From 9fc6b2551e8656db758529c3055b9daa7c21dcac Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 16 Mar 2016 09:26:38 +0100 Subject: [PATCH 37/46] [FIX] Remove field name on cmis.folder --- cmis/models/cmis_folder.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py index d78fa99..423ed97 100644 --- a/cmis/models/cmis_folder.py +++ b/cmis/models/cmis_folder.py @@ -13,11 +13,9 @@ class CmisFolder(models.AbstractModel): _name = 'cmis.folder' _inherit = 'cmis.object.ref' - name = fields.Char() - @api.model def get_initial_directory_write(self, backend): - return '/'.join([backend.initial_directory_write, + return '/'.join([backend.initial_directory_write, self._name.replace('.', '_')]) @api.multi @@ -31,7 +29,7 @@ def _create_cmis_content(self, backend, parent_cmis_object): def create_in_cmis(self, backend_id): backend = self.env['cmis.backend'].browse(backend_id) backend.ensure_one() - vals ={} + vals = {} for rec in self: if rec.cmis_objectid: raise Warning( From cce4311d7fe2ddcbd69951dfb5cbc06e5f30b549 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Wed, 16 Mar 2016 18:05:30 +0100 Subject: [PATCH 38/46] [IMP] Add computed field to get the name of the cmis folder to create --- cmis/models/cmis_folder.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py index 423ed97..dcdbe48 100644 --- a/cmis/models/cmis_folder.py +++ b/cmis/models/cmis_folder.py @@ -13,6 +13,14 @@ class CmisFolder(models.AbstractModel): _name = 'cmis.folder' _inherit = 'cmis.object.ref' + cmis_folder_name = fields.Char(compute='get_names_for_cmis_folder') + + @api.multi + def get_names_for_cmis_folder(self): + names = dict(self.name_get()) + for rec in self: + rec.cmis_folder_name = names[rec.id] + @api.model def get_initial_directory_write(self, backend): return '/'.join([backend.initial_directory_write, @@ -22,7 +30,8 @@ def get_initial_directory_write(self, backend): def _create_cmis_content(self, backend, parent_cmis_object): self.ensure_one() repo = backend.check_auth() - new_folder = repo.createFolder(parent_cmis_object, self.name) + new_folder = repo.createFolder( + parent_cmis_object, self.cmis_folder_name) return new_folder.getProperties()['cmis:objectId'] @api.multi From e08dee3ce37dc285717d4fcf8d7ab81df015a9d0 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 17 Mar 2016 17:22:55 +0100 Subject: [PATCH 39/46] [IMP] Modularity: allow to specify properties to use when creating a cmis:object --- cmis/models/cmis_folder.py | 42 +++--------------------- cmis/models/cmis_object_ref.py | 60 +++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py index dcdbe48..2f609fa 100644 --- a/cmis/models/cmis_folder.py +++ b/cmis/models/cmis_folder.py @@ -3,7 +3,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import api, fields, models -from openerp.exceptions import Warning from openerp.tools.translate import _ @@ -12,46 +11,13 @@ class CmisFolder(models.AbstractModel): """ _name = 'cmis.folder' _inherit = 'cmis.object.ref' - - cmis_folder_name = fields.Char(compute='get_names_for_cmis_folder') - - @api.multi - def get_names_for_cmis_folder(self): - names = dict(self.name_get()) - for rec in self: - rec.cmis_folder_name = names[rec.id] - - @api.model - def get_initial_directory_write(self, backend): - return '/'.join([backend.initial_directory_write, - self._name.replace('.', '_')]) + _cmis_object_type = 'cmis:folder' @api.multi - def _create_cmis_content(self, backend, parent_cmis_object): + def _create_cmis_object(self, backend, parent_cmis_object): self.ensure_one() + props = self._get_cmis_create_object_properties() repo = backend.check_auth() new_folder = repo.createFolder( - parent_cmis_object, self.cmis_folder_name) + parent_cmis_object, self.cmis_content_name, properties=props) return new_folder.getProperties()['cmis:objectId'] - - @api.multi - def create_in_cmis(self, backend_id): - backend = self.env['cmis.backend'].browse(backend_id) - backend.ensure_one() - vals = {} - for rec in self: - if rec.cmis_objectid: - raise Warning( - _("Folder %s already exists in CMIS (backend: %s)" % ( - rec.name, rec.backend_id.name))) - parent_cmis_object = backend.get_folder_by_path( - self.get_initial_directory_write(backend), - create_if_not_found=True) - cmis_objectid = rec._create_cmis_content( - backend, parent_cmis_object) - rec.write({ - 'cmis_objectid': cmis_objectid, - 'backend_id': backend.id - }) - vals[rec.id] = cmis_objectid - return vals diff --git a/cmis/models/cmis_object_ref.py b/cmis/models/cmis_object_ref.py index 6f7c62f..9c7aab8 100644 --- a/cmis/models/cmis_object_ref.py +++ b/cmis/models/cmis_object_ref.py @@ -2,7 +2,8 @@ # © 2016 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models +from openerp import api, fields, models +from openerp.exceptions import UserError from openerp.tools.translate import _ @@ -11,15 +12,66 @@ class CmisObjectRef(models.AbstractModel): a cmis container """ _name = 'cmis.object.ref' + _cmis_object_type = None # The object type in cmis ex :cmis:folder cmis_objectid = fields.Char( - string="CMIS ObjectId", requried=True, index=True) + string="CMIS ObjectId", requried=True, index=True, copy=False) backend_id = fields.Many2one( comodel_name="cmis.backend", - string="Backend") - + string="Backend", + copy=False) + + cmis_content_name = fields.Char(compute='get_names_for_cmis_content') + _sql_constraints = [ ('cmis_object_ref_uniq', 'unique (objectid, backend_id)', "Cmis object Id must be uniquein a given backend !"), ] + + @api.multi + def get_names_for_cmis_content(self): + names = dict(self.name_get()) + for rec in self: + rec.cmis_content_name = names[rec.id] + + @api.model + def get_initial_directory_write(self, backend): + return '/'.join([backend.initial_directory_write, + self._name.replace('.', '_')]) + + @api.multi + def _get_cmis_create_object_properties(self): + """Return a dictionary of cmis properties to apply when + creating the cmis object + """ + self.ensure_one() + ret = {} + if self._cmis_object_type: + ret['cmis:objectTypeId'] = self._cmis_object_type + return ret + + def _create_cmis_object(self, backend, parent_cmis_object): + raise NotImplementedError('Must be implemented by specific types') + + @api.multi + def create_in_cmis(self, backend_id): + backend = self.env['cmis.backend'].browse(backend_id) + backend.ensure_one() + vals = {} + for rec in self: + if rec.cmis_objectid: + raise UserError( + _("Object %s already exists in CMIS (backend: %s)" % ( + rec.name, rec.backend_id.name))) + parent_cmis_object = backend.get_folder_by_path( + self.get_initial_directory_write(backend), + create_if_not_found=True) + cmis_objectid = rec._create_cmis_object( + backend, parent_cmis_object) + rec.write({ + 'cmis_objectid': cmis_objectid, + 'backend_id': backend.id + }) + vals[rec.id] = cmis_objectid + return vals From e30eb69d03357f66d5323ab772a22a54f73143e3 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 09:07:55 +0200 Subject: [PATCH 40/46] [IMP] Rename backend_id to cmis_backend_id --- cmis/models/cmis_object_ref.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cmis/models/cmis_object_ref.py b/cmis/models/cmis_object_ref.py index 9c7aab8..bed4601 100644 --- a/cmis/models/cmis_object_ref.py +++ b/cmis/models/cmis_object_ref.py @@ -16,16 +16,17 @@ class CmisObjectRef(models.AbstractModel): cmis_objectid = fields.Char( string="CMIS ObjectId", requried=True, index=True, copy=False) - backend_id = fields.Many2one( + cmis_backend_id = fields.Many2one( comodel_name="cmis.backend", string="Backend", + oldname='backend_id', copy=False) cmis_content_name = fields.Char(compute='get_names_for_cmis_content') _sql_constraints = [ ('cmis_object_ref_uniq', - 'unique (objectid, backend_id)', + 'unique (objectid, cmis_backend_id)', "Cmis object Id must be uniquein a given backend !"), ] @@ -55,15 +56,15 @@ def _create_cmis_object(self, backend, parent_cmis_object): raise NotImplementedError('Must be implemented by specific types') @api.multi - def create_in_cmis(self, backend_id): - backend = self.env['cmis.backend'].browse(backend_id) + def create_in_cmis(self, cmis_backend_id): + backend = self.env['cmis.backend'].browse(cmis_backend_id) backend.ensure_one() vals = {} for rec in self: if rec.cmis_objectid: raise UserError( _("Object %s already exists in CMIS (backend: %s)" % ( - rec.name, rec.backend_id.name))) + rec.name, rec.cmis_backend_id.name))) parent_cmis_object = backend.get_folder_by_path( self.get_initial_directory_write(backend), create_if_not_found=True) @@ -71,7 +72,7 @@ def create_in_cmis(self, backend_id): backend, parent_cmis_object) rec.write({ 'cmis_objectid': cmis_objectid, - 'backend_id': backend.id + 'cmis_backend_id': backend.id }) vals[rec.id] = cmis_objectid return vals From 51f331530bd07fc067559bafecf97b84543f1687 Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Mon, 18 Apr 2016 10:42:18 +0200 Subject: [PATCH 41/46] [PEP8] --- cmis/__init__.py | 10 +++++----- cmis/models/cmis_backend.py | 4 ++-- cmis/models/cmis_folder.py | 3 +-- cmis/models/cmis_object_ref.py | 12 ++++++------ 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cmis/__init__.py b/cmis/__init__.py index a806aa9..0a6db3a 100644 --- a/cmis/__init__.py +++ b/cmis/__init__.py @@ -4,13 +4,13 @@ import logging import httplib2 import functools +from . import ( + backend, + models, +) + logger = logging.getLogger(__name__) logger.warning('Disable SSL Certificate Validation by python code') httplib2.Http = functools.partial( httplib2.Http, disable_ssl_certificate_validation=True) - -from . import ( - backend, - models, -) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index d1986de..542dab2 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -99,7 +99,7 @@ def get_folder_by_path(self, path, create_if_not_found=True, cmis_parent_objectid=None): self.ensure_one() repo = self.check_auth() - if cmis_parent_objectid: + if cmis_parent_objectid: path = repo.getObject( cmis_parent_objectid).getPaths()[0] + '/' + path traversed = [] @@ -110,7 +110,7 @@ def get_folder_by_path(self, path, create_if_not_found=True, new_root = repo.getObjectByPath('/'.join(traversed)) except ObjectNotFoundException: if create_if_not_found: - new_root = repo.createFolder(root, part) + new_root = repo.createFolder(new_root, part) else: return False root = new_root diff --git a/cmis/models/cmis_folder.py b/cmis/models/cmis_folder.py index 2f609fa..d210c61 100644 --- a/cmis/models/cmis_folder.py +++ b/cmis/models/cmis_folder.py @@ -2,8 +2,7 @@ # © 2016 ACSONE SA/NV () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models -from openerp.tools.translate import _ +from openerp import api, models class CmisFolder(models.AbstractModel): diff --git a/cmis/models/cmis_object_ref.py b/cmis/models/cmis_object_ref.py index bed4601..d924d87 100644 --- a/cmis/models/cmis_object_ref.py +++ b/cmis/models/cmis_object_ref.py @@ -20,14 +20,14 @@ class CmisObjectRef(models.AbstractModel): comodel_name="cmis.backend", string="Backend", oldname='backend_id', - copy=False) - + copy=False) + cmis_content_name = fields.Char(compute='get_names_for_cmis_content') - + _sql_constraints = [ - ('cmis_object_ref_uniq', - 'unique (objectid, cmis_backend_id)', - "Cmis object Id must be uniquein a given backend !"), + ('cmis_object_ref_uniq', + 'unique (objectid, cmis_backend_id)', + "Cmis object Id must be uniquein a given backend !"), ] @api.multi From 7bf3843485777fd8d19295d269e589227e62f0fd Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Fri, 27 May 2016 13:23:01 +0200 Subject: [PATCH 42/46] [IMP] Avoid searching for all folder paths to check if a path exists --- cmis/models/cmis_backend.py | 45 +++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index 542dab2..ee9a043 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -62,15 +62,15 @@ def check_directory_of_write(self): # login with the cmis account repo = this.check_auth() folder_path_write = this.initial_directory_write - # Testing the path - rs = repo.query("SELECT cmis:path FROM cmis:folder") - bool_path_write = self.check_existing_path(rs, folder_path_write) + path_write_objectid = self.get_folder_by_path( + folder_path_write, + create_if_not_found=False, + cmis_parent_objectid=None) # Check if we can create a doc from OE to EDM # Document properties - if bool_path_write: - sub = repo.getObjectByPath(folder_path_write) + if path_write_objectid: try: - sub.createDocumentFromString( + path_write_objectid.createDocumentFromString( datas_fname, contentString='hello, world', contentType='text/plain') @@ -81,7 +81,8 @@ def check_directory_of_write(self): except cmislib.exceptions.RuntimeException: raise CMISError( ("Please check your access right.")) - self.get_error_for_path(bool_path_write, folder_path_write) + self.get_error_for_path(path_write_objectid != False, + folder_path_write) @api.multi def check_directory_of_read(self): @@ -89,10 +90,12 @@ def check_directory_of_read(self): for this in self: repo = this.check_auth() folder_path_read = this.initial_directory_read - # Testing the path - rs = repo.query("SELECT cmis:path FROM cmis:folder ") - bool_path_read = self.check_existing_path(rs, folder_path_read) - self.get_error_for_path(bool_path_read, folder_path_read) + path_read_objectid = self.get_folder_by_path( + folder_path_read, + create_if_not_found=False, + cmis_parent_objectid=None) + self.get_error_for_path(path_read_objectid != False, + folder_path_read) @api.multi def get_folder_by_path(self, path, create_if_not_found=True, @@ -103,28 +106,22 @@ def get_folder_by_path(self, path, create_if_not_found=True, path = repo.getObject( cmis_parent_objectid).getPaths()[0] + '/' + path traversed = [] + try: + return repo.getObjectByPath(path) + except ObjectNotFoundException: + if not create_if_not_found: + return False + # The path doesn't exist and must be created for part in path.split('/'): try: part = '%s' % part traversed.append(part) new_root = repo.getObjectByPath('/'.join(traversed)) except ObjectNotFoundException: - if create_if_not_found: - new_root = repo.createFolder(new_root, part) - else: - return False + new_root = repo.createFolder(new_root, part) root = new_root return root - def check_existing_path(self, rs, folder_path): - """Function to check if the path is correct""" - for one_rs in rs: - # Print name of files - cmis_path = one_rs.getProperties()['cmis:path'] - if folder_path == cmis_path or folder_path in cmis_path: - return True - return False - def get_error_for_path(self, is_valid, path): """Return following the boolean the right error message""" if is_valid: From 19f3739ee19b513971a4560772318e2e027dd39c Mon Sep 17 00:00:00 2001 From: Laurent Mignon Date: Tue, 21 Jun 2016 16:03:08 +0200 Subject: [PATCH 43/46] Remove reference to read direcrtory --- cmis/i18n/fr.po | 15 --------------- cmis/models/cmis_backend.py | 19 ------------------- cmis/tests/test_model.py | 1 - cmis/views/cmis_backend_view.xml | 14 +------------- 4 files changed, 1 insertion(+), 48 deletions(-) diff --git a/cmis/i18n/fr.po b/cmis/i18n/fr.po index 0824870..9038e71 100644 --- a/cmis/i18n/fr.po +++ b/cmis/i18n/fr.po @@ -88,11 +88,6 @@ msgstr "Quelquechose s'est mal passé. _auth() a été appelé sans identifiant. msgid "Error path for : %s" msgstr "Erreur de chemin : %s" -#. module: cmis -#: field:cmis.backend,storing_ok:0 -msgid "Allow storing in this backend" -msgstr "Permettre le stockage dans ce backend" - #. module: cmis #: code:addons/cmis/cmis_backend.py:168 #, python-format @@ -112,11 +107,6 @@ msgstr "Permission refusée.\n" msgid "Cmis Configuration" msgstr "Configuration CMIS" -#. module: cmis -#: field:cmis.backend,initial_directory_read:0 -msgid "Initial directory for reading" -msgstr "Répertoire initial pour la lecture" - #. module: cmis #: field:cmis.binding,updated_on:0 msgid "Last Update in Dms" @@ -161,11 +151,6 @@ msgstr "Version" msgid "Initial directory for writing" msgstr "Répertoire initial pour l'écriture" -#. module: cmis -#: field:cmis.backend,browsing_ok:0 -msgid "Allow browsing this backend" -msgstr "Permettre la navigation dans ce backend" - #. module: cmis #: field:cmis.binding,dms_id:0 msgid "ID in Dms" diff --git a/cmis/models/cmis_backend.py b/cmis/models/cmis_backend.py index ee9a043..b169e74 100644 --- a/cmis/models/cmis_backend.py +++ b/cmis/models/cmis_backend.py @@ -28,14 +28,8 @@ class CmisBackend(models.Model): required=True) password = fields.Char( required=True) - initial_directory_read = fields.Char( - 'Initial directory for reading', required=True, default='/') initial_directory_write = fields.Char( 'Initial directory for writing', required=True, default='/') - browsing_ok = fields.Boolean( - 'Allow browsing this backend') - storing_ok = fields.Boolean( - 'Allow storing in this backend') @api.multi def _get_base_adapter(self): @@ -84,19 +78,6 @@ def check_directory_of_write(self): self.get_error_for_path(path_write_objectid != False, folder_path_write) - @api.multi - def check_directory_of_read(self): - """Check access right to read from the path""" - for this in self: - repo = this.check_auth() - folder_path_read = this.initial_directory_read - path_read_objectid = self.get_folder_by_path( - folder_path_read, - create_if_not_found=False, - cmis_parent_objectid=None) - self.get_error_for_path(path_read_objectid != False, - folder_path_read) - @api.multi def get_folder_by_path(self, path, create_if_not_found=True, cmis_parent_objectid=None): diff --git a/cmis/tests/test_model.py b/cmis/tests/test_model.py index 6d60852..4881ce8 100644 --- a/cmis/tests/test_model.py +++ b/cmis/tests/test_model.py @@ -25,7 +25,6 @@ def setUp(self): 'location': "http://localhost:8081/alfresco/s/cmis", 'username': 'admin', 'password': 'admin', - 'initial_directory_read': '/', 'initial_directory_write': '/', } diff --git a/cmis/views/cmis_backend_view.xml b/cmis/views/cmis_backend_view.xml index 025ef34..972ed69 100644 --- a/cmis/views/cmis_backend_view.xml +++ b/cmis/views/cmis_backend_view.xml @@ -23,23 +23,11 @@
- - -