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
1=== added directory 'cmis_read'
2=== added file 'cmis_read/__init__.py'
3--- cmis_read/__init__.py 1970-01-01 00:00:00 +0000
4+++ cmis_read/__init__.py 2014-06-12 19:57:17 +0000
5@@ -0,0 +1,25 @@
6+# -*- encoding: utf-8 -*-
7+##############################################################################
8+#
9+# OpenERP, Open Source Management Solution
10+# This module copyright (C) 2014 Savoir-faire Linux
11+# (<http://www.savoirfairelinux.com>).
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+##############################################################################
27+
28+from . import wizard
29+
30+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
31
32=== added file 'cmis_read/__openerp__.py'
33--- cmis_read/__openerp__.py 1970-01-01 00:00:00 +0000
34+++ cmis_read/__openerp__.py 2014-06-12 19:57:17 +0000
35@@ -0,0 +1,74 @@
36+# -*- encoding: utf-8 -*-
37+##############################################################################
38+#
39+# OpenERP, Open Source Management Solution
40+# This module copyright (C) 2014 Savoir-faire Linux
41+# (<http://www.savoirfairelinux.com>).
42+#
43+# This program is free software: you can redistribute it and/or modify
44+# it under the terms of the GNU Affero General Public License as
45+# published by the Free Software Foundation, either version 3 of the
46+# License, or (at your option) any later version.
47+#
48+# This program is distributed in the hope that it will be useful,
49+# but WITHOUT ANY WARRANTY; without even the implied warranty of
50+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51+# GNU Affero General Public License for more details.
52+#
53+# You should have received a copy of the GNU Affero General Public License
54+# along with this program. If not, see <http://www.gnu.org/licenses/>.
55+#
56+##############################################################################
57+
58+{
59+ 'name': 'CMIS Read',
60+ 'version': '0.1',
61+ 'category': 'Knowledge Management',
62+ 'summary': 'Store Document File in a Remote CMIS Server',
63+ 'description': """
64+This module allows you to use the CMIS backend to search in the DMS repository
65+and attach documents to OpenERP records.
66+
67+Configuration
68+=============
69+
70+Create a new CMIS backend with the host, login and password.
71+
72+Usage
73+=====
74+
75+* On one OpenERP record, click "Add from DMS".
76+* Type your query and then click on "Search".
77+* Filter your results if necessary
78+* Select the documents you want to attach
79+* Selected documents will be enqueued for importing
80+
81+Contributors
82+------------
83+* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
84+""",
85+ 'author': 'Savoir-faire Linux',
86+ 'website': 'www.savoirfairelinux.com',
87+ 'license': 'AGPL-3',
88+ 'depends': [
89+ 'document',
90+ 'cmis'
91+ ],
92+ 'data': [
93+ 'security/ir.model.access.csv',
94+ 'wizard/document_wizard_view.xml',
95+ ],
96+ 'js': [
97+ 'static/src/js/document.js'
98+ ],
99+ 'qweb': [
100+ 'static/src/xml/document.xml'
101+ ],
102+ 'test': [],
103+ 'demo': [
104+ ],
105+ 'installable': True,
106+ 'auto_install': False,
107+}
108+
109+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
110
111=== added directory 'cmis_read/i18n'
112=== added file 'cmis_read/i18n/cmis_read.pot'
113--- cmis_read/i18n/cmis_read.pot 1970-01-01 00:00:00 +0000
114+++ cmis_read/i18n/cmis_read.pot 2014-06-12 19:57:17 +0000
115@@ -0,0 +1,119 @@
116+# Translation of OpenERP Server.
117+# This file contains the translation of the following modules:
118+# * cmis_read
119+#
120+msgid ""
121+msgstr ""
122+"Project-Id-Version: OpenERP Server 7.0\n"
123+"Report-Msgid-Bugs-To: \n"
124+"POT-Creation-Date: 2014-03-21 14:55+0000\n"
125+"PO-Revision-Date: 2014-03-21 10:55-0500\n"
126+"Last-Translator: EL Hadji DEM <elhadji.dem@savoirfairelinux.com>\n"
127+"Language-Team: \n"
128+"MIME-Version: 1.0\n"
129+"Content-Type: text/plain; charset=UTF-8\n"
130+"Content-Transfer-Encoding: 8bit\n"
131+"Plural-Forms: \n"
132+"X-Generator: Poedit 1.5.4\n"
133+
134+#. module: cmis_read
135+#: field:ir.attachment.dms,file_id:0
136+msgid "File ID"
137+msgstr ""
138+
139+#. module: cmis_read
140+#: field:ir.attachment.dms.wizard,attachment_ids:0
141+msgid "Attachments"
142+msgstr ""
143+
144+#. module: cmis_read
145+#: view:ir.attachment.dms.wizard:0
146+msgid "Search Document"
147+msgstr ""
148+
149+#. module: cmis_read
150+#: field:ir.attachment.dms,name:0 help:ir.attachment.dms,name:0
151+#: field:ir.attachment.dms.wizard,name:0 help:ir.attachment.dms.wizard,name:0
152+msgid "File name"
153+msgstr ""
154+
155+#. module: cmis_read
156+#: code:addons/cmis_read/wizard/document_wizard.py:59
157+#, python-format
158+msgid "You have to fill in the file name. And try again"
159+msgstr ""
160+
161+#. module: cmis_read
162+#: help:ir.attachment.dms,file_id:0
163+msgid "File Id"
164+msgstr ""
165+
166+#. module: cmis_read
167+#: model:_description:0 model:ir.model,name:cmis_read.model_ir_attachment_dms
168+msgid "ir.attachment.dms"
169+msgstr ""
170+
171+#. module: cmis_read
172+#: field:ir.attachment.dms,owner:0 help:ir.attachment.dms,owner:0
173+msgid "Owner"
174+msgstr ""
175+
176+#. module: cmis_read
177+#: view:ir.attachment.dms.wizard:0
178+msgid ""
179+"This action allows you to search by file name and to add the document you "
180+"select"
181+msgstr ""
182+
183+#. module: cmis_read
184+#. openerp-web
185+#: code:addons/cmis_read/static/src/js/document.js:26
186+#, python-format
187+msgid "Search Document from DMS"
188+msgstr ""
189+
190+#. module: cmis_read
191+#. openerp-web
192+#: code:addons/cmis_read/static/src/xml/document.xml:7
193+#, python-format
194+msgid "Add Doc from DMS..."
195+msgstr ""
196+
197+#. module: cmis_read
198+#: code:addons/cmis_read/wizard/document_wizard.py:58
199+#: code:addons/cmis_read/wizard/document_wizard.py:86
200+#, python-format
201+msgid "Error"
202+msgstr ""
203+
204+#. module: cmis_read
205+#: view:ir.attachment.dms.wizard:0
206+msgid "Cancel"
207+msgstr ""
208+
209+#. module: cmis_read
210+#: view:ir.attachment.dms.wizard:0
211+msgid "Apply"
212+msgstr ""
213+
214+#. module: cmis_read
215+#: model:_description:0
216+#: model:ir.model,name:cmis_read.model_ir_attachment_dms_wizard
217+msgid "ir.attachment.dms.wizard"
218+msgstr ""
219+
220+#. module: cmis_read
221+#: view:ir.attachment.dms.wizard:0
222+msgid "Search"
223+msgstr ""
224+
225+#. module: cmis_read
226+#: view:ir.attachment.dms.wizard:0
227+msgid "or"
228+msgstr ""
229+
230+#. module: cmis_read
231+#: code:addons/cmis_read/wizard/document_wizard.py:87
232+#, python-format
233+msgid "You have to select at least 1 Document. And try again"
234+msgstr ""
235
236=== added directory 'cmis_read/security'
237=== added file 'cmis_read/security/ir.model.access.csv'
238--- cmis_read/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
239+++ cmis_read/security/ir.model.access.csv 2014-06-12 19:57:17 +0000
240@@ -0,0 +1,2 @@
241+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
242+access_ir_attachment_dms_wizard,access_ir_attachment_dms_wizard,model_ir_attachment_dms_wizard,base.group_document_user,1,1,1,1
243
244=== added directory 'cmis_read/static'
245=== added directory 'cmis_read/static/src'
246=== added directory 'cmis_read/static/src/js'
247=== added file 'cmis_read/static/src/js/document.js'
248--- cmis_read/static/src/js/document.js 1970-01-01 00:00:00 +0000
249+++ cmis_read/static/src/js/document.js 2014-06-12 19:57:17 +0000
250@@ -0,0 +1,44 @@
251+openerp.cmis_read = function(instance, m) {
252+var _t = instance.web._t,
253+ QWeb = instance.web.qweb;
254+
255+ instance.web.Sidebar.include({
256+ redraw: function() {
257+ var self = this;
258+ this._super.apply(this, arguments);
259+ self.$el.find('.oe_sidebar_add_attachment').after(QWeb.render('AddDocfromdms', {widget: self}))
260+ self.$el.find('.oe_sidebar_add_dms_doc').on('click', function (e) {
261+ self.on_cmis_doc();
262+ });
263+ },
264+ on_cmis_doc: function(state) {
265+ var self = this;
266+ var view = self.getParent();
267+ var ids = ( view.fields_view.type != "form" )? view.groups.get_selection().ids : [ view.datarecord.id ];
268+ var ds = new instance.web.DataSet(this, 'ir.attachment', context);
269+ // you can pass in other data using the context dictionary variable
270+ var context = {
271+ 'model': view.dataset.model,
272+ 'ids': ids,
273+ };
274+ // the action dictionary variable sends data in the "self.do_action" method
275+ var action = {
276+ name: _t("Search Document from DMS"),
277+ type: 'ir.actions.act_window',
278+ res_model: 'ir.attachment.dms.wizard',
279+ view_mode: 'form',
280+ view_type: 'form',
281+ views: [[false, 'form']],
282+ target: 'new',
283+ context: context,
284+ };
285+ // self.do_action accepts the action parameter and opens the new view
286+ self.do_action(action, {
287+ // refresh list of documents
288+ on_close: function () {
289+ self.do_attachement_update(self.dataset, self.model_id);
290+ }
291+ });
292+ }
293+ });
294+};
295
296=== added directory 'cmis_read/static/src/xml'
297=== added file 'cmis_read/static/src/xml/document.xml'
298--- cmis_read/static/src/xml/document.xml 1970-01-01 00:00:00 +0000
299+++ cmis_read/static/src/xml/document.xml 2014-06-12 19:57:17 +0000
300@@ -0,0 +1,10 @@
301+<?xml version="1.0" encoding="UTF-8"?>
302+<!-- vim:fdl=1:
303+-->
304+<templates id="template" xml:space="preserve">
305+
306+<t t-name="AddDocfromdms">
307+ <li class="oe_sidebar_add_dms_doc"><span><b>Add Doc from DMS...</b></span></li>
308+</t>
309+
310+</templates>
311
312=== added directory 'cmis_read/wizard'
313=== added file 'cmis_read/wizard/__init__.py'
314--- cmis_read/wizard/__init__.py 1970-01-01 00:00:00 +0000
315+++ cmis_read/wizard/__init__.py 2014-06-12 19:57:17 +0000
316@@ -0,0 +1,25 @@
317+# -*- encoding: utf-8 -*-
318+##############################################################################
319+#
320+# OpenERP, Open Source Management Solution
321+# This module copyright (C) 2014 Savoir-faire Linux
322+# (<http://www.savoirfairelinux.com>).
323+#
324+# This program is free software: you can redistribute it and/or modify
325+# it under the terms of the GNU Affero General Public License as
326+# published by the Free Software Foundation, either version 3 of the
327+# License, or (at your option) any later version.
328+#
329+# This program is distributed in the hope that it will be useful,
330+# but WITHOUT ANY WARRANTY; without even the implied warranty of
331+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
332+# GNU Affero General Public License for more details.
333+#
334+# You should have received a copy of the GNU Affero General Public License
335+# along with this program. If not, see <http://www.gnu.org/licenses/>.
336+#
337+##############################################################################
338+
339+from . import document_wizard
340+
341+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
342
343=== added file 'cmis_read/wizard/document_wizard.py'
344--- cmis_read/wizard/document_wizard.py 1970-01-01 00:00:00 +0000
345+++ cmis_read/wizard/document_wizard.py 2014-06-12 19:57:17 +0000
346@@ -0,0 +1,184 @@
347+# -*- encoding: utf-8 -*-
348+##############################################################################
349+#
350+# OpenERP, Open Source Management Solution
351+# This module copyright (C) 2014 Savoir-faire Linux
352+# (<http://www.savoirfairelinux.com>).
353+#
354+# This program is free software: you can redistribute it and/or modify
355+# it under the terms of the GNU Affero General Public License as
356+# published by the Free Software Foundation, either version 3 of the
357+# License, or (at your option) any later version.
358+#
359+# This program is distributed in the hope that it will be useful,
360+# but WITHOUT ANY WARRANTY; without even the implied warranty of
361+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
362+# GNU Affero General Public License for more details.
363+#
364+# You should have received a copy of the GNU Affero General Public License
365+# along with this program. If not, see <http://www.gnu.org/licenses/>.
366+#
367+##############################################################################
368+
369+from openerp.osv import orm, fields
370+from openerp.tools.translate import _
371+from openerp.addons.connector.session import ConnectorSession
372+from openerp.addons.connector.queue.job import job
373+from openerp import SUPERUSER_ID
374+import logging
375+_logger = logging.getLogger(__name__)
376+
377+
378+class ir_attachment_edm_wizard(orm.Model):
379+ _name = 'ir.attachment.dms.wizard'
380+
381+ _columns = {
382+ 'name': fields.char('File name', size=150, help="File name"),
383+ 'attachment_ids': fields.one2many('ir.attachment.dms',
384+ 'wizard_id'),
385+ }
386+
387+ # Search documents from dms.
388+ def search_doc(self, cr, uid, ids, context=None):
389+ if context is None:
390+ context = {}
391+ this = self.browse(cr, uid, ids, context=context)[0]
392+ data = self.read(cr, uid, ids, [], context=context)[0]
393+ if not data['name']:
394+ raise orm.except_orm(_('Error'),
395+ _('You have to fill in the file name.' +
396+ 'And try again'))
397+ if not hasattr(ids, '__iter__'):
398+ ids = [ids]
399+ session = ConnectorSession(cr, uid, context=context)
400+ file_name = data['name']
401+ for backend_id in ids:
402+ search_doc_from_dms(session, 'ir.attachment',
403+ backend_id, file_name, this.id)
404+ return {
405+ 'type': 'ir.actions.act_window',
406+ 'res_model': 'ir.attachment.dms.wizard',
407+ 'view_mode': 'form',
408+ 'view_type': 'form',
409+ 'res_id': this.id,
410+ 'views': [(False, 'form')],
411+ 'target': 'new',
412+ }
413+
414+ # Adding documents from Document Management (EDM) to OE.
415+ def action_apply(self, cr, uid, ids, context=None):
416+ ir_attachment_dms_obj = self.pool.get('ir.attachment.dms')
417+ if context is None:
418+ context = {}
419+ model = context['model']
420+ res_id = context['ids'][0]
421+ ir_model_obj = self.pool.get(context['model'])
422+ name = ir_model_obj.browse(cr, uid, context['ids'],
423+ context=context)[0]['name']
424+ data = self.read(cr, uid, ids, [], context=context)[0]
425+
426+ if not hasattr(ids, '__iter__'):
427+ ids = [ids]
428+ session = ConnectorSession(cr, uid, context=context)
429+ # Just take the lines we select in the tree view
430+ selected_data = [one_attachment.id for one_attachment in
431+ ir_attachment_dms_obj.browse(
432+ cr, uid, data['attachment_ids'], context)
433+ if one_attachment.selectable_ok]
434+ data['attachment_ids'] = selected_data
435+ if not data['attachment_ids']:
436+ raise orm.except_orm(_('Error'),
437+ _('You have to select at least 1 Document.' +
438+ 'And try again'))
439+ for backend_id in ids:
440+ # Create doc in OE from DMS.
441+ create_doc_from_dms.delay(session, 'ir.attachment', backend_id,
442+ data, name, model, res_id, uid)
443+ return {'type': 'ir.actions.act_window_close'}
444+
445+
446+class ir_attachment_dms(orm.TransientModel):
447+ _name = 'ir.attachment.dms'
448+
449+ _columns = {
450+ 'name': fields.char('File name', size=150,
451+ readonly=True,
452+ help="File name"),
453+ 'owner': fields.char('Owner', size=150,
454+ readonly=True,
455+ help="Owner"),
456+ 'file_id': fields.char('File ID', size=150,
457+ readonly=True,
458+ help="File Id"),
459+ 'wizard_id': fields.many2one('ir.attachment.dms.wizard',
460+ string='Wizard',
461+ required=True),
462+ 'selectable_ok': fields.boolean('Selected', help="Selected."),
463+ }
464+
465+
466+def search_doc_from_dms(session, model_name, backend_id, file_name, wizard_id):
467+ ir_attach_dms_obj = session.pool.get('ir.attachment.dms')
468+ cmis_backend_obj = session.pool.get('cmis.backend')
469+ if session.context is None:
470+ session.context = {}
471+ # login with the cmis account
472+ repo = cmis_backend_obj._auth(session.cr, session.uid,
473+ context=session.context)
474+
475+ # Search name of doc and delete it if the document is already existed
476+ attachment_ids = ir_attach_dms_obj.search(session.cr, session.uid, [])
477+ ir_attach_dms_obj.unlink(session.cr, session.uid,
478+ attachment_ids, context=session.context)
479+ results = cmis_backend_obj.safe_query(
480+ "SELECT cmis:name, cmis:createdBy, cmis:objectId, "
481+ "cmis:contentStreamLength FROM cmis:document "
482+ "WHERE cmis:name LIKE '%%%s%%'", file_name, repo)
483+ for result in results:
484+ info = result.getProperties()
485+ if info['cmis:contentStreamLength'] != 0:
486+ data_attach = {
487+ 'name': info['cmis:name'],
488+ 'owner': info['cmis:createdBy'],
489+ 'file_id': info['cmis:objectId'],
490+ 'wizard_id': wizard_id,
491+ }
492+ ir_attach_dms_obj.create(session.cr, session.uid, data_attach,
493+ context=session.context)
494+
495+
496+@job
497+def create_doc_from_dms(session, model_name, backend_id, data, name,
498+ model, res_id, uid, filters=None):
499+ ir_attach_obj = session.pool.get('ir.attachment')
500+ ir_attach_dms_obj = session.pool.get('ir.attachment.dms')
501+ cmis_backend_obj = session.pool.get('cmis.backend')
502+ if session.context is None:
503+ session.context = {}
504+ # login with the cmis account
505+ repo = cmis_backend_obj._auth(
506+ session.cr, session.uid, context=session.context)
507+ for attach in ir_attach_dms_obj.browse(session.cr, session.uid,
508+ data['attachment_ids'],
509+ context=session.context):
510+ # Get results from id of document
511+ results = repo.query(" SELECT * FROM cmis:document WHERE \
512+ cmis:objectId ='" + attach.file_id + "'")
513+ for result in results:
514+ info = result.getProperties()
515+ data_attach = {
516+ 'name': info['cmis:name'],
517+ 'description': info['cmis:description'],
518+ 'type': 'binary',
519+ 'datas': result.getContentStream().read().encode('base64'),
520+ 'res_model': model,
521+ 'res_name': name,
522+ 'res_id': res_id,
523+ 'user_id': uid,
524+ }
525+ session.context['bool_testdoc'] = True
526+ ir_attach_obj.create(session.cr, session.uid,
527+ data_attach, context=session.context)
528+ return True
529+
530+# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
531
532=== added file 'cmis_read/wizard/document_wizard_view.xml'
533--- cmis_read/wizard/document_wizard_view.xml 1970-01-01 00:00:00 +0000
534+++ cmis_read/wizard/document_wizard_view.xml 2014-06-12 19:57:17 +0000
535@@ -0,0 +1,47 @@
536+<?xml version="1.0"?>
537+<openerp>
538+ <data>
539+
540+ <!-- wizard view -->
541+ <record id="wizard_view" model="ir.ui.view">
542+ <field name="name">Search Document</field>
543+ <field name="model">ir.attachment.dms.wizard</field>
544+ <field name="arch" type="xml">
545+ <form string="Search Document" version="7.0">
546+ <div>
547+ This action allows you to search by file name and to add the document you select
548+ </div>
549+ <group>
550+ <div width="100%%">
551+ <field name="name" width="70%%" class="oe_inline"/>
552+ <button name="search_doc" string="Search" type="object"
553+ width="15%%" class="oe_inline oe_highlight" />
554+ </div>
555+ </group>
556+ <field name="attachment_ids"/>
557+ <footer>
558+ <button name="action_apply" string="Apply" type="object"
559+ class="oe_highlight"/>
560+ or
561+ <button special="cancel" string="Cancel" type="object"
562+ class="oe_link"/>
563+ </footer>
564+ </form>
565+ </field>
566+ </record>
567+
568+
569+ <record id="wizard_attachment_tree_view" model="ir.ui.view">
570+ <field name="name">Ir Attachment Dms</field>
571+ <field name="model">ir.attachment.dms</field>
572+ <field name="arch" type="xml">
573+ <tree string="Attachment" editable="bottom" create="false" delete="false">
574+ <field name="selectable_ok"/>
575+ <field name="name"/>
576+ <field name="owner"/>
577+ </tree>
578+ </field>
579+ </record>
580+
581+ </data>
582+</openerp>

Subscribers

People subscribed via source and target branches

to status/vote changes: