Commit 2ca62f1f authored by Romain Courteaud's avatar Romain Courteaud

erp5_gadget_interface_validator: stop relying on appcache

Use the precache script to get the list of gadgets.
Ensure to also check the launcher gadget.

Report subgadget service error.
parent 5471b5bb
...@@ -257,8 +257,7 @@ ...@@ -257,8 +257,7 @@
// XXX Load in an iframe // XXX Load in an iframe
return context.declareGadget('gadget_interface_loader.html', { return context.declareGadget('gadget_interface_loader.html', {
scope: gadget_to_check_url, scope: gadget_to_check_url,
element: element, element: element
sandbox: 'iframe'
}); });
}) })
.push(function (result) { .push(function (result) {
...@@ -356,13 +355,21 @@ ...@@ -356,13 +355,21 @@
return this.changeState(options); return this.changeState(options);
}) })
.onStateChange(function () { .onStateChange(function (modification_dict) {
var context = this, var context = this,
required_interface_list = [], required_interface_list = [],
gadget_method_list = [], gadget_method_list = [],
error_list = []; error_list = [];
if (modification_dict.hasOwnProperty('gadget_to_check_url')) {
return getOrDeclareGadget(context, context.state.gadget_to_check_url) return getOrDeclareGadget(context, context.state.gadget_to_check_url)
/*
.push(undefined, function (error) {
console.warn('oups', error);
context.element.innerHTML = '';
return;
});
*/
.push(function (gadget_to_check) { .push(function (gadget_to_check) {
// Get the list of interfaces/methods // Get the list of interfaces/methods
...@@ -402,7 +409,8 @@ ...@@ -402,7 +409,8 @@
for (i = 0; i < method_table.length; i += 1) { for (i = 0; i < method_table.length; i += 1) {
for (j = 0; j < method_table[i].length; j += 1) { for (j = 0; j < method_table[i].length; j += 1) {
// Check method declared twice // Check method declared twice
if (interface_method_list.indexOf(method_table[i][j].name) >= 0) { if (interface_method_list.indexOf(method_table[i][j].name) >=
0) {
error_list.push({ error_list.push({
details: "Method documented in multiple interface\n" + details: "Method documented in multiple interface\n" +
method_table[i][j].name method_table[i][j].name
...@@ -465,9 +473,21 @@ ...@@ -465,9 +473,21 @@
.push(undefined, function (error) { .push(undefined, function (error) {
console.warn(error); console.warn(error);
context.element.firstElementChild.textContent = context.element.firstElementChild.textContent =
"Unexpected error"; "Unexpected error: " + error;
}); });
}
if (modification_dict.hasOwnProperty('error')) {
console.warn(context.state.error);
context.element.firstElementChild.textContent =
"Unexpected error: " + context.state.error;
}
})
.allowPublicAcquisition('reportServiceError', function (param_list) {
// Subgadget services failed.
// Report it as an error instead of crashing the page
return this.changeState({error: param_list[0]});
}); });
}(window, rJS, RSVP, DOMParser, jIO, console, document)); }(window, rJS, RSVP, DOMParser, jIO, console, document));
\ No newline at end of file
...@@ -150,11 +150,13 @@ ...@@ -150,11 +150,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -198,16 +200,20 @@ ...@@ -198,16 +200,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -230,7 +236,7 @@ ...@@ -230,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>972.15264.49528.31470</string> </value> <value> <string>981.53320.7091.32256</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +254,7 @@ ...@@ -248,7 +254,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1544521627.98</float> <float>1581589017.29</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -257,16 +263,20 @@ ...@@ -257,16 +263,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -316,7 +326,9 @@ ...@@ -316,7 +326,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */ /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global rJS, window*/ /*global rJS, window, document*/
(function (window, rJS) { (function (window, rJS, document) {
"use strict"; "use strict";
rJS(window) rJS(window)
.declareMethod("declareGadgetToCheck", function (url) { .declareMethod("declareGadgetToCheck", function (url) {
return this.declareGadget(url, { var div = document.createElement('div'),
scope: 'gadget_to_check' gadget = this;
this.element.innerHTML = '';
this.element.appendChild(div);
return gadget.declareGadget(url, {
scope: 'gadget_to_check',
sandbox: 'iframe',
element: div
}) })
.push(function () { .push(function () {
// Do not return the loaded gadget. // Do not return the loaded gadget.
...@@ -29,4 +35,4 @@ ...@@ -29,4 +35,4 @@
}); });
}); });
}(window, rJS)); }(window, rJS, document));
\ No newline at end of file \ No newline at end of file
...@@ -148,11 +148,13 @@ ...@@ -148,11 +148,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -196,16 +198,20 @@ ...@@ -196,16 +198,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -228,7 +234,7 @@ ...@@ -228,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>970.15515.25000.46984</string> </value> <value> <string>981.53324.16635.57019</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +252,7 @@ ...@@ -246,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1536845809.9</float> <float>1581589224.71</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -255,16 +261,20 @@ ...@@ -255,16 +261,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -312,7 +322,9 @@ ...@@ -312,7 +322,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
/*global window, rJS, RSVP, jIO, QueryFactory, SimpleQuery */ /*global window, rJS, RSVP, jIO, QueryFactory, SimpleQuery, URL */
/*jslint indent: 2, maxerr: 3, nomen: true */ /*jslint indent: 2, maxerr: 3, nomen: true */
(function (window, rJS, RSVP, jIO, QueryFactory, SimpleQuery) { (function (window, rJS, RSVP, jIO, QueryFactory, SimpleQuery, URL) {
"use strict"; "use strict";
////////////////////////////////////////////// //////////////////////////////////////////////
...@@ -12,16 +12,25 @@ ...@@ -12,16 +12,25 @@
return (new RegExp(suffix + '$', 'i')).test(str); return (new RegExp(suffix + '$', 'i')).test(str);
} }
function fetchAppcacheData(appcache_url) { function fetchPrecacheData(precache_url) {
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return jIO.util.ajax({ return jIO.util.ajax({
url: appcache_url, url: precache_url,
dataType: 'text' dataType: 'json'
}); });
}) })
.push(function (evt) { .push(function (evt) {
return evt.target.responseText.split('\n'); var key,
precache_dict = evt.target.response,
result_list = [],
precache_absolute_url = (new URL(precache_url, window.location)).href;
for (key in precache_dict) {
if (precache_dict.hasOwnProperty(key)) {
result_list.push((new URL(key, precache_absolute_url)).href);
}
}
return result_list;
}); });
} }
...@@ -32,8 +41,8 @@ ...@@ -32,8 +41,8 @@
var gadget_list = [], var gadget_list = [],
i; i;
for (i = 0; i < filename_list.length; i += 1) { for (i = 0; i < filename_list.length; i += 1) {
if (endsWith(filename_list[i], '.html') && if (endsWith(filename_list[i], '.html') ||
(filename_list[i][0] !== '#')) { endsWith(filename_list[i], '/')) {
gadget_list.push(filename_list[i]); gadget_list.push(filename_list[i]);
} }
} }
...@@ -66,11 +75,11 @@ ...@@ -66,11 +75,11 @@
InterfaceValidatorStorage.prototype.buildQuery = function (options) { InterfaceValidatorStorage.prototype.buildQuery = function (options) {
// XXX HARDCODED // XXX HARDCODED
var query = QueryFactory.create(options.query || ''); var query = QueryFactory.create(options.query || '');
if (!((query instanceof SimpleQuery) && (query.key === 'appcache_url'))) { if (!((query instanceof SimpleQuery) && (query.key === 'precache_url'))) {
// Only accept simple query with an appcache_url // Only accept simple query with an appcache_url
return []; return [];
} }
return fetchAppcacheData(query.value) return fetchPrecacheData(query.value)
// return fetchAppcacheData('gadget_interface_validator_test.appcache') // return fetchAppcacheData('gadget_interface_validator_test.appcache')
.push(function (filename_list) { .push(function (filename_list) {
return filterGadgetList(filename_list); return filterGadgetList(filename_list);
...@@ -123,4 +132,4 @@ ...@@ -123,4 +132,4 @@
return wrapJioCall(this, 'get', arguments); return wrapJioCall(this, 'get', arguments);
}); });
}(window, rJS, RSVP, jIO, QueryFactory, SimpleQuery)); }(window, rJS, RSVP, jIO, QueryFactory, SimpleQuery, URL));
\ No newline at end of file \ No newline at end of file
...@@ -148,11 +148,13 @@ ...@@ -148,11 +148,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -196,16 +198,20 @@ ...@@ -196,16 +198,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -228,7 +234,7 @@ ...@@ -228,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.34342.13291.34082</string> </value> <value> <string>981.51931.38103.24746</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +252,7 @@ ...@@ -246,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1530196276.82</float> <float>1581590120.37</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -255,16 +261,20 @@ ...@@ -255,16 +261,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -312,7 +322,9 @@ ...@@ -312,7 +322,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
"list_method": "portal_catalog", "list_method": "portal_catalog",
"query": "urn:jio:allDocs", "query": "urn:jio:allDocs",
"portal_type": [], "portal_type": [],
"search_column_list": [['appcache_url', 'Appcache']], "search_column_list": [['precache_url', 'Precache']],
"sort_column_list": [], "sort_column_list": [],
"sort": [], "sort": [],
"title": "Gadgets", "title": "Gadgets",
......
...@@ -148,11 +148,13 @@ ...@@ -148,11 +148,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -196,16 +198,20 @@ ...@@ -196,16 +198,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -228,7 +234,7 @@ ...@@ -228,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>972.15241.36748.63146</string> </value> <value> <string>977.38881.34981.23125</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +252,7 @@ ...@@ -246,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1544537143.01</float> <float>1581503610.2</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -255,16 +261,20 @@ ...@@ -255,16 +261,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -312,7 +322,9 @@ ...@@ -312,7 +322,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment