Skip to content

Commit fee208d

Browse files
authored
✨ [Frontend] Search users for sharing (#6974)
1 parent 116a6c0 commit fee208d

File tree

15 files changed

+387
-218
lines changed

15 files changed

+387
-218
lines changed

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

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -148,54 +148,59 @@ qx.Class.define("osparc.dashboard.CardBase", {
148148
return false;
149149
},
150150

151-
// groups -> [orgMembs, orgs, [productEveryone], [everyone]];
152-
setIconAndTooltip: function(shareIcon, accessRights, groups) {
153-
shareIcon.setSource(osparc.dashboard.CardBase.SHARE_ICON);
154-
if (osparc.data.model.Study.canIWrite(accessRights)) {
155-
shareIcon.set({
156-
toolTipText: qx.locale.Manager.tr("Share")
157-
});
151+
populateShareIcon: async function(shareIcon, accessRights) {
152+
const gids = Object.keys(accessRights).map(key => parseInt(key));
153+
154+
const groupsStore = osparc.store.Groups.getInstance();
155+
156+
// Icon
157+
const groupEveryone = groupsStore.getEveryoneGroup();
158+
const groupProductEveryone = groupsStore.getEveryoneProductGroup();
159+
const organizations = groupsStore.getOrganizations();
160+
const organizationIds = Object.keys(organizations).map(key => parseInt(key));
161+
if (gids.includes(groupEveryone.getGroupId()) || gids.includes(groupProductEveryone.getGroupId())) {
162+
shareIcon.setSource(osparc.dashboard.CardBase.SHARED_ALL);
163+
} else if (organizationIds.filter(value => gids.includes(value)).length) { // find intersection
164+
shareIcon.setSource(osparc.dashboard.CardBase.SHARED_ORGS);
165+
} else if (gids.length === 1) {
166+
shareIcon.setSource(osparc.dashboard.CardBase.SHARE_ICON);
167+
} else {
168+
shareIcon.setSource(osparc.dashboard.CardBase.SHARED_USER);
158169
}
159-
let sharedGrps = [];
160-
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
161-
for (let i=0; i<groups.length; i++) {
162-
if (groups[i].length === 0) {
163-
// user has no read access to the productEveryone
164-
continue;
170+
171+
// Tooltip
172+
const sharedGrps = [];
173+
const groups = [];
174+
groups.push(groupEveryone);
175+
groups.push(groupProductEveryone);
176+
groups.push(...Object.values(organizations));
177+
groups.forEach(group => {
178+
const idx = gids.indexOf(group.getGroupId());
179+
if (idx > -1) {
180+
sharedGrps.push(group);
181+
gids.splice(idx, 1);
165182
}
166-
const sharedGrp = [];
167-
const gids = Object.keys(accessRights);
168-
for (let j=0; j<gids.length; j++) {
169-
const gid = parseInt(gids[j]);
170-
if (gid === myGroupId) {
171-
continue;
172-
}
173-
const grp = groups[i].find(group => group.getGroupId() === gid);
174-
if (grp) {
175-
sharedGrp.push(grp);
183+
});
184+
// once the groups were removed, the remaining group ids are users' primary groups ids
185+
const usersStore = osparc.store.Users.getInstance();
186+
const myGroupId = groupsStore.getMyGroupId();
187+
for (let i=0; i<gids.length; i++) {
188+
const gid = gids[i];
189+
if (myGroupId !== gid) {
190+
const user = await usersStore.getUser(gid);
191+
if (user) {
192+
sharedGrps.push(user);
176193
}
177194
}
178-
if (sharedGrp.length === 0) {
179-
continue;
180-
} else {
181-
sharedGrps = sharedGrps.concat(sharedGrp);
182-
}
183-
switch (i) {
184-
case 0:
185-
shareIcon.setSource(osparc.dashboard.CardBase.SHARED_USER);
186-
break;
187-
case 1:
188-
shareIcon.setSource(osparc.dashboard.CardBase.SHARED_ORGS);
189-
break;
190-
case 2:
191-
case 3:
192-
shareIcon.setSource(osparc.dashboard.CardBase.SHARED_ALL);
193-
break;
194-
}
195195
}
196196

197-
// tooltip
197+
const canIWrite = osparc.data.model.Study.canIWrite(accessRights);
198198
if (sharedGrps.length === 0) {
199+
if (canIWrite) {
200+
shareIcon.set({
201+
toolTipText: qx.locale.Manager.tr("Share")
202+
});
203+
}
199204
return;
200205
}
201206
const sharedGrpLabels = [];
@@ -215,17 +220,6 @@ qx.Class.define("osparc.dashboard.CardBase", {
215220
shareIcon.addListener("mouseover", () => hint.show(), this);
216221
shareIcon.addListener("mouseout", () => hint.exclude(), this);
217222
},
218-
219-
// groups -> [orgMembs, orgs, [productEveryone], [everyone]];
220-
populateShareIcon: function(shareIcon, accessRights) {
221-
const groupsStore = osparc.store.Groups.getInstance();
222-
const orgMembs = Object.values(groupsStore.getReachableUsers());
223-
const orgs = Object.values(groupsStore.getOrganizations());
224-
const productEveryone = [groupsStore.getEveryoneProductGroup()];
225-
const everyone = [groupsStore.getEveryoneGroup()];
226-
const groups = [orgMembs, orgs, productEveryone, everyone];
227-
osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups);
228-
},
229223
},
230224

231225
properties: {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,22 @@ qx.Class.define("osparc.data.Resources", {
878878
}
879879
}
880880
},
881+
/*
882+
* USERS
883+
*/
884+
"users": {
885+
useCache: false, // osparc.store.Groups handles the cache
886+
endpoints: {
887+
get: {
888+
method: "GET",
889+
url: statics.API + "/groups/{gid}/users"
890+
},
891+
search: {
892+
method: "POST",
893+
url: statics.API + "/users:search"
894+
}
895+
}
896+
},
881897
/*
882898
* WALLETS
883899
*/
@@ -958,7 +974,7 @@ qx.Class.define("osparc.data.Resources", {
958974
}
959975
}
960976
},
961-
"users": {
977+
"poUsers": {
962978
endpoints: {
963979
search: {
964980
method: "GET",

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ qx.Class.define("osparc.data.Roles", {
165165
}
166166
},
167167

168-
__createIntoFromRoles: function(roles, showWording = true) {
168+
__createRolesLayout: function(roles, showWording = true) {
169169
const rolesLayout = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)).set({
170170
alignY: "middle",
171171
paddingRight: 10
@@ -202,23 +202,34 @@ qx.Class.define("osparc.data.Roles", {
202202
},
203203

204204
createRolesOrgInfo: function() {
205-
return this.__createIntoFromRoles(osparc.data.Roles.ORG);
205+
return this.__createRolesLayout(osparc.data.Roles.ORG);
206206
},
207207

208208
createRolesWalletInfo: function() {
209-
return this.__createIntoFromRoles(osparc.data.Roles.WALLET);
209+
return this.__createRolesLayout(osparc.data.Roles.WALLET);
210210
},
211211

212212
createRolesStudyInfo: function() {
213-
return this.__createIntoFromRoles(osparc.data.Roles.STUDY);
213+
return this.__createRolesLayout(osparc.data.Roles.STUDY);
214214
},
215215

216216
createRolesServicesInfo: function() {
217-
return this.__createIntoFromRoles(osparc.data.Roles.SERVICES);
217+
return this.__createRolesLayout(osparc.data.Roles.SERVICES);
218218
},
219219

220220
createRolesWorkspaceInfo: function(showWording = true) {
221-
return this.__createIntoFromRoles(osparc.data.Roles.WORKSPACE, showWording);
222-
}
221+
return this.__createRolesLayout(osparc.data.Roles.WORKSPACE, showWording);
222+
},
223+
224+
replaceSpacerWithWidget: function(rolesLayout, widget) {
225+
if (rolesLayout && rolesLayout.getChildren()) {
226+
// remove spacer
227+
rolesLayout.remove(rolesLayout.getChildren()[0]);
228+
// add widget
229+
rolesLayout.addAt(widget, 0, {
230+
flex: 1
231+
});
232+
}
233+
},
223234
}
224235
});

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,19 @@ qx.Class.define("osparc.data.model.Study", {
274274
},
275275

276276
canIWrite: function(studyAccessRights) {
277-
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
278277
const groupsStore = osparc.store.Groups.getInstance();
279278
const orgIDs = groupsStore.getOrganizationIds();
280-
orgIDs.push(myGroupId);
279+
orgIDs.push(groupsStore.getMyGroupId());
281280
if (orgIDs.length) {
282281
return osparc.share.CollaboratorsStudy.canGroupsWrite(studyAccessRights, (orgIDs));
283282
}
284283
return false;
285284
},
286285

287286
canIDelete: function(studyAccessRights) {
288-
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
289287
const groupsStore = osparc.store.Groups.getInstance();
290288
const orgIDs = groupsStore.getOrganizationIds();
291-
orgIDs.push(myGroupId);
289+
orgIDs.push(groupsStore.getMyGroupId());
292290
if (orgIDs.length) {
293291
return osparc.share.CollaboratorsStudy.canGroupsDelete(studyAccessRights, (orgIDs));
294292
}

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

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

31-
let description = "";
32-
if (userData["first_name"]) {
33-
description = userData["first_name"];
34-
if (userData["last_name"]) {
35-
description += " " + userData["last_name"];
31+
const userId = ("id" in userData) ? parseInt(userData["id"]) : parseInt(userData["userId"]);
32+
const groupId = ("gid" in userData) ? parseInt(userData["gid"]) : parseInt(userData["groupId"]);
33+
const username = userData["userName"];
34+
const email = ("login" in userData) ? userData["login"] : userData["email"];
35+
const firstName = ("first_name" in userData) ? userData["first_name"] : userData["firstName"];
36+
const lastName = ("last_name" in userData) ? userData["last_name"] : userData["lastName"];
37+
let description = [firstName, lastName].join(" ").trim(); // the null values will be replaced by empty strings
38+
if (email) {
39+
if (description) {
40+
description += " - "
3641
}
37-
description += " - ";
42+
description += email;
3843
}
39-
if (userData["login"]) {
40-
description += userData["login"];
41-
}
42-
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"], userData["userName"]);
44+
const thumbnail = osparc.utils.Avatar.emailToThumbnail(email, username);
4345
this.set({
44-
userId: parseInt(userData["id"]),
45-
groupId: parseInt(userData["gid"]),
46-
username: userData["userName"],
47-
firstName: userData["first_name"],
48-
lastName: userData["last_name"],
49-
email: userData["login"],
50-
label: userData["userName"],
51-
description,
46+
userId,
47+
groupId,
48+
username,
49+
firstName,
50+
lastName,
51+
email,
5252
thumbnail,
53+
label: username,
54+
description,
5355
});
5456
},
5557

0 commit comments

Comments
 (0)