Skip to content

Commit 118b363

Browse files
authored
πŸŽ¨πŸ› [Frontend] Retry /auth/logout call if times out (#6558)
1 parent c13e822 commit 118b363

File tree

18 files changed

+115
-74
lines changed

18 files changed

+115
-74
lines changed

β€Žservices/static-webserver/client/source/class/osparc/Application.jsβ€Ž

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ qx.Class.define("osparc.Application", {
432432
.then(data => {
433433
if (data.role.toLowerCase() === "guest") {
434434
// Logout a guest trying to access the Dashboard
435-
osparc.auth.Manager.getInstance().logout();
435+
this.logout();
436436
} else {
437437
this.__loadMainPage();
438438
}
@@ -564,18 +564,22 @@ qx.Class.define("osparc.Application", {
564564
* Resets session and restarts
565565
*/
566566
logout: function(forcedReason) {
567-
if (forcedReason) {
568-
osparc.FlashMessenger.getInstance().logAs(forcedReason, "WARNING", 0);
569-
} else {
570-
osparc.FlashMessenger.getInstance().logAs(this.tr("You are logged out"), "INFO");
571-
}
572567
const isLoggedIn = osparc.auth.Manager.getInstance().isLoggedIn();
573568
if (isLoggedIn) {
574569
osparc.auth.Manager.getInstance().logout()
575-
.finally(() => this.__closeAllAndToLoginPage());
570+
.finally(() => this.__loggedOut(forcedReason));
571+
} else {
572+
this.__loggedOut(forcedReason);
573+
}
574+
},
575+
576+
__loggedOut: function(forcedReason) {
577+
if (forcedReason) {
578+
osparc.FlashMessenger.getInstance().logAs(forcedReason, "WARNING", 0);
576579
} else {
577-
this.__closeAllAndToLoginPage();
580+
osparc.FlashMessenger.getInstance().logAs(this.tr("You are logged out"), "INFO");
578581
}
582+
this.__closeAllAndToLoginPage();
579583
},
580584

581585
__closeAllAndToLoginPage: function() {

β€Žservices/static-webserver/client/source/class/osparc/auth/Manager.jsβ€Ž

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,15 @@ qx.Class.define("osparc.auth.Manager", {
212212
"client_session_id": osparc.utils.Utils.getClientSessionID()
213213
}
214214
};
215-
return osparc.data.Resources.fetch("auth", "postLogout", params)
216-
.then(data => this.fireEvent("loggedOut"))
217-
.catch(error => console.log("already logged out"))
218-
.finally(this.__logoutUser());
215+
const options = {
216+
timeout: 5000,
217+
timeoutRetries: 5
218+
};
219+
return osparc.data.Resources.fetch("auth", "postLogout", params, options)
220+
.finally(() => {
221+
this.__logoutUser();
222+
this.fireEvent("loggedOut");
223+
});
219224
},
220225

221226
resetPasswordRequest: function(email, successCbk, failCbk, context) {

β€Žservices/static-webserver/client/source/class/osparc/dashboard/ResourceFilter.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
180180
});
181181

182182

183-
if (this.__tagButtons.length >= maxTags) {
183+
if (this.__tagButtons.length > maxTags) {
184184
const showAllButton = new qx.ui.form.Button(this.tr("All Tags..."), "@FontAwesome5Solid/tags/20");
185185
showAllButton.set({
186186
appearance: "filter-toggle-button"

β€Žservices/static-webserver/client/source/class/osparc/dashboard/ServiceBrowser.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ qx.Class.define("osparc.dashboard.ServiceBrowser", {
128128
this._hideLoadingPage();
129129
const params = {
130130
url: {
131-
"studyId": studyId
131+
studyId
132132
}
133133
};
134-
osparc.data.Resources.fetch("studies", "delete", params, studyId);
134+
osparc.data.Resources.fetch("studies", "delete", params);
135135
};
136136
const isStudyCreation = true;
137137
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);

β€Žservices/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.jsβ€Ž

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,24 +672,24 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
672672
limit: osparc.dashboard.ResourceBrowserBase.PAGINATED_STUDIES,
673673
}
674674
};
675-
676675
const nextPageParams = this.__getNextPageParams();
677676
if (nextPageParams) {
678677
params.url.offset = nextPageParams.offset;
679678
params.url.limit = nextPageParams.limit;
680679
}
681-
const options = {
682-
resolveWResponse: true
683-
};
684-
685680
const requestParams = this.__getRequestParams();
686681
Object.entries(requestParams).forEach(([key, value]) => {
687682
params.url[key] = value;
688683
});
684+
685+
const options = {
686+
resolveWResponse: true
687+
};
688+
689689
if ("text" in requestParams) {
690-
return osparc.data.Resources.fetch("studies", "getPageSearch", params, undefined, options);
690+
return osparc.data.Resources.fetch("studies", "getPageSearch", params, options);
691691
}
692-
return osparc.data.Resources.fetch("studies", "getPage", params, undefined, options);
692+
return osparc.data.Resources.fetch("studies", "getPage", params, options);
693693
},
694694

695695
invalidateStudies: function() {
@@ -1220,7 +1220,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
12201220
studyId
12211221
}
12221222
};
1223-
osparc.data.Resources.fetch("studies", "delete", params, studyId);
1223+
osparc.data.Resources.fetch("studies", "delete", params);
12241224
};
12251225
const isStudyCreation = true;
12261226
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);
@@ -1545,7 +1545,10 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
15451545
"studyId": studyData["uuid"]
15461546
}
15471547
};
1548-
const fetchPromise = osparc.data.Resources.fetch("studies", "duplicate", params, null, {"pollTask": true});
1548+
const options = {
1549+
pollTask: true
1550+
};
1551+
const fetchPromise = osparc.data.Resources.fetch("studies", "duplicate", params, options);
15491552
const interval = 1000;
15501553
const pollTasks = osparc.data.PollTasks.getInstance();
15511554
pollTasks.createPollingTask(fetchPromise, interval)

β€Žservices/static-webserver/client/source/class/osparc/dashboard/TemplateBrowser.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
145145
this._hideLoadingPage();
146146
const params = {
147147
url: {
148-
"studyId": studyId
148+
studyId
149149
}
150150
};
151-
osparc.data.Resources.fetch("studies", "delete", params, studyId);
151+
osparc.data.Resources.fetch("studies", "delete", params);
152152
};
153153
const isStudyCreation = true;
154154
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);

