Merge lp:~savoirfairelinux-openerp/knowledge-addons/cmis_read into lp:knowledge-addons/7.0

Status: Rejected
Rejected by: Sandy Carter (http://www.savoirfairelinux.com)
Proposed branch: lp:~savoirfairelinux-openerp/knowledge-addons/cmis_read
Merge into: lp:knowledge-addons/7.0
Diff against target: 582 lines (+530/-0)
9 files modified
cmis_read/__init__.py (+25/-0)
cmis_read/__openerp__.py (+74/-0)
cmis_read/i18n/cmis_read.pot (+119/-0)
cmis_read/security/ir.model.access.csv (+2/-0)
cmis_read/static/src/js/document.js (+44/-0)
cmis_read/static/src/xml/document.xml (+10/-0)
cmis_read/wizard/__init__.py (+25/-0)
cmis_read/wizard/document_wizard.py (+184/-0)
cmis_read/wizard/document_wizard_view.xml (+47/-0)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/knowledge-addons/cmis_read
Reviewer Review Type Date Requested Status
Sandy Carter (http://www.savoirfairelinux.com) Needs Resubmitting
Maxime Chambreuil (http://www.savoirfairelinux.com) Approve
OpenERP Community Reviewer/Maintainer Pending
Review via email: mp+212260@code.launchpad.net

Description of the change

Add cmis_read; It allows to use the CMIS backend to search in the DMS repository
and attach documents to OpenERP records.

To post a comment you must log in.
17. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] fix pep8 error, add control when reading from DMS

Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) :
review: Approve
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote :

test

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

l.377 osv.TransientModel should be orm.TransientModel
l.504 POSSIBLE SQL INJECTION: (with quotes in a filename) please use the library's code escapes, don't write your own

Flake8:
cmis_read/wizard/document_wizard.py:102:9: F841 local variable 'file_name' is assigned to but never used
cmis_read/wizard/document_wizard.py:115:5: E265 block comment should start with '# '
cmis_read/wizard/document_wizard.py:120:6: E111 indentation is not a multiple of four
cmis_read/wizard/document_wizard.py:120:6: E113 unexpected indentation
cmis_read/wizard/document_wizard.py:148:5: E265 block comment should start with '# '

review: Needs Fixing
Revision history for this message
El Hadji Dem (http://www.savoirfairelinux.com) (eh-dem) wrote :

@scaerter: thanks for comments

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

openerp.modules.loading: The transient model ir.attachment.dms (ir.attachment.dms) should not have explicit access rules!

review: Needs Fixing
Revision history for this message
El Hadji Dem (http://www.savoirfairelinux.com) (eh-dem) wrote :

l.504 : it is a cmis query

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Injection is still possible. It is an entry point for malicious queries or accidental breaks.

18. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Take comments from LP

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

l.471 Still severe bug and injection potential

Try:
filename = "sql%' OR '1' = '1' OR '%injection"

CMIS must provide a code escape function, otherwise use OpenERP's. It is important that you don't do this manually.

https://en.wikipedia.org/wiki/Sql_injection

There are also no unittests. The previous example would be a good thing to test.

review: Needs Fixing
19. By El Hadji Dem (http://www.savoirfairelinux.com)

[fixed comments from LP, for uniitests, we have to install Alfresco,]

Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote :

In the log of a reading job, I get :

Traceback (most recent call last): File "/home/max/openerp/cmis/bzr/connector/connector/queue/worker.py", line 122, in run_job job.perform(session) File "/home/max/openerp/cmis/bzr/connector/connector/queue/job.py", line 472, in perform self.result = self.func(session, *self.args, **self.kwargs) File "/home/max/openerp/cmis/bzr/knowledge/cmis_read/wizard/document_wizard.py", line 169, in create_doc_from_dms data_attach, context=session.context) File "/home/max/openerp/cmis/bzr/knowledge/cmis_write/ir_attachment.py", line 77, in create user_login) File "/home/max/openerp/cmis/bzr/connector/connector/queue/job.py", line 653, in delay **kwargs) File "/home/max/openerp/cmis/bzr/connector/connector/queue/job.py", line 131, in enqueue_resolve_args description=description) File "/home/max/openerp/cmis/bzr/connector/connector/queue/job.py", line 115, in enqueue self.store(job) File "/home/max/openerp/cmis/bzr/connector/connector/queue/job.py", line 220, in store self.session.context) File "/home/max/openerp/cmis/bzr/addons/mail/mail_thread.py", line 252, in create thread_id = super(mail_thread, self).create(cr, uid, values, context=context_operation) File "/home/max/openerp/cmis/bzr/connector/connector/producer.py", line 42, in create record_id = create_original(self, cr, uid, vals, context=context) File "/opt/openerp/7.0/server/openerp/osv/orm.py", line 4486, in create upd2.append(self._columns[field]._symbol_set[1](vals[field])) File "/opt/openerp/7.0/server/openerp/osv/fields.py", line 232, in <lambda> self._symbol_f = self._symbol_set_char = lambda x: _symbol_set_char(self, x) File "/opt/openerp/7.0/server/openerp/osv/fields.py", line 224, in _symbol_set_char return u_symb[:self.size].encode('utf8') MemoryError

review: Needs Fixing (test)
20. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] fix bug when we read document in OE

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

l.469,502: Queries are still not fully sanitized, any quotes or percent sizes in the input will result in unexpected behaviour. This is a security risk and a major bug potential.
I highly recommend you to add a function to sanitize input in the cmis module for queries and follow the documentation from http://wiki.alfresco.com/wiki/CMIS_Query_Language#Literals

Basic escaping:

    \\ represents \
    \' represents '

In addition to basic escaping, in LIKE expressions

    \% represents %
    \_ represents _

review: Needs Fixing
21. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Add constraint for avoidind SQL Injection

22. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Added a function to sanitize filename

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

For better usability and security, your sanitize function should wrap the query function, the same way OE does, so that there is no way to call the query the wrong way.

Something along the lines of

safe_query(" SELECT cmis:name, cmis:createdBy, cmis:objectId, "
           "cmis:contentStreamLength FROM cmis:document "
           "WHERE cmis:name LIKE '%%%s%%'", filename)

def safe_query(query, *args):
    args = map(sanitize_input, args)
    return repo.query(query % args)

Make sure to make the these functions general purpose, not specific to this particular instance as it seems now (function name sanitize_input_filename_field sounds specific to filename, when it can be used on any query).

Finally, _make sure to put these functions in your topmost dependency (cmis) so any depending module can use it reliably.

review: Needs Fixing
23. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Change the view where we search document from DMS and print the results below the search field

Revision history for this message
El Hadji Dem (http://www.savoirfairelinux.com) (eh-dem) wrote :

@Sandy Carter:
'repo' is not defined.I change the way to do

24. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Call the defined function in cmis module to clean query

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Looking better

review: Approve
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) :
review: Approve
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Hi,

It seems nice.

I left a few comments in the diff. I won't really block on them but you should have a look.

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

Thank you for your review, Guewen, I learned a few things.

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

This MP have been moved to MP to https://github.com/OCA/knowledge/pull/7

review: Needs Resubmitting

Unmerged revisions

24. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Call the defined function in cmis module to clean query

23. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Change the view where we search document from DMS and print the results below the search field

22. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Added a function to sanitize filename

21. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Add constraint for avoidind SQL Injection

20. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] fix bug when we read document in OE

19. By El Hadji Dem (http://www.savoirfairelinux.com)

[fixed comments from LP, for uniitests, we have to install Alfresco,]

18. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] Take comments from LP

