Skip to content

Commit 1f18a84

Browse files
authored
♻️✨ [Frontend] Enh: model Groups and Users. And their Store (#6769)
1 parent 2efc9e0 commit 1f18a84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1260
-1130
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ qx.Class.define("osparc.auth.Data", {
4343
check: "Number"
4444
},
4545

46-
/**
47-
* org IDs
48-
*/
49-
orgIds: {
50-
init: [],
51-
nullable: false,
52-
check: "Array"
53-
},
54-
5546
/**
5647
* Basic authentification with a token
5748
*/

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ qx.Class.define("osparc.auth.Manager", {
255255
role: profile.role.toLowerCase()
256256
});
257257
this.updateProfile(profile);
258-
if ("organizations" in profile["groups"]) {
259-
const orgIds = [];
260-
profile["groups"]["organizations"].forEach(org => orgIds.push(org["gid"]));
261-
authData.setOrgIds(orgIds);
262-
}
263258
const role = profile.role.toLowerCase();
264259
osparc.data.Permissions.getInstance().setRole(role);
265260

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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ qx.Class.define("osparc.dashboard.CardBase", {
9999

100100
filterSharedWith: function(checks, sharedWith) {
101101
if (sharedWith && sharedWith !== "show-all") {
102-
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
102+
const groupsStore = osparc.store.Groups.getInstance();
103+
const myGroupId = groupsStore.getMyGroupId();
103104
if (checks && myGroupId in checks) {
104105
const myAccessRights = checks[myGroupId];
105106
const totalAccess = "delete" in myAccessRights ? myAccessRights["delete"] : myAccessRights["write"];
@@ -108,10 +109,9 @@ qx.Class.define("osparc.dashboard.CardBase", {
108109
} else if (sharedWith === "shared-with-me") {
109110
return totalAccess;
110111
} else if (sharedWith === "shared-with-everyone") {
111-
const store = osparc.store.Store.getInstance();
112112
const everyoneGroupIds = [
113-
store.getEveryoneProductGroup()["gid"],
114-
store.getEveryoneGroup()["gid"]
113+
groupsStore.getEveryoneProductGroup().getGroupId(),
114+
groupsStore.getEveryoneGroup().getGroupId(),
115115
];
116116
const found = Object.keys(checks).some(gId => everyoneGroupIds.includes(parseInt(gId)));
117117
return !found;
@@ -168,7 +168,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
168168
if (gid === myGroupId) {
169169
continue;
170170
}
171-
const grp = groups[i].find(group => group["gid"] === gid);
171+
const grp = groups[i].find(group => group.getGroupId() === gid);
172172
if (grp) {
173173
sharedGrp.push(grp);
174174
}
@@ -203,7 +203,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
203203
sharedGrpLabels.push("...");
204204
break;
205205
}
206-
const sharedGrpLabel = sharedGrps[i]["label"];
206+
const sharedGrpLabel = sharedGrps[i].getLabel();
207207
if (!sharedGrpLabels.includes(sharedGrpLabel)) {
208208
sharedGrpLabels.push(sharedGrpLabel);
209209
}
@@ -216,25 +216,13 @@ qx.Class.define("osparc.dashboard.CardBase", {
216216

217217
// groups -> [orgMembs, orgs, [productEveryone], [everyone]];
218218
populateShareIcon: function(shareIcon, accessRights) {
219-
const store = osparc.store.Store.getInstance();
220-
Promise.all([
221-
store.getGroupEveryone(),
222-
store.getProductEveryone(),
223-
store.getReachableMembers(),
224-
store.getGroupsOrganizations()
225-
])
226-
.then(values => {
227-
const everyone = values[0] ? [values[0]] : [];
228-
const productEveryone = values[1] ? [values[1]] : [];
229-
const orgMembs = [];
230-
const orgMembers = values[2];
231-
for (const gid of Object.keys(orgMembers)) {
232-
orgMembs.push(orgMembers[gid]);
233-
}
234-
const orgs = values.length === 4 ? values[3] : [];
235-
const groups = [orgMembs, orgs, productEveryone, everyone];
236-
osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups);
237-
});
219+
const groupsStore = osparc.store.Groups.getInstance();
220+
const orgMembs = Object.values(groupsStore.getReachableUsers());
221+
const orgs = Object.values(groupsStore.getOrganizations());
222+
const productEveryone = [groupsStore.getEveryoneProductGroup()];
223+
const everyone = [groupsStore.getEveryoneGroup()];
224+
const groups = [orgMembs, orgs, productEveryone, everyone];
225+
osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups);
238226
},
239227
},
240228

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ qx.Class.define("osparc.dashboard.Dashboard", {
178178
}, this);
179179

180180
const preResourcePromises = [];
181-
const store = osparc.store.Store.getInstance();
182-
preResourcePromises.push(store.getAllGroupsAndMembers());
181+
const groupsStore = osparc.store.Groups.getInstance();
182+
preResourcePromises.push(groupsStore.fetchGroupsAndMembers());
183183
preResourcePromises.push(osparc.store.Services.getServicesLatest(false));
184184
Promise.all(preResourcePromises)
185185
.then(() => {

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -474,29 +474,28 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
474474
let groupContainer = this.__getGroupContainer(orgId);
475475
if (groupContainer === null) {
476476
groupContainer = this.__createGroupContainer(orgId, "loading-label");
477-
osparc.store.Store.getInstance().getOrganizationOrUser(orgId)
478-
.then(org => {
479-
if (org && org["collabType"] !== 2) {
480-
let icon = "";
481-
if (org.thumbnail) {
482-
icon = org.thumbnail;
483-
} else if (org["collabType"] === 0) {
484-
icon = "@FontAwesome5Solid/globe/24";
485-
} else if (org["collabType"] === 1) {
486-
icon = "@FontAwesome5Solid/users/24";
487-
}
488-
groupContainer.set({
489-
headerIcon: icon,
490-
headerLabel: org.label
491-
});
492-
} else {
493-
groupContainer.exclude();
494-
}
495-
})
496-
.finally(() => {
497-
this._add(groupContainer);
498-
this.__moveNoGroupToLast();
477+
const groupsStore = osparc.store.Groups.getInstance();
478+
const group = groupsStore.getGroup(orgId);
479+
if (group) {
480+
let icon = "";
481+
if (group.getThumbnail()) {
482+
icon = group.getThumbnail();
483+
} else if (group["collabType"] === 0) {
484+
icon = "@FontAwesome5Solid/globe/24";
485+
} else if (group["collabType"] === 1) {
486+
icon = "@FontAwesome5Solid/users/24";
487+
} else if (group["collabType"] === 2) {
488+
icon = "@FontAwesome5Solid/user/24";
489+
}
490+
groupContainer.set({
491+
headerIcon: icon,
492+
headerLabel: group.getLabel(),
499493
});
494+
} else {
495+
groupContainer.exclude();
496+
}
497+
this._add(groupContainer);
498+
this.__moveNoGroupToLast();
500499
}
501500
const card = this.__createCard(resourceData);
502501
this.__addCardToContainer(card, groupContainer);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ qx.Class.define("osparc.data.Resources", {
765765
* ORGANIZATIONS
766766
*/
767767
"organizations": {
768-
useCache: true,
768+
useCache: false, // osparc.store.Groups handles the cache
769769
endpoints: {
770770
get: {
771771
method: "GET",
@@ -793,7 +793,7 @@ qx.Class.define("osparc.data.Resources", {
793793
* ORGANIZATION MEMBERS
794794
*/
795795
"organizationMembers": {
796-
useCache: false,
796+
useCache: false, // osparc.store.Groups handles the cache
797797
endpoints: {
798798
get: {
799799
method: "GET",
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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 Group data.
20+
*/
21+
22+
qx.Class.define("osparc.data.model.Group", {
23+
extend: qx.core.Object,
24+
25+
/**
26+
* @param groupData {Object} Object containing the serialized Group Data
27+
*/
28+
construct: function(groupData) {
29+
this.base(arguments);
30+
31+
this.set({
32+
groupId: groupData.gid,
33+
label: groupData.label,
34+
description: groupData.description,
35+
accessRights: groupData.accessRights,
36+
thumbnail: groupData.thumbnail,
37+
groupMembers: {},
38+
});
39+
},
40+
41+
properties: {
42+
groupId: {
43+
check: "Number",
44+
nullable: false,
45+
init: null,
46+
event: "changeGroupId",
47+
},
48+
49+
label: {
50+
check: "String",
51+
nullable: false,
52+
init: null,
53+
event: "changeLabel",
54+
},
55+
56+
description: {
57+
check: "String",
58+
nullable: true,
59+
init: null,
60+
event: "changeDescription",
61+
},
62+
63+
accessRights: {
64+
check: "Object",
65+
nullable: false,
66+
init: null,
67+
event: "changeAccessRights",
68+
},
69+
70+
thumbnail: {
71+
check: "String",
72+
nullable: true,
73+
init: "",
74+
event: "changeThumbnail",
75+
},
76+
77+
groupMembers: {
78+
check: "Object",
79+
nullable: true,
80+
init: null,
81+
event: "changeGroupMembers",
82+
},
83+
84+
groupType: {
85+
check: ["me", "organization", "productEveryone", "everyone"],
86+
nullable: false,
87+
init: null,
88+
},
89+
},
90+
91+
events: {
92+
"memberAdded": "qx.event.type.Event",
93+
"memberRemoved": "qx.event.type.Event",
94+
},
95+
96+
statics: {
97+
getProperties: function() {
98+
return Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group));
99+
}
100+
},
101+
102+
members: {
103+
getGroupMemberByUserId: function(userId) {
104+
return Object.values(this.getGroupMembers()).find(user => user.getUserId() === userId);
105+
},
106+
107+
getGroupMemberByLogin: function(userEmail) {
108+
return Object.values(this.getGroupMembers()).find(user => user.getLogin() === userEmail);
109+
},
110+
111+
addGroupMember: function(user) {
112+
this.getGroupMembers()[user.getGroupId()] = user;
113+
this.fireEvent("memberAdded");
114+
},
115+
116+
removeGroupMember: function(userId) {
117+
const groupMember = this.getGroupMemberByUserId(userId);
118+
if (groupMember) {
119+
delete this.getGroupMembers()[groupMember.getGroupId()];
120+
this.fireEvent("memberRemoved");
121+
}
122+
},
123+
124+
serialize: function() {
125+
const jsonObject = {};
126+
const propertyKeys = this.self().getProperties();
127+
propertyKeys.forEach(key => {
128+
jsonObject[key] = this.get(key);
129+
});
130+
return jsonObject;
131+
}
132+
}
133+
});

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ qx.Class.define("osparc.data.model.Study", {
275275

276276
canIWrite: function(studyAccessRights) {
277277
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
278-
const orgIDs = [...osparc.auth.Data.getInstance().getOrgIds()];
278+
const groupsStore = osparc.store.Groups.getInstance();
279+
const orgIDs = groupsStore.getOrganizationIds();
279280
orgIDs.push(myGroupId);
280281
if (orgIDs.length) {
281282
return osparc.share.CollaboratorsStudy.canGroupsWrite(studyAccessRights, (orgIDs));
@@ -285,7 +286,8 @@ qx.Class.define("osparc.data.model.Study", {
285286

286287
canIDelete: function(studyAccessRights) {
287288
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
288-
const orgIDs = [...osparc.auth.Data.getInstance().getOrgIds()];
289+
const groupsStore = osparc.store.Groups.getInstance();
290+
const orgIDs = groupsStore.getOrganizationIds();
289291
orgIDs.push(myGroupId);
290292
if (orgIDs.length) {
291293
return osparc.share.CollaboratorsStudy.canGroupsDelete(studyAccessRights, (orgIDs));

0 commit comments

Comments
 (0)