Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️✨ [Frontend] Enh: model Groups and Users. And their Store #6769

Merged
merged 69 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
46cfc97
[skip ci] Groups store
odeimaiz Nov 19, 2024
9a8f538
[skip ci] more refactoring
odeimaiz Nov 19, 2024
ea1dc43
[skip ci] do not cache
odeimaiz Nov 19, 2024
ae881a9
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 19, 2024
a2724eb
[skip ci] Groups
odeimaiz Nov 19, 2024
fb1e149
Store back
odeimaiz Nov 19, 2024
3304d6e
minor
odeimaiz Nov 19, 2024
05ed765
object
odeimaiz Nov 19, 2024
ce71a5d
getMyGroupId
odeimaiz Nov 20, 2024
c1f149c
[skip ci] refactoring
odeimaiz Nov 20, 2024
f47ea7c
[skip ci] refactor
odeimaiz Nov 20, 2024
ab1ba4f
[skip ci] more
odeimaiz Nov 20, 2024
07a164d
simplify
odeimaiz Nov 20, 2024
96de2f2
less promises
odeimaiz Nov 20, 2024
128f2e3
[skip ci] refactoring
odeimaiz Nov 20, 2024
ae4b74c
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 20, 2024
ffb56ae
[skip ci] modeling
odeimaiz Nov 20, 2024
5f9a860
groupMembers
odeimaiz Nov 20, 2024
296df6f
fixes
odeimaiz Nov 20, 2024
575eaaa
User model
odeimaiz Nov 20, 2024
658cbb6
user model
odeimaiz Nov 20, 2024
1b06549
not a promise
odeimaiz Nov 20, 2024
11c77f9
Collaborators
odeimaiz Nov 20, 2024
be8e66a
Sharing
odeimaiz Nov 20, 2024
7df3aec
renamings
odeimaiz Nov 21, 2024
cb182c6
more specific
odeimaiz Nov 21, 2024
706ff1f
reachable users
odeimaiz Nov 21, 2024
b100155
[skip ci] cleanup
odeimaiz Nov 21, 2024
9682ea8
[skip ci] more refactoring
odeimaiz Nov 21, 2024
99882dd
minor
odeimaiz Nov 21, 2024
c1958b2
minor
odeimaiz Nov 21, 2024
5b5b0df
list group members
odeimaiz Nov 21, 2024
c8f7c3e
unused
odeimaiz Nov 21, 2024
4b3d9d1
listedMember
odeimaiz Nov 21, 2024
4c3149e
unused
odeimaiz Nov 21, 2024
7282d24
postMember
odeimaiz Nov 21, 2024
cd8718d
removeMember
odeimaiz Nov 21, 2024
1548cad
postMember
odeimaiz Nov 21, 2024
4f7d4a7
patchAccessRights
odeimaiz Nov 21, 2024
e35ecdc
patch working
odeimaiz Nov 21, 2024
1f4291e
refactor
odeimaiz Nov 21, 2024
c02d07d
nMembers
odeimaiz Nov 21, 2024
0be0661
working
odeimaiz Nov 21, 2024
5efca2a
patchGroup
odeimaiz Nov 21, 2024
30a0f2d
patch working
odeimaiz Nov 21, 2024
125a3e3
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 21, 2024
a3c21cb
post and delete organization
odeimaiz Nov 21, 2024
32b9762
[skip ci] working post and delete
odeimaiz Nov 21, 2024
3899dbc
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 21, 2024
20e35b5
fix
odeimaiz Nov 21, 2024
5cfb0d7
wallet members list
odeimaiz Nov 22, 2024
e0250c0
Merge branch 'enh/model-organizations' of github.com:odeimaiz/osparc-…
odeimaiz Nov 22, 2024
4d8f5ed
minor
odeimaiz Nov 22, 2024
55ac409
Nicer wallet members list
odeimaiz Nov 22, 2024
bdb7265
fix push wallet notifications
odeimaiz Nov 22, 2024
cc4d566
fix notification
odeimaiz Nov 22, 2024
4448bff
Share with everyone
odeimaiz Nov 22, 2024
5ab8d23
rename
odeimaiz Nov 22, 2024
f6855aa
cleanup
odeimaiz Nov 22, 2024
80cf2e5
org notification
odeimaiz Nov 22, 2024
9f83b41
default thumbnail for org
odeimaiz Nov 22, 2024
034aadb
aesthetics
odeimaiz Nov 22, 2024
2b40c91
last
odeimaiz Nov 22, 2024
7409c3c
II
odeimaiz Nov 22, 2024
b1a39d0
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 25, 2024
f080a1c
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 25, 2024
ed64f76
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 25, 2024
ef10eeb
Merge branch 'master' into enh/model-organizations
odeimaiz Nov 25, 2024
3c61457
Merge branch 'master' into enh/model-organizations
matusdrobuliak66 Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading