diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4fa62d57..f5a287c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,6 @@ exclude: | (?x) # NOT INSTALLABLE ADDONS - ^cmis_web_proxy/| ^cmis_web_proxy_alf/| ^cmis_web_report_write/| ^cmis_web_report_write_alf/| diff --git a/cmis_web_proxy/README.rst b/cmis_web_proxy/README.rst index 484d308d..937bb06b 100644 --- a/cmis_web_proxy/README.rst +++ b/cmis_web_proxy/README.rst @@ -27,4 +27,4 @@ Maintainer :alt: ACSONE SA/NV :target: http://www.acsone.eu -This module is maintained by ACSONE SA/NV. \ No newline at end of file +This module is maintained by ACSONE SA/NV. diff --git a/cmis_web_proxy/__manifest__.py b/cmis_web_proxy/__manifest__.py index fec4de70..d525c9b6 100644 --- a/cmis_web_proxy/__manifest__.py +++ b/cmis_web_proxy/__manifest__.py @@ -6,13 +6,19 @@ "summary": """ Odoo as proxy server for your cmis requests.""", "category": "Document Management", - "version": "14.0.1.0.1", + "version": "16.0.1.0.1", "license": "AGPL-3", "author": "ACSONE SA/NV", "website": "https://alfodoo.org", "depends": ["cmis_web"], - "data": ["views/cmis_backend.xml", "views/cmis_web_proxy.xml"], + "data": ["views/cmis_backend.xml"], "external_dependencies": {"python": ["requests", "cmislib"]}, "images": ["static/description/main_icon.png"], - "installable": False, + "assets": { + "web.assets_backend": [ + "/cmis_web_proxy/static/src/cmis_folder/cmis_folder.js", + "/cmis_web_proxy/static/src/cmis_object_wrapper_service.js", + ], + }, + "installable": True, } diff --git a/cmis_web_proxy/controllers/cmis.py b/cmis_web_proxy/controllers/cmis.py index a6f1855e..9d9c818f 100644 --- a/cmis_web_proxy/controllers/cmis.py +++ b/cmis_web_proxy/controllers/cmis.py @@ -10,8 +10,6 @@ from odoo.exceptions import AccessError from odoo.http import request -from odoo.addons.web.controllers import main - _logger = logging.getLogger(__name__) try: @@ -24,68 +22,68 @@ READ_ACCESS_CMIS_ACTIONS = {"query"} WRITE_ACCESS_CMIS_ACTIONS = { - "createRelationship", - # "createPolicy", method at repository level: not supported - # "createItem", method at repository level: not supported - "bulkUpdate", - # "createType", method at repository level: not supported - # "updateType", method at repository level: not supported - "createDocument", - "createFolder", - "createDocumentFromSource", - # "createPolicy", method at repository level: not supported - "update", - "setContent", - "checkOut", - "cancelCheckOut", - "checkIn", - # "applyPolicy", method at repository level: not supported - # "applyACL", method at repository level: not supported + "createRelationship", + # "createPolicy", method at repository level: not supported + # "createItem", method at repository level: not supported + "bulkUpdate", + # "createType", method at repository level: not supported + # "updateType", method at repository level: not supported + "createDocument", + "createFolder", + "createDocumentFromSource", + # "createPolicy", method at repository level: not supported + "update", + "setContent", + "checkOut", + "cancelCheckOut", + "checkIn", + # "applyPolicy", method at repository level: not supported + # "applyACL", method at repository level: not supported } UNLINK_ACCESS_CMIS_ACTIONS = { - "delete", - "deleteContent", - "removeObjectFromFolder", - # "removePolicy", method at repository level: not supported - # "deleteType", method at repository level: not supported + "delete", + "deleteContent", + "removeObjectFromFolder", + # "removePolicy", method at repository level: not supported + # "deleteType", method at repository level: not supported } READ_ACCESS_ALLOWABLE_ACTIONS = { - "canGetDescendants", - "canGetChildren", - "canGetFolderParent", - "canGetObjectParents", - "canGetProperties", - "canGetContentStream", - "canGetAllVersions", - "canGetObjectRelationships", - "canGetAppliedPolicies", - "canGetACL", + "canGetDescendants", + "canGetChildren", + "canGetFolderParent", + "canGetObjectParents", + "canGetProperties", + "canGetContentStream", + "canGetAllVersions", + "canGetObjectRelationships", + "canGetAppliedPolicies", + "canGetACL", } WRITE_ACCESS_ALLOWABLE_ACTIONS = { - "canCreateDocument", - "canCreateFolder", - # "canCreatePolicy", - "canCreateRelationship", - "canUpdateProperties", - "canMoveObject", - "canSetContentStream", - "canAddObjectToFolder", - "canCheckOut", - "canCancelCheckOut", - "canCheckIn", - # "canApplyPolicy", - # "canApplyACL", + "canCreateDocument", + "canCreateFolder", + # "canCreatePolicy", + "canCreateRelationship", + "canUpdateProperties", + "canMoveObject", + "canSetContentStream", + "canAddObjectToFolder", + "canCheckOut", + "canCancelCheckOut", + "canCheckIn", + # "canApplyPolicy", + # "canApplyACL", } UNLINK_ACCESS_ALLOWABLE_ACTIONS = { - "canRemoveObjectFromFolder", - "canDeleteObject", - "canDeleteContentStream", - "canDeleteTree", - # "canRemovePolicy", + "canRemoveObjectFromFolder", + "canDeleteObject", + "canDeleteContentStream", + "canDeleteTree", + # "canRemovePolicy", } CMSI_ACTIONS_OPERATION_MAP = {} @@ -384,7 +382,7 @@ def _check_cmis_content_access( token_cmis_objectid = getattr(model_inst, field_name) if not token_cmis_objectid: _logger.info( - "The referenced model doesn't reference a CMIS " "content (%s, %s)", + "The referenced model doesn't reference a CMIS content (%s, %s)", model_inst._name, model_inst.id, ) @@ -506,7 +504,6 @@ def _check_access(self, cmis_path, proxy_info, params): csrf=False, methods=["GET", "POST"], ) - @main.serialize_exception def call_cmis_services(self, backend_id, cmis_path="", **kwargs): """Call at the root of the CMIS repository. These calls are for requesting the global services provided by the CMIS Container diff --git a/cmis_web_proxy/models/cmis_backend.py b/cmis_web_proxy/models/cmis_backend.py index 758aebc2..fd23f3e4 100644 --- a/cmis_web_proxy/models/cmis_backend.py +++ b/cmis_web_proxy/models/cmis_backend.py @@ -10,9 +10,6 @@ class CmisBackend(models.Model): _inherit = "cmis.backend" - def _clear_caches(self): - self.get_by_id.clear_cache(self) - @api.onchange("is_cmis_proxy") def _onchange_is_cmis_proxy(self): self.apply_odoo_security = self.is_cmis_proxy @@ -27,7 +24,7 @@ def _compute_proxy_location(self): help="If checked, all the CMIS requests from the client will be " "done to the Odoo server in place of to a direct call to the" "CMIS Container. In such a case, Odoo act as a proxy server " - "between the widget and the cmis container and all the requets " + "between the widget and the cmis container and all the requests " "are done by using the configured account on the backend. ", ) apply_odoo_security = fields.Boolean( @@ -75,7 +72,6 @@ def get_by_id(self, backend_id): return backend def write(self, vals): - self.get_proxy_info_by_id.clear_cache(self) if "is_cmis_proxy" in vals and vals["is_cmis_proxy"] is False: vals["apply_odoo_security"] = False return super(CmisBackend, self).write(vals) diff --git a/cmis_web_proxy/static/src/cmis_folder/cmis_folder.js b/cmis_web_proxy/static/src/cmis_folder/cmis_folder.js new file mode 100644 index 00000000..ff7900b0 --- /dev/null +++ b/cmis_web_proxy/static/src/cmis_folder/cmis_folder.js @@ -0,0 +1,41 @@ +/** @odoo-module **/ + +/* --------------------------------------------------------- ++ * Odoo cmis_web ++ * Authors Laurent Mignon 2016, Maxime Franco 2023 Acsone SA/NV ++ * License in __openerp__.py at root level of the module ++ *--------------------------------------------------------- ++*/ + +import {CmisFolderField} from "@cmis_web/cmis_folder/cmis_folder"; +import {patch} from "@web/core/utils/patch"; + +patch(CmisFolderField.prototype, "open_with_proxy", { + getCmisObjectWrapperParams() { + const params = this._super(...arguments); + params.applyOdooSecurity = this.backend.apply_odoo_security; + return params; + }, + + genCmisSessionToken() { + return JSON.stringify({ + model: this.props.record.resModel, + res_id: this.props.record.resId, + field_name: this.props.name, + }); + }, + + setCmisSessionToken() { + if (this.backend.apply_odoo_security) { + this.cmisSession.setToken(this.genCmisSessionToken()); + } + }, + + async setRootFolderId() { + var self = this; + self.setCmisSessionToken(); + this._super(...arguments); + }, +}); + +CmisFolderField.props.backend[0].shape.apply_odoo_security = Boolean; diff --git a/cmis_web_proxy/static/src/cmis_object_wrapper_service.js b/cmis_web_proxy/static/src/cmis_object_wrapper_service.js new file mode 100644 index 00000000..399cf2ef --- /dev/null +++ b/cmis_web_proxy/static/src/cmis_object_wrapper_service.js @@ -0,0 +1,25 @@ +/** @odoo-module **/ + +/* --------------------------------------------------------- ++ * Odoo cmis_web ++ * Authors Laurent Mignon 2016, Quentin Groulard 2023 Acsone SA/NV ++ * License in __openerp__.py at root level of the module ++ *--------------------------------------------------------- ++*/ + +import {CmisObjectWrapper} from "@cmis_web/cmis_object_wrapper_service"; +import {patch} from "@web/core/utils/patch"; + +patch(CmisObjectWrapper.prototype, "alfresco_proxy_url", { + getPreviewUrl() { + var _url = this._super(...arguments); + if (_url) { + var prefix = "&"; + if (_url.indexOf("?") < 0) { + prefix = "?"; + } + return _url + prefix + "renderedObjectId=" + this.objectId; + } + return _url; + }, +}); diff --git a/cmis_web_proxy/static/src/js/form_widget.js b/cmis_web_proxy/static/src/js/form_widget.js deleted file mode 100644 index a2c92c63..00000000 --- a/cmis_web_proxy/static/src/js/form_widget.js +++ /dev/null @@ -1,66 +0,0 @@ -/* --------------------------------------------------------- - + * Odoo web_cmis_viewer - + * Author Laurent Mignon 2016 Acsone SA/NV - + * License in __openerp__.py at root level of the module - + *--------------------------------------------------------- - +*/ - -odoo.define("cmis_web_proxy.form_widgets", function (require) { - "use strict"; - - var form_widgets = require("cmis_web.form_widgets"); - - form_widgets.CmisObjectWrapper.include({ - get_preview_url: function () { - var _url = this._super.apply(this, arguments); - if (_url) { - var prefix = "&"; - if (_url.indexOf("?") < 0) { - prefix = "?"; - } - return _url + prefix + "renderedObjectId=" + this.objectId; - } - }, - }); - - form_widgets.FieldCmisFolder.include({ - gen_cmis_session_token: function () { - return JSON.stringify({ - model: this.model, - res_id: this.res_id, - field_name: this.name, - }); - }, - - set_cmis_session_token: function () { - if (this.apply_odoo_security) { - this.cmis_session.setToken(this.gen_cmis_session_token()); - } - }, - - set_root_folder_id: function (folderId) { - var self = this; - $.when(self.cmis_session_initialized, self.table_rendered).done( - function () { - self.set_cmis_session_token(); - } - ); - this._super.apply(this, arguments); - }, - - bind_cmis_config: function (backend) { - this._super.apply(this, arguments); - this.apply_odoo_security = backend.apply_odoo_security; - }, - - get_preview_url_params: function (cmisObjectWrapped) { - var params = this._super.apply(this, arguments); - if (this.apply_odoo_security) { - // Add the token as parameter and into the http headers - var token = this.gen_cmis_session_token(); - params.token = token; - } - return params; - }, - }); -}); diff --git a/cmis_web_proxy/tests/test_cmis_proxy.py b/cmis_web_proxy/tests/test_cmis_proxy.py index 90d30af2..d2d9d54a 100644 --- a/cmis_web_proxy/tests/test_cmis_proxy.py +++ b/cmis_web_proxy/tests/test_cmis_proxy.py @@ -9,6 +9,7 @@ from cmislib.exceptions import NotSupportedException import odoo.tests.common as common +from odoo.tools import config as odoo_config _logger = logging.getLogger(__name__) @@ -59,18 +60,17 @@ def setUp(self): "apply_odoo_security": False, "username": cmis_user, "password": cmis_pwd, - "version": "1.0", } ) web_descr = self.cmis_backend.get_web_description()[self.cmis_backend.id] - proxy_path = web_descr["cmis_location"] + proxy_path = web_descr["location"] self.authenticate("admin", "admin") self.cmis_url = "http://%s:%d%s" % ( common.HOST, - common.PORT, + odoo_config["http_port"], proxy_path, ) - self.headers = {"Cookie": "session_id=%s" % self.session_id} + self.headers = {"Cookie": "session_id=%s" % self.opener.cookies["session_id"]} self.cmis_client = CmisClient( self.cmis_url, "admin", "admin", headers=self.headers ) diff --git a/cmis_web_proxy/views/cmis_web_proxy.xml b/cmis_web_proxy/views/cmis_web_proxy.xml deleted file mode 100644 index 8998bb3e..00000000 --- a/cmis_web_proxy/views/cmis_web_proxy.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - -