Skip to content

Commit

Permalink
♻️✨ [Frontend] Enh: model Groups and Users. And their Store (#6769)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Nov 25, 2024
1 parent 2efc9e0 commit 1f18a84
Show file tree
Hide file tree
Showing 47 changed files with 1,260 additions and 1,130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ qx.Class.define("osparc.auth.Data", {
check: "Number"
},

/**
* org IDs
*/
orgIds: {
init: [],
nullable: false,
check: "Array"
},

/**
* Basic authentification with a token
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ qx.Class.define("osparc.auth.Manager", {
role: profile.role.toLowerCase()
});
this.updateProfile(profile);
if ("organizations" in profile["groups"]) {
const orgIds = [];
profile["groups"]["organizations"].forEach(org => orgIds.push(org["gid"]));
authData.setOrgIds(orgIds);
}
const role = profile.role.toLowerCase();
osparc.data.Permissions.getInstance().setRole(role);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ qx.Class.define("osparc.dashboard.CardBase", {

filterSharedWith: function(checks, sharedWith) {
if (sharedWith && sharedWith !== "show-all") {
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
const groupsStore = osparc.store.Groups.getInstance();
const myGroupId = groupsStore.getMyGroupId();
if (checks && myGroupId in checks) {
const myAccessRights = checks[myGroupId];
const totalAccess = "delete" in myAccessRights ? myAccessRights["delete"] : myAccessRights["write"];
Expand All @@ -108,10 +109,9 @@ qx.Class.define("osparc.dashboard.CardBase", {
} else if (sharedWith === "shared-with-me") {
return totalAccess;
} else if (sharedWith === "shared-with-everyone") {
const store = osparc.store.Store.getInstance();
const everyoneGroupIds = [
store.getEveryoneProductGroup()["gid"],
store.getEveryoneGroup()["gid"]
groupsStore.getEveryoneProductGroup().getGroupId(),
groupsStore.getEveryoneGroup().getGroupId(),
];
const found = Object.keys(checks).some(gId => everyoneGroupIds.includes(parseInt(gId)));
return !found;
Expand Down Expand Up @@ -168,7 +168,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
if (gid === myGroupId) {
continue;
}
const grp = groups[i].find(group => group["gid"] === gid);
const grp = groups[i].find(group => group.getGroupId() === gid);
if (grp) {
sharedGrp.push(grp);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
sharedGrpLabels.push("...");
break;
}
const sharedGrpLabel = sharedGrps[i]["label"];
const sharedGrpLabel = sharedGrps[i].getLabel();
if (!sharedGrpLabels.includes(sharedGrpLabel)) {
sharedGrpLabels.push(sharedGrpLabel);
}
Expand All @@ -216,25 +216,13 @@ qx.Class.define("osparc.dashboard.CardBase", {

// groups -> [orgMembs, orgs, [productEveryone], [everyone]];
populateShareIcon: function(shareIcon, accessRights) {
const store = osparc.store.Store.getInstance();
Promise.all([
store.getGroupEveryone(),
store.getProductEveryone(),
store.getReachableMembers(),
store.getGroupsOrganizations()
])
.then(values => {
const everyone = values[0] ? [values[0]] : [];
const productEveryone = values[1] ? [values[1]] : [];
const orgMembs = [];
const orgMembers = values[2];
for (const gid of Object.keys(orgMembers)) {
orgMembs.push(orgMembers[gid]);
}
const orgs = values.length === 4 ? values[3] : [];
const groups = [orgMembs, orgs, productEveryone, everyone];
osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups);
});
const groupsStore = osparc.store.Groups.getInstance();
const orgMembs = Object.values(groupsStore.getReachableUsers());
const orgs = Object.values(groupsStore.getOrganizations());
const productEveryone = [groupsStore.getEveryoneProductGroup()];
const everyone = [groupsStore.getEveryoneGroup()];
const groups = [orgMembs, orgs, productEveryone, everyone];
osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups);
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ qx.Class.define("osparc.dashboard.Dashboard", {
}, this);

const preResourcePromises = [];
const store = osparc.store.Store.getInstance();
preResourcePromises.push(store.getAllGroupsAndMembers());
const groupsStore = osparc.store.Groups.getInstance();
preResourcePromises.push(groupsStore.fetchGroupsAndMembers());
preResourcePromises.push(osparc.store.Services.getServicesLatest(false));
Promise.all(preResourcePromises)
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,29 +474,28 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
let groupContainer = this.__getGroupContainer(orgId);
if (groupContainer === null) {
groupContainer = this.__createGroupContainer(orgId, "loading-label");
osparc.store.Store.getInstance().getOrganizationOrUser(orgId)
.then(org => {
if (org && org["collabType"] !== 2) {
let icon = "";
if (org.thumbnail) {
icon = org.thumbnail;
} else if (org["collabType"] === 0) {
icon = "@FontAwesome5Solid/globe/24";
} else if (org["collabType"] === 1) {
icon = "@FontAwesome5Solid/users/24";
}
groupContainer.set({
headerIcon: icon,
headerLabel: org.label
});
} else {
groupContainer.exclude();
}
})
.finally(() => {
this._add(groupContainer);
this.__moveNoGroupToLast();
const groupsStore = osparc.store.Groups.getInstance();
const group = groupsStore.getGroup(orgId);
if (group) {
let icon = "";
if (group.getThumbnail()) {
icon = group.getThumbnail();
} else if (group["collabType"] === 0) {
icon = "@FontAwesome5Solid/globe/24";
} else if (group["collabType"] === 1) {
icon = "@FontAwesome5Solid/users/24";
} else if (group["collabType"] === 2) {
icon = "@FontAwesome5Solid/user/24";
}
groupContainer.set({
headerIcon: icon,
headerLabel: group.getLabel(),
});
} else {
groupContainer.exclude();
}
this._add(groupContainer);
this.__moveNoGroupToLast();
}
const card = this.__createCard(resourceData);
this.__addCardToContainer(card, groupContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ qx.Class.define("osparc.data.Resources", {
* ORGANIZATIONS
*/
"organizations": {
useCache: true,
useCache: false, // osparc.store.Groups handles the cache
endpoints: {
get: {
method: "GET",
Expand Down Expand Up @@ -793,7 +793,7 @@ qx.Class.define("osparc.data.Resources", {
* ORGANIZATION MEMBERS
*/
"organizationMembers": {
useCache: false,
useCache: false, // osparc.store.Groups handles the cache
endpoints: {
get: {
method: "GET",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* ************************************************************************
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 Group data.
*/

qx.Class.define("osparc.data.model.Group", {
extend: qx.core.Object,

/**
* @param groupData {Object} Object containing the serialized Group Data
*/
construct: function(groupData) {
this.base(arguments);

this.set({
groupId: groupData.gid,
label: groupData.label,
description: groupData.description,
accessRights: groupData.accessRights,
thumbnail: groupData.thumbnail,
groupMembers: {},
});
},

properties: {
groupId: {
check: "Number",
nullable: false,
init: null,
event: "changeGroupId",
},

label: {
check: "String",
nullable: false,
init: null,
event: "changeLabel",
},

description: {
check: "String",
nullable: true,
init: null,
event: "changeDescription",
},

accessRights: {
check: "Object",
nullable: false,
init: null,
event: "changeAccessRights",
},

thumbnail: {
check: "String",
nullable: true,
init: "",
event: "changeThumbnail",
},

groupMembers: {
check: "Object",
nullable: true,
init: null,
event: "changeGroupMembers",
},

groupType: {
check: ["me", "organization", "productEveryone", "everyone"],
nullable: false,
init: null,
},
},

events: {
"memberAdded": "qx.event.type.Event",
"memberRemoved": "qx.event.type.Event",
},

statics: {
getProperties: function() {
return Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group));
}
},

members: {
getGroupMemberByUserId: function(userId) {
return Object.values(this.getGroupMembers()).find(user => user.getUserId() === userId);
},

getGroupMemberByLogin: function(userEmail) {
return Object.values(this.getGroupMembers()).find(user => user.getLogin() === userEmail);
},

addGroupMember: function(user) {
this.getGroupMembers()[user.getGroupId()] = user;
this.fireEvent("memberAdded");
},

removeGroupMember: function(userId) {
const groupMember = this.getGroupMemberByUserId(userId);
if (groupMember) {
delete this.getGroupMembers()[groupMember.getGroupId()];
this.fireEvent("memberRemoved");
}
},

serialize: function() {
const jsonObject = {};
const propertyKeys = this.self().getProperties();
propertyKeys.forEach(key => {
jsonObject[key] = this.get(key);
});
return jsonObject;
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ qx.Class.define("osparc.data.model.Study", {

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

canIDelete: function(studyAccessRights) {
const myGroupId = osparc.auth.Data.getInstance().getGroupId();
const orgIDs = [...osparc.auth.Data.getInstance().getOrgIds()];
const groupsStore = osparc.store.Groups.getInstance();
const orgIDs = groupsStore.getOrganizationIds();
orgIDs.push(myGroupId);
if (orgIDs.length) {
return osparc.share.CollaboratorsStudy.canGroupsDelete(studyAccessRights, (orgIDs));
Expand Down
Loading

0 comments on commit 1f18a84

Please sign in to comment.