17. By El Hadji Dem (http://www.savoirfairelinux.com)

[IMP] fix pep8 error, add control when reading from DMS

16. By El Hadji Dem (http://www.savoirfairelinux.com)

[ADD] add cmis_read module;It allows to allows you to use the CMIS backend to search in the DMS repository

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'cmis_read'
=== added file 'cmis_read/__init__.py'
--- cmis_read/__init__.py 1970-01-01 00:00:00 +0000
+++ cmis_read/__init__.py 2014-06-12 19:57:17 +0000
@@ -0,0 +1,25 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import wizard
24
25# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
026
=== added file 'cmis_read/__openerp__.py'
--- cmis_read/__openerp__.py 1970-01-01 00:00:00 +0000
+++ cmis_read/__openerp__.py 2014-06-12 19:57:17 +0000
@@ -0,0 +1,74 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{
24 'name': 'CMIS Read',
25 'version': '0.1',
26 'category': 'Knowledge Management',
27 'summary': 'Store Document File in a Remote CMIS Server',
28 'description': """
29This module allows you to use the CMIS backend to search in the DMS repository
30and attach documents to OpenERP records.
31
32Configuration
33=============
34
35Create a new CMIS backend with the host, login and password.
36
37Usage
38=====
39
40* On one OpenERP record, click "Add from DMS".
41* Type your query and then click on "Search".
42* Filter your results if necessary
43* Select the documents you want to attach
44* Selected documents will be enqueued for importing
45
46Contributors
47------------
48* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
49""",
50 'author': 'Savoir-faire Linux',
51 'website': 'www.savoirfairelinux.com',
52 'license': 'AGPL-3',
53 'depends': [
54 'document',
55 'cmis'
56 ],
57 'data': [
58 'security/ir.model.access.csv',
59 'wizard/document_wizard_view.xml',
60 ],
61 'js': [
62 'static/src/js/document.js'
63 ],
64 'qweb': [
65 'static/src/xml/document.xml'
66 ],
67 'test': [],
68 'demo': [
69 ],
70 'installable': True,
71 'auto_install': False,
72}
73
74# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
075
=== added directory 'cmis_read/i18n'
=== added file 'cmis_read/i18n/cmis_read.pot'
--- cmis_read/i18n/cmis_read.pot 1970-01-01 00:00:00 +0000
+++ cmis_read/i18n/cmis_read.pot 2014-06-12 19:57:17 +0000
@@ -0,0 +1,119 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * cmis_read
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-03-21 14:55+0000\n"
10"PO-Revision-Date: 2014-03-21 10:55-0500\n"
11"Last-Translator: EL Hadji DEM <elhadji.dem@savoirfairelinux.com>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: 8bit\n"
16"Plural-Forms: \n"
17"X-Generator: Poedit 1.5.4\n"
18
19#. module: cmis_read
20#: field:ir.attachment.dms,file_id:0
21msgid "File ID"
22msgstr ""
23
24#. module: cmis_read
25#: field:ir.attachment.dms.wizard,attachment_ids:0
26msgid "Attachments"
27msgstr ""
28
29#. module: cmis_read
30#: view:ir.attachment.dms.wizard:0
31msgid "Search Document"
32msgstr ""
33
34#. module: cmis_read
35#: field:ir.attachment.dms,name:0 help:ir.attachment.dms,name:0
36#: field:ir.attachment.dms.wizard,name:0 help:ir.attachment.dms.wizard,name:0
37msgid "File name"
38msgstr ""
39
40#. module: cmis_read
41#: code:addons/cmis_read/wizard/document_wizard.py:59
42#, python-format
43msgid "You have to fill in the file name. And try again"
44msgstr ""
45
46#. module: cmis_read
47#: help:ir.attachment.dms,file_id:0
48msgid "File Id"
49msgstr ""
50
51#. module: cmis_read
52#: model:_description:0 model:ir.model,name:cmis_read.model_ir_attachment_dms
53msgid "ir.attachment.dms"
54msgstr ""
55
56#. module: cmis_read
57#: field:ir.attachment.dms,owner:0 help:ir.attachment.dms,owner:0
58msgid "Owner"
59msgstr ""
60
61#. module: cmis_read
62#: view:ir.attachment.dms.wizard:0
63msgid ""
64"This action allows you to search by file name and to add the document you "
65"select"
66msgstr ""
67
68#. module: cmis_read
69#. openerp-web
70#: code:addons/cmis_read/static/src/js/document.js:26
71#, python-format
72msgid "Search Document from DMS"
73msgstr ""
74
75#. module: cmis_read
76#. openerp-web
77#: code:addons/cmis_read/static/src/xml/document.xml:7
78#, python-format
79msgid "Add Doc from DMS..."
80msgstr ""
81
82#. module: cmis_read
83#: code:addons/cmis_read/wizard/document_wizard.py:58
84#: code:addons/cmis_read/wizard/document_wizard.py:86
85#, python-format
86msgid "Error"
87msgstr ""
88
89#. module: cmis_read
90#: view:ir.attachment.dms.wizard:0
91msgid "Cancel"
92msgstr ""
93
94#. module: cmis_read
95#: view:ir.attachment.dms.wizard:0
96msgid "Apply"
97msgstr ""
98
99#. module: cmis_read
100#: model:_description:0
101#: model:ir.model,name:cmis_read.model_ir_attachment_dms_wizard
102msgid "ir.attachment.dms.wizard"
103msgstr ""
104
105#. module: cmis_read
106#: view:ir.attachment.dms.wizard:0
107msgid "Search"
108msgstr ""
109
110#. module: cmis_read
111#: view:ir.attachment.dms.wizard:0
112msgid "or"
113msgstr ""
114
115#. module: cmis_read
116#: code:addons/cmis_read/wizard/document_wizard.py:87
117#, python-format
118msgid "You have to select at least 1 Document. And try again"
119msgstr ""
0120
=== added directory 'cmis_read/security'
=== added file 'cmis_read/security/ir.model.access.csv'
--- cmis_read/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ cmis_read/security/ir.model.access.csv 2014-06-12 19:57:17 +0000
@@ -0,0 +1,2 @@
1id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2access_ir_attachment_dms_wizard,access_ir_attachment_dms_wizard,model_ir_attachment_dms_wizard,base.group_document_user,1,1,1,1
03
=== added directory 'cmis_read/static'
=== added directory 'cmis_read/static/src'
=== added directory 'cmis_read/static/src/js'
=== added file 'cmis_read/static/src/js/document.js'
--- cmis_read/static/src/js/document.js 1970-01-01 00:00:00 +0000
+++ cmis_read/static/src/js/document.js 2014-06-12 19:57:17 +0000
@@ -0,0 +1,44 @@
1openerp.cmis_read = function(instance, m) {
2var _t = instance.web._t,
3 QWeb = instance.web.qweb;
4
5 instance.web.Sidebar.include({
6 redraw: function() {
7 var self = this;
8 this._super.apply(this, arguments);
9 self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddDocfromdms', {widget: self}))
10 self.$el.find('.oe_sidebar_add_dms_doc').on('click', function (e) {
11 self.on_cmis_doc();
12 });
13 },
14 on_cmis_doc: function(state) {
15 var self = this;
16 var view = self.getParent();
17 var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ];
18 var ds = new instance.web.DataSet(this, 'ir.attachment', context);
19 // you can pass in other data using the context dictionary variable
20 var context = {
21 'model': view.dataset.model,
22 'ids': ids,
23 };
24 // the action dictionary variable sends data in the "self.do_action" method
25 var action = {
26 name: _t("Search Document from DMS"),
27 type: 'ir.actions.act_window',
28 res_model: 'ir.attachment.dms.wizard',
29 view_mode: 'form',
30 view_type: 'form',
31 views: [[false, 'form']],
32 target: 'new',
33 context: context,
34 };
35 // self.do_action accepts the action parameter and opens the new view
36 self.do_action(action, {
37 // refresh list of documents
38 on_close: function () {
39 self.do_attachement_update(self.dataset, self.model_id);
40 }
41 });
42 }
43 });
44};
045
=== added directory 'cmis_read/static/src/xml'
=== added file 'cmis_read/static/src/xml/document.xml'
--- cmis_read/static/src/xml/document.xml 1970-01-01 00:00:00 +0000
+++ cmis_read/static/src/xml/document.xml 2014-06-12 19:57:17 +0000
@@ -0,0 +1,10 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- vim:fdl=1:
3-->
4<templates id="template" xml:space="preserve">
5
6<t t-name="AddDocfromdms">
7 <li class="oe_sidebar_add_dms_doc"><span><b>Add Doc from DMS...</b></span></li>
8</t>
9
10</templates>
011
=== added directory 'cmis_read/wizard'
=== added file 'cmis_read/wizard/__init__.py'
--- cmis_read/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ cmis_read/wizard/__init__.py 2014-06-12 19:57:17 +0000
@@ -0,0 +1,25 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import document_wizard
24
25# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
026
=== added file 'cmis_read/wizard/document_wizard.py'
--- cmis_read/wizard/document_wizard.py 1970-01-01 00:00:00 +0000
+++ cmis_read/wizard/document_wizard.py 2014-06-12 19:57:17 +0000
@@ -0,0 +1,184 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv import orm, fields
24from openerp.tools.translate import _
25from openerp.addons.connector.session import ConnectorSession
26from openerp.addons.connector.queue.job import job
27from openerp import SUPERUSER_ID
28import logging
29_logger = logging.getLogger(__name__)
30
31
32class ir_attachment_edm_wizard(orm.Model):
33 _name = 'ir.attachment.dms.wizard'
34
35 _columns = {
36 'name': fields.char('File name', size=150, help="File name"),
37 'attachment_ids': fields.one2many('ir.attachment.dms',
38 'wizard_id'),
39 }
40
41 # Search documents from dms.
42 def search_doc(self, cr, uid, ids, context=None):
43 if context is None:
44 context = {}
45 this = self.browse(cr, uid, ids, context=context)[0]
46 data = self.read(cr, uid, ids, [], context=context)[0]
47 if not data['name']:
48 raise orm.except_orm(_('Error'),
49 _('You have to fill in the file name.' +
50 'And try again'))
51 if not hasattr(ids, '__iter__'):
52 ids = [ids]
53 session = ConnectorSession(cr, uid, context=context)
54 file_name = data['name']
55 for backend_id in ids:
56 search_doc_from_dms(session, 'ir.attachment',
57 backend_id, file_name, this.id)
58 return {
59 'type': 'ir.actions.act_window',
60 'res_model': 'ir.attachment.dms.wizard',
61 'view_mode': 'form',
62 'view_type': 'form',
63 'res_id': this.id,
64 'views': [(False, 'form')],
65 'target': 'new',
66 }
67
68 # Adding documents from Document Management (EDM) to OE.
69 def action_apply(self, cr, uid, ids, context=None):
70 ir_attachment_dms_obj = self.pool.get('ir.attachment.dms')
71 if context is None:
72 context = {}
73 model = context['model']
74 res_id = context['ids'][0]
75 ir_model_obj = self.pool.get(context['model'])
76 name = ir_model_obj.browse(cr, uid, context['ids'],
77 context=context)[0]['name']
78 data = self.read(cr, uid, ids, [], context=context)[0]
79
80 if not hasattr(ids, '__iter__'):
81 ids = [ids]
82 session = ConnectorSession(cr, uid, context=context)
83 # Just take the lines we select in the tree view
84 selected_data = [one_attachment.id for one_attachment in
85 ir_attachment_dms_obj.browse(
86 cr, uid, data['attachment_ids'], context)
87 if one_attachment.selectable_ok]
88 data['attachment_ids'] = selected_data
89 if not data['attachment_ids']:
90 raise orm.except_orm(_('Error'),
91 _('You have to select at least 1 Document.' +
92 'And try again'))
93 for backend_id in ids:
94 # Create doc in OE from DMS.
95 create_doc_from_dms.delay(session, 'ir.attachment', backend_id,
96 data, name, model, res_id, uid)
97 return {'type': 'ir.actions.act_window_close'}
98
99
100class ir_attachment_dms(orm.TransientModel):
101 _name = 'ir.attachment.dms'
102
103 _columns = {
104 'name': fields.char('File name', size=150,
105 readonly=True,
106 help="File name"),
107 'owner': fields.char('Owner', size=150,
108 readonly=True,
109 help="Owner"),
110 'file_id': fields.char('File ID', size=150,
111 readonly=True,
112 help="File Id"),
113 'wizard_id': fields.many2one('ir.attachment.dms.wizard',
114 string='Wizard',
115 required=True),
116 'selectable_ok': fields.boolean('Selected', help="Selected."),
117 }
118
119
120def search_doc_from_dms(session, model_name, backend_id, file_name, wizard_id):
121 ir_attach_dms_obj = session.pool.get('ir.attachment.dms')
122 cmis_backend_obj = session.pool.get('cmis.backend')
123 if session.context is None:
124 session.context = {}
125 # login with the cmis account
126 repo = cmis_backend_obj._auth(session.cr, session.uid,
127 context=session.context)
128
129 # Search name of doc and delete it if the document is already existed
130 attachment_ids = ir_attach_dms_obj.search(session.cr, session.uid, [])
131 ir_attach_dms_obj.unlink(session.cr, session.uid,
132 attachment_ids, context=session.context)
133 results = cmis_backend_obj.safe_query(
134 "SELECT cmis:name, cmis:createdBy, cmis:objectId, "
135 "cmis:contentStreamLength FROM cmis:document "
136 "WHERE cmis:name LIKE '%%%s%%'", file_name, repo)
137 for result in results:
138 info = result.getProperties()
139 if info['cmis:contentStreamLength'] != 0:
140 data_attach = {
141 'name': info['cmis:name'],
142 'owner': info['cmis:createdBy'],
143 'file_id': info['cmis:objectId'],
144 'wizard_id': wizard_id,
145 }
146 ir_attach_dms_obj.create(session.cr, session.uid, data_attach,
147 context=session.context)
148
149
150@job
151def create_doc_from_dms(session, model_name, backend_id, data, name,
152 model, res_id, uid, filters=None):
153 ir_attach_obj = session.pool.get('ir.attachment')
154 ir_attach_dms_obj = session.pool.get('ir.attachment.dms')
155 cmis_backend_obj = session.pool.get('cmis.backend')
156 if session.context is None:
157 session.context = {}
158 # login with the cmis account
159 repo = cmis_backend_obj._auth(
160 session.cr, session.uid, context=session.context)
161 for attach in ir_attach_dms_obj.browse(session.cr, session.uid,
162 data['attachment_ids'],
163 context=session.context):
164 # Get results from id of document
165 results = repo.query(" SELECT * FROM cmis:document WHERE \
166 cmis:objectId ='" + attach.file_id + "'")
167 for result in results:
168 info = result.getProperties()
169 data_attach = {
170 'name': info['cmis:name'],
171 'description': info['cmis:description'],
172 'type': 'binary',
173 'datas': result.getContentStream().read().encode('base64'),
174 'res_model': model,
175 'res_name': name,
176 'res_id': res_id,
177 'user_id': uid,
178 }
179 session.context['bool_testdoc'] = True
180 ir_attach_obj.create(session.cr, session.uid,
181 data_attach, context=session.context)
182 return True
183
184# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
0185
=== added file 'cmis_read/wizard/document_wizard_view.xml'
--- cmis_read/wizard/document_wizard_view.xml 1970-01-01 00:00:00 +0000
+++ cmis_read/wizard/document_wizard_view.xml 2014-06-12 19:57:17 +0000
@@ -0,0 +1,47 @@
1<?xml version="1.0"?>
2<openerp>
3 <data>
4
5 <!-- wizard view -->
6 <record id="wizard_view" model="ir.ui.view">
7 <field name="name">Search Document</field>
8 <field name="model">ir.attachment.dms.wizard</field>
9 <field name="arch" type="xml">
10 <form string="Search Document" version="7.0">
11 <div>
12 This action allows you to search by file name and to add the document you select
13 </div>
14 <group>
15 <div width="100%%">
16 <field name="name" width="70%%" class="oe_inline"/>
17 <button name="search_doc" string="Search" type="object"
18 width="15%%" class="oe_inline oe_highlight" />
19 </div>
20 </group>
21 <field name="attachment_ids"/>
22 <footer>
23 <button name="action_apply" string="Apply" type="object"
24 class="oe_highlight"/>
25 or
26 <button special="cancel" string="Cancel" type="object"
27 class="oe_link"/>
28 </footer>
29 </form>
30 </field>
31 </record>
32
33
34 <record id="wizard_attachment_tree_view" model="ir.ui.view">
35 <field name="name">Ir Attachment Dms</field>
36 <field name="model">ir.attachment.dms</field>
37 <field name="arch" type="xml">
38 <tree string="Attachment" editable="bottom" create="false" delete="false">
39 <field name="selectable_ok"/>
40 <field name="name"/>
41 <field name="owner"/>
42 </tree>
43 </field>
44 </record>
45
46 </data>
47</openerp>

Subscribers

People subscribed via source and target branches

to status/vote changes: