From 72a5d99c71c674813a68a10912f9a714202679f6 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 14:43:00 +0100 Subject: [PATCH 01/20] refactor --- .../source/class/osparc/data/Resources.js | 12 +- .../osparc/desktop/account/ProfilePage.js | 112 +++++++----------- 2 files changed, 54 insertions(+), 70 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/Resources.js b/services/static-webserver/client/source/class/osparc/data/Resources.js index 1332df084a9..de1d5aeddaa 100644 --- a/services/static-webserver/client/source/class/osparc/data/Resources.js +++ b/services/static-webserver/client/source/class/osparc/data/Resources.js @@ -722,7 +722,11 @@ qx.Class.define("osparc.data.Resources", { getOne: { method: "GET", url: statics.API + "/me" - } + }, + patch: { + method: "PATCH", + url: statics.API + "/me" + }, } }, /* @@ -1117,7 +1121,11 @@ qx.Class.define("osparc.data.Resources", { postResetPassword: { method: "POST", url: statics.API + "/auth/reset-password/{code}" - } + }, + changeEmail: { + method: "POST", + url: statics.API + "/auth/change-email" + }, } }, /* diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index a4f9b773ea3..eff1f2b4e4f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -12,13 +12,14 @@ Authors: * Pedro Crespo (pcrespov) + * Odei Maiz (odeimaiz) ************************************************************************ */ /** * User profile in preferences dialog * - * - user name, surname, email, avatar + * - first name, last name, username, email * */ @@ -47,6 +48,28 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { __userProfileData: null, __userProfileModel: null, + __fetchProfile: function() { + osparc.data.Resources.getOne("profile", {}, null, false) + .then(profile => { + this.__setDataToModel(profile); + }) + .catch(err => { + console.error(err); + }); + }, + + __setDataToModel: function(data) { + if (data) { + this.__userProfileData = data; + this.__userProfileModel.set({ + "firstName": data["first_name"] || "", + "lastName": data["last_name"] || "", + "email": data["login"], + "expirationDate": data["expirationDate"] || null + }); + } + }, + __createProfileUser: function() { // layout const box = osparc.ui.window.TabbedView.createSectionBox(this.tr("User")); @@ -140,55 +163,30 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { return; } - const requests = { - email: null, - names: null - }; - if (this.__userProfileData["login"] !== model.getEmail()) { - if (emailValidator.validate()) { - const emailReq = new osparc.io.request.ApiRequest("/auth/change-email", "POST"); - emailReq.setRequestData({ - "email": model.getEmail() - }); - requests.email = emailReq; - } - } - if (this.__userProfileData["first_name"] !== model.getFirstName() || this.__userProfileData["last_name"] !== model.getLastName()) { if (namesValidator.validate()) { - const profileReq = new osparc.io.request.ApiRequest("/me", "PATCH"); - profileReq.setRequestData({ - "first_name": model.getFirstName(), - "last_name": model.getLastName() - }); - requests.names = profileReq; + const params = { + data: { + "first_name": model.getFirstName(), + "last_name": model.getLastName(), + } + }; + osparc.data.Resources.fetch("profile", "patch", params) + .then(() => { + this.__setDataToModel(Object.assign(this.__userProfileData, params.data)); + osparc.auth.Manager.getInstance().updateProfile(this.__userProfileData); + const msg = this.tr("Profile updated"); + osparc.FlashMessenger.getInstance().logAs(msg, "INFO"); + }) + .catch(err => { + this.__resetDataToModel(); + const msg = err.message || this.tr("Failed to update profile"); + osparc.FlashMessenger.getInstance().logAs(msg, "ERROR"); + console.error(err); + }); } } - - Object.keys(requests).forEach(key => { - const req = requests[key]; - if (req === null) { - return; - } - - req.addListenerOnce("success", e => { - const reqData = e.getTarget().getRequestData(); - this.__setDataToModel(Object.assign(this.__userProfileData, reqData)); - osparc.auth.Manager.getInstance().updateProfile(this.__userProfileData); - const res = e.getTarget().getResponse(); - const msg = (res && res.data) ? res.data : this.tr("Profile updated"); - osparc.FlashMessenger.getInstance().logAs(msg, "INFO"); - }, this); - - req.addListenerOnce("fail", e => { - this.__resetDataToModel(); - const msg = osparc.data.Resources.getErrorMsg(e.getTarget().getResponse()) || this.tr("Failed to update profile"); - osparc.FlashMessenger.getInstance().logAs(msg, "ERROR"); - }, this); - - req.send(); - }); - }, this); + }); return box; }, @@ -261,28 +259,6 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { return box; }, - __fetchProfile: function() { - osparc.data.Resources.getOne("profile", {}, null, false) - .then(profile => { - this.__setDataToModel(profile); - }) - .catch(err => { - console.error(err); - }); - }, - - __setDataToModel: function(data) { - if (data) { - this.__userProfileData = data; - this.__userProfileModel.set({ - "firstName": data["first_name"] || "", - "lastName": data["last_name"] || "", - "email": data["login"], - "expirationDate": data["expirationDate"] || null - }); - } - }, - __resetDataToModel: function() { this.__setDataToModel(this.__userProfileData); }, From e45e83f6518553e2034496d4a3c9e8c07337b8e8 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 15:09:05 +0100 Subject: [PATCH 02/20] username --- .../client/source/class/osparc/auth/Data.js | 19 +++++++------------ .../source/class/osparc/auth/Manager.js | 1 + .../class/osparc/desktop/account/MyAccount.js | 13 +++++++------ .../osparc/desktop/account/ProfilePage.js | 18 ++++++++++++++---- .../osparc/product/quickStart/s4l/Welcome.js | 2 +- .../product/quickStart/s4lacad/Welcome.js | 2 +- .../product/quickStart/s4llite/Welcome.js | 2 +- .../osparc/product/quickStart/tis/Welcome.js | 2 +- 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/auth/Data.js b/services/static-webserver/client/source/class/osparc/auth/Data.js index b12a322351d..468da44e69f 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Data.js +++ b/services/static-webserver/client/source/class/osparc/auth/Data.js @@ -53,6 +53,13 @@ qx.Class.define("osparc.auth.Data", { apply: "__applyAuth" }, + username: { + check: "String", + init: null, + nullable: false, + event: "changeUsername", + }, + /** * Email of logged in user, otherwise null */ @@ -135,18 +142,6 @@ qx.Class.define("osparc.auth.Data", { return osparc.utils.Utils.cookie.getCookie("user") === "logout"; }, - getUserName: function() { - const firstName = this.getFirstName(); - if (firstName) { - return firstName; - } - const email = this.getEmail(); - if (email) { - return osparc.utils.Utils.getNameFromEmail(email); - } - return "user"; - }, - getFriendlyRole: function() { const role = this.getRole(); let friendlyRole = role.replace(/_/g, " "); diff --git a/services/static-webserver/client/source/class/osparc/auth/Manager.js b/services/static-webserver/client/source/class/osparc/auth/Manager.js index 5b5efeef7d0..0cdda5c49b6 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Manager.js +++ b/services/static-webserver/client/source/class/osparc/auth/Manager.js @@ -240,6 +240,7 @@ qx.Class.define("osparc.auth.Manager", { const authData = osparc.auth.Data.getInstance(); authData.set({ email: profile["login"], + username: profile["userName"], firstName: profile["first_name"] || profile["login"], lastName: profile["last_name"] || "", expirationDate: "expirationDate" in profile ? new Date(profile["expirationDate"]) : null diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js index d61bbb5f4d4..6bfd2a894cf 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js @@ -68,6 +68,13 @@ qx.Class.define("osparc.desktop.account.MyAccount", { converter: lastName => authData.getFirstName() + " " + lastName }); + const usernameLabel = new qx.ui.basic.Label().set({ + font: "text-14", + alignX: "center" + }); + authData.bind("username", usernameLabel, "value"); + layout.add(usernameLabel); + if (authData.getRole() !== "user") { const role = authData.getFriendlyRole(); const roleLabel = new qx.ui.basic.Label(role).set({ @@ -77,12 +84,6 @@ qx.Class.define("osparc.desktop.account.MyAccount", { layout.add(roleLabel); } - const emailLabel = new qx.ui.basic.Label(email).set({ - font: "text-13", - alignX: "center" - }); - layout.add(emailLabel); - if (withSpacer) { layout.add(new qx.ui.core.Spacer(15, 15)); } diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index eff1f2b4e4f..0112b8b1721 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -31,9 +31,6 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { this._setLayout(new qx.ui.layout.VBox(15)); - this.__userProfileData = null; - this.__userProfileModel = null; - this.__fetchProfile(); this._add(this.__createProfileUser()); @@ -64,6 +61,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { this.__userProfileModel.set({ "firstName": data["first_name"] || "", "lastName": data["last_name"] || "", + "username": data["userName"] || "", "email": data["login"], "expirationDate": data["expirationDate"] || null }); @@ -86,6 +84,10 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { placeholder: this.tr("Last Name") }); + const username = new qx.ui.form.TextField().set({ + placeholder: this.tr("username") + }); + const email = new qx.ui.form.TextField().set({ placeholder: this.tr("Email"), readOnly: true @@ -94,6 +96,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { const form = new qx.ui.form.Form(); form.add(firstName, "First Name", null, "firstName"); form.add(lastName, "Last Name", null, "lastName"); + form.add(username, "Username", null, "username"); form.add(email, "Email", null, "email"); box.add(new qx.ui.form.renderer.Single(form)); @@ -118,6 +121,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { const raw = { "firstName": "", "lastName": "", + "username": "", "email": "", "expirationDate": null }; @@ -132,6 +136,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { } }); controller.addTarget(lastName, "value", "lastName", true); + controller.addTarget(username, "value", "username", true); controller.addTarget(expirationDate, "value", "expirationDate", false, { converter: expirationDay => { if (expirationDay) { @@ -163,12 +168,17 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { return; } - if (this.__userProfileData["first_name"] !== model.getFirstName() || this.__userProfileData["last_name"] !== model.getLastName()) { + if ( + this.__userProfileData["first_name"] !== model.getFirstName() || + this.__userProfileData["last_name"] !== model.getLastName() || + this.__userProfileData["username"] !== model.getUsername() + ) { if (namesValidator.validate()) { const params = { data: { "first_name": model.getFirstName(), "last_name": model.getLastName(), + "userName": model.getUsername(), } }; osparc.data.Resources.fetch("profile", "patch", params) diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js index 518416f1373..a86db13f920 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js @@ -55,7 +55,7 @@ qx.Class.define("osparc.product.quickStart.s4l.Welcome", { }); content.add(intro1); - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUserName()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); content.add(welcome); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js index c81b9813d51..8dede866771 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js @@ -55,7 +55,7 @@ qx.Class.define("osparc.product.quickStart.s4lacad.Welcome", { }); content.add(intro1); - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUserName()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); content.add(welcome); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js index 77e187a1d8c..140b7f1b763 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js @@ -25,7 +25,7 @@ qx.Class.define("osparc.product.quickStart.s4llite.Welcome", { members: { _populateCard: function() { - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUserName()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); this._add(welcome); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js index 7e6c7e2980e..17fdad5ef8c 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js @@ -25,7 +25,7 @@ qx.Class.define("osparc.product.quickStart.tis.Welcome", { members: { _populateCard: function() { - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUserName()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); this._add(welcome); From 2e9dff4bf4a36601f064cdb47a2ad5ceadf07403 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 15:23:46 +0100 Subject: [PATCH 03/20] minor --- .../client/source/class/osparc/desktop/account/ProfilePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index 0112b8b1721..18f33a523ce 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -96,7 +96,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { const form = new qx.ui.form.Form(); form.add(firstName, "First Name", null, "firstName"); form.add(lastName, "Last Name", null, "lastName"); - form.add(username, "Username", null, "username"); + form.add(username, "username", null, "username"); form.add(email, "Email", null, "email"); box.add(new qx.ui.form.renderer.Single(form)); From 16664b9bd55940bd67481fc98784a4f3c08b988b Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 15:26:25 +0100 Subject: [PATCH 04/20] getFriendlyUsername --- .../client/source/class/osparc/auth/Data.js | 8 ++++++++ .../source/class/osparc/product/quickStart/s4l/Welcome.js | 2 +- .../class/osparc/product/quickStart/s4lacad/Welcome.js | 2 +- .../class/osparc/product/quickStart/s4llite/Welcome.js | 2 +- .../source/class/osparc/product/quickStart/tis/Welcome.js | 2 +- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/auth/Data.js b/services/static-webserver/client/source/class/osparc/auth/Data.js index 468da44e69f..b4b7097464e 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Data.js +++ b/services/static-webserver/client/source/class/osparc/auth/Data.js @@ -142,6 +142,14 @@ qx.Class.define("osparc.auth.Data", { return osparc.utils.Utils.cookie.getCookie("user") === "logout"; }, + getFriendlyUsername: function() { + const firstName = this.getFirstName(); + if (firstName) { + return firstName; + } + return this.getUsername(); + }, + getFriendlyRole: function() { const role = this.getRole(); let friendlyRole = role.replace(/_/g, " "); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js index a86db13f920..8e4386e2258 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/s4l/Welcome.js @@ -55,7 +55,7 @@ qx.Class.define("osparc.product.quickStart.s4l.Welcome", { }); content.add(intro1); - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getFriendlyUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); content.add(welcome); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js index 8dede866771..49f5fa773dc 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/s4lacad/Welcome.js @@ -55,7 +55,7 @@ qx.Class.define("osparc.product.quickStart.s4lacad.Welcome", { }); content.add(intro1); - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getFriendlyUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); content.add(welcome); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js index 140b7f1b763..47fd5da29ab 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/s4llite/Welcome.js @@ -25,7 +25,7 @@ qx.Class.define("osparc.product.quickStart.s4llite.Welcome", { members: { _populateCard: function() { - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getFriendlyUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); this._add(welcome); diff --git a/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js b/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js index 17fdad5ef8c..25f3c6444aa 100644 --- a/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js +++ b/services/static-webserver/client/source/class/osparc/product/quickStart/tis/Welcome.js @@ -25,7 +25,7 @@ qx.Class.define("osparc.product.quickStart.tis.Welcome", { members: { _populateCard: function() { - const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getUsername()) + ","; + const welcomeText = this.tr("Welcome onboard ") + osparc.utils.Utils.capitalize(osparc.auth.Data.getInstance().getFriendlyUsername()) + ","; const welcome = osparc.product.quickStart.Utils.createLabel(welcomeText); this._add(welcome); From 77284ee0e54050771c8a2e57ce8305feec74e2e4 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:10:24 +0100 Subject: [PATCH 05/20] Privacy section --- .../osparc/desktop/account/ProfilePage.js | 153 ++++++++++++++---- 1 file changed, 125 insertions(+), 28 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index 18f33a523ce..0ab4786926c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -34,6 +34,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { this.__fetchProfile(); this._add(this.__createProfileUser()); + this._add(this.__createPrivacySection()); if (osparc.store.StaticInfo.getInstance().is2FARequired()) { this._add(this.__create2FASection()); } @@ -44,26 +45,39 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { members: { __userProfileData: null, __userProfileModel: null, + __userPrivacyData: null, + __userPrivacyModel: null, __fetchProfile: function() { osparc.data.Resources.getOne("profile", {}, null, false) .then(profile => { - this.__setDataToModel(profile); + this.__setDataToProfile(profile); + this.__setDataToPrivacy(profile["privacy"]); }) .catch(err => { console.error(err); }); }, - __setDataToModel: function(data) { + __setDataToProfile: function(data) { if (data) { this.__userProfileData = data; this.__userProfileModel.set({ + "username": data["userName"] || "", "firstName": data["first_name"] || "", "lastName": data["last_name"] || "", - "username": data["userName"] || "", "email": data["login"], - "expirationDate": data["expirationDate"] || null + "expirationDate": data["expirationDate"] || null, + }); + } + }, + + __setDataToPrivacy: function(privacyData) { + if (privacyData) { + this.__userPrivacyData = privacyData; + this.__userPrivacyModel.set({ + "hideFullname": privacyData["hideFullname"] || true, + "hideEmail": privacyData["hideEmail"] || true, }); } }, @@ -76,27 +90,26 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { maxWidth: 500 }); + const username = new qx.ui.form.TextField().set({ + placeholder: this.tr("username") + }); + const firstName = new qx.ui.form.TextField().set({ placeholder: this.tr("First Name") }); - const lastName = new qx.ui.form.TextField().set({ placeholder: this.tr("Last Name") }); - const username = new qx.ui.form.TextField().set({ - placeholder: this.tr("username") - }); - const email = new qx.ui.form.TextField().set({ placeholder: this.tr("Email"), readOnly: true }); const form = new qx.ui.form.Form(); + form.add(username, "username", null, "username"); form.add(firstName, "First Name", null, "firstName"); form.add(lastName, "Last Name", null, "lastName"); - form.add(username, "username", null, "username"); form.add(email, "Email", null, "email"); box.add(new qx.ui.form.renderer.Single(form)); @@ -119,16 +132,17 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { // binding to a model const raw = { + "username": "", "firstName": "", "lastName": "", - "username": "", "email": "", - "expirationDate": null + "expirationDate": null, }; const model = this.__userProfileModel = qx.data.marshal.Json.createModel(raw); const controller = new qx.data.controller.Object(model); + controller.addTarget(username, "value", "username", true); controller.addTarget(email, "value", "email", true); controller.addTarget(firstName, "value", "firstName", true, null, { converter: function(data) { @@ -136,7 +150,6 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { } }); controller.addTarget(lastName, "value", "lastName", true); - controller.addTarget(username, "value", "username", true); controller.addTarget(expirationDate, "value", "expirationDate", false, { converter: expirationDay => { if (expirationDay) { @@ -164,32 +177,35 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { updateBtn.addListener("execute", () => { if (!osparc.data.Permissions.getInstance().canDo("user.user.update", true)) { - this.__resetDataToModel(); + this.__resetUserData(); return; } - if ( - this.__userProfileData["first_name"] !== model.getFirstName() || - this.__userProfileData["last_name"] !== model.getLastName() || - this.__userProfileData["username"] !== model.getUsername() - ) { + const patchData = {}; + if (this.__userProfileData["username"] !== model.getUsername()) { + patchData["userName"] = model.getUsername(); + } + if (this.__userProfileData["first_name"] !== model.getFirstName()) { + patchData["first_name"] = model.getFirstName(); + } + if (this.__userProfileData["last_name"] !== model.getLastName()) { + patchData["last_name"] = model.getLastName(); + } + + if (Object.keys(patchData).length) { if (namesValidator.validate()) { const params = { - data: { - "first_name": model.getFirstName(), - "last_name": model.getLastName(), - "userName": model.getUsername(), - } + data: patchData }; osparc.data.Resources.fetch("profile", "patch", params) .then(() => { - this.__setDataToModel(Object.assign(this.__userProfileData, params.data)); + this.__setDataToProfile(Object.assign(this.__userProfileData, params.data)); osparc.auth.Manager.getInstance().updateProfile(this.__userProfileData); const msg = this.tr("Profile updated"); osparc.FlashMessenger.getInstance().logAs(msg, "INFO"); }) .catch(err => { - this.__resetDataToModel(); + this.__resetUserData(); const msg = err.message || this.tr("Failed to update profile"); osparc.FlashMessenger.getInstance().logAs(msg, "ERROR"); console.error(err); @@ -201,6 +217,83 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { return box; }, + __createPrivacySection: function() { + const box = osparc.ui.window.TabbedView.createSectionBox(this.tr("Privacy")); + box.set({ + alignX: "left", + maxWidth: 500 + }); + + const label = osparc.ui.window.TabbedView.createHelpLabel(this.tr("For Privacy reasons, you might want to hide your Full Name and/or the email to other users")); + box.add(label); + + const hideFullname = new qx.ui.form.CheckBox().set({ + value: true + }); + const hideEmail = new qx.ui.form.CheckBox().set({ + value: true + }); + + const form = new qx.ui.form.Form(); + form.add(hideFullname, "Hide Full Name", null, "hideFullname"); + form.add(hideEmail, "Hide email", null, "hideEmail"); + box.add(new qx.ui.form.renderer.Single(form)); + + // binding to a model + const raw = { + "hideFullname": true, + "hideEmail": true, + }; + + const model = this.__userPrivacyModel = qx.data.marshal.Json.createModel(raw); + const controller = new qx.data.controller.Object(model); + controller.addTarget(hideFullname, "value", "hideFullname", true); + controller.addTarget(hideEmail, "value", "hideEmail", true); + + const privacyBtn = new qx.ui.form.Button("Update Privacy").set({ + appearance: "form-button", + alignX: "right", + allowGrowX: false + }); + box.add(privacyBtn); + privacyBtn.addListener("execute", () => { + if (!osparc.data.Permissions.getInstance().canDo("user.user.update", true)) { + this.__resetPrivacyData(); + return; + } + const patchData = { + "privacy": {} + }; + if (this.__userProfileData["privacy"]["hideFullname"] !== model.getHideFullname()) { + patchData["privacy"]["hideFullname"] = model.getHideFullname(); + } + if (this.__userProfileData["privacy"]["hideEmail"] !== model.getHideEmail()) { + patchData["privacy"]["hideEmail"] = model.getHideEmail(); + } + + if (Object.keys(patchData["privacy"]).length) { + const params = { + data: patchData + }; + osparc.data.Resources.fetch("profile", "patch", params) + .then(() => { + this.__setDataToPrivacy(Object.assign(this.__userProfileData, params.data)); + // osparc.auth.Manager.getInstance().updateProfile(this.__userProfileData); + const msg = this.tr("Profile updated"); + osparc.FlashMessenger.getInstance().logAs(msg, "INFO"); + }) + .catch(err => { + this.__resetPrivacyData(); + const msg = err.message || this.tr("Failed to update profile"); + osparc.FlashMessenger.getInstance().logAs(msg, "ERROR"); + console.error(err); + }); + } + }); + + return box; + }, + __create2FASection: function() { const box = osparc.ui.window.TabbedView.createSectionBox(this.tr("2 Factor Authentication")); @@ -269,8 +362,12 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { return box; }, - __resetDataToModel: function() { - this.__setDataToModel(this.__userProfileData); + __resetUserData: function() { + this.__setDataToProfile(this.__userProfileData); + }, + + __resetPrivacyData: function() { + this.__setDataToPrivacy(this.__userPrivacyData); }, __createPasswordSection: function() { From b4f87ad1ff4ec3e7baf562ef8f1499866273b923 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:16:36 +0100 Subject: [PATCH 06/20] minor --- .../source/class/osparc/desktop/account/MyAccountWindow.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js index 9881c9e71bd..f1d40722217 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js @@ -22,10 +22,10 @@ qx.Class.define("osparc.desktop.account.MyAccountWindow", { this.base(arguments, "credits", this.tr("My Account")); const width = 900; - const height = 600; + const maxHeight = 700; this.set({ width, - height + maxHeight }); const myAccount = this.__myAccount = new osparc.desktop.account.MyAccount(); From be22c9337e6c55b700b8f0929ea08ff3188249b1 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:20:30 +0100 Subject: [PATCH 07/20] scrolled content --- .../source/class/osparc/desktop/account/MyAccountWindow.js | 4 +++- .../client/source/class/osparc/ui/window/TabbedView.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js index f1d40722217..a86eeeb9507 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js @@ -22,10 +22,12 @@ qx.Class.define("osparc.desktop.account.MyAccountWindow", { this.base(arguments, "credits", this.tr("My Account")); const width = 900; + const height = 700; const maxHeight = 700; this.set({ width, - maxHeight + height, + maxHeight, }); const myAccount = this.__myAccount = new osparc.desktop.account.MyAccount(); diff --git a/services/static-webserver/client/source/class/osparc/ui/window/TabbedView.js b/services/static-webserver/client/source/class/osparc/ui/window/TabbedView.js index cea8a1f0b06..e3c75167676 100644 --- a/services/static-webserver/client/source/class/osparc/ui/window/TabbedView.js +++ b/services/static-webserver/client/source/class/osparc/ui/window/TabbedView.js @@ -88,7 +88,9 @@ qx.Class.define("osparc.ui.window.TabbedView", { widget.set({ margin: 10 }); - page.add(widget, { + const scroll = new qx.ui.container.Scroll(); + scroll.add(widget); + page.add(scroll, { flex: 1 }); return page; From e604ddbd17939ada5b6d25bc1d1016edf9411d17 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:24:05 +0100 Subject: [PATCH 08/20] minor --- .../class/osparc/desktop/account/MyAccount.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js index 6bfd2a894cf..2380a9745f3 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js @@ -42,6 +42,7 @@ qx.Class.define("osparc.desktop.account.MyAccount", { }); const authData = osparc.auth.Data.getInstance(); + const email = authData.getEmail(); const avatarSize = 80; const img = new qx.ui.basic.Image().set({ @@ -56,10 +57,17 @@ qx.Class.define("osparc.desktop.account.MyAccount", { }); layout.add(img); - const name = new qx.ui.basic.Label().set({ + const usernameLabel = new qx.ui.basic.Label().set({ font: "text-14", alignX: "center" }); + authData.bind("username", usernameLabel, "value"); + layout.add(usernameLabel); + + const name = new qx.ui.basic.Label().set({ + font: "text-13", + alignX: "center" + }); layout.add(name); authData.bind("firstName", name, "value", { converter: firstName => firstName + " " + authData.getLastName() @@ -68,13 +76,6 @@ qx.Class.define("osparc.desktop.account.MyAccount", { converter: lastName => authData.getFirstName() + " " + lastName }); - const usernameLabel = new qx.ui.basic.Label().set({ - font: "text-14", - alignX: "center" - }); - authData.bind("username", usernameLabel, "value"); - layout.add(usernameLabel); - if (authData.getRole() !== "user") { const role = authData.getFriendlyRole(); const roleLabel = new qx.ui.basic.Label(role).set({ From a52f27bbc3f74b4dbb81301fbb4f932faac95210 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:32:10 +0100 Subject: [PATCH 09/20] minors --- .../class/osparc/desktop/account/ProfilePage.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index 0ab4786926c..3387bbb7f94 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -264,10 +264,10 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { const patchData = { "privacy": {} }; - if (this.__userProfileData["privacy"]["hideFullname"] !== model.getHideFullname()) { + if (this.__userPrivacyData["hideFullname"] !== model.getHideFullname()) { patchData["privacy"]["hideFullname"] = model.getHideFullname(); } - if (this.__userProfileData["privacy"]["hideEmail"] !== model.getHideEmail()) { + if (this.__userPrivacyData["hideEmail"] !== model.getHideEmail()) { patchData["privacy"]["hideEmail"] = model.getHideEmail(); } @@ -277,14 +277,13 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { }; osparc.data.Resources.fetch("profile", "patch", params) .then(() => { - this.__setDataToPrivacy(Object.assign(this.__userProfileData, params.data)); - // osparc.auth.Manager.getInstance().updateProfile(this.__userProfileData); - const msg = this.tr("Profile updated"); + this.__setDataToPrivacy(Object.assign(this.__userPrivacyData, params.data)); + const msg = this.tr("Privacy updated"); osparc.FlashMessenger.getInstance().logAs(msg, "INFO"); }) .catch(err => { this.__resetPrivacyData(); - const msg = err.message || this.tr("Failed to update profile"); + const msg = err.message || this.tr("Failed to update privacy"); osparc.FlashMessenger.getInstance().logAs(msg, "ERROR"); console.error(err); }); From a533c0e5699cc69443735e5bfe3f733988974e43 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:35:39 +0100 Subject: [PATCH 10/20] minor --- .../client/source/class/osparc/desktop/account/ProfilePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index 3387bbb7f94..e1394623226 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -277,7 +277,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { }; osparc.data.Resources.fetch("profile", "patch", params) .then(() => { - this.__setDataToPrivacy(Object.assign(this.__userPrivacyData, params.data)); + this.__setDataToPrivacy(Object.assign(this.__userPrivacyData, params.data["privacy"])); const msg = this.tr("Privacy updated"); osparc.FlashMessenger.getInstance().logAs(msg, "INFO"); }) From 497b23c8618b713a8542020131e204193b53b004 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 16:41:59 +0100 Subject: [PATCH 11/20] fix init --- .../client/source/class/osparc/desktop/account/ProfilePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index e1394623226..6d53e3c0e8a 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -76,8 +76,8 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { if (privacyData) { this.__userPrivacyData = privacyData; this.__userPrivacyModel.set({ - "hideFullname": privacyData["hideFullname"] || true, - "hideEmail": privacyData["hideEmail"] || true, + "hideFullname": "hideFullname" in privacyData ? privacyData["hideFullname"] : true, + "hideEmail": "hideEmail" in privacyData ? privacyData["hideEmail"] : true, }); } }, From c1f2d05574214673bf07695fdb578c754b27d891 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:10:10 +0100 Subject: [PATCH 12/20] minor --- .../client/source/class/osparc/store/Groups.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 08ebcc2904c..a872e69f7e4 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -94,8 +94,8 @@ qx.Class.define("osparc.store.Groups", { this.setGroupMe(groupMe); const myAuthData = osparc.auth.Data.getInstance(); groupMe.set({ - label: osparc.data.model.User.namesToLabel(myAuthData.getFirstName(), myAuthData.getLastName()), - description: myAuthData.getEmail(), + label: myAuthData.getUsername(), + description: `${myAuthData.getFirstName()} ${myAuthData.getLastName()} - ${myAuthData.getEmail()}`, thumbnail: osparc.data.model.User.emailToThumbnail(myAuthData.getEmail()), }) return orgs; From a81ce15149fb94dd623bec8a160b03dfdf1de26d Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:38:09 +0100 Subject: [PATCH 13/20] minor --- .../client/source/class/osparc/auth/Data.js | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/auth/Data.js b/services/static-webserver/client/source/class/osparc/auth/Data.js index b4b7097464e..4a55c04633d 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Data.js +++ b/services/static-webserver/client/source/class/osparc/auth/Data.js @@ -25,6 +25,38 @@ qx.Class.define("osparc.auth.Data", { type: "singleton", properties: { + /** + * Basic authentification with a token + */ + auth: { + init: null, + nullable: true, + check: "osparc.io.request.authentication.Token", + apply: "__applyAuth" + }, + + role: { + check: ["anonymous", "guest", "user", "tester", "product_owner", "admin"], + init: null, + nullable: false, + event: "changeRole", + apply: "__applyRole" + }, + + guest: { + check: "Boolean", + init: true, + nullable: false, + event: "changeGuest" + }, + + loggedIn: { + check: "Boolean", + nullable: false, + init: false, + event: "changeLoggedIn", + }, + /** * User Id */ @@ -43,16 +75,6 @@ qx.Class.define("osparc.auth.Data", { check: "Number" }, - /** - * Basic authentification with a token - */ - auth: { - init: null, - nullable: true, - check: "osparc.io.request.authentication.Token", - apply: "__applyAuth" - }, - username: { check: "String", init: null, @@ -83,34 +105,12 @@ qx.Class.define("osparc.auth.Data", { event: "changeLastName" }, - role: { - check: ["anonymous", "guest", "user", "tester", "product_owner", "admin"], - init: null, - nullable: false, - event: "changeRole", - apply: "__applyRole" - }, - - guest: { - check: "Boolean", - init: true, - nullable: false, - event: "changeGuest" - }, - expirationDate: { init: null, nullable: true, check: "Date", event: "changeExpirationDate" }, - - loggedIn: { - check: "Boolean", - nullable: false, - init: false, - event: "changeLoggedIn", - } }, members: { From 255a850f3ea20b5cfdef12f4de1aa91a54a9a9c2 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:39:56 +0100 Subject: [PATCH 14/20] minor --- .../static-webserver/client/source/class/osparc/utils/Avatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/utils/Avatar.js b/services/static-webserver/client/source/class/osparc/utils/Avatar.js index a2f8c378490..2d5f0418946 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Avatar.js +++ b/services/static-webserver/client/source/class/osparc/utils/Avatar.js @@ -34,7 +34,7 @@ qx.Class.define("osparc.utils.Avatar", { type: "static", statics: { - getUrl: function(email, size = 100, defIcon = "identicon", rating = "g") { + getUrl: function(email = "", size = 100, defIcon = "identicon", rating = "g") { // MD5 (Message-Digest Algorithm) by WebToolkit let MD5 = function(s) { function L(k, d) { From 2b20a92a0747d8916eb838c1ecd409c364774e79 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:40:15 +0100 Subject: [PATCH 15/20] replace "login" by "email" --- .../client/source/class/osparc/data/model/Group.js | 2 +- .../client/source/class/osparc/data/model/User.js | 9 +++++---- .../class/osparc/desktop/organizations/MembersList.js | 8 ++++---- .../source/class/osparc/desktop/wallets/MembersList.js | 8 ++++---- .../class/osparc/filter/CollaboratorToggleButton.js | 6 +++--- .../client/source/class/osparc/share/Collaborators.js | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index 4ab5a8da6f4..3afec8ca34b 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -105,7 +105,7 @@ qx.Class.define("osparc.data.model.Group", { }, getGroupMemberByLogin: function(userEmail) { - return Object.values(this.getGroupMembers()).find(user => user.getLogin() === userEmail); + return Object.values(this.getGroupMembers()).find(user => user.getEmail() === userEmail); }, addGroupMember: function(user) { diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index b3c03d837c6..bea1c4860de 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -29,12 +29,13 @@ qx.Class.define("osparc.data.model.User", { this.base(arguments); const label = this.self().namesToLabel(userData["first_name"], userData["last_name"]) || userData["login"]; + const thumbnail = this.self().emailToThumbnail(userData.login); this.set({ userId: userData.id, groupId: userData.gid, label: label, - login: userData.login, - thumbnail: this.self().emailToThumbnail(userData.login), + email: userData.login, + thumbnail: thumbnail, accessRights: userData.accessRights, }); }, @@ -61,11 +62,11 @@ qx.Class.define("osparc.data.model.User", { event: "changeLabel", }, - login: { + email: { check: "String", nullable: true, init: null, - event: "changeLogin", + event: "changeEmail", }, accessRights: { diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index b2e8bcda97f..0a3df0faa3b 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -70,8 +70,8 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { if (sorted !== 0) { return sorted; } - if (("login" in a) && ("login" in b)) { - return a["login"].localeCompare(b["login"]); + if (("email" in a) && ("email" in b)) { + return a["email"].localeCompare(b["email"]); } return 0; } @@ -156,7 +156,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("name", "title", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); - ctrl.bindProperty("login", "subtitleMD", null, item, id); + ctrl.bindProperty("email", "subtitleMD", null, item, id); ctrl.bindProperty("options", "options", null, item, id); ctrl.bindProperty("showOptions", "showOptions", null, item, id); }, @@ -233,7 +233,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { member["groupId"] = groupMember.getGroupId(); member["thumbnail"] = groupMember.getThumbnail(); member["name"] = groupMember.getLabel(); - member["login"] = groupMember.getLogin(); + member["email"] = groupMember.getEmail(); member["accessRights"] = groupMember.getAccessRights(); let options = []; if (canIDelete) { diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index da72d06c4e1..4f5b1dd796a 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -70,8 +70,8 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { if (sorted !== 0) { return sorted; } - if (("login" in a) && ("login" in b)) { - return a["login"].localeCompare(b["login"]); + if (("email" in a) && ("email" in b)) { + return a["email"].localeCompare(b["email"]); } return 0; } @@ -172,7 +172,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("name", "title", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); - ctrl.bindProperty("login", "subtitleMD", null, item, id); + ctrl.bindProperty("email", "subtitleMD", null, item, id); ctrl.bindProperty("options", "options", null, item, id); ctrl.bindProperty("showOptions", "showOptions", null, item, id); }, @@ -223,7 +223,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { collaborator["groupId"] = collab.getGroupId(); collaborator["thumbnail"] = collab.getThumbnail(); collaborator["name"] = collab.getLabel(); - collaborator["login"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getLogin(); + collaborator["email"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getEmail(); collaborator["accessRights"] = { read: accessRights["read"], write: accessRights["write"], diff --git a/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js index 6100ace059d..23c061cebd3 100644 --- a/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js +++ b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js @@ -24,10 +24,10 @@ qx.Class.define("osparc.filter.CollaboratorToggleButton", { }); let label = collaborator.getLabel(); - if ("getLogin" in collaborator) { + if ("getEmail" in collaborator) { // user - label += ` (${collaborator.getLogin()})`; - this.setToolTipText(collaborator.getLogin()); + label += ` (${collaborator.getEmail()})`; + this.setToolTipText(collaborator.getEmail()); } this.setLabel(label); diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 4fa94acfb78..426d201d2ab 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -295,7 +295,7 @@ qx.Class.define("osparc.share.Collaborators", { ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("name", "title", null, item, id); // user ctrl.bindProperty("label", "title", null, item, id); // organization - ctrl.bindProperty("login", "subtitleMD", null, item, id); // user + ctrl.bindProperty("email", "subtitleMD", null, item, id); // user ctrl.bindProperty("description", "subtitle", null, item, id); // organization ctrl.bindProperty("resourceType", "resourceType", null, item, id); // Resource type ctrl.bindProperty("accessRights", "accessRights", null, item, id); @@ -413,7 +413,7 @@ qx.Class.define("osparc.share.Collaborators", { if ("getUserId" in collab) { // user collaborator["name"] = collab.getLabel(); - collaborator["login"] = collab.getLogin(); + collaborator["email"] = collab.getEmail(); } else { // org/group collaborator["label"] = collab.getLabel(); From 2d00910b999b7f1e16732dd12df108bcc5785a50 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:49:22 +0100 Subject: [PATCH 16/20] more props to User model --- .../source/class/osparc/data/model/User.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index bea1c4860de..e5577544392 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -34,6 +34,9 @@ qx.Class.define("osparc.data.model.User", { userId: userData.id, groupId: userData.gid, label: label, + username: userData["username"] || "", + firstName: userData["first_name"], + lastName: userData["last_name"], email: userData.login, thumbnail: thumbnail, accessRights: userData.accessRights, @@ -62,6 +65,27 @@ qx.Class.define("osparc.data.model.User", { event: "changeLabel", }, + username: { + check: "String", + nullable: true, + init: null, + event: "changeUsername", + }, + + firstName: { + init: "", + nullable: true, + check: "String", + event: "changeFirstName" + }, + + lastName: { + init: "", + nullable: true, + check: "String", + event: "changeLastName" + }, + email: { check: "String", nullable: true, From 0be20ef597c47b6e7d3ffa64de966e23fcabc1e4 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:54:23 +0100 Subject: [PATCH 17/20] minor --- .../source/class/osparc/data/model/User.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index e5577544392..d86507743d3 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -28,18 +28,24 @@ qx.Class.define("osparc.data.model.User", { construct: function(userData) { this.base(arguments); - const label = this.self().namesToLabel(userData["first_name"], userData["last_name"]) || userData["login"]; - const thumbnail = this.self().emailToThumbnail(userData.login); + let label = userData["login"]; + if (userData["first_name"]) { + label = qx.lang.String.firstUp(userData["first_name"]); + if (userData["last_name"]) { + label += " " + qx.lang.String.firstUp(userData["last_name"]); + } + } + const thumbnail = this.self().emailToThumbnail(userData["login"]); this.set({ - userId: userData.id, - groupId: userData.gid, + userId: userData["id"], + groupId: userData["gid"], label: label, username: userData["username"] || "", firstName: userData["first_name"], lastName: userData["last_name"], - email: userData.login, - thumbnail: thumbnail, - accessRights: userData.accessRights, + email: userData["login"], + thumbnail, + accessRights: userData["accessRights"], }); }, From aa301bf707a16c1b416fc1d82afd91f47f792299 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 17:58:09 +0100 Subject: [PATCH 18/20] refactoring --- .../source/class/osparc/data/model/User.js | 19 +------------------ .../source/class/osparc/store/Groups.js | 2 +- .../source/class/osparc/utils/Avatar.js | 4 ++++ 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index d86507743d3..75121158881 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -35,7 +35,7 @@ qx.Class.define("osparc.data.model.User", { label += " " + qx.lang.String.firstUp(userData["last_name"]); } } - const thumbnail = this.self().emailToThumbnail(userData["login"]); + const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]); this.set({ userId: userData["id"], groupId: userData["gid"], @@ -113,21 +113,4 @@ qx.Class.define("osparc.data.model.User", { event: "changeThumbnail", }, }, - - statics: { - namesToLabel: function(firstName, lastName) { - let label = ""; - if (firstName) { - label = osparc.utils.Utils.firstsUp(firstName); - if (lastName) { - label += " " + osparc.utils.Utils.firstsUp(lastName); - } - } - return label; - }, - - emailToThumbnail: function(email) { - return osparc.utils.Avatar.getUrl(email, 32) - }, - } }); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index a872e69f7e4..0e27637c3fd 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -96,7 +96,7 @@ qx.Class.define("osparc.store.Groups", { groupMe.set({ label: myAuthData.getUsername(), description: `${myAuthData.getFirstName()} ${myAuthData.getLastName()} - ${myAuthData.getEmail()}`, - thumbnail: osparc.data.model.User.emailToThumbnail(myAuthData.getEmail()), + thumbnail: osparc.utils.Avatar.emailToThumbnail(myAuthData.getEmail()), }) return orgs; }); diff --git a/services/static-webserver/client/source/class/osparc/utils/Avatar.js b/services/static-webserver/client/source/class/osparc/utils/Avatar.js index 2d5f0418946..a2d40081bcb 100644 --- a/services/static-webserver/client/source/class/osparc/utils/Avatar.js +++ b/services/static-webserver/client/source/class/osparc/utils/Avatar.js @@ -34,6 +34,10 @@ qx.Class.define("osparc.utils.Avatar", { type: "static", statics: { + emailToThumbnail: function(email) { + return this.getUrl(email, 32) + }, + getUrl: function(email = "", size = 100, defIcon = "identicon", rating = "g") { // MD5 (Message-Digest Algorithm) by WebToolkit let MD5 = function(s) { From 7c606ba7fc05f35925f221466adea042a780a3f9 Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Fri, 6 Dec 2024 18:02:56 +0100 Subject: [PATCH 19/20] UserMember --- .../source/class/osparc/data/model/User.js | 8 ---- .../class/osparc/data/model/UserMember.js | 44 +++++++++++++++++++ .../source/class/osparc/store/Groups.js | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 services/static-webserver/client/source/class/osparc/data/model/UserMember.js diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index 75121158881..dc943c3202a 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -45,7 +45,6 @@ qx.Class.define("osparc.data.model.User", { lastName: userData["last_name"], email: userData["login"], thumbnail, - accessRights: userData["accessRights"], }); }, @@ -99,13 +98,6 @@ qx.Class.define("osparc.data.model.User", { event: "changeEmail", }, - accessRights: { - check: "Object", - nullable: false, - init: null, - event: "changeAccessRights", - }, - thumbnail: { check: "String", nullable: true, diff --git a/services/static-webserver/client/source/class/osparc/data/model/UserMember.js b/services/static-webserver/client/source/class/osparc/data/model/UserMember.js new file mode 100644 index 00000000000..82628ae33ec --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/data/model/UserMember.js @@ -0,0 +1,44 @@ +/* ************************************************************************ + + osparc - the simcore frontend + + https://osparc.io + + Copyright: + 2024 IT'IS Foundation, https://itis.swiss + + License: + MIT: https://opensource.org/licenses/MIT + + Authors: + * Odei Maiz (odeimaiz) + +************************************************************************ */ + +/** + * Class that stores User data + access rights to the resource. + */ + +qx.Class.define("osparc.data.model.UserMember", { + extend: osparc.data.model.User, + + /** + * @param userData {Object} Object containing the serialized User Data + */ + construct: function(userData) { + this.base(arguments, userData); + + this.set({ + accessRights: userData["accessRights"], + }); + }, + + properties: { + accessRights: { + check: "Object", + nullable: false, + init: null, + event: "changeAccessRights", + }, + }, +}); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 0e27637c3fd..862f97d06b1 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -115,7 +115,7 @@ qx.Class.define("osparc.store.Groups", { // reset group's group members group.setGroupMembers({}); orgMembers.forEach(orgMember => { - const user = new osparc.data.model.User(orgMember); + const user = new osparc.data.model.UserMember(orgMember); this.__addToUsersCache(user, groupId); }); } From 30920d141dcaa480f785ee1dd65b785d6c93a8cb Mon Sep 17 00:00:00 2001 From: odeimaiz Date: Mon, 9 Dec 2024 10:15:16 +0100 Subject: [PATCH 20/20] @pcrespov capital U --- .../source/class/osparc/desktop/account/ProfilePage.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js index 6d53e3c0e8a..53fcc95d0b8 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/account/ProfilePage.js @@ -34,7 +34,9 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { this.__fetchProfile(); this._add(this.__createProfileUser()); - this._add(this.__createPrivacySection()); + if (osparc.utils.Utils.isDevelopmentPlatform()) { + this._add(this.__createPrivacySection()); + } if (osparc.store.StaticInfo.getInstance().is2FARequired()) { this._add(this.__create2FASection()); } @@ -107,7 +109,7 @@ qx.Class.define("osparc.desktop.account.ProfilePage", { }); const form = new qx.ui.form.Form(); - form.add(username, "username", null, "username"); + form.add(username, "Username", null, "username"); form.add(firstName, "First Name", null, "firstName"); form.add(lastName, "Last Name", null, "lastName"); form.add(email, "Email", null, "email");