Skip to content

Commit 7f9f92f

Browse files
authored
🎨 [Frontend] Enh: users are identified by username (#6934)
1 parent 825c22a commit 7f9f92f

File tree

13 files changed

+101
-72
lines changed

13 files changed

+101
-72
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,9 @@ qx.Class.define("osparc.auth.Data", {
8282
event: "changeUsername",
8383
},
8484

85-
/**
86-
* Email of logged in user, otherwise null
87-
*/
8885
email: {
8986
init: null,
90-
nullable: true,
87+
nullable: true, // email of logged in user, otherwise null
9188
check: "String"
9289
},
9390

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ qx.Class.define("osparc.auth.Manager", {
241241
authData.set({
242242
email: profile["login"],
243243
username: profile["userName"],
244-
firstName: profile["first_name"] || profile["login"],
245-
lastName: profile["last_name"] || "",
244+
firstName: profile["first_name"],
245+
lastName: profile["last_name"],
246246
expirationDate: "expirationDate" in profile ? new Date(profile["expirationDate"]) : null
247247
});
248248
},

services/static-webserver/client/source/class/osparc/dashboard/CardBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
674674
__showBlockedCardFromStatus: function(lockedStatus) {
675675
const status = lockedStatus["status"];
676676
const owner = lockedStatus["owner"];
677-
let toolTip = osparc.utils.Utils.firstsUp(owner["first_name"] || this.tr("A user"), owner["last_name"] || "");
677+
let toolTip = osparc.utils.Utils.firstsUp(owner["first_name"] || this.tr("A user"), owner["last_name"] || ""); // it will be replaced by "userName"
678678
let image = null;
679679
switch (status) {
680680
case "CLOSING":

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ qx.Class.define("osparc.data.model.Group", {
104104
return Object.values(this.getGroupMembers()).find(user => user.getUserId() === userId);
105105
},
106106

107+
getGroupMemberByUsername: function(username) {
108+
return Object.values(this.getGroupMembers()).find(user => user.getUsername() === username);
109+
},
110+
107111
getGroupMemberByLogin: function(userEmail) {
108112
return Object.values(this.getGroupMembers()).find(user => user.getEmail() === userEmail);
109113
},

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

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

31-
let label = userData["login"];
31+
let description = "";
3232
if (userData["first_name"]) {
33-
label = qx.lang.String.firstUp(userData["first_name"]);
33+
description = userData["first_name"];
3434
if (userData["last_name"]) {
35-
label += " " + qx.lang.String.firstUp(userData["last_name"]);
35+
description += " " + userData["last_name"];
3636
}
37+
description += " - ";
38+
}
39+
if (userData["login"]) {
40+
description += userData["login"];
3741
}
3842
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]);
3943
this.set({
40-
userId: userData["id"],
41-
groupId: userData["gid"],
42-
label: label,
43-
username: userData["username"] || "",
44+
userId: parseInt(userData["id"]),
45+
groupId: parseInt(userData["gid"]),
46+
username: userData["userName"],
4447
firstName: userData["first_name"],
4548
lastName: userData["last_name"],
4649
email: userData["login"],
50+
label: userData["userName"],
51+
description,
4752
thumbnail,
4853
});
4954
},
@@ -70,24 +75,31 @@ qx.Class.define("osparc.data.model.User", {
7075
event: "changeLabel",
7176
},
7277

73-
username: {
78+
description: {
7479
check: "String",
7580
nullable: true,
7681
init: null,
82+
event: "changeDescription",
83+
},
84+
85+
username: {
86+
check: "String",
87+
nullable: false,
88+
init: null,
7789
event: "changeUsername",
7890
},
7991

8092
firstName: {
81-
init: "",
82-
nullable: true,
8393
check: "String",
94+
nullable: true,
95+
init: "",
8496
event: "changeFirstName"
8597
},
8698

8799
lastName: {
88-
init: "",
89-
nullable: true,
90100
check: "String",
101+
nullable: true,
102+
init: "",
91103
event: "changeLastName"
92104
},
93105

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
9494
lockedBy = studyData["state"]["locked"]["owner"];
9595
}
9696
if (locked && lockedBy["user_id"] !== osparc.auth.Data.getInstance().getUserId()) {
97-
const msg = `${studyAlias} ${qx.locale.Manager.tr("is already open by")} ${
97+
const msg = `${studyAlias} ${qx.locale.Manager.tr("is already open by")} ${ // it will be replaced "userName"
9898
"first_name" in lockedBy && lockedBy["first_name"] != null ?
9999
lockedBy["first_name"] :
100100
qx.locale.Manager.tr("another user.")

services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
7070
if (sorted !== 0) {
7171
return sorted;
7272
}
73-
if (("email" in a) && ("email" in b)) {
74-
return a["email"].localeCompare(b["email"]);
73+
if (("label" in a) && ("label" in b)) {
74+
return a["label"].localeCompare(b["label"]);
7575
}
7676
return 0;
7777
}
@@ -105,22 +105,17 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
105105
alignY: "middle"
106106
}));
107107

108-
const userEmail = new qx.ui.form.TextField().set({
108+
const newMemberUserName = new qx.ui.form.TextField().set({
109109
required: true,
110-
placeholder: this.tr(" New Member's email")
110+
placeholder: this.tr(" New Member's username")
111111
});
112-
hBox.add(userEmail, {
112+
hBox.add(newMemberUserName, {
113113
flex: 1
114114
});
115115

116-
const validator = new qx.ui.form.validation.Manager();
117-
validator.add(userEmail, qx.util.Validate.email());
118-
119116
const addBtn = new qx.ui.form.Button(this.tr("Add"));
120117
addBtn.addListener("execute", function() {
121-
if (validator.validate()) {
122-
this.__addMember(userEmail.getValue());
123-
}
118+
this.__addMember(newMemberUserName.getValue());
124119
}, this);
125120
hBox.add(addBtn);
126121

@@ -154,9 +149,9 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
154149
ctrl.bindProperty("userId", "model", null, item, id);
155150
ctrl.bindProperty("userId", "key", null, item, id);
156151
ctrl.bindProperty("thumbnail", "thumbnail", null, item, id);
157-
ctrl.bindProperty("name", "title", null, item, id);
152+
ctrl.bindProperty("label", "title", null, item, id);
153+
ctrl.bindProperty("description", "subtitleMD", null, item, id);
158154
ctrl.bindProperty("accessRights", "accessRights", null, item, id);
159-
ctrl.bindProperty("email", "subtitleMD", null, item, id);
160155
ctrl.bindProperty("options", "options", null, item, id);
161156
ctrl.bindProperty("showOptions", "showOptions", null, item, id);
162157
},
@@ -217,23 +212,25 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
217212
const canIDelete = organization.getAccessRights()["delete"];
218213

219214
const introText = canIWrite ?
220-
this.tr("You can add new members and promote or demote existing ones.") :
215+
this.tr("You can add new members and promote or demote existing ones.<br>In order to add new members, type their username or email if this is public.") :
221216
this.tr("You can't add new members to this Organization. Please contact an Administrator or Manager.");
222217
this.__introLabel.setValue(introText);
223218

224219
this.__memberInvitation.set({
225220
enabled: canIWrite
226221
});
227222

223+
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
228224
const membersList = [];
229225
const groupMembers = organization.getGroupMembers();
230226
Object.values(groupMembers).forEach(groupMember => {
227+
const gid = parseInt(groupMember.getGroupId());
231228
const member = {};
232-
member["userId"] = groupMember.getUserId();
233-
member["groupId"] = groupMember.getGroupId();
229+
member["userId"] = gid === myGroupId ? osparc.auth.Data.getInstance().getUserId() : groupMember.getUserId();
230+
member["groupId"] = gid;
234231
member["thumbnail"] = groupMember.getThumbnail();
235-
member["name"] = groupMember.getLabel();
236-
member["email"] = groupMember.getEmail();
232+
member["label"] = groupMember.getLabel();
233+
member["description"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : groupMember.getDescription();
237234
member["accessRights"] = groupMember.getAccessRights();
238235
let options = [];
239236
if (canIDelete) {
@@ -287,7 +284,6 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
287284
}
288285
// Let me go?
289286
const openStudy = osparc.store.Store.getInstance().getCurrentStudy();
290-
const myGroupId = osparc.store.Groups.getInstance().getMyGroupId();
291287
if (
292288
openStudy === null &&
293289
canIWrite &&
@@ -303,16 +299,18 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
303299
membersList.forEach(member => membersModel.append(qx.data.marshal.Json.createModel(member)));
304300
},
305301

306-
__addMember: async function(orgMemberEmail) {
302+
__addMember: async function(newMemberIdentifier) {
307303
if (this.__currentOrg === null) {
308304
return;
309305
}
310306

311307
const orgId = this.__currentOrg.getGroupId();
312308
const groupsStore = osparc.store.Groups.getInstance();
313-
groupsStore.postMember(orgId, orgMemberEmail)
309+
const isEmail = osparc.utils.Utils.isEmail(newMemberIdentifier);
310+
const request = isEmail ? groupsStore.addMember(orgId, null, newMemberIdentifier) : groupsStore.addMember(orgId, newMemberIdentifier);
311+
request
314312
.then(newMember => {
315-
const text = orgMemberEmail + this.tr(" successfully added");
313+
const text = newMemberIdentifier + this.tr(" successfully added");
316314
osparc.FlashMessenger.getInstance().logAs(text);
317315
this.__reloadOrgMembers();
318316

services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
7070
if (sorted !== 0) {
7171
return sorted;
7272
}
73-
if (("email" in a) && ("email" in b)) {
74-
return a["email"].localeCompare(b["email"]);
73+
if (("label" in a) && ("label" in b)) {
74+
return a["label"].localeCompare(b["label"]);
7575
}
7676
return 0;
7777
}
@@ -170,9 +170,9 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
170170
ctrl.bindProperty("userId", "key", null, item, id);
171171
ctrl.bindProperty("groupId", "gid", null, item, id);
172172
ctrl.bindProperty("thumbnail", "thumbnail", null, item, id);
173-
ctrl.bindProperty("name", "title", null, item, id);
173+
ctrl.bindProperty("label", "title", null, item, id);
174+
ctrl.bindProperty("description", "subtitleMD", null, item, id);
174175
ctrl.bindProperty("accessRights", "accessRights", null, item, id);
175-
ctrl.bindProperty("email", "subtitleMD", null, item, id);
176176
ctrl.bindProperty("options", "options", null, item, id);
177177
ctrl.bindProperty("showOptions", "showOptions", null, item, id);
178178
},
@@ -222,8 +222,8 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
222222
collaborator["userId"] = gid === myGroupId ? osparc.auth.Data.getInstance().getUserId() : collab.getUserId();
223223
collaborator["groupId"] = collab.getGroupId();
224224
collaborator["thumbnail"] = collab.getThumbnail();
225-
collaborator["name"] = collab.getLabel();
226-
collaborator["email"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getEmail();
225+
collaborator["label"] = collab.getLabel();
226+
collaborator["description"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getDescription();
227227
collaborator["accessRights"] = {
228228
read: accessRights["read"],
229229
write: accessRights["write"],

services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ qx.Class.define("osparc.filter.CollaboratorToggleButton", {
2424
});
2525

2626
let label = collaborator.getLabel();
27-
if ("getEmail" in collaborator) {
28-
// user
27+
if ("getEmail" in collaborator && collaborator.getEmail()) {
2928
label += ` (${collaborator.getEmail()})`;
30-
this.setToolTipText(collaborator.getEmail());
3129
}
3230
this.setLabel(label);
3331

32+
if (collaborator.getDescription()) {
33+
const ttt = collaborator.getLabel() + "<br>" + collaborator.getDescription();
34+
this.setToolTipText(ttt);
35+
}
36+
3437
let iconPath = null;
3538
switch (collaborator["collabType"]) {
3639
case 0:

services/static-webserver/client/source/class/osparc/share/Collaborators.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,8 @@ qx.Class.define("osparc.share.Collaborators", {
293293
ctrl.bindProperty("gid", "key", null, item, id);
294294
ctrl.bindProperty("collabType", "collabType", null, item, id);
295295
ctrl.bindProperty("thumbnail", "thumbnail", null, item, id);
296-
ctrl.bindProperty("name", "title", null, item, id); // user
297-
ctrl.bindProperty("label", "title", null, item, id); // organization
298-
ctrl.bindProperty("email", "subtitleMD", null, item, id); // user
299-
ctrl.bindProperty("description", "subtitle", null, item, id); // organization
296+
ctrl.bindProperty("label", "title", null, item, id);
297+
ctrl.bindProperty("description", "subtitleMD", null, item, id);
300298
ctrl.bindProperty("resourceType", "resourceType", null, item, id); // Resource type
301299
ctrl.bindProperty("accessRights", "accessRights", null, item, id);
302300
ctrl.bindProperty("showOptions", "showOptions", null, item, id);
@@ -409,15 +407,11 @@ qx.Class.define("osparc.share.Collaborators", {
409407
const collaborator = {
410408
"gid": collab.getGroupId(),
411409
"thumbnail": collab.getThumbnail(),
410+
"label": collab.getLabel(),
411+
"description": collab.getDescription(),
412412
};
413-
if ("getUserId" in collab) {
414-
// user
415-
collaborator["name"] = collab.getLabel();
416-
collaborator["email"] = collab.getEmail();
417-
} else {
418-
// org/group
419-
collaborator["label"] = collab.getLabel();
420-
collaborator["description"] = collab.getDescription();
413+
if (!("getUserId" in collab)) {
414+
// orgnanization
421415
if (everyoneGIds.includes(parseInt(gid))) {
422416
collaborator["thumbnail"] = "@FontAwesome5Solid/globe/32";
423417
} else if (!collaborator["thumbnail"]) {

0 commit comments

Comments
 (0)