Skip to content

Commit

Permalink
[FIX] cmis_web: improve safety of the checkout process
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-halleux committed Sep 29, 2022
1 parent f419a18 commit 4da9793
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
11 changes: 9 additions & 2 deletions cmis_web/i18n/cmis_web.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-09-29 09:27+0000\n"
"PO-Revision-Date: 2022-09-29 09:27+0000\n"
"POT-Creation-Date: 2022-09-29 10:37+0000\n"
"PO-Revision-Date: 2022-09-29 10:37+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -142,6 +142,13 @@ msgstr ""
msgid "Cancel Edit"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Cancel checkout"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
Expand Down
9 changes: 8 additions & 1 deletion cmis_web/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-09-29 09:27+0000\n"
"POT-Creation-Date: 2022-09-29 10:37+0000\n"
"PO-Revision-Date: 2019-04-25 16:05+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -54,6 +54,7 @@ msgstr "Un document avec le même nom existe déjà."
#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Actions"
msgstr ""

Expand Down Expand Up @@ -135,6 +136,12 @@ msgstr "Annuler"
msgid "Cancel Edit"
msgstr "Annuler l'édition"

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
msgid "Cancel checkout"
msgstr "Annuler la modification en cours"

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
Expand Down
43 changes: 41 additions & 2 deletions cmis_web/static/src/js/form_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ odoo.define('cmis_web.form_widgets', function (require) {
this.versionSeriesId = this.getSuccinctProperty('cmis:versionSeriesId', cmis_object);
this.versionLabel = this.getSuccinctProperty('cmis:versionLabel');
this.url = this.cmis_session.getContentStreamURL(this.objectId, 'attachment');
this.isCheckedOut = !!this.getSuccinctProperty("cmis:versionSeriesCheckedOutId");
this.allowableActions = cmis_object.allowableActions;
this.renditions = cmis_object.renditions;
},
Expand Down Expand Up @@ -1102,10 +1103,20 @@ odoo.define('cmis_web.form_widgets', function (require) {
this.cmis_session.checkOut(self.document.objectId)
.ok(function(data) {
var dialog = new CmisCheckinDialog(self, self.wrap_cmis_object(data), true);
dialog.onDestroy(function() {
self.verify_is_checked_out()
.then(function (isCheckedOut) {
if (isCheckedOut) {
return self._cancel_checkout.bind(self)();
}
})
.catch((error) => console.log("error"))
.finally(() => self.trigger_up("reload"));
});
dialog.open();
})
.notOk(function() {
self._cancel_checkout();
self._cancel_checkout.bind(self);
});

},
Expand All @@ -1124,8 +1135,32 @@ odoo.define('cmis_web.form_widgets', function (require) {

},

on_cancel_checkout: function (e) {
var self = this;
this._cancel_checkout().finally(() => self.trigger_up('reload'));
},

_cancel_checkout: function () {
this.cmis_session.cancelCheckOut(this.document.objectId);
var self = this;
return new Promise(function(resolve, reject) {
self.cmis_session.cancelCheckOut(self.document.objectId)
.ok((data) => resolve(data))
.notOk((error) => reject(error));
});
},

verify_is_checked_out: function() {
var self = this;
return new Promise(function (resolve) {
self.cmis_session.getObject(self.document.objectId)
.ok(function (doc) {
resolve(self.wrap_cmis_object(doc).isCheckedOut)
})
.notOk(function (doc) {
// safer to assume the doc is checked out
resolve(true)
})
});
},

toggle_more_action: function name() {
Expand Down Expand Up @@ -1179,6 +1214,10 @@ odoo.define('cmis_web.form_widgets', function (require) {
self.stopEvent(e);
self.on_click_get_properties();
});
$el_actions.find('.content-action-cancel-checkout').on('click', function (e) {
self.stopEvent(e);
self.on_cancel_checkout();
});
},

register_document_add_events: function () {
Expand Down
6 changes: 4 additions & 2 deletions cmis_web/static/src/xml/form_widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,10 @@
</button>
<ul class="dropdown-menu btn-block" t-att-aria-labelledby="object.getSuccinctProperty('cmis:objectId')" overflow-working="0">
<li t-if='canUpdateProperties'><a class='content-action-rename' href="#">Rename</a></li>
<li><a class='content-action-checkin' href="#">Import new version</a></li>
<li><a class='content-action-history' href="#">Show document history</a></li>
<li t-if='canUpdateProperties'><a class='content-action-checkin' href="#">Import new version</a></li>
<li t-if="canGetContentStream"><a class='content-action-history' href="#">Show document history</a></li>
<li t-if='object.isCheckedOut' role="separator" class="divider"></li>
<li t-if='object.isCheckedOut'><a class='content-action-cancel-checkout' href="#">Cancel checkout</a></li>
</ul>
</div>
</t>
Expand Down

0 comments on commit 4da9793

Please sign in to comment.