β€Žservices/static-webserver/client/source/class/osparc/data/Resources.jsβ€Ž

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ qx.Class.define("osparc.data.Resources", {
113113
"studies": {
114114
useCache: true,
115115
idField: "uuid",
116+
deleteId: "studyId",
116117
endpoints: {
117118
get: {
118119
method: "GET",
@@ -711,6 +712,7 @@ qx.Class.define("osparc.data.Resources", {
711712
"tokens": {
712713
useCache: true,
713714
idField: "service",
715+
deleteId: "service",
714716
endpoints: {
715717
get: {
716718
method: "GET",
@@ -1200,8 +1202,9 @@ qx.Class.define("osparc.data.Resources", {
12001202
* TAGS
12011203
*/
12021204
"tags": {
1203-
idField: "id",
12041205
useCache: true,
1206+
idField: "id",
1207+
deleteId: "tagId",
12051208
endpoints: {
12061209
get: {
12071210
method: "GET",
@@ -1244,22 +1247,24 @@ qx.Class.define("osparc.data.Resources", {
12441247
* @param {String} resource Name of the resource as defined in the static property 'resources'.
12451248
* @param {String} endpoint Name of the endpoint. Several endpoints can be defined for each resource.
12461249
* @param {Object} params Object containing the parameters for the url and for the body of the request, under the properties 'url' and 'data', respectively.
1247-
* @param {String} deleteId When deleting, id of the element that needs to be deleted from the cache.
1248-
* @param {Object} options Collections of options
1250+
* @param {Object} options Collections of options (pollTask, resolveWResponse, timeout, timeoutRetries)
12491251
*/
1250-
fetch: function(resource, endpoint, params = {}, deleteId, options = {}) {
1252+
fetch: function(resource, endpoint, params = {}, options = {}) {
12511253
return new Promise((resolve, reject) => {
12521254
if (this.self().resources[resource] == null) {
12531255
reject(Error(`Error while fetching ${resource}: the resource is not defined`));
12541256
}
12551257

12561258
const resourceDefinition = this.self().resources[resource];
1257-
const res = new osparc.io.rest.Resource(resourceDefinition.endpoints);
1258-
1259+
const res = new osparc.io.rest.Resource(resourceDefinition.endpoints, options.timeout);
12591260
if (!res.includesRoute(endpoint)) {
12601261
reject(Error(`Error while fetching ${resource}: the endpoint is not defined`));
12611262
}
12621263

1264+
const sendRequest = () => {
1265+
res[endpoint](params.url || null, params.data || null);
1266+
}
1267+
12631268
res.addListenerOnce(endpoint + "Success", e => {
12641269
const response = e.getRequest().getResponse();
12651270
const endpointDef = resourceDefinition.endpoints[endpoint];
@@ -1276,7 +1281,8 @@ qx.Class.define("osparc.data.Resources", {
12761281
}
12771282
}
12781283
if (useCache) {
1279-
if (endpoint.includes("delete")) {
1284+
if (endpoint.includes("delete") && resourceDefinition["deleteId"] && resourceDefinition["deleteId"] in params.url) {
1285+
const deleteId = params.url[resourceDefinition["deleteId"]];
12801286
this.__removeCached(resource, deleteId);
12811287
} else if (endpointDef.method === "POST" && options.pollTask !== true) {
12821288
this.__addCached(resource, data);
@@ -1297,7 +1303,15 @@ qx.Class.define("osparc.data.Resources", {
12971303
}
12981304
}, this);
12991305

1300-
res.addListenerOnce(endpoint + "Error", e => {
1306+
res.addListener(endpoint + "Error", e => {
1307+
if (e.getPhase() === "timeout") {
1308+
if (options.timeout && options.timeoutRetries) {
1309+
options.timeoutRetries--;
1310+
sendRequest();
1311+
return;
1312+
}
1313+
}
1314+
13011315
let message = null;
13021316
let status = null;
13031317
if (e.getData().error) {
@@ -1330,7 +1344,7 @@ qx.Class.define("osparc.data.Resources", {
13301344
if ("status" in err && err.status === 401) {
13311345
// Unauthorized again, the cookie might have expired.
13321346
// We can assume that all calls after this will respond with 401, so bring the user ot the login page.
1333-
qx.core.Init.getApplication().logout(qx.locale.Manager.tr("You were logged out"));
1347+
qx.core.Init.getApplication().logout(qx.locale.Manager.tr("You were logged out. Your cookie might have expired."));
13341348
}
13351349
});
13361350
}
@@ -1345,7 +1359,7 @@ qx.Class.define("osparc.data.Resources", {
13451359
reject(err);
13461360
});
13471361

1348-
res[endpoint](params.url || null, params.data || null);
1362+
sendRequest();
13491363
});
13501364
},
13511365

@@ -1362,7 +1376,7 @@ qx.Class.define("osparc.data.Resources", {
13621376
const options = {
13631377
resolveWResponse: true
13641378
};
1365-
this.fetch(resource, endpoint, params, null, options)
1379+
this.fetch(resource, endpoint, params, options)
13661380
.then(resp => {
13671381
// sometimes there is a kind of a double "data"
13681382
const meta = ("_meta" in resp["data"]) ? resp["data"]["_meta"] : resp["_meta"];
@@ -1426,14 +1440,14 @@ qx.Class.define("osparc.data.Resources", {
14261440
* @param {Object} params Object containing the parameters for the url and for the body of the request, under the properties 'url' and 'data', respectively.
14271441
* @param {Boolean} useCache Whether the cache has to be used. If false, an API call will be issued.
14281442
*/
1429-
get: function(resource, params, useCache = true) {
1443+
get: function(resource, params = {}, useCache = true, options = {}) {
14301444
if (useCache) {
14311445
const stored = this.__getCached(resource);
14321446
if (stored) {
14331447
return Promise.resolve(stored);
14341448
}
14351449
}
1436-
return this.fetch(resource, "get", params || {});
1450+
return this.fetch(resource, "get", params, options);
14371451
},
14381452

14391453
/**
@@ -1489,14 +1503,14 @@ qx.Class.define("osparc.data.Resources", {
14891503

14901504
statics: {
14911505
API: "/v0",
1492-
fetch: function(resource, endpoint, params, deleteId, options = {}) {
1493-
return this.getInstance().fetch(resource, endpoint, params, deleteId, options);
1506+
fetch: function(resource, endpoint, params, options = {}) {
1507+
return this.getInstance().fetch(resource, endpoint, params, options);
14941508
},
14951509
getOne: function(resource, params, id, useCache) {
14961510
return this.getInstance().getOne(resource, params, id, useCache);
14971511
},
1498-
get: function(resource, params, useCache) {
1499-
return this.getInstance().get(resource, params, useCache);
1512+
get: function(resource, params, useCache, options) {
1513+
return this.getInstance().get(resource, params, useCache, options);
15001514
},
15011515

15021516
getServiceUrl: function(key, version) {

β€Žservices/static-webserver/client/source/class/osparc/desktop/MainPage.jsβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ qx.Class.define("osparc.desktop.MainPage", {
232232
},
233233
data: data["studyData"]
234234
};
235-
const fetchPromise = osparc.data.Resources.fetch("studies", "postToTemplate", params, null, {"pollTask": true});
235+
const options = {
236+
pollTask: true
237+
};
238+
const fetchPromise = osparc.data.Resources.fetch("studies", "postToTemplate", params, options);
236239
const pollTasks = osparc.data.PollTasks.getInstance();
237240
const interval = 1000;
238241
pollTasks.createPollingTask(fetchPromise, interval)

β€Žservices/static-webserver/client/source/class/osparc/desktop/StudyEditorIdlingTracker.jsβ€Ž

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,18 @@ qx.Class.define("osparc.desktop.StudyEditorIdlingTracker", {
101101
const timeSinceInactivityThreshold = this.__idlingTime - inactivityThresholdT;
102102
if (timeSinceInactivityThreshold % this.self().INACTIVITY_REQUEST_PERIOD_S == 0) {
103103
// check if backend reports project as inactive
104-
osparc.data.Resources.fetch("studies", "getInactivity", {
104+
const params = {
105105
url: {
106106
studyId: this.__studyUuid
107107
}
108-
}).then(data => {
109-
if (data["is_inactive"]) {
110-
this.__displayFlashMessage(flashMessageDurationS);
111-
}
112-
}).catch(err => {
113-
console.error(err);
114-
});
108+
};
109+
osparc.data.Resources.fetch("studies", "getInactivity", params)
110+
.then(data => {
111+
if (data["is_inactive"]) {
112+
this.__displayFlashMessage(flashMessageDurationS);
113+
}
114+
})
115+
.catch(err => console.error(err));
115116
}
116117
}
117118
};

β€Žservices/static-webserver/client/source/class/osparc/desktop/credits/TransactionsTableModel.jsβ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ qx.Class.define("osparc.desktop.credits.TransactionsTableModel", {
5353
members: {
5454
// overridden
5555
_loadRowCount() {
56-
osparc.data.Resources.fetch("payments", "get", {
56+
const params = {
5757
url: {
5858
limit: 1,
5959
offset: 0
6060
}
61-
}, undefined, {
61+
};
62+
const options = {
6263
resolveWResponse: true
63-
})
64+
};
65+
osparc.data.Resources.fetch("payments", "get", params, options)
6466
.then(({ data: resp }) => {
6567
this._onRowCountLoaded(resp["_meta"].total)
6668
})

0 commit comments

Comments
Β (0)