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