Skip to content

Commit c74f4b0

Browse files
authored
✨ [Frontend] username and privacy settings (#6916)
1 parent 9a23d6e commit c74f4b0

File tree

20 files changed

+324
-168
lines changed

20 files changed

+324
-168
lines changed

services/static-webserver/client/source/class/osparc/auth/Data.js

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,38 @@ qx.Class.define("osparc.auth.Data", {
2525
type: "singleton",
2626

2727
properties: {
28+
/**
29+
* Basic authentification with a token
30+
*/
31+
auth: {
32+
init: null,
33+
nullable: true,
34+
check: "osparc.io.request.authentication.Token",
35+
apply: "__applyAuth"
36+
},
37+
38+
role: {
39+
check: ["anonymous", "guest", "user", "tester", "product_owner", "admin"],
40+
init: null,
41+
nullable: false,
42+
event: "changeRole",
43+
apply: "__applyRole"
44+
},
45+
46+
guest: {
47+
check: "Boolean",
48+
init: true,
49+
nullable: false,
50+
event: "changeGuest"
51+
},
52+
53+
loggedIn: {
54+
check: "Boolean",
55+
nullable: false,
56+
init: false,
57+
event: "changeLoggedIn",
58+
},
59+
2860
/**
2961
* User Id
3062
*/
@@ -43,14 +75,11 @@ qx.Class.define("osparc.auth.Data", {
4375
check: "Number"
4476
},
4577

46-
/**
47-
* Basic authentification with a token
48-
*/
49-
auth: {
78+
username: {
79+
check: "String",
5080
init: null,
51-
nullable: true,
52-
check: "osparc.io.request.authentication.Token",
53-
apply: "__applyAuth"
81+
nullable: false,
82+
event: "changeUsername",
5483
},
5584

5685
/**
@@ -76,34 +105,12 @@ qx.Class.define("osparc.auth.Data", {
76105
event: "changeLastName"
77106
},
78107

79-
role: {
80-
check: ["anonymous", "guest", "user", "tester", "product_owner", "admin"],
81-
init: null,
82-
nullable: false,
83-
event: "changeRole",
84-
apply: "__applyRole"
85-
},
86-
87-
guest: {
88-
check: "Boolean",
89-
init: true,
90-
nullable: false,
91-
event: "changeGuest"
92-
},
93-
94108
expirationDate: {
95109
init: null,
96110
nullable: true,
97111
check: "Date",
98112
event: "changeExpirationDate"
99113
},
100-
101-
loggedIn: {
102-
check: "Boolean",
103-
nullable: false,
104-
init: false,
105-
event: "changeLoggedIn",
106-
}
107114
},
108115

109116
members: {
@@ -135,16 +142,12 @@ qx.Class.define("osparc.auth.Data", {
135142
return osparc.utils.Utils.cookie.getCookie("user") === "logout";
136143
},
137144

138-
getUserName: function() {
145+
getFriendlyUsername: function() {
139146
const firstName = this.getFirstName();
140147
if (firstName) {
141148
return firstName;
142149
}
143-
const email = this.getEmail();
144-
if (email) {
145-
return osparc.utils.Utils.getNameFromEmail(email);
146-
}
147-
return "user";
150+
return this.getUsername();
148151
},
149152

150153
getFriendlyRole: function() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ qx.Class.define("osparc.auth.Manager", {
240240
const authData = osparc.auth.Data.getInstance();
241241
authData.set({
242242
email: profile["login"],
243+
username: profile["userName"],
243244
firstName: profile["first_name"] || profile["login"],
244245
lastName: profile["last_name"] || "",
245246
expirationDate: "expirationDate" in profile ? new Date(profile["expirationDate"]) : null

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,11 @@ qx.Class.define("osparc.data.Resources", {
722722
getOne: {
723723
method: "GET",
724724
url: statics.API + "/me"
725-
}
725+
},
726+
patch: {
727+
method: "PATCH",
728+
url: statics.API + "/me"
729+
},
726730
}
727731
},
728732
/*
@@ -1117,7 +1121,11 @@ qx.Class.define("osparc.data.Resources", {
11171121
postResetPassword: {
11181122
method: "POST",
11191123
url: statics.API + "/auth/reset-password/{code}"
1120-
}
1124+
},
1125+
changeEmail: {
1126+
method: "POST",
1127+
url: statics.API + "/auth/change-email"
1128+
},
11211129
}
11221130
},
11231131
/*

services/static-webserver/client/source/class/osparc/data/model/Group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ qx.Class.define("osparc.data.model.Group", {
105105
},
106106

107107
getGroupMemberByLogin: function(userEmail) {
108-
return Object.values(this.getGroupMembers()).find(user => user.getLogin() === userEmail);
108+
return Object.values(this.getGroupMembers()).find(user => user.getEmail() === userEmail);
109109
},
110110

111111
addGroupMember: function(user) {

services/static-webserver/client/source/class/osparc/data/model/User.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,23 @@ qx.Class.define("osparc.data.model.User", {
2828
construct: function(userData) {
2929
this.base(arguments);
3030

31-
const label = this.self().namesToLabel(userData["first_name"], userData["last_name"]) || userData["login"];
31+
let label = userData["login"];
32+
if (userData["first_name"]) {
33+
label = qx.lang.String.firstUp(userData["first_name"]);
34+
if (userData["last_name"]) {
35+
label += " " + qx.lang.String.firstUp(userData["last_name"]);
36+
}
37+
}
38+
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]);
3239
this.set({
33-
userId: userData.id,
34-
groupId: userData.gid,
40+
userId: userData["id"],
41+
groupId: userData["gid"],
3542
label: label,
36-
login: userData.login,
37-
thumbnail: this.self().emailToThumbnail(userData.login),
38-
accessRights: userData.accessRights,
43+
username: userData["username"] || "",
44+
firstName: userData["first_name"],
45+
lastName: userData["last_name"],
46+
email: userData["login"],
47+
thumbnail,
3948
});
4049
},
4150

@@ -61,18 +70,32 @@ qx.Class.define("osparc.data.model.User", {
6170
event: "changeLabel",
6271
},
6372

64-
login: {
73+
username: {
6574
check: "String",
6675
nullable: true,
6776
init: null,
68-
event: "changeLogin",
77+
event: "changeUsername",
6978
},
7079

71-
accessRights: {
72-
check: "Object",
73-
nullable: false,
80+
firstName: {
81+
init: "",
82+
nullable: true,
83+
check: "String",
84+
event: "changeFirstName"
85+
},
86+
87+
lastName: {
88+
init: "",
89+
nullable: true,
90+
check: "String",
91+
event: "changeLastName"
92+
},
93+
94+
email: {
95+
check: "String",
96+
nullable: true,
7497
init: null,
75-
event: "changeAccessRights",
98+
event: "changeEmail",
7699
},
77100

78101
thumbnail: {
@@ -82,21 +105,4 @@ qx.Class.define("osparc.data.model.User", {
82105
event: "changeThumbnail",
83106
},
84107
},
85-
86-
statics: {
87-
namesToLabel: function(firstName, lastName) {
88-
let label = "";
89-
if (firstName) {
90-
label = osparc.utils.Utils.firstsUp(firstName);
91-
if (lastName) {
92-
label += " " + osparc.utils.Utils.firstsUp(lastName);
93-
}
94-
}
95-
return label;
96-
},
97-
98-
emailToThumbnail: function(email) {
99-
return osparc.utils.Avatar.getUrl(email, 32)
100-
},
101-
}
102108
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2024 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
/**
19+
* Class that stores User data + access rights to the resource.
20+
*/
21+
22+
qx.Class.define("osparc.data.model.UserMember", {
23+
extend: osparc.data.model.User,
24+
25+
/**
26+
* @param userData {Object} Object containing the serialized User Data
27+
*/
28+
construct: function(userData) {
29+
this.base(arguments, userData);
30+
31+
this.set({
32+
accessRights: userData["accessRights"],
33+
});
34+
},
35+
36+
properties: {
37+
accessRights: {
38+
check: "Object",
39+
nullable: false,
40+
init: null,
41+
event: "changeAccessRights",
42+
},
43+
},
44+
});

services/static-webserver/client/source/class/osparc/desktop/account/MyAccount.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ qx.Class.define("osparc.desktop.account.MyAccount", {
4242
});
4343

4444
const authData = osparc.auth.Data.getInstance();
45+
4546
const email = authData.getEmail();
4647
const avatarSize = 80;
4748
const img = new qx.ui.basic.Image().set({
@@ -56,10 +57,17 @@ qx.Class.define("osparc.desktop.account.MyAccount", {
5657
});
5758
layout.add(img);
5859

59-
const name = new qx.ui.basic.Label().set({
60+
const usernameLabel = new qx.ui.basic.Label().set({
6061
font: "text-14",
6162
alignX: "center"
6263
});
64+
authData.bind("username", usernameLabel, "value");
65+
layout.add(usernameLabel);
66+
67+
const name = new qx.ui.basic.Label().set({
68+
font: "text-13",
69+
alignX: "center"
70+
});
6371
layout.add(name);
6472
authData.bind("firstName", name, "value", {
6573
converter: firstName => firstName + " " + authData.getLastName()
@@ -77,12 +85,6 @@ qx.Class.define("osparc.desktop.account.MyAccount", {
7785
layout.add(roleLabel);
7886
}
7987

80-
const emailLabel = new qx.ui.basic.Label(email).set({
81-
font: "text-13",
82-
alignX: "center"
83-
});
84-
layout.add(emailLabel);
85-
8688
if (withSpacer) {
8789
layout.add(new qx.ui.core.Spacer(15, 15));
8890
}

services/static-webserver/client/source/class/osparc/desktop/account/MyAccountWindow.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ qx.Class.define("osparc.desktop.account.MyAccountWindow", {
2222
this.base(arguments, "credits", this.tr("My Account"));
2323

2424
const width = 900;
25-
const height = 600;
25+
const height = 700;
26+
const maxHeight = 700;
2627
this.set({
2728
width,
28-
height
29+
height,
30+
maxHeight,
2931
});
3032

3133
const myAccount = this.__myAccount = new osparc.desktop.account.MyAccount();

0 commit comments

Comments
 (0)