From 188e71e1af53a30795df91817564933debca39ee Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 11:56:37 +0200 Subject: [PATCH 1/7] remove fake.dev --- .../client/source/class/osparc/Application.js | 10 -- .../source/class/osparc/dev/__init__.js | 3 - .../class/osparc/dev/fake/srv/__init__.js | 11 -- .../class/osparc/dev/fake/srv/db/Project.js | 23 ---- .../class/osparc/dev/fake/srv/db/User.js | 42 ------- .../dev/fake/srv/restapi/Authentication.js | 103 ------------------ .../class/osparc/dev/fake/srv/restapi/User.js | 50 --------- 7 files changed, 242 deletions(-) delete mode 100644 services/static-webserver/client/source/class/osparc/dev/__init__.js delete mode 100644 services/static-webserver/client/source/class/osparc/dev/fake/srv/__init__.js delete mode 100644 services/static-webserver/client/source/class/osparc/dev/fake/srv/db/Project.js delete mode 100644 services/static-webserver/client/source/class/osparc/dev/fake/srv/db/User.js delete mode 100644 services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/Authentication.js delete mode 100644 services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/User.js diff --git a/services/static-webserver/client/source/class/osparc/Application.js b/services/static-webserver/client/source/class/osparc/Application.js index 9d5b4567274..f00f4e12c93 100644 --- a/services/static-webserver/client/source/class/osparc/Application.js +++ b/services/static-webserver/client/source/class/osparc/Application.js @@ -79,11 +79,6 @@ qx.Class.define("osparc.Application", { e.returnValue = ""; } }); - if (qx.core.Environment.get("dev.enableFakeSrv")) { - console.debug("Fake server enabled"); - osparc.dev.fake.srv.restapi.User; - osparc.dev.fake.srv.restapi.Authentication; - } // Setting up auth manager osparc.auth.Manager.getInstance().addListener("logout", () => this.__restart(), this); @@ -275,11 +270,6 @@ qx.Class.define("osparc.Application", { __restart: function() { let isLogged = osparc.auth.Manager.getInstance().isLoggedIn(); - if (qx.core.Environment.get("dev.disableLogin")) { - console.warn("Login page was disabled", "Starting main application ..."); - isLogged = true; - } - if (isLogged) { this.__loadMainPage(); } else { diff --git a/services/static-webserver/client/source/class/osparc/dev/__init__.js b/services/static-webserver/client/source/class/osparc/dev/__init__.js deleted file mode 100644 index 6b574aaa5c7..00000000000 --- a/services/static-webserver/client/source/class/osparc/dev/__init__.js +++ /dev/null @@ -1,3 +0,0 @@ -/** - * Development, testing and debugging tools. - */ diff --git a/services/static-webserver/client/source/class/osparc/dev/fake/srv/__init__.js b/services/static-webserver/client/source/class/osparc/dev/fake/srv/__init__.js deleted file mode 100644 index 3849866954e..00000000000 --- a/services/static-webserver/client/source/class/osparc/dev/fake/srv/__init__.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Fake server. It is activated using qx.Environment - * - * - Enable qx environment value via url parameter as - * http://localhost:8080/index.html?qxenv:dev.enableFakeSrv:true - * - * - This feature can be activated as - *
- *    qx serve --set qx.allowUrlSettings=true
- * 
- */ diff --git a/services/static-webserver/client/source/class/osparc/dev/fake/srv/db/Project.js b/services/static-webserver/client/source/class/osparc/dev/fake/srv/db/Project.js deleted file mode 100644 index f5e615f4580..00000000000 --- a/services/static-webserver/client/source/class/osparc/dev/fake/srv/db/Project.js +++ /dev/null @@ -1,23 +0,0 @@ -qx.Class.define("osparc.dev.fake.srv.db.Project", { - type: "static", - - statics: { - DUMMYNAMES: ["My EM-Simulation", "FDTD-Simulation", "Some Neuro-Simulatoin", "Clancy Model", "DemoPrj", "LF Simulation"], - - /** - * Creates a json object for a given study id - */ - getObject: function(studyId) { - const name = osparc.dev.fake.srv.db.Project.DUMMYNAMES[studyId]; - let study = { - id: studyId, - name: name, - description: "Short description of study " + name, - thumbnail: "https://imgplaceholder.com/171x96/cccccc/757575/ion-plus-round", - createdDate: new Date(1990 + name.length, 11, 25), - modifiedDate: new Date(1990 + name.length, 12, 25) - }; - return study; - } - } -}); diff --git a/services/static-webserver/client/source/class/osparc/dev/fake/srv/db/User.js b/services/static-webserver/client/source/class/osparc/dev/fake/srv/db/User.js deleted file mode 100644 index 6bbc9418999..00000000000 --- a/services/static-webserver/client/source/class/osparc/dev/fake/srv/db/User.js +++ /dev/null @@ -1,42 +0,0 @@ -qx.Class.define("osparc.dev.fake.srv.db.User", { - type: "static", - - statics: { - DUMMYNAMES: ["bizzy", "crespo", "anderegg", "guidon", "tobi", "maiz", "zastrow"], - - /** - * Creates a json object for a given user id - */ - getObject: function(userId) { - const uname = osparc.dev.fake.srv.db.User.DUMMYNAMES[userId]; - const uemail = osparc.dev.fake.srv.db.User.getEmail(userId); - let user = { - id: userId, - username: uname, - fullname: qx.lang.String.capitalize(uname), - email: uemail, - avatarUrl: osparc.utils.Avatar.getUrl(uemail, 200), - passwordHash: "z43", // This is supposed to be hashed - projects: [] // Ids of projects associated to it - }; - - const pnames = osparc.dev.fake.srv.db.Project.DUMMYNAMES; - for (let i = 0; i < uname.length; i++) { - const pid = i % pnames.length; - user.projects.push(osparc.dev.fake.srv.db.Project.getObject(pid)); - } - return user; - }, - - getEmail: function(userId) { - const userName = osparc.dev.fake.srv.db.User.DUMMYNAMES[userId]; - let tail = "@itis.ethz.ch"; - - if (userName == "tobi") { - tail = "@oetiker.ch"; - } - return userName + tail; - } - - } -}); diff --git a/services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/Authentication.js b/services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/Authentication.js deleted file mode 100644 index d60968125e3..00000000000 --- a/services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/Authentication.js +++ /dev/null @@ -1,103 +0,0 @@ -qx.Class.define("osparc.dev.fake.srv.restapi.Authentication", { - type: "static", - - statics: { - REMEMBER: false, - - mockData: [{ - method: "GET", - url: "api/v1.0/token", - response: function(request) { - console.log("Received request:", request); - - // Defaults unauthorized - let status = 401; - let headers = { - "Content-Type": "application/json" - }; - let body = null; - - const login = osparc.dev.fake.srv.restapi.Authentication.decodeAuthHeader(request.requestHeaders); - - const userId = osparc.dev.fake.srv.restapi.Authentication.checkCredentials(login); - if (userId !== null) { - console.debug("User ", osparc.dev.fake.srv.db.User.DUMMYNAMES[userId], "is logging in ..."); - status = 200; - body = { - token: osparc.dev.fake.srv.restapi.Authentication.createToken(userId) - }; - } - - request.respond(status, headers, qx.lang.Json.stringify(body)); - } - }], - - createToken: function(userId, expiration=24) { - return "this-is-a-dummy-token-that-expires-in-" + String(expiration) + "hours-for-" + String(userId); - }, - - getUserIdFromToken: function(token) { - if (token.startsWith("this-is-a-dummy-token-that-expires-in-")) { - let parts = token.split("-"); - return parts.pop(); - } - return null; - }, - - checkCredentials: function(login) { - let userId = osparc.dev.fake.srv.db.User.DUMMYNAMES.findIndex(function(userName, userIndex) { - const user = osparc.dev.fake.srv.db.User.getObject(userIndex); - return (login.email == user.email || login.email == user.username) && login.password == user.passwordHash; - }); - return userId>=0? userId: null; - }, - - /** - * Gets {email, password} from header - * produced by qx.io.request.authentication.Basic - */ - decodeAuthHeader: function(requestHeaders) { - let res = { - email: null, - password: null - }; - let header = requestHeaders["Authorization"]; - - // Remove 'Basic $value' - let value = header.split(" ")[1]; - // parse '$username : $password' - let pair = qx.util.Base64.decode(value).split(":"); - res.email = pair[0]; - res.password = pair[1]; - - return res; - }, - - /** - * Parse {email:, password:} object extracting - * parameters from body - * - */ - parseLoginParameters: function(requestBody) { - let res = { - email: null, - password: null - }; - - let vars = requestBody.split("&"); - for (let i = 0; i < vars.length; ++i) { - let pair = vars[i].split("="); - res[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); - } - return res; - } - }, - - defer: function(mystatics) { - if (qx.core.Environment.get("dev.enableFakeSrv")) { - console.debug("REST API Authentication enabled"); - qx.dev.FakeServer.getInstance().configure(mystatics.mockData); - } - } - -}); diff --git a/services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/User.js b/services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/User.js deleted file mode 100644 index 69a0db741e3..00000000000 --- a/services/static-webserver/client/source/class/osparc/dev/fake/srv/restapi/User.js +++ /dev/null @@ -1,50 +0,0 @@ -qx.Class.define("osparc.dev.fake.srv.restapi.User", { - type: "static", - - statics: { - mockData: [{ - method: "GET", - url: "api/v1.0/user/{id}", - response: function(request) { - let status = 200; // OK - let headers = { - "Content-Type": "application/json" - }; - - let parts = qx.util.StringSplit.split(request.url, "/"); - let userId = parts[parts.length - 1]; - let data = osparc.dev.fake.srv.db.User.createMock(userId); - let body = qx.lang.Json.stringify(data); - request.respond(status, headers, body); - // FIXME: unite api/v1/uisers - } - }, { - method: "GET", - url: "api/v1.0/users", - response: function(request) { - let users = osparc.dev.fake.srv.db.User.DUMMYNAMES; - - let data = []; - for (let i = 0; i < users.length; i++) { - data.push({ - id: i, - username: users[i] - }); - } - request.respond(200, - { - "Content-Type": "application/json" - }, - qx.lang.Json.stringify(data)); - } - }] - }, - - defer: function(mystatics) { - if (qx.core.Environment.get("dev.enableFakeSrv")) { - console.debug("REST API enabled", this.classname); - qx.dev.FakeServer.getInstance().configure(mystatics.mockData); - } - } - -}); From 2ecd7acf9140c7622df5fcf7757e7c12277d4140 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 13:49:31 +0200 Subject: [PATCH 2/7] only users with Write access can update disableServiceAutoStart --- .../client/source/class/osparc/dashboard/ResourceDetails.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js index 8cdbfc2de59..d8951445e9c 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js @@ -662,7 +662,9 @@ qx.Class.define("osparc.dashboard.ResourceDetails", { if (osparc.utils.Resources.isStudy(resourceData) || osparc.utils.Resources.isTemplate(resourceData)) { if (osparc.product.Utils.showDisableServiceAutoStart()) { const study = new osparc.data.model.Study(resourceData); - const autoStartButton = osparc.info.StudyUtils.createDisableServiceAutoStart(study); + const autoStartButton = osparc.info.StudyUtils.createDisableServiceAutoStart(study).set({ + enabled: osparc.data.model.Study.canIWrite(this.__resourceData["accessRights"]) + }); // eslint-disable-next-line no-underscore-dangle servicesBootOpts._add(new qx.ui.core.Spacer(null, 15)); // eslint-disable-next-line no-underscore-dangle From edad415e8f6b217e7b8abf3312746ecb15776dd1 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 14:08:54 +0200 Subject: [PATCH 3/7] Autostart services --- .../client/source/class/osparc/info/StudyUtils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/info/StudyUtils.js b/services/static-webserver/client/source/class/osparc/info/StudyUtils.js index 53284e82d46..a6a93011b89 100644 --- a/services/static-webserver/client/source/class/osparc/info/StudyUtils.js +++ b/services/static-webserver/client/source/class/osparc/info/StudyUtils.js @@ -184,16 +184,18 @@ qx.Class.define("osparc.info.StudyUtils", { * @param study {osparc.data.model.Study} Study Model */ createDisableServiceAutoStart: function(study) { + // the wording is now opposite to the value of the property + // Autostart services to true by default + const devObj = study.getDev(); const cb = new qx.ui.form.CheckBox().set({ - label: qx.locale.Manager.tr("Disable Services Auto Start"), + value: "disableServiceAutoStart" in devObj ? !devObj["disableServiceAutoStart"] : true, + label: qx.locale.Manager.tr("Autostart services"), toolTipText: qx.locale.Manager.tr("This will help opening and closing studies faster"), iconPosition: "right" }); - const devObj = study.getDev(); - cb.setValue(("disableServiceAutoStart" in devObj) ? devObj["disableServiceAutoStart"] : false); cb.addListener("changeValue", e => { const newVal = e.getData(); - devObj["disableServiceAutoStart"] = newVal; + devObj["disableServiceAutoStart"] = !newVal; study.updateStudy({ dev: devObj }); From e139fef03e070d321f2771210e7139bb5fbf5306 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 14:21:26 +0200 Subject: [PATCH 4/7] Reload button for Usage table --- .../client/source/class/osparc/desktop/credits/Usage.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/credits/Usage.js b/services/static-webserver/client/source/class/osparc/desktop/credits/Usage.js index b3e344976c8..d0666750cfc 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/credits/Usage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/credits/Usage.js @@ -55,7 +55,7 @@ qx.Class.define("osparc.desktop.credits.Usage", { selectBoxContainer.add(this.__fetchingImg); container.add(selectBoxContainer); - const filterContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox()) + const filterContainer = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)) this.__dateFilters = new osparc.desktop.credits.DateFilters(); this.__dateFilters.addListener("change", e => { this.__table.getTableModel().setFilters(e.getData()) @@ -73,6 +73,12 @@ qx.Class.define("osparc.desktop.credits.Usage", { this.__handleExport() }); filterContainer.add(this.__exportButton); + const refreshButton = new qx.ui.form.Button(this.tr("Reload"), "@FontAwesome5Solid/sync-alt/14").set({ + allowStretchY: false, + alignY: "bottom" + }); + refreshButton.addListener("execute", () => this.__table && this.__table.getTableModel().reloadData()); + filterContainer.add(refreshButton) container.add(filterContainer); this._add(container); From 7ad624d9badc725618faf7a2fe4950668aa0f69b Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 15:04:08 +0200 Subject: [PATCH 5/7] No personal wallet found --- .../osparc/desktop/wallets/WalletsList.js | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js index 865fafa5be6..099d2f44016 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js @@ -23,10 +23,22 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", { this._setLayout(new qx.ui.layout.VBox(10)); - this.__addHeader("Personal") + this.__addHeader(this.tr("Personal"), true); + this.__noPersonalWalletsLabel = new qx.ui.basic.Label().set({ + value: this.tr("No personal wallet found"), + font: "text-13", + marginLeft: 10 + }); + this._add(this.__noPersonalWalletsLabel); this.__personalWalletsModel = this.__addWalletsList() - this.__sharedHeader = this.__addHeader("Shared with me") + this.__addHeader(this.tr("Shared with me"), false); + this.__noSharedWalletsLabel = new qx.ui.basic.Label().set({ + value: this.tr("No shared wallets found"), + font: "text-13", + marginLeft: 10 + }); + this._add(this.__noSharedWalletsLabel); this.__sharedWalletsModel = this.__addWalletsList({ flex: 1 }) this.loadWallets(); @@ -47,6 +59,8 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", { }, members: { + __noPersonalWalletsLabel: null, + __noSharedWalletsLabel: null, __personalWalletsModel: null, __sharedWalletsModel: null, @@ -125,11 +139,13 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", { } }); this.setWalletsLoaded(true); - if (this.__sharedWalletsModel.getLength() === 0) { - this.__sharedHeader.exclude() - } else { - this.__sharedHeader.show() - } + + this.__noPersonalWalletsLabel.set({ + visibility: this.__personalWalletsModel.getLength() ? "excluded" : "visible" + }); + this.__noSharedWalletsLabel.set({ + visibility: this.__sharedWalletsModel.getLength() ? "excluded" : "visible" + }); }, __openEditWallet: function(walletId) { @@ -187,24 +203,25 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", { win.close(); }, - __addHeader: function(label) { - const header = new qx.ui.container.Composite(new qx.ui.layout.HBox()) + __addHeader: function(label, showCurrently) { + const header = new qx.ui.container.Composite(new qx.ui.layout.HBox()); const userWallets = new qx.ui.basic.Label().set({ - value: this.tr(label), + value: label, alignX: "left", rich: true, font: "text-14" }); - header.add(userWallets) + header.add(userWallets); header.add(new qx.ui.core.Spacer(), { flex: 1 }); - const selectColumn = new qx.ui.basic.Label("Currently in use").set({ - marginRight: 18 - }); - header.add(selectColumn) + if (showCurrently) { + const selectColumn = new qx.ui.basic.Label(this.tr("Currently in use")).set({ + marginRight: 18 + }); + header.add(selectColumn) + } this._add(header); - return header } } }); From 2299df31708ebe5c3a9531db166b47d5e9b16f7a Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 15:05:30 +0200 Subject: [PATCH 6/7] Credit Account --- .../client/source/class/osparc/desktop/wallets/WalletsList.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js index 099d2f44016..1c1e243fc2b 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletsList.js @@ -25,7 +25,7 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", { this.__addHeader(this.tr("Personal"), true); this.__noPersonalWalletsLabel = new qx.ui.basic.Label().set({ - value: this.tr("No personal wallet found"), + value: this.tr("No personal Credit Account found"), font: "text-13", marginLeft: 10 }); @@ -34,7 +34,7 @@ qx.Class.define("osparc.desktop.wallets.WalletsList", { this.__addHeader(this.tr("Shared with me"), false); this.__noSharedWalletsLabel = new qx.ui.basic.Label().set({ - value: this.tr("No shared wallets found"), + value: this.tr("No shared Credit Accounts found"), font: "text-13", marginLeft: 10 }); From 5792e66d32e72de84f2a36628acd1c13e265c303 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 25 Apr 2024 16:30:06 +0200 Subject: [PATCH 7/7] minor --- .../source/class/osparc/MaintenanceTracker.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/MaintenanceTracker.js b/services/static-webserver/client/source/class/osparc/MaintenanceTracker.js index 64a14dd4a0e..0274270e2ea 100644 --- a/services/static-webserver/client/source/class/osparc/MaintenanceTracker.js +++ b/services/static-webserver/client/source/class/osparc/MaintenanceTracker.js @@ -96,7 +96,7 @@ qx.Class.define("osparc.MaintenanceTracker", { __setMaintenance: function(maintenanceData) { // ignore old maintenance - if (new Date(maintenanceData.end).getTime() < new Date().getTime()) { + if (maintenanceData && (new Date(maintenanceData.end).getTime() < new Date().getTime())) { console.warn(`Old maintenance "${maintenanceData.reason}" wasn't removed"`); return; } @@ -115,27 +115,21 @@ qx.Class.define("osparc.MaintenanceTracker", { (oldEnd === null || oldEnd.getTime() !== this.getEnd().getTime()) || oldReason !== this.getReason() ) { - this.__scheduleMaintenance(); + this.__scheduleStart(); } }, - __scheduleMaintenance: function() { - this.__scheduleStart(); - }, - __scheduleStart: function() { - if (this.getStart() === null) { - this.__removeRibbonMessage(); - this.__removeScheduledLogout(); - } else { + this.__removeRibbonMessage(); + this.__removeScheduledLogout(); + + if (this.getStart()) { this.__scheduleRibbonMessage(); this.__scheduleLogout(); } }, __scheduleRibbonMessage: function() { - this.__removeRibbonMessage(); - const now = new Date(); const diffClosable = this.getStart().getTime() - now.getTime() - this.self().CLOSABLE_WARN_IN_ADVANCE; const diffPermanent = this.getStart().getTime() - now.getTime() - this.self().PERMANENT_WARN_IN_ADVANCE; @@ -177,8 +171,6 @@ qx.Class.define("osparc.MaintenanceTracker", { }, __scheduleLogout: function() { - this.__removeScheduledLogout(); - const now = new Date(); if (this.getStart().getTime() > now.getTime()) { const diff = this.getStart().getTime() - now.getTime();