From 46cfc97a6129472fee1747a413f4840be73c0b21 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 13:27:52 +0100 Subject: [PATCH 01/59] [skip ci] Groups store --- .../source/class/osparc/dashboard/CardBase.js | 10 +- .../class/osparc/dashboard/Dashboard.js | 4 +- .../dashboard/ResourceContainerManager.js | 3 +- .../desktop/credits/BuyCreditsStepper.js | 5 +- .../osparc/desktop/credits/Transactions.js | 5 +- .../desktop/organizations/MembersList.js | 3 +- .../desktop/paymentMethods/PaymentMethods.js | 5 +- .../desktop/preferences/pages/ClustersPage.js | 2 +- .../osparc/desktop/wallets/MembersList.js | 4 +- .../osparc/editor/AnnotationNoteCreator.js | 2 +- .../class/osparc/editor/OrganizationEditor.js | 3 +- .../osparc/filter/OrganizationsAndMembers.js | 2 +- .../source/class/osparc/info/CommentUI.js | 2 +- .../osparc/notification/NotificationUI.js | 10 +- .../class/osparc/share/Collaborators.js | 2 +- .../class/osparc/share/CollaboratorsStudy.js | 2 +- .../osparc/share/CollaboratorsWorkspace.js | 2 +- .../osparc/share/NewCollaboratorsManager.js | 2 +- .../class/osparc/share/PublishTemplate.js | 2 +- .../class/osparc/share/ShareePermissions.js | 2 +- .../source/class/osparc/store/Groups.js | 348 ++++++++++++++++++ .../client/source/class/osparc/store/Store.js | 190 +--------- .../osparc/ui/list/OrganizationListItem.js | 4 +- .../class/osparc/workbench/Annotation.js | 2 +- .../class/osparc/workbench/WorkbenchUI.js | 2 +- 25 files changed, 393 insertions(+), 225 deletions(-) create mode 100644 services/static-webserver/client/source/class/osparc/store/Groups.js diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index 1b7a8fe6e82..e6ae75a152c 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -216,12 +216,12 @@ qx.Class.define("osparc.dashboard.CardBase", { // groups -> [orgMembs, orgs, [productEveryone], [everyone]]; populateShareIcon: function(shareIcon, accessRights) { - const store = osparc.store.Store.getInstance(); + const groupsStore = osparc.store.Groups.getInstance(); Promise.all([ - store.getGroupEveryone(), - store.getProductEveryone(), - store.getReachableMembers(), - store.getGroupsOrganizations() + groupsStore.getGroupEveryone(), + groupsStore.getProductEveryone(), + groupsStore.getReachableMembers(), + groupsStore.getGroupsOrganizations() ]) .then(values => { const everyone = values[0] ? [values[0]] : []; diff --git a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js index 4a1420ade43..714123543cc 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js @@ -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.getAllGroupsAndMembers()); preResourcePromises.push(osparc.store.Services.getServicesLatest(false)); Promise.all(preResourcePromises) .then(() => { diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js index fa99ba050dd..d44f6056d30 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js @@ -474,7 +474,8 @@ 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) + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getOrganizationOrUser(orgId) .then(org => { if (org && org["collabType"] !== 2) { let icon = ""; diff --git a/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js b/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js index 37e4a351a8b..1c13aaa8124 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js +++ b/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js @@ -10,9 +10,10 @@ qx.Class.define("osparc.desktop.credits.BuyCreditsStepper", { construct(paymentMethods) { this.base(arguments); this.__paymentMethods = paymentMethods; - const store = osparc.store.Store.getInstance(); - store.getGroupsMe() + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getGroupsMe() .then(personalGroup => { + const store = osparc.store.Store.getInstance(); this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid) this.__buildLayout() }); diff --git a/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js b/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js index 93a2ee3dcae..f94b5d8765d 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js +++ b/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js @@ -31,9 +31,10 @@ qx.Class.define("osparc.desktop.credits.Transactions", { } } - const store = osparc.store.Store.getInstance(); - store.getGroupsMe() + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getGroupsMe() .then(personalGroup => { + const store = osparc.store.Store.getInstance(); this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid); this.__personalWalletId = this.__personalWallet.getWalletId(); this.__buildLayout(); diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index eb694304233..7dab73cc7d1 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -309,7 +309,8 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const productEveryone = await osparc.store.Store.getInstance().getProductEveryone(); + const groupsStore = osparc.store.Groups.getInstance(); + const productEveryone = await groupsStore.getProductEveryone(); const orgId = this.__currentOrg.getGid(); const params = { diff --git a/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js b/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js index 2e7032aa694..6699545d39c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js +++ b/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js @@ -23,9 +23,10 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", { this._setLayout(new qx.ui.layout.VBox(20)); - const store = osparc.store.Store.getInstance(); - store.getGroupsMe() + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getGroupsMe() .then(personalGroup => { + const store = osparc.store.Store.getInstance(); const personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid) this.__personalWalletId = personalWallet.getWalletId() this.__buildLayout() diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js index e68f7f7577f..b3348f42b5c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js @@ -278,7 +278,7 @@ qx.Class.define("osparc.desktop.preferences.pages.ClustersPage", { this.__organizationsAndMembers.reloadVisibleCollaborators(memberKeys); } - osparc.store.Store.getInstance().getPotentialCollaborators() + osparc.store.Groups.getInstance().getPotentialCollaborators() .then(potentialCollaborators => { clusterMembers.forEach(clusterMember => { const gid = clusterMember.gid; diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index 8aa4c4de229..e7c155a3682 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -211,7 +211,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const myGroupId = osparc.auth.Data.getInstance().getGroupId(); const membersList = []; - const potentialCollaborators = await osparc.store.Store.getInstance().getPotentialCollaborators(true); + const potentialCollaborators = await osparc.store.Groups.getInstance().getPotentialCollaborators(true); const canIWrite = wallet.getMyAccessRights()["write"]; wallet.getAccessRights().forEach(accessRights => { const gid = accessRights["gid"]; @@ -289,7 +289,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); // push 'WALLET_SHARED' notification - osparc.store.Store.getInstance().getPotentialCollaborators() + osparc.store.Groups.getInstance().getPotentialCollaborators() .then(potentialCollaborators => { gids.forEach(gid => { if (gid in potentialCollaborators && "id" in potentialCollaborators[gid]) { diff --git a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js index 1073c1b7faf..0d72035d38f 100644 --- a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js +++ b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js @@ -142,7 +142,7 @@ qx.Class.define("osparc.editor.AnnotationNoteCreator", { __setRecipientGid: function(gid) { this.setRecipientGid(gid); - osparc.store.Store.getInstance().getGroup(gid) + osparc.store.Groups.getInstance().getGroup(gid) .then(user => { this.getChildControl("selected-recipient").setValue(user.label); }); diff --git a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js index b528e760c01..d418df1e27b 100644 --- a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js +++ b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js @@ -39,7 +39,8 @@ qx.Class.define("osparc.editor.OrganizationEditor", { converter: val => val ? val : "" }); } else { - osparc.store.Store.getInstance().getGroupsOrganizations() + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getGroupsOrganizations() .then(orgs => { const existingNames = orgs.map(org => org["label"]); const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames) diff --git a/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js b/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js index bb3e9f47a01..2d45199661f 100644 --- a/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js +++ b/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js @@ -69,7 +69,7 @@ qx.Class.define("osparc.filter.OrganizationsAndMembers", { this.__collaboratorsToBeRemoved = collaboratorsToBeRemoved.map(collaboratorToBeRemoved => parseInt(collaboratorToBeRemoved)); } - osparc.store.Store.getInstance().getPotentialCollaborators() + osparc.store.Groups.getInstance().getPotentialCollaborators() .then(potentialCollaborators => { this.__visibleCollaborators = potentialCollaborators; this.__addOrgsAndMembers(); diff --git a/services/static-webserver/client/source/class/osparc/info/CommentUI.js b/services/static-webserver/client/source/class/osparc/info/CommentUI.js index 62871860da6..06b121d1287 100644 --- a/services/static-webserver/client/source/class/osparc/info/CommentUI.js +++ b/services/static-webserver/client/source/class/osparc/info/CommentUI.js @@ -117,7 +117,7 @@ qx.Class.define("osparc.info.CommentUI", { const commentContent = this.getChildControl("comment-content"); commentContent.setValue(this.__comment["contents"]); - const user = osparc.store.Store.getInstance().getUser(this.__comment["user_id"]) + const user = osparc.store.Groups.getInstance().getUser(this.__comment["user_id"]) if (user) { const userSource = osparc.utils.Avatar.getUrl(user["login"], 32); thumbnail.setSource(userSource); diff --git a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js index 67194c84418..c3350768413 100644 --- a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js +++ b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js @@ -134,7 +134,7 @@ qx.Class.define("osparc.notification.NotificationUI", { case "NEW_ORGANIZATION": icon.setSource("@FontAwesome5Solid/users/14"); if (resourceId) { - osparc.store.Store.getInstance().getGroup(resourceId) + osparc.store.Groups.getInstance().getGroup(resourceId) .then(group => descriptionLabel.setValue("You're now member of '" + group["label"] + "'")) .catch(() => this.setEnabled(false)); } @@ -157,7 +157,7 @@ qx.Class.define("osparc.notification.NotificationUI", { .catch(() => this.setEnabled(false)); } if (userFromId) { - const user = osparc.store.Store.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUser(userFromId); if (user) { descriptionLabel.setValue("was shared by " + user["label"]); } @@ -177,7 +177,7 @@ qx.Class.define("osparc.notification.NotificationUI", { } } if (userFromId) { - const user = osparc.store.Store.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUser(userFromId); if (user) { descriptionLabel.setValue("was shared by " + user["label"]); } @@ -196,7 +196,7 @@ qx.Class.define("osparc.notification.NotificationUI", { .catch(() => this.setEnabled(false)); } if (userFromId) { - const user = osparc.store.Store.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUser(userFromId); if (user) { descriptionLabel.setValue("was added by " + user["label"]); } @@ -264,7 +264,7 @@ qx.Class.define("osparc.notification.NotificationUI", { __openOrganizationDetails: function(orgId) { // make sure org is available - osparc.store.Store.getInstance().getGroup(orgId) + osparc.store.Groups.getInstance().getGroup(orgId) .then(org => { if (org) { const orgsWindow = osparc.desktop.organizations.OrganizationsWindow.openWindow(); diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 66e75202ce6..b794d185cd2 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -341,7 +341,7 @@ qx.Class.define("osparc.share.Collaborators", { }, __getCollaborators: function() { - osparc.store.Store.getInstance().getPotentialCollaborators() + osparc.store.Groups.getInstance().getPotentialCollaborators() .then(potentialCollaborators => { this.__collaborators = Object.assign(this.__collaborators, potentialCollaborators); this._reloadCollaboratorsList(); diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index 58f47059cd6..86df4bedee4 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -257,7 +257,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { __pushNotifications: function(gids) { // push 'STUDY_SHARED'/'TEMPLATE_SHARED' notification - osparc.store.Store.getInstance().getPotentialCollaborators() + osparc.store.Groups.getInstance().getPotentialCollaborators() .then(potentialCollaborators => { gids.forEach(gid => { if (gid in potentialCollaborators && "id" in potentialCollaborators[gid]) { diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js index d8bb906794c..c57d385a9c9 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js @@ -157,7 +157,7 @@ qx.Class.define("osparc.share.CollaboratorsWorkspace", { ); }; - const groupData = await osparc.store.Store.getInstance().getGroup(groupId); + const groupData = await osparc.store.Groups.getInstance().getGroup(groupId); const isOrganization = (groupData && !("id" in groupData)); if (isOrganization) { const msg = this.tr(`Demoting to ${osparc.data.Roles.WORKSPACE[1].label} will remove write access to all the members of the Organization. Are you sure?`); diff --git a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js index 65510ea9142..db2ca38c3fd 100644 --- a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js +++ b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js @@ -112,7 +112,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { // all users can share services with ProductEveryone includeProductEveryone = true; } - osparc.store.Store.getInstance().getPotentialCollaborators(false, includeProductEveryone) + osparc.store.Groups.getInstance().getPotentialCollaborators(false, includeProductEveryone) .then(potentialCollaborators => { this.__visibleCollaborators = potentialCollaborators; const anyCollaborator = Object.keys(potentialCollaborators).length; diff --git a/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js b/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js index 746d8360870..efd453b238d 100644 --- a/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js +++ b/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js @@ -61,7 +61,7 @@ qx.Class.define("osparc.share.PublishTemplate", { addCollaborators.addListener("addCollaborators", e => { const gids = e.getData(); if (gids.length) { - osparc.store.Store.getInstance().getPotentialCollaborators(false, true) + osparc.store.Groups.getInstance().getPotentialCollaborators(false, true) .then(potentialCollaborators => { const currentGids = this.getSelectedGroups(); gids.forEach(gid => { diff --git a/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js b/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js index c0c4a4c6b89..a96299190db 100644 --- a/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js +++ b/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js @@ -33,7 +33,7 @@ qx.Class.define("osparc.share.ShareePermissions", { this._add(layout); for (let i=0; i { if (group) { layout.add(new qx.ui.basic.Label(group.label), { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js new file mode 100644 index 00000000000..52077b73808 --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -0,0 +1,348 @@ +/* ************************************************************************ + + 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) + +************************************************************************ */ + +qx.Class.define("osparc.store.Groups", { + extend: qx.core.Object, + type: "singleton", + + construct: function() { + this.base(arguments); + + this.groupsCached = []; + }, + + events: { + "groupAdded": "qx.event.type.Data", + "groupRemoved": "qx.event.type.Data", + "groupMoved": "qx.event.type.Data", + }, + + statics: { + curateOrderBy: function(orderBy) { + const curatedOrderBy = osparc.utils.Utils.deepCloneObject(orderBy); + if (curatedOrderBy.field !== "name") { + // only "modified_at" and "name" supported + curatedOrderBy.field = "modified_at"; + } + return curatedOrderBy; + }, + }, + + members: { + groupsCached: null, + + fetchGroups: function() { + if (osparc.auth.Data.getInstance().isGuest()) { + return new Promise(resolve => { + resolve([]); + }); + } + + return osparc.data.Resources.getInstance().getAllPages("groups") + .then(groupsData => { + const groups = []; + groupsData.forEach(groupData => { + const group = this.__addToCache(groupData); + groups.push(group); + }); + return groups; + }); + }, + + __getGroups: function(group) { + return new Promise(resolve => { + osparc.data.Resources.get("organizations") + .then(groups => { + resolve(groups[group]); + }) + .catch(err => console.error(err)); + }); + }, + + getGroupsMe: function() { + return this.__getGroups("me"); + }, + + getGroupsOrganizations: function() { + return this.__getGroups("organizations"); + }, + + getProductEveryone: function() { + return this.__getGroups("product"); + }, + + getGroupEveryone: function() { + return this.__getGroups("all"); + }, + + __getAllGroups: function() { + return new Promise(resolve => { + const promises = []; + promises.push(this.getGroupsMe()); + promises.push(this.getReachableMembers()); + promises.push(this.getGroupsOrganizations()); + promises.push(this.getProductEveryone()); + promises.push(this.getGroupEveryone()); + Promise.all(promises) + .then(values => { + const groups = []; + const groupMe = values[0]; + groupMe["collabType"] = 2; + groups.push(groupMe); + const orgMembers = values[1]; + for (const gid of Object.keys(orgMembers)) { + orgMembers[gid]["collabType"] = 2; + groups.push(orgMembers[gid]); + } + values[2].forEach(org => { + org["collabType"] = 1; + groups.push(org); + }); + const groupProductEveryone = values[3]; + if (groupProductEveryone) { + groupProductEveryone["collabType"] = 0; + groups.push(groupProductEveryone); + } + const groupEveryone = values[4]; + if (groupEveryone) { + groupEveryone["collabType"] = 0; + groups.push(groupEveryone); + } + resolve(groups); + }); + }); + }, + + getOrganizationOrUser: function(orgId) { + return new Promise(resolve => { + this.__getAllGroups() + .then(orgs => { + const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); + if (idx > -1) { + resolve(orgs[idx]); + } + resolve(null); + }); + }); + }, + + getAllGroupsAndMembers: function() { + return new Promise(resolve => { + osparc.data.Resources.get("organizations") + .then(resp => { + this.setEveryoneGroup(resp["all"]); + this.setEveryoneProductGroup(resp["product"]); + const orgMembersPromises = []; + const orgs = resp["organizations"]; + orgs.forEach(org => { + const params = { + url: { + "gid": org["gid"] + } + }; + orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); + }); + Promise.all(orgMembersPromises) + .then(orgMemberss => { + const reachableMembers = this.getReachableMembers(); + orgMemberss.forEach(orgMembers => { + orgMembers.forEach(orgMember => { + orgMember["label"] = osparc.utils.Utils.firstsUp( + `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, + `${orgMember["last_name"] ? orgMember["last_name"] : ""}` + ); + reachableMembers[orgMember["gid"]] = orgMember; + }); + }); + resolve(); + }); + }); + }); + }, + + getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { + return new Promise((resolve, reject) => { + const promises = []; + promises.push(this.getGroupsOrganizations()); + promises.push(this.getReachableMembers()); + promises.push(this.getEveryoneProductGroup()); + Promise.all(promises) + .then(values => { + const orgs = values[0]; // array + const members = values[1]; // object + const productEveryone = values[2]; // entry + const potentialCollaborators = {}; + orgs.forEach(org => { + if (org["accessRights"]["read"]) { + // maybe because of migration script, some users have access to the product everyone group + // rely on the includeProductEveryone argument to exclude it if necessary + if (org["gid"] === productEveryone["gid"] && !includeProductEveryone) { + return; + } + org["collabType"] = 1; + potentialCollaborators[org["gid"]] = org; + } + }); + for (const gid of Object.keys(members)) { + members[gid]["collabType"] = 2; + potentialCollaborators[gid] = members[gid]; + } + if (includeMe) { + const myData = osparc.auth.Data.getInstance(); + const myGid = myData.getGroupId(); + potentialCollaborators[myGid] = { + "login": myData.getEmail(), + "first_name": myData.getFirstName(), + "last_name": myData.getLastName(), + "collabType": 2 + }; + } + if (includeProductEveryone && productEveryone) { + productEveryone["collabType"] = 0; + potentialCollaborators[productEveryone["gid"]] = productEveryone; + } + resolve(potentialCollaborators); + }) + .catch(err => { + console.error(err); + reject(err); + }); + }); + }, + + getGroup: function(gid) { + return new Promise(resolve => { + if (gid) { + this.getPotentialCollaborators() + .then(potentialCollaborators => { + let group = null; + if (gid in potentialCollaborators) { + group = potentialCollaborators[gid]; + } + resolve(group); + }) + .catch(() => resolve(null)); + } else { + resolve(null); + } + }); + }, + + getUser: function(uid) { + if (uid) { + const visibleMembers = this.getReachableMembers(); + return Object.values(visibleMembers).find(member => member.id === uid); + } + return null; + }, + + postGroup: function(name, parentGroupId = null, workspaceId = null) { + const newGroupData = { + name, + parentGroupId, + workspaceId, + }; + const params = { + data: newGroupData + }; + return osparc.data.Resources.getInstance().fetch("groups", "post", params) + .then(groupData => { + const group = this.__addToCache(groupData); + this.fireDataEvent("groupAdded", group); + return group; + }); + }, + + deleteGroup: function(groupId, workspaceId) { + const params = { + "url": { + groupId + } + }; + return osparc.data.Resources.getInstance().fetch("groups", "delete", params) + .then(() => { + const group = this.getGroup(groupId); + if (group) { + this.__deleteFromCache(groupId, workspaceId); + this.fireDataEvent("groupRemoved", group); + } + }) + .catch(console.error); + }, + + putGroup: function(groupId, updateData) { + const group = this.getGroup(groupId); + const oldParentGroupId = group.getParentGroupId(); + const params = { + "url": { + groupId + }, + data: updateData + }; + return osparc.data.Resources.getInstance().fetch("groups", "update", params) + .then(groupData => { + this.__addToCache(groupData); + if (updateData.parentGroupId !== oldParentGroupId) { + this.fireDataEvent("groupMoved", { + group, + oldParentGroupId, + }); + } + }) + .catch(console.error); + }, + + /* + getGroup: function(groupId = null) { + return this.groupsCached.find(f => f.getGroupId() === groupId); + }, + */ + + __addToCache: function(groupData) { + let group = this.groupsCached.find(f => f.getGroupId() === groupData["groupId"] && f.getWorkspaceId() === groupData["workspaceId"]); + if (group) { + const props = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group)); + // put + Object.keys(groupData).forEach(key => { + if (key === "createdAt") { + group.set("createdAt", new Date(groupData["createdAt"])); + } else if (key === "modifiedAt") { + group.set("lastModified", new Date(groupData["modifiedAt"])); + } else if (key === "trashedAt") { + group.set("trashedAt", new Date(groupData["trashedAt"])); + } else if (props.includes(key)) { + group.set(key, groupData[key]); + } + }); + } else { + // get and post + group = new osparc.data.model.Group(groupData); + this.groupsCached.unshift(group); + } + return group; + }, + + __deleteFromCache: function(groupId, workspaceId) { + const idx = this.groupsCached.findIndex(f => f.getGroupId() === groupId && f.getWorkspaceId() === workspaceId); + if (idx > -1) { + this.groupsCached.splice(idx, 1); + return true; + } + return false; + } + } +}); diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 89ccc5e51a0..c9de1c8b40a 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -457,193 +457,6 @@ qx.Class.define("osparc.store.Store", { }); }, - __getGroups: function(group) { - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(groups => { - resolve(groups[group]); - }) - .catch(err => console.error(err)); - }); - }, - - getGroupsMe: function() { - return this.__getGroups("me"); - }, - - getGroupsOrganizations: function() { - return this.__getGroups("organizations"); - }, - - getProductEveryone: function() { - return this.__getGroups("product"); - }, - - getGroupEveryone: function() { - return this.__getGroups("all"); - }, - - __getAllGroups: function() { - return new Promise(resolve => { - const promises = []; - promises.push(this.getGroupsMe()); - promises.push(this.getReachableMembers()); - promises.push(this.getGroupsOrganizations()); - promises.push(this.getProductEveryone()); - promises.push(this.getGroupEveryone()); - Promise.all(promises) - .then(values => { - const groups = []; - const groupMe = values[0]; - groupMe["collabType"] = 2; - groups.push(groupMe); - const orgMembers = values[1]; - for (const gid of Object.keys(orgMembers)) { - orgMembers[gid]["collabType"] = 2; - groups.push(orgMembers[gid]); - } - values[2].forEach(org => { - org["collabType"] = 1; - groups.push(org); - }); - const groupProductEveryone = values[3]; - if (groupProductEveryone) { - groupProductEveryone["collabType"] = 0; - groups.push(groupProductEveryone); - } - const groupEveryone = values[4]; - if (groupEveryone) { - groupEveryone["collabType"] = 0; - groups.push(groupEveryone); - } - resolve(groups); - }); - }); - }, - - getOrganizationOrUser: function(orgId) { - return new Promise(resolve => { - this.__getAllGroups() - .then(orgs => { - const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); - if (idx > -1) { - resolve(orgs[idx]); - } - resolve(null); - }); - }); - }, - - getAllGroupsAndMembers: function() { - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(resp => { - this.setEveryoneGroup(resp["all"]); - this.setEveryoneProductGroup(resp["product"]); - const orgMembersPromises = []; - const orgs = resp["organizations"]; - orgs.forEach(org => { - const params = { - url: { - "gid": org["gid"] - } - }; - orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); - }); - Promise.all(orgMembersPromises) - .then(orgMemberss => { - const reachableMembers = this.getReachableMembers(); - orgMemberss.forEach(orgMembers => { - orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - reachableMembers[orgMember["gid"]] = orgMember; - }); - }); - resolve(); - }); - }); - }); - }, - - getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { - return new Promise((resolve, reject) => { - const promises = []; - promises.push(this.getGroupsOrganizations()); - promises.push(this.getReachableMembers()); - promises.push(this.getEveryoneProductGroup()); - Promise.all(promises) - .then(values => { - const orgs = values[0]; // array - const members = values[1]; // object - const productEveryone = values[2]; // entry - const potentialCollaborators = {}; - orgs.forEach(org => { - if (org["accessRights"]["read"]) { - // maybe because of migration script, some users have access to the product everyone group - // rely on the includeProductEveryone argument to exclude it if necessary - if (org["gid"] === productEveryone["gid"] && !includeProductEveryone) { - return; - } - org["collabType"] = 1; - potentialCollaborators[org["gid"]] = org; - } - }); - for (const gid of Object.keys(members)) { - members[gid]["collabType"] = 2; - potentialCollaborators[gid] = members[gid]; - } - if (includeMe) { - const myData = osparc.auth.Data.getInstance(); - const myGid = myData.getGroupId(); - potentialCollaborators[myGid] = { - "login": myData.getEmail(), - "first_name": myData.getFirstName(), - "last_name": myData.getLastName(), - "collabType": 2 - }; - } - if (includeProductEveryone && productEveryone) { - productEveryone["collabType"] = 0; - potentialCollaborators[productEveryone["gid"]] = productEveryone; - } - resolve(potentialCollaborators); - }) - .catch(err => { - console.error(err); - reject(err); - }); - }); - }, - - getGroup: function(gid) { - return new Promise(resolve => { - if (gid) { - this.getPotentialCollaborators() - .then(potentialCollaborators => { - let group = null; - if (gid in potentialCollaborators) { - group = potentialCollaborators[gid]; - } - resolve(group); - }) - .catch(() => resolve(null)); - } else { - resolve(null); - } - }); - }, - - getUser: function(uid) { - if (uid) { - const visibleMembers = this.getReachableMembers(); - return Object.values(visibleMembers).find(member => member.id === uid); - } - return null; - }, - reloadCreditPrice: function() { const store = osparc.store.Store.getInstance(); store.setCreditPrice(null); @@ -782,7 +595,8 @@ qx.Class.define("osparc.store.Store", { resolve(oldClassifiers); return; } - this.getGroupsOrganizations() + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getGroupsOrganizations() .then(orgs => { if (orgs.length === 0) { this.setClassifiers([]); diff --git a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js index 6da8294c011..e0e2aeb1845 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js @@ -83,8 +83,8 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { thumbnail.setSource(osparc.utils.Icons.organization(osparc.ui.list.ListItemWithMenu.ICON_SIZE)); } if (this.isPropertyInitialized("key")) { - const store = osparc.store.Store.getInstance(); - store.getProductEveryone() + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.getProductEveryone() .then(groupProductEveryone => { if (groupProductEveryone && parseInt(this.getKey()) === groupProductEveryone["gid"]) { thumbnail.setSource(osparc.utils.Icons.everyone(osparc.ui.list.ListItemWithMenu.ICON_SIZE)); diff --git a/services/static-webserver/client/source/class/osparc/workbench/Annotation.js b/services/static-webserver/client/source/class/osparc/workbench/Annotation.js index 904b71125eb..46527fa70c5 100644 --- a/services/static-webserver/client/source/class/osparc/workbench/Annotation.js +++ b/services/static-webserver/client/source/class/osparc/workbench/Annotation.js @@ -96,7 +96,7 @@ qx.Class.define("osparc.workbench.Annotation", { let representation = null; switch (this.getType()) { case "note": { - const user = await osparc.store.Store.getInstance().getGroup(attrs.recipientGid); + const user = await osparc.store.Groups.getInstance().getGroup(attrs.recipientGid); representation = this.__svgLayer.drawAnnotationNote(attrs.x, attrs.y, user ? user.label : "", attrs.text); break; } diff --git a/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js b/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js index 504faf3c33f..13ffce6e055 100644 --- a/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js +++ b/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js @@ -1935,7 +1935,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", { const win = osparc.editor.AnnotationNoteCreator.popUpInWindow(noteEditor); noteEditor.addListener("addNote", () => { const gid = noteEditor.getRecipientGid(); - osparc.store.Store.getInstance().getGroup(gid) + osparc.store.Groups.getInstance().getGroup(gid) .then(user => { serializeData.attributes.recipientGid = gid; serializeData.attributes.text = noteEditor.getNote(); From 9a8f53884707d2ee920819827675af2c93e11095 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 13:45:26 +0100 Subject: [PATCH 02/59] [skip ci] more refactoring --- .../source/class/osparc/dashboard/CardBase.js | 6 +- .../source/class/osparc/data/model/Group.js | 124 ++++++++++++++++++ .../class/osparc/share/Collaborators.js | 6 +- .../osparc/share/CollaboratorsService.js | 6 +- .../class/osparc/share/CollaboratorsStudy.js | 6 +- .../source/class/osparc/store/Groups.js | 27 ++++ .../client/source/class/osparc/store/Store.js | 20 --- 7 files changed, 165 insertions(+), 30 deletions(-) create mode 100644 services/static-webserver/client/source/class/osparc/data/model/Group.js diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index e6ae75a152c..943b9636196 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -108,10 +108,10 @@ 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 groupsStore = osparc.store.Groups.getInstance(); const everyoneGroupIds = [ - store.getEveryoneProductGroup()["gid"], - store.getEveryoneGroup()["gid"] + groupsStore.getEveryoneProductGroup()["gid"], + groupsStore.getEveryoneGroup()["gid"] ]; const found = Object.keys(checks).some(gId => everyoneGroupIds.includes(parseInt(gId))); return !found; diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js new file mode 100644 index 00000000000..9277b18c84a --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -0,0 +1,124 @@ +/* ************************************************************************ + + 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({ + workspaceId: groupData.workspaceId, + groupId: groupData.groupId, + parentGroupId: groupData.parentGroupId, + name: groupData.name, + myAccessRights: groupData.myAccessRights, + owner: groupData.owner, + createdAt: new Date(groupData.createdAt), + lastModified: new Date(groupData.modifiedAt), + trashedAt: groupData.trashedAt ? new Date(groupData.trashedAt) : this.getTrashedAt(), + }); + }, + + properties: { + workspaceId: { + check: "Number", + nullable: true, + init: null, + event: "changeWorkspaceId" + }, + + groupId: { + check: "Number", + nullable: false, + init: null, + event: "changeGroupId" + }, + + parentGroupId: { + check: "Number", + nullable: true, + init: null, + event: "changeParentGroupId" + }, + + name: { + check: "String", + nullable: false, + init: null, + event: "changeName" + }, + + myAccessRights: { + check: "Object", + nullable: false, + init: null, + event: "changeMyAccessRights" + }, + + owner: { + check: "Number", + nullable: true, + init: null, + event: "changeOwner" + }, + + createdAt: { + check: "Date", + nullable: true, + init: null, + event: "changeCreatedAt" + }, + + lastModified: { + check: "Date", + nullable: true, + init: null, + event: "changeLastModified" + }, + + trashedAt: { + check: "Date", + nullable: true, + init: null, + }, + }, + + statics: { + getProperties: function() { + return Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group)); + } + }, + + members: { + serialize: function() { + const jsonObject = {}; + const propertyKeys = this.self().getProperties(); + propertyKeys.forEach(key => { + jsonObject[key] = this.get(key); + }); + return jsonObject; + } + } +}); diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index b794d185cd2..76844f4f0e2 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -402,10 +402,10 @@ qx.Class.define("osparc.share.Collaborators", { // reload list this.__collaboratorsModel.removeAll(); - const store = osparc.store.Store.getInstance(); + const groupsStore = osparc.store.Groups.getInstance(); const everyoneGIds = [ - store.getEveryoneProductGroup()["gid"], - store.getEveryoneGroup()["gid"] + groupsStore.getEveryoneProductGroup()["gid"], + groupsStore.getEveryoneGroup()["gid"] ]; const accessRights = this._serializedDataCopy["accessRights"]; const collaboratorsList = []; diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js index 5ae55925f58..f6d2ec531c8 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js @@ -66,14 +66,16 @@ qx.Class.define("osparc.share.CollaboratorsService", { }, getEveryoneProductObj: function() { - const everyoneProductGroup = osparc.store.Store.getInstance().getEveryoneProductGroup(); + const groupsStore = osparc.store.Groups.getInstance(); + const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); const everyone = osparc.utils.Utils.deepCloneObject(everyoneProductGroup); everyone["accessRights"] = this.getCollaboratorAccessRight(); return everyone; }, getEveryoneObj: function() { - const everyoneGroup = osparc.store.Store.getInstance().getEveryoneGroup(); + const groupsStore = osparc.store.Groups.getInstance(); + const everyoneGroup = groupsStore.getEveryoneGroup(); const everyone = osparc.utils.Utils.deepCloneObject(everyoneGroup); everyone["accessRights"] = this.getCollaboratorAccessRight(); return everyone; diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index 86df4bedee4..2110fe4be69 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -107,14 +107,16 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { }, getEveryoneProductObj: function(isStudy) { - const everyoneProductGroup = osparc.store.Store.getInstance().getEveryoneProductGroup(); + const groupsStore = osparc.store.Groups.getInstance(); + const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); const everyone = osparc.utils.Utils.deepCloneObject(everyoneProductGroup); everyone["accessRights"] = isStudy ? this.getCollaboratorAccessRight() : this.getViewerAccessRight(); return everyone; }, getEveryoneObj: function(isStudy) { - const everyoneGroup = osparc.store.Store.getInstance().getEveryoneGroup(); + const groupsStore = osparc.store.Groups.getInstance(); + const everyoneGroup = groupsStore.getEveryoneGroup(); const everyone = osparc.utils.Utils.deepCloneObject(everyoneGroup); everyone["accessRights"] = isStudy ? this.getCollaboratorAccessRight() : this.getViewerAccessRight(); return everyone; diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 52077b73808..c5020fdc50e 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -25,6 +25,33 @@ qx.Class.define("osparc.store.Groups", { this.groupsCached = []; }, + properties: { + organizations: { + check: "Object", + init: {} + }, + + organizationMembers: { + check: "Object", + init: {} + }, + + reachableMembers: { + check: "Object", + init: {} + }, + + everyoneProductGroup: { + check: "Object", + init: {} + }, + + everyoneGroup: { + check: "Object", + init: {} + }, + }, + events: { "groupAdded": "qx.event.type.Data", "groupRemoved": "qx.event.type.Data", diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index c9de1c8b40a..d56b6e9c232 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -174,26 +174,6 @@ qx.Class.define("osparc.store.Store", { check: "Array", init: [] }, - organizations: { - check: "Object", - init: {} - }, - organizationMembers: { - check: "Object", - init: {} - }, - reachableMembers: { - check: "Object", - init: {} - }, - everyoneProductGroup: { - check: "Object", - init: {} - }, - everyoneGroup: { - check: "Object", - init: {} - }, clusters: { check: "Array", init: [], From ea1dc43b41d31804eeb476adc3facc36d6e37ab5 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 13:59:33 +0100 Subject: [PATCH 03/59] [skip ci] do not cache --- .../client/source/class/osparc/data/Resources.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/Resources.js b/services/static-webserver/client/source/class/osparc/data/Resources.js index 007ba33eddd..8ff5eb822ba 100644 --- a/services/static-webserver/client/source/class/osparc/data/Resources.js +++ b/services/static-webserver/client/source/class/osparc/data/Resources.js @@ -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", @@ -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", From a2724ebb474d71838c14422210cd95f99c4cff92 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 17:12:32 +0100 Subject: [PATCH 04/59] [skip ci] Groups --- .../class/osparc/dashboard/Dashboard.js | 4 +- .../source/class/osparc/data/model/Group.js | 64 +++------- .../source/class/osparc/store/Groups.js | 114 ++++++++++-------- 3 files changed, 87 insertions(+), 95 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js index 714123543cc..639407882ca 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js @@ -178,8 +178,10 @@ 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.getAllGroupsAndMembers()); + preResourcePromises.push(groupsStore.fetchAll()); preResourcePromises.push(osparc.store.Services.getServicesLatest(false)); Promise.all(preResourcePromises) .then(() => { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index 9277b18c84a..3e78a215de4 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -29,26 +29,15 @@ qx.Class.define("osparc.data.model.Group", { this.base(arguments); this.set({ - workspaceId: groupData.workspaceId, groupId: groupData.groupId, - parentGroupId: groupData.parentGroupId, - name: groupData.name, - myAccessRights: groupData.myAccessRights, - owner: groupData.owner, - createdAt: new Date(groupData.createdAt), - lastModified: new Date(groupData.modifiedAt), - trashedAt: groupData.trashedAt ? new Date(groupData.trashedAt) : this.getTrashedAt(), + label: groupData.label, + description: groupData.description, + accessRights: groupData.accessRights, + thumbnail: groupData.thumbnail, }); }, properties: { - workspaceId: { - check: "Number", - nullable: true, - init: null, - event: "changeWorkspaceId" - }, - groupId: { check: "Number", nullable: false, @@ -56,51 +45,36 @@ qx.Class.define("osparc.data.model.Group", { event: "changeGroupId" }, - parentGroupId: { - check: "Number", - nullable: true, - init: null, - event: "changeParentGroupId" - }, - - name: { + label: { check: "String", nullable: false, init: null, - event: "changeName" - }, - - myAccessRights: { - check: "Object", - nullable: false, - init: null, - event: "changeMyAccessRights" + event: "changeLabel" }, - owner: { - check: "Number", + description: { + check: "String", nullable: true, init: null, - event: "changeOwner" + event: "changeDescription" }, - createdAt: { - check: "Date", - nullable: true, + accessRights: { + check: "Object", + nullable: false, init: null, - event: "changeCreatedAt" + event: "changeAccessRights" }, - lastModified: { - check: "Date", + thumbnail: { + check: "String", nullable: true, - init: null, - event: "changeLastModified" + init: "" }, - trashedAt: { - check: "Date", - nullable: true, + groupType: { + check: ["me", "organization", "productEveryone", "everyone"], + nullable: false, init: null, }, }, diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index c5020fdc50e..5317fad8583 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -23,30 +23,36 @@ qx.Class.define("osparc.store.Groups", { this.base(arguments); this.groupsCached = []; + this.usersCached = []; }, properties: { - organizations: { - check: "Object", + everyoneGroup: { + check: "osparc.data.model.Group", init: {} }, - organizationMembers: { - check: "Object", + everyoneProductGroup: { + check: "osparc.data.model.Group", init: {} }, - reachableMembers: { - check: "Object", + organizations: { + check: "Array", + init: [] + }, + + meGroup: { + check: "osparc.data.model.Group", init: {} }, - everyoneProductGroup: { + organizationMembers: { check: "Object", init: {} }, - everyoneGroup: { + reachableMembers: { check: "Object", init: {} }, @@ -71,6 +77,7 @@ qx.Class.define("osparc.store.Groups", { members: { groupsCached: null, + usersCached: null, fetchGroups: function() { if (osparc.auth.Data.getInstance().isGuest()) { @@ -78,15 +85,58 @@ qx.Class.define("osparc.store.Groups", { resolve([]); }); } + const useCache = false; + return osparc.data.Resources.get("organizations", {}, useCache) + .then(resp => { + const everyoneGroup = new osparc.data.model.Group(resp["all"]).set({ + groupType: "everyone" + }); + const productEveryoneGroup = new osparc.data.model.Group(resp["product"]).set({ + groupType: "productEveryone" + }); + const meGroup = new osparc.data.model.Group(resp["me"]).set({ + groupType: "productEveryone" + }); + const orgs = []; + resp["organizations"].forEach(organization => { + const org = new osparc.data.model.Group(organization).set({ + groupType: "organization" + }); + orgs.push(org); + }); + this.setEveryoneGroup(everyoneGroup); + this.setEveryoneProductGroup(productEveryoneGroup); + this.setMeGroup(meGroup); + this.setOrganizations(orgs); + return orgs; + }); + }, - return osparc.data.Resources.getInstance().getAllPages("groups") - .then(groupsData => { - const groups = []; - groupsData.forEach(groupData => { - const group = this.__addToCache(groupData); - groups.push(group); + fetchAll: function() { + this.fetchGroups() + .then(orgs => { + const orgMembersPromises = []; + orgs.forEach(org => { + const params = { + url: { + gid: org.getGroupId() + } + }; + orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); }); - return groups; + Promise.all(orgMembersPromises) + .then(orgMemberss => { + const reachableMembers = this.getReachableMembers(); + orgMemberss.forEach(orgMembers => { + orgMembers.forEach(orgMember => { + orgMember["label"] = osparc.utils.Utils.firstsUp( + `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, + `${orgMember["last_name"] ? orgMember["last_name"] : ""}` + ); + reachableMembers[orgMember["gid"]] = orgMember; + }); + }); + }); }); }, @@ -167,40 +217,6 @@ qx.Class.define("osparc.store.Groups", { }); }, - getAllGroupsAndMembers: function() { - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(resp => { - this.setEveryoneGroup(resp["all"]); - this.setEveryoneProductGroup(resp["product"]); - const orgMembersPromises = []; - const orgs = resp["organizations"]; - orgs.forEach(org => { - const params = { - url: { - "gid": org["gid"] - } - }; - orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); - }); - Promise.all(orgMembersPromises) - .then(orgMemberss => { - const reachableMembers = this.getReachableMembers(); - orgMemberss.forEach(orgMembers => { - orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - reachableMembers[orgMember["gid"]] = orgMember; - }); - }); - resolve(); - }); - }); - }); - }, - getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { return new Promise((resolve, reject) => { const promises = []; From fb1e14942cd4915866f5fc2614ba25a3f6d11039 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 17:17:44 +0100 Subject: [PATCH 05/59] Store back --- .../client/source/class/osparc/store/Store.js | 206 ++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index d56b6e9c232..c96b8ee416a 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -174,6 +174,26 @@ qx.Class.define("osparc.store.Store", { check: "Array", init: [] }, + organizations: { + check: "Object", + init: {} + }, + organizationMembers: { + check: "Object", + init: {} + }, + reachableMembers: { + check: "Object", + init: {} + }, + everyoneProductGroup: { + check: "Object", + init: {} + }, + everyoneGroup: { + check: "Object", + init: {} + }, clusters: { check: "Array", init: [], @@ -436,6 +456,192 @@ qx.Class.define("osparc.store.Store", { }); }); }, + __getGroups: function(group) { + return new Promise(resolve => { + osparc.data.Resources.get("organizations") + .then(groups => { + resolve(groups[group]); + }) + .catch(err => console.error(err)); + }); + }, + + getGroupsMe: function() { + return this.__getGroups("me"); + }, + + getGroupsOrganizations: function() { + return this.__getGroups("organizations"); + }, + + getProductEveryone: function() { + return this.__getGroups("product"); + }, + + getGroupEveryone: function() { + return this.__getGroups("all"); + }, + + __getAllGroups: function() { + return new Promise(resolve => { + const promises = []; + promises.push(this.getGroupsMe()); + promises.push(this.getReachableMembers()); + promises.push(this.getGroupsOrganizations()); + promises.push(this.getProductEveryone()); + promises.push(this.getGroupEveryone()); + Promise.all(promises) + .then(values => { + const groups = []; + const groupMe = values[0]; + groupMe["collabType"] = 2; + groups.push(groupMe); + const orgMembers = values[1]; + for (const gid of Object.keys(orgMembers)) { + orgMembers[gid]["collabType"] = 2; + groups.push(orgMembers[gid]); + } + values[2].forEach(org => { + org["collabType"] = 1; + groups.push(org); + }); + const groupProductEveryone = values[3]; + if (groupProductEveryone) { + groupProductEveryone["collabType"] = 0; + groups.push(groupProductEveryone); + } + const groupEveryone = values[4]; + if (groupEveryone) { + groupEveryone["collabType"] = 0; + groups.push(groupEveryone); + } + resolve(groups); + }); + }); + }, + + getOrganizationOrUser: function(orgId) { + return new Promise(resolve => { + this.__getAllGroups() + .then(orgs => { + const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); + if (idx > -1) { + resolve(orgs[idx]); + } + resolve(null); + }); + }); + }, + + getAllGroupsAndMembers: function() { + return new Promise(resolve => { + osparc.data.Resources.get("organizations") + .then(resp => { + this.setEveryoneGroup(resp["all"]); + this.setEveryoneProductGroup(resp["product"]); + const orgMembersPromises = []; + const orgs = resp["organizations"]; + orgs.forEach(org => { + const params = { + url: { + "gid": org["gid"] + } + }; + orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); + }); + Promise.all(orgMembersPromises) + .then(orgMemberss => { + const reachableMembers = this.getReachableMembers(); + orgMemberss.forEach(orgMembers => { + orgMembers.forEach(orgMember => { + orgMember["label"] = osparc.utils.Utils.firstsUp( + `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, + `${orgMember["last_name"] ? orgMember["last_name"] : ""}` + ); + reachableMembers[orgMember["gid"]] = orgMember; + }); + }); + resolve(); + }); + }); + }); + }, + + getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { + return new Promise((resolve, reject) => { + const promises = []; + promises.push(this.getGroupsOrganizations()); + promises.push(this.getReachableMembers()); + promises.push(this.getEveryoneProductGroup()); + Promise.all(promises) + .then(values => { + const orgs = values[0]; // array + const members = values[1]; // object + const productEveryone = values[2]; // entry + const potentialCollaborators = {}; + orgs.forEach(org => { + if (org["accessRights"]["read"]) { + // maybe because of migration script, some users have access to the product everyone group + // rely on the includeProductEveryone argument to exclude it if necessary + if (org["gid"] === productEveryone["gid"] && !includeProductEveryone) { + return; + } + org["collabType"] = 1; + potentialCollaborators[org["gid"]] = org; + } + }); + for (const gid of Object.keys(members)) { + members[gid]["collabType"] = 2; + potentialCollaborators[gid] = members[gid]; + } + if (includeMe) { + const myData = osparc.auth.Data.getInstance(); + const myGid = myData.getGroupId(); + potentialCollaborators[myGid] = { + "login": myData.getEmail(), + "first_name": myData.getFirstName(), + "last_name": myData.getLastName(), + "collabType": 2 + }; + } + if (includeProductEveryone && productEveryone) { + productEveryone["collabType"] = 0; + potentialCollaborators[productEveryone["gid"]] = productEveryone; + } + resolve(potentialCollaborators); + }) + .catch(err => { + console.error(err); + reject(err); + }); + }); + }, + + getGroup: function(gid) { + return new Promise(resolve => { + if (gid) { + this.getPotentialCollaborators() + .then(potentialCollaborators => { + let group = null; + if (gid in potentialCollaborators) { + group = potentialCollaborators[gid]; + } + resolve(group); + }) + .catch(() => resolve(null)); + } else { + resolve(null); + } + }); + }, + + getUser: function(uid) { + if (uid) { + const visibleMembers = this.getReachableMembers(); + return Object.values(visibleMembers).find(member => member.id === uid); + } + return null; + }, reloadCreditPrice: function() { const store = osparc.store.Store.getInstance(); From 3304d6ea9ec525ed94266024178a35f901e63266 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 17:19:16 +0100 Subject: [PATCH 06/59] minor --- .../client/source/class/osparc/data/model/Group.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index 3e78a215de4..4a6043b1fde 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -29,7 +29,7 @@ qx.Class.define("osparc.data.model.Group", { this.base(arguments); this.set({ - groupId: groupData.groupId, + groupId: groupData.gid, label: groupData.label, description: groupData.description, accessRights: groupData.accessRights, From 05ed765a230f4d30f06517abe18a114feeeae3f8 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Tue, 19 Nov 2024 17:38:25 +0100 Subject: [PATCH 07/59] object --- .../source/class/osparc/store/Groups.js | 58 ++++++++----------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 5317fad8583..59d6b95c759 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -38,8 +38,8 @@ qx.Class.define("osparc.store.Groups", { }, organizations: { - check: "Array", - init: [] + check: "Object", + init: {} }, meGroup: { @@ -61,7 +61,6 @@ qx.Class.define("osparc.store.Groups", { events: { "groupAdded": "qx.event.type.Data", "groupRemoved": "qx.event.type.Data", - "groupMoved": "qx.event.type.Data", }, statics: { @@ -88,21 +87,13 @@ qx.Class.define("osparc.store.Groups", { const useCache = false; return osparc.data.Resources.get("organizations", {}, useCache) .then(resp => { - const everyoneGroup = new osparc.data.model.Group(resp["all"]).set({ - groupType: "everyone" - }); - const productEveryoneGroup = new osparc.data.model.Group(resp["product"]).set({ - groupType: "productEveryone" - }); - const meGroup = new osparc.data.model.Group(resp["me"]).set({ - groupType: "productEveryone" - }); - const orgs = []; + const everyoneGroup = this.__addToGroupsCache(resp["all"], "everyone"); + const productEveryoneGroup = this.__addToGroupsCache(resp["product"], "productEveryone"); + const meGroup = this.__addToGroupsCache(resp["me"], "me"); + const orgs = {}; resp["organizations"].forEach(organization => { - const org = new osparc.data.model.Group(organization).set({ - groupType: "organization" - }); - orgs.push(org); + const org = this.__addToGroupsCache(organization, "organization"); + orgs[org.getGroupId()] = org; }); this.setEveryoneGroup(everyoneGroup); this.setEveryoneProductGroup(productEveryoneGroup); @@ -116,17 +107,17 @@ qx.Class.define("osparc.store.Groups", { this.fetchGroups() .then(orgs => { const orgMembersPromises = []; - orgs.forEach(org => { + Object.keys(orgs).forEach(gid => { const params = { url: { - gid: org.getGroupId() + gid } }; orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); }); Promise.all(orgMembersPromises) .then(orgMemberss => { - const reachableMembers = this.getReachableMembers(); + const reachableMembers = {}; orgMemberss.forEach(orgMembers => { orgMembers.forEach(orgMember => { orgMember["label"] = osparc.utils.Utils.firstsUp( @@ -136,6 +127,7 @@ qx.Class.define("osparc.store.Groups", { reachableMembers[orgMember["gid"]] = orgMember; }); }); + this.setReachableMembers(reachableMembers); }); }); }, @@ -304,7 +296,7 @@ qx.Class.define("osparc.store.Groups", { }; return osparc.data.Resources.getInstance().fetch("groups", "post", params) .then(groupData => { - const group = this.__addToCache(groupData); + const group = this.__addToGroupsCache(groupData); this.fireDataEvent("groupAdded", group); return group; }); @@ -320,7 +312,7 @@ qx.Class.define("osparc.store.Groups", { .then(() => { const group = this.getGroup(groupId); if (group) { - this.__deleteFromCache(groupId, workspaceId); + this.__deleteFromGroupsCache(groupId, workspaceId); this.fireDataEvent("groupRemoved", group); } }) @@ -338,7 +330,7 @@ qx.Class.define("osparc.store.Groups", { }; return osparc.data.Resources.getInstance().fetch("groups", "update", params) .then(groupData => { - this.__addToCache(groupData); + this.__addToGroupsCache(groupData); if (updateData.parentGroupId !== oldParentGroupId) { this.fireDataEvent("groupMoved", { group, @@ -355,32 +347,28 @@ qx.Class.define("osparc.store.Groups", { }, */ - __addToCache: function(groupData) { - let group = this.groupsCached.find(f => f.getGroupId() === groupData["groupId"] && f.getWorkspaceId() === groupData["workspaceId"]); + __addToGroupsCache: function(groupData, groupType) { + let group = this.groupsCached.find(f => f.getGroupId() === groupData["gid"]); if (group) { const props = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group)); // put Object.keys(groupData).forEach(key => { - if (key === "createdAt") { - group.set("createdAt", new Date(groupData["createdAt"])); - } else if (key === "modifiedAt") { - group.set("lastModified", new Date(groupData["modifiedAt"])); - } else if (key === "trashedAt") { - group.set("trashedAt", new Date(groupData["trashedAt"])); - } else if (props.includes(key)) { + if (props.includes(key)) { group.set(key, groupData[key]); } }); } else { // get and post - group = new osparc.data.model.Group(groupData); + group = new osparc.data.model.Group(groupData).set({ + groupType + }); this.groupsCached.unshift(group); } return group; }, - __deleteFromCache: function(groupId, workspaceId) { - const idx = this.groupsCached.findIndex(f => f.getGroupId() === groupId && f.getWorkspaceId() === workspaceId); + __deleteFromGroupsCache: function(groupId, workspaceId) { + const idx = this.groupsCached.findIndex(f => f.getGroupId() === groupId); if (idx > -1) { this.groupsCached.splice(idx, 1); return true; From ce71a5de746cc9411c8fbd2bbed95c872d1d5c98 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 10:45:29 +0100 Subject: [PATCH 08/59] getMyGroupId --- .../source/class/osparc/dashboard/CardBase.js | 8 +- .../desktop/credits/BuyCreditsStepper.js | 10 +-- .../osparc/desktop/credits/Transactions.js | 12 ++- .../desktop/paymentMethods/PaymentMethods.js | 12 ++- .../desktop/preferences/pages/ClustersPage.js | 83 +++++++++---------- .../source/class/osparc/store/Groups.js | 12 +-- .../client/source/class/osparc/store/Store.js | 5 +- 7 files changed, 65 insertions(+), 77 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index 943b9636196..47072a2c232 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -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"]; @@ -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 groupsStore = osparc.store.Groups.getInstance(); const everyoneGroupIds = [ - groupsStore.getEveryoneProductGroup()["gid"], - groupsStore.getEveryoneGroup()["gid"] + groupsStore.getEveryoneProductGroup().getGroupId(), + groupsStore.getEveryoneGroup().getGroupId(), ]; const found = Object.keys(checks).some(gId => everyoneGroupIds.includes(parseInt(gId))); return !found; diff --git a/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js b/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js index 1c13aaa8124..79a29649647 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js +++ b/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js @@ -11,12 +11,10 @@ qx.Class.define("osparc.desktop.credits.BuyCreditsStepper", { this.base(arguments); this.__paymentMethods = paymentMethods; const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getGroupsMe() - .then(personalGroup => { - const store = osparc.store.Store.getInstance(); - this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid) - this.__buildLayout() - }); + const myGid = groupsStore.getMyGroupId() + const store = osparc.store.Store.getInstance(); + this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === myGid) + this.__buildLayout() }, events: { "completed": "qx.event.type.Event" diff --git a/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js b/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js index f94b5d8765d..610ab82754e 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js +++ b/services/static-webserver/client/source/class/osparc/desktop/credits/Transactions.js @@ -32,13 +32,11 @@ qx.Class.define("osparc.desktop.credits.Transactions", { } const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getGroupsMe() - .then(personalGroup => { - const store = osparc.store.Store.getInstance(); - this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid); - this.__personalWalletId = this.__personalWallet.getWalletId(); - this.__buildLayout(); - }); + const myGid = groupsStore.getMyGroupId() + const store = osparc.store.Store.getInstance(); + this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === myGid); + this.__personalWalletId = this.__personalWallet.getWalletId(); + this.__buildLayout(); }, members: { diff --git a/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js b/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js index 6699545d39c..fa90ceddbe2 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js +++ b/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js @@ -24,13 +24,11 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", { this._setLayout(new qx.ui.layout.VBox(20)); const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getGroupsMe() - .then(personalGroup => { - const store = osparc.store.Store.getInstance(); - const personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid) - this.__personalWalletId = personalWallet.getWalletId() - this.__buildLayout() - }); + const myGid = groupsStore.getMyGroupId(); + const store = osparc.store.Store.getInstance(); + const personalWallet = store.getWallets().find(wallet => wallet.getOwner() === myGid) + this.__personalWalletId = personalWallet.getWalletId() + this.__buildLayout() }, properties: { diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js index b3348f42b5c..19ae3f44691 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js @@ -265,49 +265,46 @@ qx.Class.define("osparc.desktop.preferences.pages.ClustersPage", { const clusterMembers = clusterModel.getMembersList(); - osparc.store.Store.getInstance().getGroupsMe() - .then(myGroup => { - const myGid = myGroup["gid"]; - const membersModel = clusterModel.getMembers(); - const getter = "get"+String(myGid); - const canWrite = membersModel[getter] ? membersModel[getter]().getWrite() : false; - if (canWrite) { - this.__selectOrgMemberLayout.show(); - const memberKeys = []; - clusterMembers.forEach(clusterMember => memberKeys.push(clusterMember["gid"])); - this.__organizationsAndMembers.reloadVisibleCollaborators(memberKeys); - } - - osparc.store.Groups.getInstance().getPotentialCollaborators() - .then(potentialCollaborators => { - clusterMembers.forEach(clusterMember => { - const gid = clusterMember.gid; - if (gid in potentialCollaborators) { - const collaborator = potentialCollaborators[gid]; - const collabObj = {}; - if (collaborator["collabType"] === 1) { - collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24"; - collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]); - collabObj["login"] = collaborator["description"]; - } else if (collaborator["collabType"] === 2) { - collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); - collaborator["name"] = osparc.utils.Utils.firstsUp( - `${"first_name" in collaborator && collaborator["first_name"] != null ? - collaborator["first_name"] : collaborator["login"]}`, - `${"last_name" in collaborator && collaborator["last_name"] ? - collaborator["last_name"] : ""}` - ); - collabObj["login"] = collaborator["login"]; - } - if (Object.keys(collabObj).length) { - collabObj["id"] = collaborator["gid"]; - collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember)); - collabObj["showOptions"] = canWrite; - membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj)); - } - } - }); - }); + const myGid = groupsStore.getMyGroupId(); + const membersModel = clusterModel.getMembers(); + const getter = "get"+String(myGid); + const canWrite = membersModel[getter] ? membersModel[getter]().getWrite() : false; + if (canWrite) { + this.__selectOrgMemberLayout.show(); + const memberKeys = []; + clusterMembers.forEach(clusterMember => memberKeys.push(clusterMember["gid"])); + this.__organizationsAndMembers.reloadVisibleCollaborators(memberKeys); + } + + osparc.store.Groups.getInstance().getPotentialCollaborators() + .then(potentialCollaborators => { + clusterMembers.forEach(clusterMember => { + const gid = clusterMember.gid; + if (gid in potentialCollaborators) { + const collaborator = potentialCollaborators[gid]; + const collabObj = {}; + if (collaborator["collabType"] === 1) { + collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24"; + collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]); + collabObj["login"] = collaborator["description"]; + } else if (collaborator["collabType"] === 2) { + collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); + collaborator["name"] = osparc.utils.Utils.firstsUp( + `${"first_name" in collaborator && collaborator["first_name"] != null ? + collaborator["first_name"] : collaborator["login"]}`, + `${"last_name" in collaborator && collaborator["last_name"] ? + collaborator["last_name"] : ""}` + ); + collabObj["login"] = collaborator["login"]; + } + if (Object.keys(collabObj).length) { + collabObj["id"] = collaborator["gid"]; + collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember)); + collabObj["showOptions"] = canWrite; + membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj)); + } + } + }); }); }, diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 59d6b95c759..a6a0d442d8d 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -42,7 +42,7 @@ qx.Class.define("osparc.store.Groups", { init: {} }, - meGroup: { + groupMe: { check: "osparc.data.model.Group", init: {} }, @@ -89,7 +89,7 @@ qx.Class.define("osparc.store.Groups", { .then(resp => { const everyoneGroup = this.__addToGroupsCache(resp["all"], "everyone"); const productEveryoneGroup = this.__addToGroupsCache(resp["product"], "productEveryone"); - const meGroup = this.__addToGroupsCache(resp["me"], "me"); + const groupMe = this.__addToGroupsCache(resp["me"], "me"); const orgs = {}; resp["organizations"].forEach(organization => { const org = this.__addToGroupsCache(organization, "organization"); @@ -97,7 +97,7 @@ qx.Class.define("osparc.store.Groups", { }); this.setEveryoneGroup(everyoneGroup); this.setEveryoneProductGroup(productEveryoneGroup); - this.setMeGroup(meGroup); + this.setGroupMe(groupMe); this.setOrganizations(orgs); return orgs; }); @@ -142,8 +142,8 @@ qx.Class.define("osparc.store.Groups", { }); }, - getGroupsMe: function() { - return this.__getGroups("me"); + getMyGroupId: function() { + return this.getGroupMe().getGroupId(); }, getGroupsOrganizations: function() { @@ -161,7 +161,7 @@ qx.Class.define("osparc.store.Groups", { __getAllGroups: function() { return new Promise(resolve => { const promises = []; - promises.push(this.getGroupsMe()); + promises.push(this.getGroupMe()); promises.push(this.getReachableMembers()); promises.push(this.getGroupsOrganizations()); promises.push(this.getProductEveryone()); diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index c96b8ee416a..121385ece81 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -456,6 +456,7 @@ qx.Class.define("osparc.store.Store", { }); }); }, + __getGroups: function(group) { return new Promise(resolve => { osparc.data.Resources.get("organizations") @@ -466,10 +467,6 @@ qx.Class.define("osparc.store.Store", { }); }, - getGroupsMe: function() { - return this.__getGroups("me"); - }, - getGroupsOrganizations: function() { return this.__getGroups("organizations"); }, From c1f149c00b86abf93e69b4b38e8c23ae8406545b Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 10:57:03 +0100 Subject: [PATCH 09/59] [skip ci] refactoring --- .../client/source/class/osparc/auth/Data.js | 9 --------- .../source/class/osparc/auth/Manager.js | 5 ----- .../source/class/osparc/dashboard/CardBase.js | 2 +- .../source/class/osparc/data/model/Study.js | 6 ++++-- .../class/osparc/desktop/StudyEditor.js | 15 ++++++-------- .../desktop/preferences/pages/ClustersPage.js | 1 + .../class/osparc/editor/OrganizationEditor.js | 2 +- .../source/class/osparc/service/Utils.js | 5 +++-- .../source/class/osparc/store/Groups.js | 20 +++++++++---------- 9 files changed, 26 insertions(+), 39 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/auth/Data.js b/services/static-webserver/client/source/class/osparc/auth/Data.js index 276de264a4c..b12a322351d 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Data.js +++ b/services/static-webserver/client/source/class/osparc/auth/Data.js @@ -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 */ diff --git a/services/static-webserver/client/source/class/osparc/auth/Manager.js b/services/static-webserver/client/source/class/osparc/auth/Manager.js index d45f7ce15a5..8f325a0644a 100644 --- a/services/static-webserver/client/source/class/osparc/auth/Manager.js +++ b/services/static-webserver/client/source/class/osparc/auth/Manager.js @@ -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); diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index 47072a2c232..a256c4f582d 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -221,7 +221,7 @@ qx.Class.define("osparc.dashboard.CardBase", { groupsStore.getGroupEveryone(), groupsStore.getProductEveryone(), groupsStore.getReachableMembers(), - groupsStore.getGroupsOrganizations() + groupsStore.getOrganizations() ]) .then(values => { const everyone = values[0] ? [values[0]] : []; diff --git a/services/static-webserver/client/source/class/osparc/data/model/Study.js b/services/static-webserver/client/source/class/osparc/data/model/Study.js index dc96044e99f..e8929c93adf 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Study.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Study.js @@ -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)); @@ -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)); diff --git a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js index 393fc842796..14474eabd7d 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js +++ b/services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js @@ -225,15 +225,12 @@ qx.Class.define("osparc.desktop.StudyEditor", { } } - osparc.data.Resources.get("organizations") - .then(() => { - if (osparc.data.model.Study.canIWrite(study.getAccessRights())) { - this.__startAutoSaveTimer(); - } else { - const msg = this.self().READ_ONLY_TEXT; - osparc.FlashMessenger.getInstance().logAs(msg, "WARNING"); - } - }); + if (osparc.data.model.Study.canIWrite(study.getAccessRights())) { + this.__startAutoSaveTimer(); + } else { + const msg = this.self().READ_ONLY_TEXT; + osparc.FlashMessenger.getInstance().logAs(msg, "WARNING"); + } const pageContext = study.getUi().getMode(); switch (pageContext) { diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js index 19ae3f44691..57eae904e61 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js @@ -265,6 +265,7 @@ qx.Class.define("osparc.desktop.preferences.pages.ClustersPage", { const clusterMembers = clusterModel.getMembersList(); + const groupsStore = osparc.store.Groups.getInstance(); const myGid = groupsStore.getMyGroupId(); const membersModel = clusterModel.getMembers(); const getter = "get"+String(myGid); diff --git a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js index d418df1e27b..f5ea131d7ba 100644 --- a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js +++ b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js @@ -40,7 +40,7 @@ qx.Class.define("osparc.editor.OrganizationEditor", { }); } else { const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getGroupsOrganizations() + groupsStore.getOrganizations() .then(orgs => { const existingNames = orgs.map(org => org["label"]); const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames) diff --git a/services/static-webserver/client/source/class/osparc/service/Utils.js b/services/static-webserver/client/source/class/osparc/service/Utils.js index b47f3a5b5fa..d8243573f49 100644 --- a/services/static-webserver/client/source/class/osparc/service/Utils.js +++ b/services/static-webserver/client/source/class/osparc/service/Utils.js @@ -212,8 +212,9 @@ qx.Class.define("osparc.service.Utils", { }, canIWrite: function(serviceAccessRights) { - const orgIDs = [...osparc.auth.Data.getInstance().getOrgIds()]; - orgIDs.push(osparc.auth.Data.getInstance().getGroupId()); + const groupsStore = osparc.store.Groups.getInstance(); + const orgIDs = groupsStore.getOrganizationIds(); + orgIDs.push(groupsStore.getMyGroupId()); return osparc.share.CollaboratorsService.canGroupsWrite(serviceAccessRights, orgIDs); }, diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index a6a0d442d8d..c4ca9fbb7c6 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -132,6 +132,14 @@ qx.Class.define("osparc.store.Groups", { }); }, + getMyGroupId: function() { + return this.getGroupMe().getGroupId(); + }, + + getOrganizationIds: function() { + return Object.keys(this.getOrganizations()).map(org => org.getGroupsId()); + }, + __getGroups: function(group) { return new Promise(resolve => { osparc.data.Resources.get("organizations") @@ -142,14 +150,6 @@ qx.Class.define("osparc.store.Groups", { }); }, - getMyGroupId: function() { - return this.getGroupMe().getGroupId(); - }, - - getGroupsOrganizations: function() { - return this.__getGroups("organizations"); - }, - getProductEveryone: function() { return this.__getGroups("product"); }, @@ -163,7 +163,7 @@ qx.Class.define("osparc.store.Groups", { const promises = []; promises.push(this.getGroupMe()); promises.push(this.getReachableMembers()); - promises.push(this.getGroupsOrganizations()); + promises.push(this.getOrganizations()); promises.push(this.getProductEveryone()); promises.push(this.getGroupEveryone()); Promise.all(promises) @@ -212,7 +212,7 @@ qx.Class.define("osparc.store.Groups", { getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { return new Promise((resolve, reject) => { const promises = []; - promises.push(this.getGroupsOrganizations()); + promises.push(this.getOrganizations()); promises.push(this.getReachableMembers()); promises.push(this.getEveryoneProductGroup()); Promise.all(promises) From f47ea7ce4bcee4d48e9c0ae2df67f696608227cb Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 11:12:18 +0100 Subject: [PATCH 10/59] [skip ci] refactor --- .../source/class/osparc/dashboard/CardBase.js | 26 +++------- .../class/osparc/editor/OrganizationEditor.js | 14 ++--- .../source/class/osparc/store/Groups.js | 11 ++-- .../client/source/class/osparc/store/Store.js | 52 +++++++++---------- 4 files changed, 41 insertions(+), 62 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index a256c4f582d..bad4b42af49 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -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 => "gid" in group ? group["gid"] === gid : group.getGroupId() === gid); if (grp) { sharedGrp.push(grp); } @@ -217,24 +217,12 @@ qx.Class.define("osparc.dashboard.CardBase", { // groups -> [orgMembs, orgs, [productEveryone], [everyone]]; populateShareIcon: function(shareIcon, accessRights) { const groupsStore = osparc.store.Groups.getInstance(); - Promise.all([ - groupsStore.getGroupEveryone(), - groupsStore.getProductEveryone(), - groupsStore.getReachableMembers(), - groupsStore.getOrganizations() - ]) - .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 orgMembs = Object.values(groupsStore.getReachableMembers()); + 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); }, }, diff --git a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js index f5ea131d7ba..d8ab60f20cb 100644 --- a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js +++ b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js @@ -40,16 +40,10 @@ qx.Class.define("osparc.editor.OrganizationEditor", { }); } else { const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getOrganizations() - .then(orgs => { - const existingNames = orgs.map(org => org["label"]); - const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames) - title.setValue(defaultName); - }) - .catch(err => { - console.error(err); - title.setValue("New Organization"); - }); + const orgs = groupsStore.getOrganizations() + const existingNames = orgs.map(org => org["label"]); + const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames) + title.setValue(defaultName); } this.addListener("appear", () => { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index c4ca9fbb7c6..a57db324d7f 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -137,7 +137,7 @@ qx.Class.define("osparc.store.Groups", { }, getOrganizationIds: function() { - return Object.keys(this.getOrganizations()).map(org => org.getGroupsId()); + return Object.keys(this.getOrganizations()); }, __getGroups: function(group) { @@ -212,16 +212,15 @@ qx.Class.define("osparc.store.Groups", { getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { return new Promise((resolve, reject) => { const promises = []; - promises.push(this.getOrganizations()); promises.push(this.getReachableMembers()); promises.push(this.getEveryoneProductGroup()); Promise.all(promises) .then(values => { - const orgs = values[0]; // array - const members = values[1]; // object - const productEveryone = values[2]; // entry + const orgs = this.getOrganizations(); // object + const members = values[0]; // object + const productEveryone = values[1]; // entry const potentialCollaborators = {}; - orgs.forEach(org => { + Object.values(orgs).forEach(org => { if (org["accessRights"]["read"]) { // maybe because of migration script, some users have access to the product everyone group // rely on the includeProductEveryone argument to exclude it if necessary diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 121385ece81..b5fbd17ff30 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -779,38 +779,36 @@ qx.Class.define("osparc.store.Store", { return; } const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getGroupsOrganizations() - .then(orgs => { - if (orgs.length === 0) { + const orgs = Object.values(groupsStore.getOrganizations()); + if (orgs.length === 0) { + this.setClassifiers([]); + resolve([]); + return; + } + const classifierPromises = []; + orgs.forEach(org => { + classifierPromises.push(this.__getOrgClassifiers(org["gid"], !reload)); + }); + Promise.all(classifierPromises) + .then(orgsClassifiersMD => { + if (orgsClassifiersMD.length === 0) { this.setClassifiers([]); resolve([]); return; } - const classifierPromises = []; - orgs.forEach(org => { - classifierPromises.push(this.__getOrgClassifiers(org["gid"], !reload)); - }); - Promise.all(classifierPromises) - .then(orgsClassifiersMD => { - if (orgsClassifiersMD.length === 0) { - this.setClassifiers([]); - resolve([]); - return; - } - const allClassifiers = []; - orgsClassifiersMD.forEach(orgClassifiersMD => { - if ("classifiers" in orgClassifiersMD) { - const classifiers = orgClassifiersMD["classifiers"]; - Object.keys(classifiers).forEach(key => { - const classifier = classifiers[key]; - classifier.key = key; - allClassifiers.push(classifier); - }); - } + const allClassifiers = []; + orgsClassifiersMD.forEach(orgClassifiersMD => { + if ("classifiers" in orgClassifiersMD) { + const classifiers = orgClassifiersMD["classifiers"]; + Object.keys(classifiers).forEach(key => { + const classifier = classifiers[key]; + classifier.key = key; + allClassifiers.push(classifier); }); - this.setClassifiers(allClassifiers); - resolve(allClassifiers); - }); + } + }); + this.setClassifiers(allClassifiers); + resolve(allClassifiers); }); }); } From ab1ba4ffe35f2bf03f366ea41ba15a44fc3b803c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 11:19:53 +0100 Subject: [PATCH 11/59] [skip ci] more --- .../osparc/filter/CollaboratorToggleButton.js | 2 +- .../source/class/osparc/store/Groups.js | 76 ++++++++----------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js index 31d3aef3512..64b6904d283 100644 --- a/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js +++ b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js @@ -37,7 +37,7 @@ qx.Class.define("osparc.filter.CollaboratorToggleButton", { label = collaborator["login"]; } else { // org - label = collaborator["label"]; + label = collaborator.getLabel(); } this.setLabel(label); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index a57db324d7f..feff380bf68 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -211,50 +211,40 @@ qx.Class.define("osparc.store.Groups", { getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { return new Promise((resolve, reject) => { - const promises = []; - promises.push(this.getReachableMembers()); - promises.push(this.getEveryoneProductGroup()); - Promise.all(promises) - .then(values => { - const orgs = this.getOrganizations(); // object - const members = values[0]; // object - const productEveryone = values[1]; // entry - const potentialCollaborators = {}; - Object.values(orgs).forEach(org => { - if (org["accessRights"]["read"]) { - // maybe because of migration script, some users have access to the product everyone group - // rely on the includeProductEveryone argument to exclude it if necessary - if (org["gid"] === productEveryone["gid"] && !includeProductEveryone) { - return; - } - org["collabType"] = 1; - potentialCollaborators[org["gid"]] = org; - } - }); - for (const gid of Object.keys(members)) { - members[gid]["collabType"] = 2; - potentialCollaborators[gid] = members[gid]; - } - if (includeMe) { - const myData = osparc.auth.Data.getInstance(); - const myGid = myData.getGroupId(); - potentialCollaborators[myGid] = { - "login": myData.getEmail(), - "first_name": myData.getFirstName(), - "last_name": myData.getLastName(), - "collabType": 2 - }; - } - if (includeProductEveryone && productEveryone) { - productEveryone["collabType"] = 0; - potentialCollaborators[productEveryone["gid"]] = productEveryone; + const potentialCollaborators = {}; + const orgs = this.getOrganizations(); + const productEveryone = this.getEveryoneProductGroup(); + Object.values(orgs).forEach(org => { + if (org.getAccessRights()["read"]) { + // maybe because of migration script, some users have access to the product everyone group + // rely on the includeProductEveryone argument to exclude it if necessary + if (org.getGroupId() === productEveryone.getGroupId() && !includeProductEveryone) { + return; } - resolve(potentialCollaborators); - }) - .catch(err => { - console.error(err); - reject(err); - }); + org["collabType"] = 1; + potentialCollaborators[org.getGroupId()] = org; + } + }); + const members = this.getReachableMembers(); + for (const gid of Object.keys(members)) { + members[gid]["collabType"] = 2; + potentialCollaborators[gid] = members[gid]; + } + if (includeMe) { + const myData = osparc.auth.Data.getInstance(); + const myGid = myData.getGroupId(); + potentialCollaborators[myGid] = { + "login": myData.getEmail(), + "first_name": myData.getFirstName(), + "last_name": myData.getLastName(), + "collabType": 2 + }; + } + if (includeProductEveryone && productEveryone) { + productEveryone["collabType"] = 0; + potentialCollaborators[productEveryone.getGroupId()] = productEveryone; + } + resolve(potentialCollaborators); }); }, From 07a164d1755da6ec5db7bc183d6a0af63772a186 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 14:13:53 +0100 Subject: [PATCH 12/59] simplify --- .../desktop/organizations/MembersList.js | 3 +-- .../client/source/class/osparc/store/Groups.js | 18 ------------------ .../osparc/ui/list/OrganizationListItem.js | 10 ++++------ 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index 7dab73cc7d1..ed067f847b0 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -310,8 +310,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { } const groupsStore = osparc.store.Groups.getInstance(); - const productEveryone = await groupsStore.getProductEveryone(); - + const productEveryone = groupsStore.getEveryoneProductGroup(); const orgId = this.__currentOrg.getGid(); const params = { url: { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index feff380bf68..cfb6e8a60d6 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -140,24 +140,6 @@ qx.Class.define("osparc.store.Groups", { return Object.keys(this.getOrganizations()); }, - __getGroups: function(group) { - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(groups => { - resolve(groups[group]); - }) - .catch(err => console.error(err)); - }); - }, - - getProductEveryone: function() { - return this.__getGroups("product"); - }, - - getGroupEveryone: function() { - return this.__getGroups("all"); - }, - __getAllGroups: function() { return new Promise(resolve => { const promises = []; diff --git a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js index e0e2aeb1845..d3b178b7402 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js @@ -84,12 +84,10 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { } if (this.isPropertyInitialized("key")) { const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.getProductEveryone() - .then(groupProductEveryone => { - if (groupProductEveryone && parseInt(this.getKey()) === groupProductEveryone["gid"]) { - thumbnail.setSource(osparc.utils.Icons.everyone(osparc.ui.list.ListItemWithMenu.ICON_SIZE)); - } - }); + const groupProductEveryone = groupsStore.getEveryoneProductGroup(); + if (groupProductEveryone && parseInt(this.getKey()) === groupProductEveryone.getGroupId()) { + thumbnail.setSource(osparc.utils.Icons.everyone(osparc.ui.list.ListItemWithMenu.ICON_SIZE)); + } } } } From 96de2f223b1333f73b90a9bf63d0a18ac57fffe7 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 14:22:43 +0100 Subject: [PATCH 13/59] less promises --- .../class/osparc/dashboard/Dashboard.js | 2 - .../dashboard/ResourceContainerManager.js | 40 +++++----- .../source/class/osparc/store/Groups.js | 73 ++++++++----------- .../client/source/class/osparc/store/Store.js | 10 +++ 4 files changed, 57 insertions(+), 68 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js index 639407882ca..a64c57b8841 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js @@ -178,8 +178,6 @@ 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.fetchAll()); preResourcePromises.push(osparc.store.Services.getServicesLatest(false)); diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js index d44f6056d30..3cf8e85f33d 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js @@ -475,29 +475,25 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", { if (groupContainer === null) { groupContainer = this.__createGroupContainer(orgId, "loading-label"); const groupsStore = osparc.store.Groups.getInstance(); - groupsStore.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 org = groupsStore.getOrganizationOrUser(orgId); + if (org && org["collabType"] !== 2) { + let icon = ""; + if (org.getThumbnail()) { + icon = org.getThumbnail(); + } else if (org["collabType"] === 0) { + icon = "@FontAwesome5Solid/globe/24"; + } else if (org["collabType"] === 1) { + icon = "@FontAwesome5Solid/users/24"; + } + groupContainer.set({ + headerIcon: icon, + headerLabel: org.getLabel(), }); + } else { + groupContainer.exclude(); + } + this._add(groupContainer); + this.__moveNoGroupToLast(); } const card = this.__createCard(resourceData); this.__addCardToContainer(card, groupContainer); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index cfb6e8a60d6..ac1911a411b 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -141,54 +141,39 @@ qx.Class.define("osparc.store.Groups", { }, __getAllGroups: function() { - return new Promise(resolve => { - const promises = []; - promises.push(this.getGroupMe()); - promises.push(this.getReachableMembers()); - promises.push(this.getOrganizations()); - promises.push(this.getProductEveryone()); - promises.push(this.getGroupEveryone()); - Promise.all(promises) - .then(values => { - const groups = []; - const groupMe = values[0]; - groupMe["collabType"] = 2; - groups.push(groupMe); - const orgMembers = values[1]; - for (const gid of Object.keys(orgMembers)) { - orgMembers[gid]["collabType"] = 2; - groups.push(orgMembers[gid]); - } - values[2].forEach(org => { - org["collabType"] = 1; - groups.push(org); - }); - const groupProductEveryone = values[3]; - if (groupProductEveryone) { - groupProductEveryone["collabType"] = 0; - groups.push(groupProductEveryone); - } - const groupEveryone = values[4]; - if (groupEveryone) { - groupEveryone["collabType"] = 0; - groups.push(groupEveryone); - } - resolve(groups); - }); + const groups = []; + const groupMe = this.getGroupMe(); + groupMe["collabType"] = 2; + groups.push(groupMe); + const orgMembers = this.getReachableMembers(); + for (const gid of Object.keys(orgMembers)) { + orgMembers[gid]["collabType"] = 2; + groups.push(orgMembers[gid]); + } + Object.values(this.getOrganizations()).forEach(org => { + org["collabType"] = 1; + groups.push(org); }); + const groupProductEveryone = this.getEveryoneProductGroup(); + if (groupProductEveryone) { + groupProductEveryone["collabType"] = 0; + groups.push(groupProductEveryone); + } + const groupEveryone = this.getEveryoneGroup(); + if (groupEveryone) { + groupEveryone["collabType"] = 0; + groups.push(groupEveryone); + } + return groups; }, getOrganizationOrUser: function(orgId) { - return new Promise(resolve => { - this.__getAllGroups() - .then(orgs => { - const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); - if (idx > -1) { - resolve(orgs[idx]); - } - resolve(null); - }); - }); + const orgs = this.__getAllGroups(); + const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); + if (idx > -1) { + return orgs[idx]; + } + return null; }, getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index b5fbd17ff30..2813acef270 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -458,6 +458,7 @@ qx.Class.define("osparc.store.Store", { }, __getGroups: function(group) { + throw Error(); return new Promise(resolve => { osparc.data.Resources.get("organizations") .then(groups => { @@ -468,18 +469,22 @@ qx.Class.define("osparc.store.Store", { }, getGroupsOrganizations: function() { + throw Error(); return this.__getGroups("organizations"); }, getProductEveryone: function() { + throw Error(); return this.__getGroups("product"); }, getGroupEveryone: function() { + throw Error(); return this.__getGroups("all"); }, __getAllGroups: function() { + throw Error(); return new Promise(resolve => { const promises = []; promises.push(this.getGroupsMe()); @@ -518,6 +523,7 @@ qx.Class.define("osparc.store.Store", { }, getOrganizationOrUser: function(orgId) { + throw Error(); return new Promise(resolve => { this.__getAllGroups() .then(orgs => { @@ -531,6 +537,7 @@ qx.Class.define("osparc.store.Store", { }, getAllGroupsAndMembers: function() { + throw Error(); return new Promise(resolve => { osparc.data.Resources.get("organizations") .then(resp => { @@ -565,6 +572,7 @@ qx.Class.define("osparc.store.Store", { }, getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { + throw Error(); return new Promise((resolve, reject) => { const promises = []; promises.push(this.getGroupsOrganizations()); @@ -615,6 +623,7 @@ qx.Class.define("osparc.store.Store", { }, getGroup: function(gid) { + throw Error(); return new Promise(resolve => { if (gid) { this.getPotentialCollaborators() @@ -633,6 +642,7 @@ qx.Class.define("osparc.store.Store", { }, getUser: function(uid) { + throw Error(); if (uid) { const visibleMembers = this.getReachableMembers(); return Object.values(visibleMembers).find(member => member.id === uid); From 128f2e3f396257b5cfc78241910bca919c4fb09f Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 14:58:40 +0100 Subject: [PATCH 14/59] [skip ci] refactoring --- .../dashboard/ResourceContainerManager.js | 10 +- .../source/class/osparc/store/Groups.js | 29 +-- .../client/source/class/osparc/store/Store.js | 193 ------------------ 3 files changed, 21 insertions(+), 211 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js index 3cf8e85f33d..69b86e4cd66 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js @@ -476,18 +476,20 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", { groupContainer = this.__createGroupContainer(orgId, "loading-label"); const groupsStore = osparc.store.Groups.getInstance(); const org = groupsStore.getOrganizationOrUser(orgId); - if (org && org["collabType"] !== 2) { + if (org) { let icon = ""; - if (org.getThumbnail()) { - icon = org.getThumbnail(); + if ("thumbnail" in org || ("getThumbnail" in org && org.getThumbnail())) { + icon = "thumbnail" in org ? org["thumbnail"] : org.getThumbnail(); } else if (org["collabType"] === 0) { icon = "@FontAwesome5Solid/globe/24"; } else if (org["collabType"] === 1) { icon = "@FontAwesome5Solid/users/24"; + } else if (org["collabType"] === 2) { + icon = "@FontAwesome5Solid/user/24"; } groupContainer.set({ headerIcon: icon, - headerLabel: org.getLabel(), + headerLabel: "label" in org ? org["label"] : org.getLabel(), }); } else { groupContainer.exclude(); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index ac1911a411b..af8fac7f110 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -142,34 +142,35 @@ qx.Class.define("osparc.store.Groups", { __getAllGroups: function() { const groups = []; + const groupMe = this.getGroupMe(); groupMe["collabType"] = 2; groups.push(groupMe); - const orgMembers = this.getReachableMembers(); - for (const gid of Object.keys(orgMembers)) { - orgMembers[gid]["collabType"] = 2; - groups.push(orgMembers[gid]); - } + + Object.values(this.getReachableMembers()).forEach(member => { + member["collabType"] = 2; + groups.push(member); + }); + Object.values(this.getOrganizations()).forEach(org => { org["collabType"] = 1; groups.push(org); }); + const groupProductEveryone = this.getEveryoneProductGroup(); - if (groupProductEveryone) { - groupProductEveryone["collabType"] = 0; - groups.push(groupProductEveryone); - } + groupProductEveryone["collabType"] = 0; + groups.push(groupProductEveryone); + const groupEveryone = this.getEveryoneGroup(); - if (groupEveryone) { - groupEveryone["collabType"] = 0; - groups.push(groupEveryone); - } + groupEveryone["collabType"] = 0; + groups.push(groupEveryone); + return groups; }, getOrganizationOrUser: function(orgId) { const orgs = this.__getAllGroups(); - const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); + const idx = orgs.findIndex(org => "gid" in org ? org["gid"] === parseInt(orgId) : org.getGroupId() === parseInt(orgId)); if (idx > -1) { return orgs[idx]; } diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 2813acef270..17d79a9cfcd 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -457,199 +457,6 @@ qx.Class.define("osparc.store.Store", { }); }, - __getGroups: function(group) { - throw Error(); - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(groups => { - resolve(groups[group]); - }) - .catch(err => console.error(err)); - }); - }, - - getGroupsOrganizations: function() { - throw Error(); - return this.__getGroups("organizations"); - }, - - getProductEveryone: function() { - throw Error(); - return this.__getGroups("product"); - }, - - getGroupEveryone: function() { - throw Error(); - return this.__getGroups("all"); - }, - - __getAllGroups: function() { - throw Error(); - return new Promise(resolve => { - const promises = []; - promises.push(this.getGroupsMe()); - promises.push(this.getReachableMembers()); - promises.push(this.getGroupsOrganizations()); - promises.push(this.getProductEveryone()); - promises.push(this.getGroupEveryone()); - Promise.all(promises) - .then(values => { - const groups = []; - const groupMe = values[0]; - groupMe["collabType"] = 2; - groups.push(groupMe); - const orgMembers = values[1]; - for (const gid of Object.keys(orgMembers)) { - orgMembers[gid]["collabType"] = 2; - groups.push(orgMembers[gid]); - } - values[2].forEach(org => { - org["collabType"] = 1; - groups.push(org); - }); - const groupProductEveryone = values[3]; - if (groupProductEveryone) { - groupProductEveryone["collabType"] = 0; - groups.push(groupProductEveryone); - } - const groupEveryone = values[4]; - if (groupEveryone) { - groupEveryone["collabType"] = 0; - groups.push(groupEveryone); - } - resolve(groups); - }); - }); - }, - - getOrganizationOrUser: function(orgId) { - throw Error(); - return new Promise(resolve => { - this.__getAllGroups() - .then(orgs => { - const idx = orgs.findIndex(org => org.gid === parseInt(orgId)); - if (idx > -1) { - resolve(orgs[idx]); - } - resolve(null); - }); - }); - }, - - getAllGroupsAndMembers: function() { - throw Error(); - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(resp => { - this.setEveryoneGroup(resp["all"]); - this.setEveryoneProductGroup(resp["product"]); - const orgMembersPromises = []; - const orgs = resp["organizations"]; - orgs.forEach(org => { - const params = { - url: { - "gid": org["gid"] - } - }; - orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); - }); - Promise.all(orgMembersPromises) - .then(orgMemberss => { - const reachableMembers = this.getReachableMembers(); - orgMemberss.forEach(orgMembers => { - orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - reachableMembers[orgMember["gid"]] = orgMember; - }); - }); - resolve(); - }); - }); - }); - }, - - getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { - throw Error(); - return new Promise((resolve, reject) => { - const promises = []; - promises.push(this.getGroupsOrganizations()); - promises.push(this.getReachableMembers()); - promises.push(this.getEveryoneProductGroup()); - Promise.all(promises) - .then(values => { - const orgs = values[0]; // array - const members = values[1]; // object - const productEveryone = values[2]; // entry - const potentialCollaborators = {}; - orgs.forEach(org => { - if (org["accessRights"]["read"]) { - // maybe because of migration script, some users have access to the product everyone group - // rely on the includeProductEveryone argument to exclude it if necessary - if (org["gid"] === productEveryone["gid"] && !includeProductEveryone) { - return; - } - org["collabType"] = 1; - potentialCollaborators[org["gid"]] = org; - } - }); - for (const gid of Object.keys(members)) { - members[gid]["collabType"] = 2; - potentialCollaborators[gid] = members[gid]; - } - if (includeMe) { - const myData = osparc.auth.Data.getInstance(); - const myGid = myData.getGroupId(); - potentialCollaborators[myGid] = { - "login": myData.getEmail(), - "first_name": myData.getFirstName(), - "last_name": myData.getLastName(), - "collabType": 2 - }; - } - if (includeProductEveryone && productEveryone) { - productEveryone["collabType"] = 0; - potentialCollaborators[productEveryone["gid"]] = productEveryone; - } - resolve(potentialCollaborators); - }) - .catch(err => { - console.error(err); - reject(err); - }); - }); - }, - - getGroup: function(gid) { - throw Error(); - return new Promise(resolve => { - if (gid) { - this.getPotentialCollaborators() - .then(potentialCollaborators => { - let group = null; - if (gid in potentialCollaborators) { - group = potentialCollaborators[gid]; - } - resolve(group); - }) - .catch(() => resolve(null)); - } else { - resolve(null); - } - }); - }, - - getUser: function(uid) { - throw Error(); - if (uid) { - const visibleMembers = this.getReachableMembers(); - return Object.values(visibleMembers).find(member => member.id === uid); - } - return null; - }, - reloadCreditPrice: function() { const store = osparc.store.Store.getInstance(); store.setCreditPrice(null); From ffb56aeb86707bcd8ddacb68d5788bf4ba95da7c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 15:52:14 +0100 Subject: [PATCH 15/59] [skip ci] modeling --- .../desktop/organizations/MembersList.js | 20 +++---- .../organizations/OrganizationDetails.js | 4 +- .../organizations/OrganizationsList.js | 58 ++++++++----------- .../desktop/organizations/ServicesList.js | 6 +- .../desktop/organizations/TemplatesList.js | 6 +- .../source/class/osparc/store/Groups.js | 33 +++++++++++ .../osparc/ui/list/OrganizationListItem.js | 6 +- 7 files changed, 77 insertions(+), 56 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index ed067f847b0..409b216804d 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -227,7 +227,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": orgModel.getGid() + "gid": orgModel.getGroupId() } }; osparc.data.Resources.get("organizationMembers", params) @@ -311,7 +311,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const groupsStore = osparc.store.Groups.getInstance(); const productEveryone = groupsStore.getEveryoneProductGroup(); - const orgId = this.__currentOrg.getGid(); + const orgId = this.__currentOrg.getGroupId(); const params = { url: { "gid": orgId @@ -371,7 +371,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": orgMember["id"] }, data: { @@ -397,7 +397,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": "id" in orgMember ? orgMember["id"] : orgMember["key"] }, data: { @@ -426,7 +426,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": orgMember["id"] }, data: { @@ -452,7 +452,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": orgMember["id"] }, data: { @@ -478,7 +478,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": orgMember["id"] }, data: { @@ -504,7 +504,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": orgMember["id"] }, data: { @@ -526,7 +526,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { __doDeleteMember: function(orgMember) { const params = { url: { - "gid": this.__currentOrg.getGid(), + "gid": this.__currentOrg.getGroupId(), "uid": orgMember["id"] } }; @@ -557,7 +557,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": this.__currentOrg.getGid() + "gid": this.__currentOrg.getGroupId() } }; osparc.data.Resources.get("organizationMembers", params) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index c9d0501c0cd..22e68680463 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -104,13 +104,13 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { }, __updateOrganization: function(win, button, orgEditor) { - const orgKey = orgEditor.getGid(); + const groupId = orgEditor.getGroupId(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); const params = { url: { - "gid": orgKey + "gid": groupId }, data: { "label": name, diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js index c2f8656ed83..1c6f1b2c076 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js @@ -65,14 +65,11 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { statics: { sortOrganizations: function(a, b) { - const sorted = osparc.share.Collaborators.sortByAccessRights(a["accessRights"], b["accessRights"]); + const sorted = osparc.share.Collaborators.sortByAccessRights(a.getAccessRights(), b.getAccessRights()); if (sorted !== 0) { return sorted; } - if (("label" in a) && ("label" in b)) { - return a["label"].localeCompare(b["label"]); - } - return 0; + return a.getLabel().localeCompare(b.getLabel()); } }, @@ -83,7 +80,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { getOrgModel: function(orgId) { let org = null; this.__orgsModel.forEach(orgModel => { - if (orgModel.getGid() === parseInt(orgId)) { + if (orgModel.getGroupId() === parseInt(orgId)) { org = orgModel; } }); @@ -133,8 +130,8 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { orgsCtrl.setDelegate({ createItem: () => new osparc.ui.list.OrganizationListItem(), bindItem: (ctrl, item, id) => { - ctrl.bindProperty("gid", "key", null, item, id); - ctrl.bindProperty("gid", "model", null, item, id); + ctrl.bindProperty("groupId", "key", null, item, id); + ctrl.bindProperty("groupId", "model", null, item, id); ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("label", "title", null, item, id); ctrl.bindProperty("description", "subtitle", null, item, id); @@ -180,28 +177,19 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { const orgsModel = this.__orgsModel; orgsModel.removeAll(); - const useCache = false; - osparc.data.Resources.get("organizations", {}, useCache) - .then(async respOrgs => { - const orgs = respOrgs["organizations"]; - const promises = await orgs.map(async org => { - const params = { - url: { - gid: org["gid"] - } - }; - const respOrgMembers = await osparc.data.Resources.get("organizationMembers", params); - org["nMembers"] = Object.keys(respOrgMembers).length + this.tr(" members"); - return org; - }); - const orgsList = await Promise.all(promises); - orgsList.sort(this.self().sortOrganizations); - orgsList.forEach(org => orgsModel.append(qx.data.marshal.Json.createModel(org))); - this.setOrganizationsLoaded(true); - if (orgId) { - this.fireDataEvent("organizationSelected", orgId); - } - }); + const groupsStore = osparc.store.Groups.getInstance(); + const orgs = Object.values(groupsStore.getOrganizations()); + const orgsList = orgs.map(org => { + const respOrgMembers = groupsStore.getOrganizationMembers(org["gid"]); + org["nMembers"] = Object.keys(respOrgMembers).length + this.tr(" members"); + return org; + }); + orgsList.sort(this.self().sortOrganizations); + orgsList.forEach(org => orgsModel.append(org)); + this.setOrganizationsLoaded(true); + if (orgId) { + this.fireDataEvent("organizationSelected", orgId); + } }, __openEditOrganization: function(orgId) { @@ -222,7 +210,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { __deleteOrganization: function(orgKey) { let org = null; this.__orgsModel.forEach(orgModel => { - if (orgModel.getGid() === parseInt(orgKey)) { + if (orgModel.getGroupId() === parseInt(orgKey)) { org = orgModel; } }); @@ -267,13 +255,13 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { }, __createOrganization: function(win, button, orgEditor) { - const orgKey = orgEditor.getGid(); + const groupId = orgEditor.getGroupId(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); const params = { url: { - "gid": orgKey + "gid": groupId }, data: { "label": name, @@ -305,13 +293,13 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { }, __updateOrganization: function(win, button, orgEditor) { - const orgKey = orgEditor.getGid(); + const groupId = orgEditor.getGroupId(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); const params = { url: { - "gid": orgKey + "gid": groupId }, data: { "label": name, diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/ServicesList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/ServicesList.js index bf4f6a95c60..fec8d6d85e6 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/ServicesList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/ServicesList.js @@ -114,19 +114,19 @@ qx.Class.define("osparc.desktop.organizations.ServicesList", { return; } - const gid = orgModel.getGid(); + const groupId = orgModel.getGroupId(); osparc.store.Services.getServicesLatest() .then(servicesLatest => { const orgServices = []; Object.keys(servicesLatest).forEach(key => { const serviceLatest = servicesLatest[key]; - if (gid in serviceLatest["accessRights"]) { + if (groupId in serviceLatest["accessRights"]) { orgServices.push(serviceLatest); } }); orgServices.forEach(orgService => { const orgServiceCopy = osparc.utils.Utils.deepCloneObject(orgService); - orgServiceCopy["orgId"] = gid; + orgServiceCopy["orgId"] = groupId; if (orgServiceCopy["thumbnail"] === null) { orgServiceCopy["thumbnail"] = osparc.dashboard.CardBase.PRODUCT_ICON; } diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/TemplatesList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/TemplatesList.js index 70dee6617fc..bc0431ac22d 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/TemplatesList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/TemplatesList.js @@ -113,13 +113,13 @@ qx.Class.define("osparc.desktop.organizations.TemplatesList", { return; } - const gid = orgModel.getGid(); + const groupId = orgModel.getGroupId(); osparc.data.Resources.getInstance().getAllPages("templates") .then(templates => { - const orgTemplates = templates.filter(template => gid in template["accessRights"]); + const orgTemplates = templates.filter(template => groupId in template["accessRights"]); orgTemplates.forEach(orgTemplate => { const orgTemplateCopy = osparc.utils.Utils.deepCloneObject(orgTemplate); - orgTemplateCopy["orgId"] = gid; + orgTemplateCopy["orgId"] = groupId; templatesModel.append(qx.data.marshal.Json.createModel(orgTemplateCopy)); }); }); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index af8fac7f110..4306d3ea7aa 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -103,9 +103,41 @@ qx.Class.define("osparc.store.Groups", { }); }, + __fetchGroupMembers: function(groupId) { + const params = { + url: { + gid: groupId + } + }; + return osparc.data.Resources.get("organizationMembers", params) + .then(orgMembers => { + this.getOrganizationMembers()[groupId] = {}; + orgMembers.forEach(orgMember => { + orgMember["label"] = osparc.utils.Utils.firstsUp( + `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, + `${orgMember["last_name"] ? orgMember["last_name"] : ""}` + ); + this.getOrganizationMembers()[groupId][orgMember["gid"]] = orgMember; + }); + }); + }, + fetchAll: function() { this.fetchGroups() .then(orgs => { + this.resetOrganizationMembers(); + this.resetReachableMembers(); + const memberPromises = Object.keys(orgs).map(orgId => this.__fetchGroupMembers(orgId)); + Promise.all(memberPromises) + .then(() => { + Object.values(this.getOrganizationMembers()).forEach(orgMembers => { + Object.values(orgMembers).forEach(reachableMember => { + this.getReachableMembers()[reachableMember["gid"]] = reachableMember; + }); + }); + }); + + /* const orgMembersPromises = []; Object.keys(orgs).forEach(gid => { const params = { @@ -129,6 +161,7 @@ qx.Class.define("osparc.store.Groups", { }); this.setReachableMembers(reachableMembers); }); + */ }); }, diff --git a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js index d3b178b7402..c13c197e07d 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js @@ -43,7 +43,7 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { _getOptionsMenu: function() { let menu = null; const accessRights = this.getAccessRights(); - if (accessRights.getWrite()) { + if (accessRights["write"]) { const optionsMenu = this.getChildControl("options"); optionsMenu.show(); @@ -51,7 +51,7 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { position: "bottom-right" }); - if (accessRights.getWrite()) { + if (accessRights["write"]) { const editOrgButton = new qx.ui.menu.Button(this.tr("Edit details...")); editOrgButton.addListener("execute", () => { this.fireDataEvent("openEditOrganization", this.getKey()); @@ -59,7 +59,7 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { menu.add(editOrgButton); } - if (accessRights.getDelete()) { + if (accessRights["delete"]) { const deleteOrgButton = new qx.ui.menu.Button(this.tr("Delete")); this.bind("showDeleteButton", deleteOrgButton, "visibility", { converter: show => show ? "visible" : "excluded" From 5f9a860a04268a638446fb56ac224e9bf70f07d3 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 16:36:19 +0100 Subject: [PATCH 16/59] groupMembers --- .../class/osparc/dashboard/Dashboard.js | 2 +- .../source/class/osparc/data/model/Group.js | 18 ++-- .../organizations/OrganizationDetails.js | 8 +- .../organizations/OrganizationsList.js | 13 ++- .../organizations/OrganizationsWindow.js | 10 +-- .../osparc/editor/AnnotationNoteCreator.js | 2 +- .../osparc/notification/NotificationUI.js | 4 +- .../class/osparc/share/CollaboratorsStudy.js | 2 +- .../osparc/share/CollaboratorsWorkspace.js | 2 +- .../class/osparc/share/ShareePermissions.js | 2 +- .../source/class/osparc/store/Groups.js | 89 ++++++------------- .../class/osparc/workbench/Annotation.js | 2 +- .../class/osparc/workbench/WorkbenchUI.js | 2 +- 13 files changed, 65 insertions(+), 91 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js index a64c57b8841..77595025bc4 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js @@ -179,7 +179,7 @@ qx.Class.define("osparc.dashboard.Dashboard", { const preResourcePromises = []; const groupsStore = osparc.store.Groups.getInstance(); - preResourcePromises.push(groupsStore.fetchAll()); + preResourcePromises.push(groupsStore.fetchGroupsAndMembers()); preResourcePromises.push(osparc.store.Services.getServicesLatest(false)); Promise.all(preResourcePromises) .then(() => { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index 4a6043b1fde..bf7be7b1e0f 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -42,34 +42,42 @@ qx.Class.define("osparc.data.model.Group", { check: "Number", nullable: false, init: null, - event: "changeGroupId" + event: "changeGroupId", }, label: { check: "String", nullable: false, init: null, - event: "changeLabel" + event: "changeLabel", }, description: { check: "String", nullable: true, init: null, - event: "changeDescription" + event: "changeDescription", }, accessRights: { check: "Object", nullable: false, init: null, - event: "changeAccessRights" + event: "changeAccessRights", }, thumbnail: { check: "String", nullable: true, - init: "" + init: "", + event: "changeThumbnail", + }, + + groupMembers: { + check: "Object", + nullable: true, + init: null, + event: "changeGroupMembers", }, groupType: { diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index 22e68680463..242013cbcc2 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -48,12 +48,14 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { this.__orgModel = orgModel; const organizationListItem = this.__addOrganizationListItem(); - orgModel.bind("gid", organizationListItem, "key"); - orgModel.bind("gid", organizationListItem, "model"); + orgModel.bind("groupId", organizationListItem, "key"); + orgModel.bind("groupId", organizationListItem, "model"); orgModel.bind("thumbnail", organizationListItem, "thumbnail"); orgModel.bind("label", organizationListItem, "title"); orgModel.bind("description", organizationListItem, "subtitle"); - orgModel.bind("nMembers", organizationListItem, "role"); + orgModel.bindProperty("groupMembers", "role", { + converter: groupMembers => groupMembers ? Object.keys(groupMembers).length + this.tr(" members") : "-" + }); orgModel.bind("accessRights", organizationListItem, "accessRights"); // set orgModel to the tab views diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js index 1c6f1b2c076..7986fd4b5b7 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js @@ -135,7 +135,9 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("label", "title", null, item, id); ctrl.bindProperty("description", "subtitle", null, item, id); - ctrl.bindProperty("nMembers", "role", null, item, id); + ctrl.bindProperty("groupMembers", "role", { + converter: groupMembers => groupMembers ? Object.keys(groupMembers).length + this.tr(" members") : "-" + }, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); }, configureItem: item => { @@ -179,13 +181,8 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { const groupsStore = osparc.store.Groups.getInstance(); const orgs = Object.values(groupsStore.getOrganizations()); - const orgsList = orgs.map(org => { - const respOrgMembers = groupsStore.getOrganizationMembers(org["gid"]); - org["nMembers"] = Object.keys(respOrgMembers).length + this.tr(" members"); - return org; - }); - orgsList.sort(this.self().sortOrganizations); - orgsList.forEach(org => orgsModel.append(org)); + orgs.sort(this.self().sortOrganizations); + orgs.forEach(org => orgsModel.append(org)); this.setOrganizationsLoaded(true); if (orgId) { this.fireDataEvent("organizationSelected", orgId); diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsWindow.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsWindow.js index 57f7fe09c58..9564ab2a04f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsWindow.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsWindow.js @@ -49,7 +49,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsWindow", { members: { __stack: null, - __orgsList: null, + __orgsPage: null, __orgDetails: null, __buildLayout: function() { @@ -58,7 +58,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsWindow", { flex: 1 }); - const orgsPage = this.__orgsList = new osparc.desktop.organizations.OrganizationsList(); + const orgsPage = this.__orgsPage = new osparc.desktop.organizations.OrganizationsList(); const orgDetails = this.__orgDetails = new osparc.desktop.organizations.OrganizationDetails(); stack.add(orgsPage); stack.add(orgDetails); @@ -77,15 +77,15 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsWindow", { openOrganizationDetails: function(organizationId) { const openOrgDetails = orgId => { - const orgModel = this.__orgsList.getOrgModel(orgId); + const orgModel = this.__orgsPage.getOrgModel(orgId); this.__orgDetails.setCurrentOrg(orgModel); this.getChildControl("title").setValue(this.tr("Organization details")); this.__stack.setSelection([this.__orgDetails]); }; - if (this.__orgsList.isOrganizationsLoaded()) { + if (this.__orgsPage.isOrganizationsLoaded()) { openOrgDetails(organizationId); } else { - this.__orgsList.addListenerOnce("changeOrganizationsLoaded", () => openOrgDetails(organizationId)); + this.__orgsPage.addListenerOnce("changeOrganizationsLoaded", () => openOrgDetails(organizationId)); } } } diff --git a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js index 0d72035d38f..8a20f097d6b 100644 --- a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js +++ b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js @@ -142,7 +142,7 @@ qx.Class.define("osparc.editor.AnnotationNoteCreator", { __setRecipientGid: function(gid) { this.setRecipientGid(gid); - osparc.store.Groups.getInstance().getGroup(gid) + osparc.store.Groups.getInstance().fetchGroup(gid) .then(user => { this.getChildControl("selected-recipient").setValue(user.label); }); diff --git a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js index c3350768413..ce3b0a2ad30 100644 --- a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js +++ b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js @@ -134,7 +134,7 @@ qx.Class.define("osparc.notification.NotificationUI", { case "NEW_ORGANIZATION": icon.setSource("@FontAwesome5Solid/users/14"); if (resourceId) { - osparc.store.Groups.getInstance().getGroup(resourceId) + osparc.store.Groups.getInstance().fetchGroup(resourceId) .then(group => descriptionLabel.setValue("You're now member of '" + group["label"] + "'")) .catch(() => this.setEnabled(false)); } @@ -264,7 +264,7 @@ qx.Class.define("osparc.notification.NotificationUI", { __openOrganizationDetails: function(orgId) { // make sure org is available - osparc.store.Groups.getInstance().getGroup(orgId) + osparc.store.Groups.getInstance().fetchGroup(orgId) .then(org => { if (org) { const orgsWindow = osparc.desktop.organizations.OrganizationsWindow.openWindow(); diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index 2110fe4be69..849db65071f 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -226,7 +226,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { ); }; - const groupData = await osparc.store.Store.getInstance().getGroup(groupId); + const groupData = await osparc.store.Store.getInstance().fetchGroup(groupId); const isOrganization = (groupData && !("id" in groupData)); if (isOrganization) { const msg = this.tr(`Demoting to ${osparc.data.Roles.STUDY[1].label} will remove write access to all the members of the Organization. Are you sure?`); diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js index c57d385a9c9..67b53e125b0 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js @@ -157,7 +157,7 @@ qx.Class.define("osparc.share.CollaboratorsWorkspace", { ); }; - const groupData = await osparc.store.Groups.getInstance().getGroup(groupId); + const groupData = await osparc.store.Groups.getInstance().fetchGroup(groupId); const isOrganization = (groupData && !("id" in groupData)); if (isOrganization) { const msg = this.tr(`Demoting to ${osparc.data.Roles.WORKSPACE[1].label} will remove write access to all the members of the Organization. Are you sure?`); diff --git a/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js b/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js index a96299190db..790d04dac5f 100644 --- a/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js +++ b/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js @@ -33,7 +33,7 @@ qx.Class.define("osparc.share.ShareePermissions", { this._add(layout); for (let i=0; i { if (group) { layout.add(new qx.ui.basic.Label(group.label), { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 4306d3ea7aa..9c89e116804 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -47,11 +47,6 @@ qx.Class.define("osparc.store.Groups", { init: {} }, - organizationMembers: { - check: "Object", - init: {} - }, - reachableMembers: { check: "Object", init: {} @@ -78,7 +73,7 @@ qx.Class.define("osparc.store.Groups", { groupsCached: null, usersCached: null, - fetchGroups: function() { + __fetchGroups: function() { if (osparc.auth.Data.getInstance().isGuest()) { return new Promise(resolve => { resolve([]); @@ -111,58 +106,32 @@ qx.Class.define("osparc.store.Groups", { }; return osparc.data.Resources.get("organizationMembers", params) .then(orgMembers => { - this.getOrganizationMembers()[groupId] = {}; - orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - this.getOrganizationMembers()[groupId][orgMember["gid"]] = orgMember; - }); + const group = this.getOrganizations()[groupId]; + if (group) { + group.setGroupMembers({}); + orgMembers.forEach(orgMember => { + orgMember["label"] = osparc.utils.Utils.firstsUp( + `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, + `${orgMember["last_name"] ? orgMember["last_name"] : ""}` + ); + group.getGroupMembers()[orgMember["gid"]] = orgMember; + this.getReachableMembers()[orgMember["gid"]] = orgMember; + }); + } }); }, - fetchAll: function() { - this.fetchGroups() - .then(orgs => { - this.resetOrganizationMembers(); - this.resetReachableMembers(); - const memberPromises = Object.keys(orgs).map(orgId => this.__fetchGroupMembers(orgId)); - Promise.all(memberPromises) - .then(() => { - Object.values(this.getOrganizationMembers()).forEach(orgMembers => { - Object.values(orgMembers).forEach(reachableMember => { - this.getReachableMembers()[reachableMember["gid"]] = reachableMember; - }); - }); - }); - - /* - const orgMembersPromises = []; - Object.keys(orgs).forEach(gid => { - const params = { - url: { - gid - } - }; - orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); + fetchGroupsAndMembers: function() { + return new Promise(resolve => { + this.__fetchGroups() + .then(orgs => { + this.resetReachableMembers(); + const promises = Object.keys(orgs).map(orgId => this.__fetchGroupMembers(orgId)); + Promise.all(promises) + .then(() => resolve()) + .catch(err => console.error(err)); }); - Promise.all(orgMembersPromises) - .then(orgMemberss => { - const reachableMembers = {}; - orgMemberss.forEach(orgMembers => { - orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - reachableMembers[orgMember["gid"]] = orgMember; - }); - }); - this.setReachableMembers(reachableMembers); - }); - */ - }); + }) }, getMyGroupId: function() { @@ -249,7 +218,11 @@ qx.Class.define("osparc.store.Groups", { }); }, - getGroup: function(gid) { + getGroup: function(groupId = null) { + return this.groupsCached.find(f => f.getGroupId() === groupId); + }, + + fetchGroup: function(gid) { return new Promise(resolve => { if (gid) { this.getPotentialCollaborators() @@ -331,12 +304,6 @@ qx.Class.define("osparc.store.Groups", { .catch(console.error); }, - /* - getGroup: function(groupId = null) { - return this.groupsCached.find(f => f.getGroupId() === groupId); - }, - */ - __addToGroupsCache: function(groupData, groupType) { let group = this.groupsCached.find(f => f.getGroupId() === groupData["gid"]); if (group) { diff --git a/services/static-webserver/client/source/class/osparc/workbench/Annotation.js b/services/static-webserver/client/source/class/osparc/workbench/Annotation.js index 46527fa70c5..a1305129fb2 100644 --- a/services/static-webserver/client/source/class/osparc/workbench/Annotation.js +++ b/services/static-webserver/client/source/class/osparc/workbench/Annotation.js @@ -96,7 +96,7 @@ qx.Class.define("osparc.workbench.Annotation", { let representation = null; switch (this.getType()) { case "note": { - const user = await osparc.store.Groups.getInstance().getGroup(attrs.recipientGid); + const user = await osparc.store.Groups.getInstance().fetchGroup(attrs.recipientGid); representation = this.__svgLayer.drawAnnotationNote(attrs.x, attrs.y, user ? user.label : "", attrs.text); break; } diff --git a/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js b/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js index 13ffce6e055..9a964374df0 100644 --- a/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js +++ b/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js @@ -1935,7 +1935,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", { const win = osparc.editor.AnnotationNoteCreator.popUpInWindow(noteEditor); noteEditor.addListener("addNote", () => { const gid = noteEditor.getRecipientGid(); - osparc.store.Groups.getInstance().getGroup(gid) + osparc.store.Groups.getInstance().fetchGroup(gid) .then(user => { serializeData.attributes.recipientGid = gid; serializeData.attributes.text = noteEditor.getNote(); From 296df6f2b9885053591ebf577936db9c677bdaec Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 17:03:16 +0100 Subject: [PATCH 17/59] fixes --- .../class/osparc/desktop/organizations/MembersList.js | 10 +++++----- .../desktop/organizations/OrganizationDetails.js | 2 +- .../source/class/osparc/editor/OrganizationEditor.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index 409b216804d..f28e781036c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -208,13 +208,13 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const membersModel = this.__membersModel; membersModel.removeAll(); - const orgModel = this.__currentOrg; - if (orgModel === null) { + const organization = this.__currentOrg; + if (organization === null) { return; } - const canIWrite = orgModel.getAccessRights().getWrite(); - const canIDelete = orgModel.getAccessRights().getDelete(); + const canIWrite = organization.getAccessRights()["write"]; + const canIDelete = organization.getAccessRights()["delete"]; const introText = canIWrite ? this.tr("You can add new members and promote or demote existing ones.") : @@ -227,7 +227,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { - "gid": orgModel.getGroupId() + "gid": organization.getGroupId() } }; osparc.data.Resources.get("organizationMembers", params) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index 242013cbcc2..31de19e1541 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -53,7 +53,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { orgModel.bind("thumbnail", organizationListItem, "thumbnail"); orgModel.bind("label", organizationListItem, "title"); orgModel.bind("description", organizationListItem, "subtitle"); - orgModel.bindProperty("groupMembers", "role", { + orgModel.bind("groupMembers", organizationListItem, "role", { converter: groupMembers => groupMembers ? Object.keys(groupMembers).length + this.tr(" members") : "-" }); orgModel.bind("accessRights", organizationListItem, "accessRights"); diff --git a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js index d8ab60f20cb..c9fbec3f8cd 100644 --- a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js +++ b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js @@ -32,7 +32,7 @@ qx.Class.define("osparc.editor.OrganizationEditor", { organization ? this.getChildControl("save") : this.getChildControl("create"); if (organization) { - organization.bind("gid", this, "gid"); + organization.bind("groupId", this, "gid"); organization.bind("label", this, "label"); organization.bind("description", this, "description"); organization.bind("thumbnail", this, "thumbnail", { @@ -40,8 +40,8 @@ qx.Class.define("osparc.editor.OrganizationEditor", { }); } else { const groupsStore = osparc.store.Groups.getInstance(); - const orgs = groupsStore.getOrganizations() - const existingNames = orgs.map(org => org["label"]); + const orgs = groupsStore.getOrganizations(); + const existingNames = orgs.map(org => org.getLabel()); const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames) title.setValue(defaultName); } From 575eaaa00ab5033d7a1ada6b11ce7350aa7cda67 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 17:21:03 +0100 Subject: [PATCH 18/59] User model --- .../source/class/osparc/data/model/User.js | 83 +++++++++++++++++++ .../desktop/preferences/pages/ClustersPage.js | 58 +++++++------ .../source/class/osparc/store/Groups.js | 73 ++++++++-------- 3 files changed, 145 insertions(+), 69 deletions(-) create mode 100644 services/static-webserver/client/source/class/osparc/data/model/User.js diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js new file mode 100644 index 00000000000..5ceb91bed4b --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -0,0 +1,83 @@ +/* ************************************************************************ + + 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 User data. + */ + +qx.Class.define("osparc.data.model.User", { + extend: qx.core.Object, + + /** + * @param userData {Object} Object containing the serialized User Data + */ + construct: function(userData) { + this.base(arguments); + + let label = userData["login"]; + if ("first_name" in userData && userData["first_name"]) { + label = osparc.utils.Utils.firstsUp(userData["first_name"]); + if (userData["last_name"]) { + label += " " + osparc.utils.Utils.firstsUp(userData["last_name"]); + } + } + this.set({ + userId: userData.id, + groupId: userData.gid, + label: label, + login: userData.login, + accessRights: userData.accessRights, + }); + }, + + properties: { + userId: { + check: "Number", + nullable: false, + init: null, + event: "changeUserId", + }, + + groupId: { + check: "Number", + nullable: false, + init: null, + event: "changeGroupId", + }, + + label: { + check: "String", + nullable: false, + init: null, + event: "changeLabel", + }, + + login: { + check: "String", + nullable: true, + init: null, + event: "changeLogin", + }, + + accessRights: { + check: "Object", + nullable: false, + init: null, + event: "changeAccessRights", + }, + } +}); diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js index 57eae904e61..074c01207a9 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js @@ -277,36 +277,34 @@ qx.Class.define("osparc.desktop.preferences.pages.ClustersPage", { this.__organizationsAndMembers.reloadVisibleCollaborators(memberKeys); } - osparc.store.Groups.getInstance().getPotentialCollaborators() - .then(potentialCollaborators => { - clusterMembers.forEach(clusterMember => { - const gid = clusterMember.gid; - if (gid in potentialCollaborators) { - const collaborator = potentialCollaborators[gid]; - const collabObj = {}; - if (collaborator["collabType"] === 1) { - collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24"; - collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]); - collabObj["login"] = collaborator["description"]; - } else if (collaborator["collabType"] === 2) { - collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); - collaborator["name"] = osparc.utils.Utils.firstsUp( - `${"first_name" in collaborator && collaborator["first_name"] != null ? - collaborator["first_name"] : collaborator["login"]}`, - `${"last_name" in collaborator && collaborator["last_name"] ? - collaborator["last_name"] : ""}` - ); - collabObj["login"] = collaborator["login"]; - } - if (Object.keys(collabObj).length) { - collabObj["id"] = collaborator["gid"]; - collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember)); - collabObj["showOptions"] = canWrite; - membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj)); - } - } - }); - }); + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(); + clusterMembers.forEach(clusterMember => { + const gid = "gid" in clusterMember ? clusterMember["gid"] : clusterMember.getGroupId(); + if (gid in potentialCollaborators) { + const collaborator = potentialCollaborators[gid]; + const collabObj = {}; + if (collaborator["collabType"] === 1) { + collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24"; + collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]); + collabObj["login"] = collaborator["description"]; + } else if (collaborator["collabType"] === 2) { + collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); + collaborator["name"] = osparc.utils.Utils.firstsUp( + `${"first_name" in collaborator && collaborator["first_name"] != null ? + collaborator["first_name"] : collaborator["login"]}`, + `${"last_name" in collaborator && collaborator["last_name"] ? + collaborator["last_name"] : ""}` + ); + collabObj["login"] = collaborator["login"]; + } + if (Object.keys(collabObj).length) { + collabObj["id"] = collaborator["gid"]; + collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember)); + collabObj["showOptions"] = canWrite; + membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj)); + } + } + }); }, __openEditCluster: function(clusterId) { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 9c89e116804..afd10c41487 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -110,12 +110,9 @@ qx.Class.define("osparc.store.Groups", { if (group) { group.setGroupMembers({}); orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - group.getGroupMembers()[orgMember["gid"]] = orgMember; - this.getReachableMembers()[orgMember["gid"]] = orgMember; + const user = new osparc.data.model.User(orgMember) + group.getGroupMembers()[orgMember["gid"]] = user; + this.getReachableMembers()[orgMember["gid"]] = user; }); } }); @@ -180,42 +177,40 @@ qx.Class.define("osparc.store.Groups", { }, getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { - return new Promise((resolve, reject) => { - const potentialCollaborators = {}; - const orgs = this.getOrganizations(); - const productEveryone = this.getEveryoneProductGroup(); - Object.values(orgs).forEach(org => { - if (org.getAccessRights()["read"]) { - // maybe because of migration script, some users have access to the product everyone group - // rely on the includeProductEveryone argument to exclude it if necessary - if (org.getGroupId() === productEveryone.getGroupId() && !includeProductEveryone) { - return; - } - org["collabType"] = 1; - potentialCollaborators[org.getGroupId()] = org; + const potentialCollaborators = {}; + const orgs = this.getOrganizations(); + const productEveryone = this.getEveryoneProductGroup(); + Object.values(orgs).forEach(org => { + if (org.getAccessRights()["read"]) { + // maybe because of migration script, some users have access to the product everyone group + // rely on the includeProductEveryone argument to exclude it if necessary + if (org.getGroupId() === productEveryone.getGroupId() && !includeProductEveryone) { + return; } - }); - const members = this.getReachableMembers(); - for (const gid of Object.keys(members)) { - members[gid]["collabType"] = 2; - potentialCollaborators[gid] = members[gid]; - } - if (includeMe) { - const myData = osparc.auth.Data.getInstance(); - const myGid = myData.getGroupId(); - potentialCollaborators[myGid] = { - "login": myData.getEmail(), - "first_name": myData.getFirstName(), - "last_name": myData.getLastName(), - "collabType": 2 - }; - } - if (includeProductEveryone && productEveryone) { - productEveryone["collabType"] = 0; - potentialCollaborators[productEveryone.getGroupId()] = productEveryone; + org["collabType"] = 1; + potentialCollaborators[org.getGroupId()] = org; } - resolve(potentialCollaborators); }); + const members = this.getReachableMembers(); + for (const gid of Object.keys(members)) { + members[gid]["collabType"] = 2; + potentialCollaborators[gid] = members[gid]; + } + if (includeMe) { + const myData = osparc.auth.Data.getInstance(); + const myGid = myData.getGroupId(); + potentialCollaborators[myGid] = { + "login": myData.getEmail(), + "first_name": myData.getFirstName(), + "last_name": myData.getLastName(), + "collabType": 2 + }; + } + if (includeProductEveryone && productEveryone) { + productEveryone["collabType"] = 0; + potentialCollaborators[productEveryone.getGroupId()] = productEveryone; + } + return potentialCollaborators; }, getGroup: function(groupId = null) { From 658cbb6352bc0efca93888f09aa3a20a505c37d0 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 17:38:47 +0100 Subject: [PATCH 19/59] user model --- .../source/class/osparc/dashboard/CardBase.js | 4 ++-- .../dashboard/ResourceContainerManager.js | 6 ++--- .../source/class/osparc/data/model/User.js | 8 +++++++ .../desktop/preferences/pages/ClustersPage.js | 24 ++++++++----------- .../osparc/filter/OrganizationsAndMembers.js | 11 +++------ .../source/class/osparc/info/CommentAdd.js | 4 ++-- .../source/class/osparc/info/CommentUI.js | 5 ++-- .../class/osparc/navigation/UserMenuButton.js | 4 ++-- .../osparc/notification/NotificationUI.js | 8 +++---- .../class/osparc/share/Collaborators.js | 9 ++----- .../osparc/share/NewCollaboratorsManager.js | 2 +- .../class/osparc/share/PublishTemplate.js | 2 +- .../source/class/osparc/store/Groups.js | 6 ++--- 13 files changed, 43 insertions(+), 50 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index bad4b42af49..db29b945549 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -168,7 +168,7 @@ qx.Class.define("osparc.dashboard.CardBase", { if (gid === myGroupId) { continue; } - const grp = groups[i].find(group => "gid" in group ? group["gid"] === gid : group.getGroupId() === gid); + const grp = groups[i].find(group => group.getGroupId() === gid); if (grp) { sharedGrp.push(grp); } @@ -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); } diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js index 69b86e4cd66..2c1c119ca36 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js @@ -478,8 +478,8 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", { const org = groupsStore.getOrganizationOrUser(orgId); if (org) { let icon = ""; - if ("thumbnail" in org || ("getThumbnail" in org && org.getThumbnail())) { - icon = "thumbnail" in org ? org["thumbnail"] : org.getThumbnail(); + if (org.getThumbnail()) { + icon = org.getThumbnail(); } else if (org["collabType"] === 0) { icon = "@FontAwesome5Solid/globe/24"; } else if (org["collabType"] === 1) { @@ -489,7 +489,7 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", { } groupContainer.set({ headerIcon: icon, - headerLabel: "label" in org ? org["label"] : org.getLabel(), + headerLabel: org.getLabel(), }); } else { groupContainer.exclude(); diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index 5ceb91bed4b..4fa90dfaab8 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -40,6 +40,7 @@ qx.Class.define("osparc.data.model.User", { groupId: userData.gid, label: label, login: userData.login, + thumbnail: osparc.utils.Avatar.getUrl(userData.login, 32), accessRights: userData.accessRights, }); }, @@ -79,5 +80,12 @@ qx.Class.define("osparc.data.model.User", { init: null, event: "changeAccessRights", }, + + thumbnail: { + check: "String", + nullable: true, + init: "", + event: "changeThumbnail", + }, } }); diff --git a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js index 074c01207a9..d5d7e6ba6dc 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js +++ b/services/static-webserver/client/source/class/osparc/desktop/preferences/pages/ClustersPage.js @@ -279,27 +279,23 @@ qx.Class.define("osparc.desktop.preferences.pages.ClustersPage", { const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(); clusterMembers.forEach(clusterMember => { - const gid = "gid" in clusterMember ? clusterMember["gid"] : clusterMember.getGroupId(); + const gid = clusterMember.getGroupId(); if (gid in potentialCollaborators) { const collaborator = potentialCollaborators[gid]; const collabObj = {}; if (collaborator["collabType"] === 1) { - collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24"; - collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]); - collabObj["login"] = collaborator["description"]; + // group + collabObj["thumbnail"] = collaborator.getThumbnail() || "@FontAwesome5Solid/users/24"; + collabObj["login"] = collaborator.getDescription(); } else if (collaborator["collabType"] === 2) { - collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); - collaborator["name"] = osparc.utils.Utils.firstsUp( - `${"first_name" in collaborator && collaborator["first_name"] != null ? - collaborator["first_name"] : collaborator["login"]}`, - `${"last_name" in collaborator && collaborator["last_name"] ? - collaborator["last_name"] : ""}` - ); - collabObj["login"] = collaborator["login"]; + // user + collabObj["thumbnail"] = collaborator.getThumbnail() || "@FontAwesome5Solid/user/24"; + collabObj["login"] = collaborator.getLogin(); } if (Object.keys(collabObj).length) { - collabObj["id"] = collaborator["gid"]; - collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember)); + collabObj["id"] = collaborator.getGroupId(); + collabObj["name"] = collaborator.getLabel(); + collabObj["accessRights"] = clusterMember.getAccessRights(); collabObj["showOptions"] = canWrite; membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj)); } diff --git a/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js b/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js index 2d45199661f..03f07f01c97 100644 --- a/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js +++ b/services/static-webserver/client/source/class/osparc/filter/OrganizationsAndMembers.js @@ -37,14 +37,9 @@ qx.Class.define("osparc.filter.OrganizationsAndMembers", { __collaboratorsToBeRemoved: null, addOption: function(group) { - let name = ""; - if ("first_name" in group) { - name = `${group["first_name"]} ${"last_name" in group && group["last_name"] != null ? group["last_name"] : ""}`; - } else { - name = group["label"]; - } + const name = group.getLabel(); const btn = this._addOption(name); - btn.gid = group["gid"]; + btn.gid = group.getGroupId(); return btn; }, @@ -89,7 +84,7 @@ qx.Class.define("osparc.filter.OrganizationsAndMembers", { if (a["collabType"] < b["collabType"]) { return -1; } - if (a["label"] > b["label"]) { + if (a.getLabel() > b.getLabel()) { return 1; } return -1; diff --git a/services/static-webserver/client/source/class/osparc/info/CommentAdd.js b/services/static-webserver/client/source/class/osparc/info/CommentAdd.js index 060ce42ca69..b8f36a839e6 100644 --- a/services/static-webserver/client/source/class/osparc/info/CommentAdd.js +++ b/services/static-webserver/client/source/class/osparc/info/CommentAdd.js @@ -68,9 +68,9 @@ qx.Class.define("osparc.info.CommentAdd", { maxHeight: 32, decorator: "rounded", }); - const userEmail = osparc.auth.Data.getInstance().getEmail(); + const myEmail = osparc.auth.Data.getInstance().getEmail(); control.set({ - source: osparc.utils.Avatar.getUrl(userEmail, 32) + source: osparc.utils.Avatar.getUrl(myEmail, 32) }); const layout = this.getChildControl("add-comment-layout"); layout.add(control, { diff --git a/services/static-webserver/client/source/class/osparc/info/CommentUI.js b/services/static-webserver/client/source/class/osparc/info/CommentUI.js index 06b121d1287..30c5891907f 100644 --- a/services/static-webserver/client/source/class/osparc/info/CommentUI.js +++ b/services/static-webserver/client/source/class/osparc/info/CommentUI.js @@ -119,9 +119,8 @@ qx.Class.define("osparc.info.CommentUI", { const user = osparc.store.Groups.getInstance().getUser(this.__comment["user_id"]) if (user) { - const userSource = osparc.utils.Avatar.getUrl(user["login"], 32); - thumbnail.setSource(userSource); - userName.setValue(user["label"]); + thumbnail.setSource(user.getThumbnail()); + userName.setValue(user.getLabel()); } } } diff --git a/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js b/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js index ac256291335..e53fc4e7e1c 100644 --- a/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js +++ b/services/static-webserver/client/source/class/osparc/navigation/UserMenuButton.js @@ -51,7 +51,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", { const preferencesSettings = osparc.Preferences.getInstance(); preferencesSettings.addListener("changeCreditsWarningThreshold", () => this.__updateHaloColor()); - const userEmail = authData.getEmail() || "bizzy@itis.ethz.ch"; + const myEmail = authData.getEmail() || "bizzy@itis.ethz.ch"; const icon = this.getChildControl("icon"); authData.bind("role", this, "icon", { converter: role => { @@ -64,7 +64,7 @@ qx.Class.define("osparc.navigation.UserMenuButton", { icon.getContentElement().setStyles({ "margin-left": "-4px" }); - return osparc.utils.Avatar.getUrl(userEmail, 32); + return osparc.utils.Avatar.getUrl(myEmail, 32); } }); }, diff --git a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js index ce3b0a2ad30..64ca828951c 100644 --- a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js +++ b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js @@ -135,7 +135,7 @@ qx.Class.define("osparc.notification.NotificationUI", { icon.setSource("@FontAwesome5Solid/users/14"); if (resourceId) { osparc.store.Groups.getInstance().fetchGroup(resourceId) - .then(group => descriptionLabel.setValue("You're now member of '" + group["label"] + "'")) + .then(group => descriptionLabel.setValue("You're now member of '" + group.getLabel() + "'")) .catch(() => this.setEnabled(false)); } break; @@ -159,7 +159,7 @@ qx.Class.define("osparc.notification.NotificationUI", { if (userFromId) { const user = osparc.store.Groups.getInstance().getUser(userFromId); if (user) { - descriptionLabel.setValue("was shared by " + user["label"]); + descriptionLabel.setValue("was shared by " + user.getLabel()); } } break; @@ -179,7 +179,7 @@ qx.Class.define("osparc.notification.NotificationUI", { if (userFromId) { const user = osparc.store.Groups.getInstance().getUser(userFromId); if (user) { - descriptionLabel.setValue("was shared by " + user["label"]); + descriptionLabel.setValue("was shared by " + user.getLabel()); } } break; @@ -198,7 +198,7 @@ qx.Class.define("osparc.notification.NotificationUI", { if (userFromId) { const user = osparc.store.Groups.getInstance().getUser(userFromId); if (user) { - descriptionLabel.setValue("was added by " + user["label"]); + descriptionLabel.setValue("was added by " + user.getLabel()); } } break; diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 76844f4f0e2..989e8e0fd23 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -417,13 +417,8 @@ qx.Class.define("osparc.share.Collaborators", { const collaborator = osparc.utils.Utils.deepCloneObject(collab); if ("first_name" in collaborator) { // user - collaborator["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); - collaborator["name"] = osparc.utils.Utils.firstsUp( - `${"first_name" in collaborator && collaborator["first_name"] != null ? - collaborator["first_name"] : collaborator["login"]}`, - `${"last_name" in collaborator && collaborator["last_name"] ? - collaborator["last_name"] : ""}` - ); + collaborator["thumbnail"] = collaborator.getThumbnail(); + collaborator["name"] = collaborator.getLabel(); } else if (everyoneGIds.includes(parseInt(gid))) { // everyone product or everyone if (collaborator["thumbnail"] === null) { diff --git a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js index db2ca38c3fd..b3f8509dc43 100644 --- a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js +++ b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js @@ -154,7 +154,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { if (a["collabType"] < b["collabType"]) { return -1; } - if (a["label"] > b["label"]) { + if (a.getLabel() > b.getLabel()) { return 1; } return -1; diff --git a/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js b/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js index efd453b238d..015f6ca3fba 100644 --- a/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js +++ b/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js @@ -66,7 +66,7 @@ qx.Class.define("osparc.share.PublishTemplate", { const currentGids = this.getSelectedGroups(); gids.forEach(gid => { if (gid in potentialCollaborators && !currentGids.includes(gid)) { - const collabButton = new qx.ui.toolbar.Button(potentialCollaborators[gid]["label"], "@MaterialIcons/close/12"); + const collabButton = new qx.ui.toolbar.Button(potentialCollaborators[gid].getLabel(), "@MaterialIcons/close/12"); collabButton.gid = gid; this.__selectedCollabs.add(collabButton); collabButton.addListener("execute", () => { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index afd10c41487..56ea082e8a7 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -110,7 +110,7 @@ qx.Class.define("osparc.store.Groups", { if (group) { group.setGroupMembers({}); orgMembers.forEach(orgMember => { - const user = new osparc.data.model.User(orgMember) + const user = new osparc.data.model.User(orgMember); group.getGroupMembers()[orgMember["gid"]] = user; this.getReachableMembers()[orgMember["gid"]] = user; }); @@ -167,9 +167,9 @@ qx.Class.define("osparc.store.Groups", { return groups; }, - getOrganizationOrUser: function(orgId) { + getOrganizationOrUser: function(groupId) { const orgs = this.__getAllGroups(); - const idx = orgs.findIndex(org => "gid" in org ? org["gid"] === parseInt(orgId) : org.getGroupId() === parseInt(orgId)); + const idx = orgs.findIndex(org => org.getGroupId() === parseInt(groupId)); if (idx > -1) { return orgs[idx]; } From 1b065498d9e379f960f4460d424e0a041b9ae394 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 17:45:38 +0100 Subject: [PATCH 20/59] not a promise --- .../osparc/desktop/wallets/MembersList.js | 21 ++++++------- .../class/osparc/share/Collaborators.js | 8 ++--- .../class/osparc/share/CollaboratorsStudy.js | 31 +++++++++---------- .../osparc/share/NewCollaboratorsManager.js | 26 +++++++--------- .../class/osparc/share/PublishTemplate.js | 28 ++++++++--------- 5 files changed, 51 insertions(+), 63 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index e7c155a3682..232bd3d21d2 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -211,7 +211,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const myGroupId = osparc.auth.Data.getInstance().getGroupId(); const membersList = []; - const potentialCollaborators = await osparc.store.Groups.getInstance().getPotentialCollaborators(true); + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(true); const canIWrite = wallet.getMyAccessRights()["write"]; wallet.getAccessRights().forEach(accessRights => { const gid = accessRights["gid"]; @@ -289,17 +289,14 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); // push 'WALLET_SHARED' notification - osparc.store.Groups.getInstance().getPotentialCollaborators() - .then(potentialCollaborators => { - gids.forEach(gid => { - if (gid in potentialCollaborators && "id" in potentialCollaborators[gid]) { - // it's a user, not an organization - const collab = potentialCollaborators[gid]; - const uid = collab["id"]; - osparc.notification.Notifications.postNewWallet(uid, wallet.getWalletId()); - } - }); - }); + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators() + gids.forEach(gid => { + if (gid in potentialCollaborators && "getUserId" in potentialCollaborators[gid]) { + // it's a user, not an organization + const uid = potentialCollaborators[gid].getUserId(); + osparc.notification.Notifications.postNewWallet(uid, wallet.getWalletId()); + } + }); }); }, diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 989e8e0fd23..f580ef11304 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -341,11 +341,9 @@ qx.Class.define("osparc.share.Collaborators", { }, __getCollaborators: function() { - osparc.store.Groups.getInstance().getPotentialCollaborators() - .then(potentialCollaborators => { - this.__collaborators = Object.assign(this.__collaborators, potentialCollaborators); - this._reloadCollaboratorsList(); - }); + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators() + this.__collaborators = Object.assign(this.__collaborators, potentialCollaborators); + this._reloadCollaboratorsList(); }, __getLeaveStudyButton: function() { diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index 849db65071f..d02199889bd 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -259,24 +259,21 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { __pushNotifications: function(gids) { // push 'STUDY_SHARED'/'TEMPLATE_SHARED' notification - osparc.store.Groups.getInstance().getPotentialCollaborators() - .then(potentialCollaborators => { - gids.forEach(gid => { - if (gid in potentialCollaborators && "id" in potentialCollaborators[gid]) { - // it's a user, not an organization - const collab = potentialCollaborators[gid]; - const uid = collab["id"]; - if (this._resourceType === "study") { - osparc.notification.Notifications.postNewStudy(uid, this._serializedDataCopy["uuid"]); - } else if (this._resourceType === "template") { - // do not push TEMPLATE_SHARED notification if users are not supposed to see the templates - if (osparc.data.Permissions.getInstance().canRoleDo("user", "dashboard.templates.read")) { - osparc.notification.Notifications.postNewTemplate(uid, this._serializedDataCopy["uuid"]); - } - } + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators() + gids.forEach(gid => { + if (gid in potentialCollaborators && "getUserId" in potentialCollaborators[gid]) { + // it's a user, not an organization + const uid = potentialCollaborators[gid].getUserId(); + if (this._resourceType === "study") { + osparc.notification.Notifications.postNewStudy(uid, this._serializedDataCopy["uuid"]); + } else if (this._resourceType === "template") { + // do not push TEMPLATE_SHARED notification if users are not supposed to see the templates + if (osparc.data.Permissions.getInstance().canRoleDo("user", "dashboard.templates.read")) { + osparc.notification.Notifications.postNewTemplate(uid, this._serializedDataCopy["uuid"]); } - }); - }); + } + } + }); }, __checkShareePermissions: function(gids) { diff --git a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js index b3f8509dc43..dad8f976529 100644 --- a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js +++ b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js @@ -112,20 +112,18 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { // all users can share services with ProductEveryone includeProductEveryone = true; } - osparc.store.Groups.getInstance().getPotentialCollaborators(false, includeProductEveryone) - .then(potentialCollaborators => { - this.__visibleCollaborators = potentialCollaborators; - const anyCollaborator = Object.keys(potentialCollaborators).length; - // tell the user that belonging to an organization is required to start sharing - this.__introLabel.setVisibility(anyCollaborator ? "excluded" : "visible"); - this.__orgsButton.setVisibility(anyCollaborator ? "excluded" : "visible"); - - // or start sharing - this.__textFilter.setVisibility(anyCollaborator ? "visible" : "excluded"); - this.__collabButtonsContainer.setVisibility(anyCollaborator ? "visible" : "excluded"); - this.__shareButton.setVisibility(anyCollaborator ? "visible" : "excluded"); - this.__addEditors(); - }); + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(false, includeProductEveryone) + this.__visibleCollaborators = potentialCollaborators; + const anyCollaborator = Object.keys(potentialCollaborators).length; + // tell the user that belonging to an organization is required to start sharing + this.__introLabel.setVisibility(anyCollaborator ? "excluded" : "visible"); + this.__orgsButton.setVisibility(anyCollaborator ? "excluded" : "visible"); + + // or start sharing + this.__textFilter.setVisibility(anyCollaborator ? "visible" : "excluded"); + this.__collabButtonsContainer.setVisibility(anyCollaborator ? "visible" : "excluded"); + this.__shareButton.setVisibility(anyCollaborator ? "visible" : "excluded"); + this.__addEditors(); }, __collaboratorButton: function(collaborator) { diff --git a/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js b/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js index 015f6ca3fba..d638e0285b9 100644 --- a/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js +++ b/services/static-webserver/client/source/class/osparc/share/PublishTemplate.js @@ -61,22 +61,20 @@ qx.Class.define("osparc.share.PublishTemplate", { addCollaborators.addListener("addCollaborators", e => { const gids = e.getData(); if (gids.length) { - osparc.store.Groups.getInstance().getPotentialCollaborators(false, true) - .then(potentialCollaborators => { - const currentGids = this.getSelectedGroups(); - gids.forEach(gid => { - if (gid in potentialCollaborators && !currentGids.includes(gid)) { - const collabButton = new qx.ui.toolbar.Button(potentialCollaborators[gid].getLabel(), "@MaterialIcons/close/12"); - collabButton.gid = gid; - this.__selectedCollabs.add(collabButton); - collabButton.addListener("execute", () => { - this.__selectedCollabs.remove(collabButton); - this.__updateAccessRights(); - }); - } + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(false, true) + const currentGids = this.getSelectedGroups(); + gids.forEach(gid => { + if (gid in potentialCollaborators && !currentGids.includes(gid)) { + const collabButton = new qx.ui.toolbar.Button(potentialCollaborators[gid].getLabel(), "@MaterialIcons/close/12"); + collabButton.gid = gid; + this.__selectedCollabs.add(collabButton); + collabButton.addListener("execute", () => { + this.__selectedCollabs.remove(collabButton); + this.__updateAccessRights(); }); - this.__updateAccessRights(); - }); + } + }); + this.__updateAccessRights(); } }, this); }, From 11c77f981c3fa08b40c1db972b016a92c9a702f1 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 17:59:00 +0100 Subject: [PATCH 21/59] Collaborators --- .../source/class/osparc/share/Collaborators.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index f580ef11304..4bb6dbf0787 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -412,14 +412,18 @@ qx.Class.define("osparc.share.Collaborators", { if (Object.prototype.hasOwnProperty.call(this.__collaborators, gid)) { const collab = this.__collaborators[gid]; // Do not override collaborator object - const collaborator = osparc.utils.Utils.deepCloneObject(collab); - if ("first_name" in collaborator) { + const collaborator = { + "gid": collab.getGroupId(), + "thumbnail": collab.getThumbnail(), + }; + if ("getUserId" in collab) { // user - collaborator["thumbnail"] = collaborator.getThumbnail(); - collaborator["name"] = collaborator.getLabel(); - } else if (everyoneGIds.includes(parseInt(gid))) { - // everyone product or everyone - if (collaborator["thumbnail"] === null) { + collaborator["name"] = collab.getLabel(); + collaborator["login"] = collab.getLogin(); + } else { + collaborator["label"] = collab.getLabel(); + collaborator["description"] = collab.getDescription(); + if (everyoneGIds.includes(parseInt(gid))) { collaborator["thumbnail"] = "@FontAwesome5Solid/globe/32"; } } From be8e66a9c812512def3ac879e6a1a29279286115 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Wed, 20 Nov 2024 18:09:45 +0100 Subject: [PATCH 22/59] Sharing --- .../osparc/filter/CollaboratorToggleButton.js | 22 ++++--------------- .../osparc/share/NewCollaboratorsManager.js | 17 +++++--------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js index 64b6904d283..6100ace059d 100644 --- a/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js +++ b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js @@ -23,28 +23,14 @@ qx.Class.define("osparc.filter.CollaboratorToggleButton", { appearance: "tagbutton" }); - let label = null; - if (collaborator["first_name"]) { + let label = collaborator.getLabel(); + if ("getLogin" in collaborator) { // user - label = collaborator["first_name"]; - if (collaborator["last_name"]) { - label += ` ${collaborator["last_name"]}`; - } - if (collaborator["login"]) { - label += ` (${collaborator["login"]})`; - } - } else if ("login" in collaborator) { - label = collaborator["login"]; - } else { - // org - label = collaborator.getLabel(); + label += ` (${collaborator.getLogin()})`; + this.setToolTipText(collaborator.getLogin()); } this.setLabel(label); - if (collaborator["login"]) { - this.setToolTipText(collaborator["login"]); - } - let iconPath = null; switch (collaborator["collabType"]) { case 0: diff --git a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js index dad8f976529..fcbe5befff5 100644 --- a/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js +++ b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js @@ -28,7 +28,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { this.__renderLayout(); - this.__selectedCollaborators = new qx.data.Array(); + this.__selectedCollaborators = []; this.__visibleCollaborators = {}; this.__reloadCollaborators(); @@ -131,9 +131,9 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { collaboratorButton.addListener("changeValue", e => { const selected = e.getData(); if (selected) { - this.__selectedCollaborators.push(collaborator.gid); + this.__selectedCollaborators.push(collaborator.getGroupId()); } else { - this.__selectedCollaborators.remove(collaborator.gid); + this.__selectedCollaborators.remove(collaborator.getGroupId()); } this.__shareButton.setEnabled(Boolean(this.__selectedCollaborators.length)); }, this); @@ -173,7 +173,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { const existingCollaborators = existingCollabs.map(c => parseInt(c)); visibleCollaborators.forEach(visibleCollaborator => { // do not list the visibleCollaborators that are already collaborators - if (existingCollaborators.includes(visibleCollaborator["gid"])) { + if (existingCollaborators.includes(visibleCollaborator.getGroupId())) { return; } if (this.__showOrganizations === false && visibleCollaborator["collabType"] !== 2) { @@ -187,13 +187,8 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { this.__collabButtonsContainer.setEnabled(false); this.__shareButton.setFetching(true); - const addCollabs = []; - for (let i=0; i Date: Thu, 21 Nov 2024 09:48:53 +0100 Subject: [PATCH 23/59] renamings --- .../osparc/editor/AnnotationNoteCreator.js | 1 + .../source/class/osparc/info/CommentUI.js | 2 +- .../osparc/notification/NotificationUI.js | 6 ++-- .../source/class/osparc/store/Groups.js | 36 ++++++++++++------- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js index 8a20f097d6b..9567a19f3e8 100644 --- a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js +++ b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js @@ -142,6 +142,7 @@ qx.Class.define("osparc.editor.AnnotationNoteCreator", { __setRecipientGid: function(gid) { this.setRecipientGid(gid); + // only users were proposed osparc.store.Groups.getInstance().fetchGroup(gid) .then(user => { this.getChildControl("selected-recipient").setValue(user.label); diff --git a/services/static-webserver/client/source/class/osparc/info/CommentUI.js b/services/static-webserver/client/source/class/osparc/info/CommentUI.js index 30c5891907f..ea6df760a08 100644 --- a/services/static-webserver/client/source/class/osparc/info/CommentUI.js +++ b/services/static-webserver/client/source/class/osparc/info/CommentUI.js @@ -117,7 +117,7 @@ qx.Class.define("osparc.info.CommentUI", { const commentContent = this.getChildControl("comment-content"); commentContent.setValue(this.__comment["contents"]); - const user = osparc.store.Groups.getInstance().getUser(this.__comment["user_id"]) + const user = osparc.store.Groups.getInstance().getUserByUserId(this.__comment["user_id"]) if (user) { thumbnail.setSource(user.getThumbnail()); userName.setValue(user.getLabel()); diff --git a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js index 64ca828951c..386ed34e9f7 100644 --- a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js +++ b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js @@ -157,7 +157,7 @@ qx.Class.define("osparc.notification.NotificationUI", { .catch(() => this.setEnabled(false)); } if (userFromId) { - const user = osparc.store.Groups.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUserByUserId(userFromId); if (user) { descriptionLabel.setValue("was shared by " + user.getLabel()); } @@ -177,7 +177,7 @@ qx.Class.define("osparc.notification.NotificationUI", { } } if (userFromId) { - const user = osparc.store.Groups.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUserByUserId(userFromId); if (user) { descriptionLabel.setValue("was shared by " + user.getLabel()); } @@ -196,7 +196,7 @@ qx.Class.define("osparc.notification.NotificationUI", { .catch(() => this.setEnabled(false)); } if (userFromId) { - const user = osparc.store.Groups.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUserByUserId(userFromId); if (user) { descriptionLabel.setValue("was added by " + user.getLabel()); } diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 56ea082e8a7..6268af0ccc7 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -213,8 +213,28 @@ qx.Class.define("osparc.store.Groups", { return potentialCollaborators; }, - getGroup: function(groupId = null) { - return this.groupsCached.find(f => f.getGroupId() === groupId); + getOrganization: function(groupId) { + if (groupId) { + const visibleMembers = this.getOrganizations(); + return Object.values(visibleMembers).find(member => member.getGroupId() === groupId); + } + return null; + }, + + getUserByUserId: function(userId) { + if (userId) { + const visibleMembers = this.getReachableMembers(); + return Object.values(visibleMembers).find(member => member.getUserId() === userId); + } + return null; + }, + + getUserByGroupId: function(groupId) { + if (groupId) { + const visibleMembers = this.getReachableMembers(); + return Object.values(visibleMembers).find(member => member.getGroupId() === groupId); + } + return null; }, fetchGroup: function(gid) { @@ -235,14 +255,6 @@ qx.Class.define("osparc.store.Groups", { }); }, - getUser: function(uid) { - if (uid) { - const visibleMembers = this.getReachableMembers(); - return Object.values(visibleMembers).find(member => member.id === uid); - } - return null; - }, - postGroup: function(name, parentGroupId = null, workspaceId = null) { const newGroupData = { name, @@ -268,7 +280,7 @@ qx.Class.define("osparc.store.Groups", { }; return osparc.data.Resources.getInstance().fetch("groups", "delete", params) .then(() => { - const group = this.getGroup(groupId); + const group = this.getOrganization(groupId); if (group) { this.__deleteFromGroupsCache(groupId, workspaceId); this.fireDataEvent("groupRemoved", group); @@ -278,7 +290,7 @@ qx.Class.define("osparc.store.Groups", { }, putGroup: function(groupId, updateData) { - const group = this.getGroup(groupId); + const group = this.getOrganization(groupId); const oldParentGroupId = group.getParentGroupId(); const params = { "url": { From cb182c6fe2a9c3e6994f3d1152e4efbfd440d640 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 09:54:11 +0100 Subject: [PATCH 24/59] more specific --- .../osparc/editor/AnnotationNoteCreator.js | 8 +++--- .../osparc/notification/NotificationUI.js | 27 ++++++++++--------- .../source/class/osparc/store/Groups.js | 4 +-- .../class/osparc/workbench/WorkbenchUI.js | 18 ++++++------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js index 9567a19f3e8..4ff7706695f 100644 --- a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js +++ b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js @@ -143,10 +143,10 @@ qx.Class.define("osparc.editor.AnnotationNoteCreator", { __setRecipientGid: function(gid) { this.setRecipientGid(gid); // only users were proposed - osparc.store.Groups.getInstance().fetchGroup(gid) - .then(user => { - this.getChildControl("selected-recipient").setValue(user.label); - }); + const user = osparc.store.Groups.getInstance().getUserByGroupId(gid); + if (user) { + this.getChildControl("selected-recipient").setValue(user.getLabel()); + } } } }); diff --git a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js index 386ed34e9f7..f339a68bf06 100644 --- a/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js +++ b/services/static-webserver/client/source/class/osparc/notification/NotificationUI.js @@ -134,9 +134,12 @@ qx.Class.define("osparc.notification.NotificationUI", { case "NEW_ORGANIZATION": icon.setSource("@FontAwesome5Solid/users/14"); if (resourceId) { - osparc.store.Groups.getInstance().fetchGroup(resourceId) - .then(group => descriptionLabel.setValue("You're now member of '" + group.getLabel() + "'")) - .catch(() => this.setEnabled(false)); + const org = osparc.store.Groups.getInstance().getOrganization(resourceId); + if (org) { + descriptionLabel.setValue("You're now member of '" + org.getLabel() + "'") + } else { + this.setEnabled(false); + } } break; case "STUDY_SHARED": @@ -264,16 +267,14 @@ qx.Class.define("osparc.notification.NotificationUI", { __openOrganizationDetails: function(orgId) { // make sure org is available - osparc.store.Groups.getInstance().fetchGroup(orgId) - .then(org => { - if (org) { - const orgsWindow = osparc.desktop.organizations.OrganizationsWindow.openWindow(); - orgsWindow.openOrganizationDetails(orgId); - } else { - const msg = this.tr("You don't have access anymore"); - osparc.FlashMessenger.getInstance().logAs(msg, "WARNING"); - } - }); + const org = osparc.store.Groups.getInstance().getOrganization(orgId) + if (org) { + const orgsWindow = osparc.desktop.organizations.OrganizationsWindow.openWindow(); + orgsWindow.openOrganizationDetails(orgId); + } else { + const msg = this.tr("You don't have access anymore"); + osparc.FlashMessenger.getInstance().logAs(msg, "WARNING"); + } }, __openStudyDetails: function(studyId, notification) { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 6268af0ccc7..d37f02d945c 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -215,8 +215,8 @@ qx.Class.define("osparc.store.Groups", { getOrganization: function(groupId) { if (groupId) { - const visibleMembers = this.getOrganizations(); - return Object.values(visibleMembers).find(member => member.getGroupId() === groupId); + const orgs = this.getOrganizations(); + return Object.values(orgs).find(org => org.getGroupId() === groupId); } return null; }, diff --git a/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js b/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js index 9a964374df0..0bde129f15e 100644 --- a/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js +++ b/services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js @@ -1935,16 +1935,14 @@ qx.Class.define("osparc.workbench.WorkbenchUI", { const win = osparc.editor.AnnotationNoteCreator.popUpInWindow(noteEditor); noteEditor.addListener("addNote", () => { const gid = noteEditor.getRecipientGid(); - osparc.store.Groups.getInstance().fetchGroup(gid) - .then(user => { - serializeData.attributes.recipientGid = gid; - serializeData.attributes.text = noteEditor.getNote(); - if (user) { - osparc.notification.Notifications.postNewAnnotationNote(user.id, this.getStudy().getUuid()); - } - this.__addAnnotation(serializeData); - }) - .finally(() => win.close()); + serializeData.attributes.recipientGid = gid; + serializeData.attributes.text = noteEditor.getNote(); + const user = osparc.store.Groups.getInstance().getUserByGroupId(gid) + if (user) { + osparc.notification.Notifications.postNewAnnotationNote(user.getUserId(), this.getStudy().getUuid()); + } + this.__addAnnotation(serializeData); + win.close(); }, this); noteEditor.addListener("cancel", () => win.close()); } else if (type === "rect") { From 706ff1fa36eff9e44026824d1241d8aed73d672b Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 09:55:26 +0100 Subject: [PATCH 25/59] reachable users --- .../source/class/osparc/dashboard/CardBase.js | 2 +- .../client/source/class/osparc/store/Groups.js | 14 +++++++------- .../client/source/class/osparc/store/Store.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js index db29b945549..acb3fe35386 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -217,7 +217,7 @@ qx.Class.define("osparc.dashboard.CardBase", { // groups -> [orgMembs, orgs, [productEveryone], [everyone]]; populateShareIcon: function(shareIcon, accessRights) { const groupsStore = osparc.store.Groups.getInstance(); - const orgMembs = Object.values(groupsStore.getReachableMembers()); + const orgMembs = Object.values(groupsStore.getReachableUsers()); const orgs = Object.values(groupsStore.getOrganizations()); const productEveryone = [groupsStore.getEveryoneProductGroup()]; const everyone = [groupsStore.getEveryoneGroup()]; diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index d37f02d945c..c821d650b20 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -47,7 +47,7 @@ qx.Class.define("osparc.store.Groups", { init: {} }, - reachableMembers: { + reachableUsers: { check: "Object", init: {} }, @@ -112,7 +112,7 @@ qx.Class.define("osparc.store.Groups", { orgMembers.forEach(orgMember => { const user = new osparc.data.model.User(orgMember); group.getGroupMembers()[orgMember["gid"]] = user; - this.getReachableMembers()[orgMember["gid"]] = user; + this.getReachableUsers()[orgMember["gid"]] = user; }); } }); @@ -122,7 +122,7 @@ qx.Class.define("osparc.store.Groups", { return new Promise(resolve => { this.__fetchGroups() .then(orgs => { - this.resetReachableMembers(); + this.resetReachableUsers(); const promises = Object.keys(orgs).map(orgId => this.__fetchGroupMembers(orgId)); Promise.all(promises) .then(() => resolve()) @@ -146,7 +146,7 @@ qx.Class.define("osparc.store.Groups", { groupMe["collabType"] = 2; groups.push(groupMe); - Object.values(this.getReachableMembers()).forEach(member => { + Object.values(this.getReachableUsers()).forEach(member => { member["collabType"] = 2; groups.push(member); }); @@ -191,7 +191,7 @@ qx.Class.define("osparc.store.Groups", { potentialCollaborators[org.getGroupId()] = org; } }); - const members = this.getReachableMembers(); + const members = this.getReachableUsers(); for (const gid of Object.keys(members)) { members[gid]["collabType"] = 2; potentialCollaborators[gid] = members[gid]; @@ -223,7 +223,7 @@ qx.Class.define("osparc.store.Groups", { getUserByUserId: function(userId) { if (userId) { - const visibleMembers = this.getReachableMembers(); + const visibleMembers = this.getReachableUsers(); return Object.values(visibleMembers).find(member => member.getUserId() === userId); } return null; @@ -231,7 +231,7 @@ qx.Class.define("osparc.store.Groups", { getUserByGroupId: function(groupId) { if (groupId) { - const visibleMembers = this.getReachableMembers(); + const visibleMembers = this.getReachableUsers(); return Object.values(visibleMembers).find(member => member.getGroupId() === groupId); } return null; diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index 17d79a9cfcd..ada86765e4f 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -182,7 +182,7 @@ qx.Class.define("osparc.store.Store", { check: "Object", init: {} }, - reachableMembers: { + reachableUsers: { check: "Object", init: {} }, From b100155818b9dd4932ab992c0ebd6333dfea3890 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 09:57:19 +0100 Subject: [PATCH 26/59] [skip ci] cleanup --- .../client/source/class/osparc/store/Store.js | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Store.js b/services/static-webserver/client/source/class/osparc/store/Store.js index ada86765e4f..d2c2d24104e 100644 --- a/services/static-webserver/client/source/class/osparc/store/Store.js +++ b/services/static-webserver/client/source/class/osparc/store/Store.js @@ -174,26 +174,6 @@ qx.Class.define("osparc.store.Store", { check: "Array", init: [] }, - organizations: { - check: "Object", - init: {} - }, - organizationMembers: { - check: "Object", - init: {} - }, - reachableUsers: { - check: "Object", - init: {} - }, - everyoneProductGroup: { - check: "Object", - init: {} - }, - everyoneGroup: { - check: "Object", - init: {} - }, clusters: { check: "Array", init: [], From 9682ea82c31c0a48ede26dd307f14b35b5e088c2 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 10:05:27 +0100 Subject: [PATCH 27/59] [skip ci] more refactoring --- .../dashboard/ResourceContainerManager.js | 16 ++--- .../class/osparc/share/CollaboratorsStudy.js | 5 +- .../osparc/share/CollaboratorsWorkspace.js | 5 +- .../class/osparc/share/ShareePermissions.js | 64 +++++++++---------- .../source/class/osparc/store/Groups.js | 12 +--- .../class/osparc/workbench/Annotation.js | 4 +- 6 files changed, 48 insertions(+), 58 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js index 2c1c119ca36..ba1485f024f 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js @@ -475,21 +475,21 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", { if (groupContainer === null) { groupContainer = this.__createGroupContainer(orgId, "loading-label"); const groupsStore = osparc.store.Groups.getInstance(); - const org = groupsStore.getOrganizationOrUser(orgId); - if (org) { + const group = groupsStore.getGroup(orgId); + if (group) { let icon = ""; - if (org.getThumbnail()) { - icon = org.getThumbnail(); - } else if (org["collabType"] === 0) { + if (group.getThumbnail()) { + icon = group.getThumbnail(); + } else if (group["collabType"] === 0) { icon = "@FontAwesome5Solid/globe/24"; - } else if (org["collabType"] === 1) { + } else if (group["collabType"] === 1) { icon = "@FontAwesome5Solid/users/24"; - } else if (org["collabType"] === 2) { + } else if (group["collabType"] === 2) { icon = "@FontAwesome5Solid/user/24"; } groupContainer.set({ headerIcon: icon, - headerLabel: org.getLabel(), + headerLabel: group.getLabel(), }); } else { groupContainer.exclude(); diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index d02199889bd..3936b2f2856 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -226,9 +226,8 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { ); }; - const groupData = await osparc.store.Store.getInstance().fetchGroup(groupId); - const isOrganization = (groupData && !("id" in groupData)); - if (isOrganization) { + const organization = osparc.store.Groups.getInstance().getOrganization(groupId); + if (organization) { const msg = this.tr(`Demoting to ${osparc.data.Roles.STUDY[1].label} will remove write access to all the members of the Organization. Are you sure?`); const win = new osparc.ui.window.Confirmation(msg).set({ caption: this.tr("Demote"), diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js index 67b53e125b0..97dd58bc573 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js @@ -157,9 +157,8 @@ qx.Class.define("osparc.share.CollaboratorsWorkspace", { ); }; - const groupData = await osparc.store.Groups.getInstance().fetchGroup(groupId); - const isOrganization = (groupData && !("id" in groupData)); - if (isOrganization) { + const group = osparc.store.Groups.getInstance().getOrganization(groupId); + if (group) { const msg = this.tr(`Demoting to ${osparc.data.Roles.WORKSPACE[1].label} will remove write access to all the members of the Organization. Are you sure?`); const win = new osparc.ui.window.Confirmation(msg).set({ caption: this.tr("Demote"), diff --git a/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js b/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js index 790d04dac5f..bc8c92cbe99 100644 --- a/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js +++ b/services/static-webserver/client/source/class/osparc/share/ShareePermissions.js @@ -33,42 +33,40 @@ qx.Class.define("osparc.share.ShareePermissions", { this._add(layout); for (let i=0; i { - if (group) { - layout.add(new qx.ui.basic.Label(group.label), { - row: i, - column: 0 - }); + const group = osparc.store.Groups.getInstance().getGroup(shareeData.gid); + if (group) { + layout.add(new qx.ui.basic.Label(group.getLabel()), { + row: i, + column: 0 + }); - const vBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(8)); - shareeData["inaccessible_services"].forEach(inaccessibleService => { - const hBox = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)).set({ - alignY: "middle" - }); - const infoButton = new qx.ui.form.Button(null, "@MaterialIcons/info_outline/14"); - infoButton.setAppearance("strong-button"); - const label = new qx.ui.basic.Label(); - hBox.add(infoButton); - hBox.add(label); - osparc.store.Services.getService(inaccessibleService.key, inaccessibleService.version) - .then(metadata => { - label.setValue(metadata["name"] + " : " + metadata["version"]) - infoButton.addListener("execute", () => { - metadata["resourceType"] = "service"; - const resourceDetails = new osparc.dashboard.ResourceDetails(metadata); - osparc.dashboard.ResourceDetails.popUpInWindow(resourceDetails); - }, this); - }) + const vBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(8)); + shareeData["inaccessible_services"].forEach(inaccessibleService => { + const hBox = new qx.ui.container.Composite(new qx.ui.layout.HBox(5)).set({ + alignY: "middle" + }); + const infoButton = new qx.ui.form.Button(null, "@MaterialIcons/info_outline/14"); + infoButton.setAppearance("strong-button"); + const label = new qx.ui.basic.Label(); + hBox.add(infoButton); + hBox.add(label); + osparc.store.Services.getService(inaccessibleService.key, inaccessibleService.version) + .then(metadata => { + label.setValue(metadata["name"] + " : " + metadata["version"]) + infoButton.addListener("execute", () => { + metadata["resourceType"] = "service"; + const resourceDetails = new osparc.dashboard.ResourceDetails(metadata); + osparc.dashboard.ResourceDetails.popUpInWindow(resourceDetails); + }, this); + }) - vBox.add(hBox); - }); - layout.add(vBox, { - row: i, - column: 1 - }); - } + vBox.add(hBox); + }); + layout.add(vBox, { + row: i, + column: 1 }); + } } } } diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index c821d650b20..4ea4e112d30 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -139,7 +139,7 @@ qx.Class.define("osparc.store.Groups", { return Object.keys(this.getOrganizations()); }, - __getAllGroups: function() { + getGroup: function(groupId) { const groups = []; const groupMe = this.getGroupMe(); @@ -163,15 +163,9 @@ qx.Class.define("osparc.store.Groups", { const groupEveryone = this.getEveryoneGroup(); groupEveryone["collabType"] = 0; groups.push(groupEveryone); - - return groups; - }, - - getOrganizationOrUser: function(groupId) { - const orgs = this.__getAllGroups(); - const idx = orgs.findIndex(org => org.getGroupId() === parseInt(groupId)); + const idx = groups.findIndex(group => group.getGroupId() === parseInt(groupId)); if (idx > -1) { - return orgs[idx]; + return groups[idx]; } return null; }, diff --git a/services/static-webserver/client/source/class/osparc/workbench/Annotation.js b/services/static-webserver/client/source/class/osparc/workbench/Annotation.js index a1305129fb2..7444094680a 100644 --- a/services/static-webserver/client/source/class/osparc/workbench/Annotation.js +++ b/services/static-webserver/client/source/class/osparc/workbench/Annotation.js @@ -96,8 +96,8 @@ qx.Class.define("osparc.workbench.Annotation", { let representation = null; switch (this.getType()) { case "note": { - const user = await osparc.store.Groups.getInstance().fetchGroup(attrs.recipientGid); - representation = this.__svgLayer.drawAnnotationNote(attrs.x, attrs.y, user ? user.label : "", attrs.text); + const user = osparc.store.Groups.getInstance().getUserByGroupId(attrs.recipientGid); + representation = this.__svgLayer.drawAnnotationNote(attrs.x, attrs.y, user ? user.getLabel() : "", attrs.text); break; } case "rect": From 99882dd721549e6d14bb251bd2e380ffd1b2b00a Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 11:25:34 +0100 Subject: [PATCH 28/59] minor --- .../source/class/osparc/ui/list/ListItemWithMenu.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/ui/list/ListItemWithMenu.js b/services/static-webserver/client/source/class/osparc/ui/list/ListItemWithMenu.js index 4d9d1d054bb..ba4164c9205 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/ListItemWithMenu.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/ListItemWithMenu.js @@ -91,14 +91,20 @@ qx.Class.define("osparc.ui.list.ListItemWithMenu", { const accessRights = this.getAccessRights(); const role = this.getChildControl("role"); if ( - "getDelete" in accessRights && accessRights.getDelete() + "getDelete" in accessRights && accessRights.getDelete() || + "delete" in accessRights && accessRights["delete"] ) { role.setValue(osparc.data.Roles.ORG[3].label); - } else if ("getWrite" in accessRights && accessRights.getWrite()) { + } else if ( + "getWrite" in accessRights && accessRights.getWrite() || + "write" in accessRights && accessRights["write"] + ) { role.setValue(osparc.data.Roles.ORG[2].label); } else if ( ("getRead" in accessRights && accessRights.getRead()) || - ("getExecute" in accessRights && accessRights.getExecute()) + ("getExecute" in accessRights && accessRights.getExecute()) || + ("read" in accessRights && accessRights["read"]) || + ("execute" in accessRights && accessRights["execute"]) ) { role.setValue(osparc.data.Roles.ORG[1].label); } else { From c1958b2bf0102818e8ec0a1d04f0071affe55626 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 11:25:47 +0100 Subject: [PATCH 29/59] minor --- .../client/source/class/osparc/store/Groups.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 4ea4e112d30..4758c3f9f80 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -106,7 +106,7 @@ qx.Class.define("osparc.store.Groups", { }; return osparc.data.Resources.get("organizationMembers", params) .then(orgMembers => { - const group = this.getOrganizations()[groupId]; + const group = this.getOrganization(groupId); if (group) { group.setGroupMembers({}); orgMembers.forEach(orgMember => { @@ -208,9 +208,8 @@ qx.Class.define("osparc.store.Groups", { }, getOrganization: function(groupId) { - if (groupId) { - const orgs = this.getOrganizations(); - return Object.values(orgs).find(org => org.getGroupId() === groupId); + if (groupId && groupId in this.getOrganizations()) { + return this.getOrganizations()[groupId]; } return null; }, From 5b5b0dfeff4f56c022c0f904410e917c1fec881c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 11:26:01 +0100 Subject: [PATCH 30/59] list group members --- .../desktop/organizations/MembersList.js | 154 +++++++++--------- 1 file changed, 76 insertions(+), 78 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index f28e781036c..a6080e6d216 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -151,8 +151,8 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { membersCtrl.setDelegate({ createItem: () => new osparc.ui.list.MemberListItem(), bindItem: (ctrl, item, id) => { - ctrl.bindProperty("id", "model", null, item, id); - ctrl.bindProperty("id", "key", null, item, id); + ctrl.bindProperty("groupId", "model", null, item, id); + ctrl.bindProperty("groupId", "key", null, item, id); ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("name", "title", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); @@ -225,83 +225,81 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { enabled: canIWrite }); - const params = { - url: { - "gid": organization.getGroupId() + const membersList = []; + const groupMembers = organization.getGroupMembers(); + Object.values(groupMembers).forEach(groupMember => { + const member = {}; + member["groupId"] = groupMember.getGroupId(); + member["thumbnail"] = groupMember.getThumbnail(); + member["name"] = groupMember.getLabel(); + member["login"] = groupMember.getLogin(); + member["accessRights"] = groupMember.getAccessRights(); + let options = []; + if (canIDelete) { + // admin... + if (groupMember.getAccessRights()["delete"]) { + // ...on admin + options = []; + } else if (groupMember.getAccessRights()["write"]) { + // ...on manager + options = [ + "promoteToAdministrator", + "demoteToMember", + "removeMember" + ]; + } else if (groupMember.getAccessRights()["read"]) { + // ...on member + options = [ + "promoteToManager", + "demoteToUser", + "removeMember" + ]; + } else if (!groupMember.getAccessRights()["read"]) { + // ...on user + options = [ + "promoteToMember", + "removeMember" + ]; + } + } else if (canIWrite) { + // manager... + if (groupMember.getAccessRights()["delete"]) { + // ...on admin + options = []; + } else if (groupMember.getAccessRights()["write"]) { + // ...on manager + options = []; + } else if (groupMember.getAccessRights()["read"]) { + // ...on member + options = [ + "promoteToManager", + "demoteToUser", + "removeMember" + ]; + } else if (!groupMember.getAccessRights()["read"]) { + // ...on user + options = [ + "promoteToMember", + "removeMember" + ]; + } } - }; - osparc.data.Resources.get("organizationMembers", params) - .then(members => { - const membersList = []; - members.forEach(member => { - member["thumbnail"] = osparc.utils.Avatar.getUrl(member["login"], 32); - member["name"] = osparc.utils.Utils.firstsUp(member["first_name"] || member["login"], member["last_name"] || ""); - let options = []; - if (canIDelete) { - // admin... - if (member["accessRights"]["delete"]) { - // ...on admin - options = []; - } else if (member["accessRights"]["write"]) { - // ...on manager - options = [ - "promoteToAdministrator", - "demoteToMember", - "removeMember" - ]; - } else if (member["accessRights"]["read"]) { - // ...on member - options = [ - "promoteToManager", - "demoteToUser", - "removeMember" - ]; - } else if (!member["accessRights"]["read"]) { - // ...on user - options = [ - "promoteToMember", - "removeMember" - ]; - } - } else if (canIWrite) { - // manager... - if (member["accessRights"]["delete"]) { - // ...on admin - options = []; - } else if (member["accessRights"]["write"]) { - // ...on manager - options = []; - } else if (member["accessRights"]["read"]) { - // ...on member - options = [ - "promoteToManager", - "demoteToUser", - "removeMember" - ]; - } else if (!member["accessRights"]["read"]) { - // ...on user - options = [ - "promoteToMember", - "removeMember" - ]; - } - } - // Let me go? - const openStudy = osparc.store.Store.getInstance().getCurrentStudy(); - if ( - openStudy === null && - canIWrite && - members.length > 1 && member["gid"] === osparc.auth.Data.getInstance().getGroupId() - ) { - options.push("leave"); - } - member["options"] = options; - member["showOptions"] = Boolean(options.length); - membersList.push(member); - }); - membersList.sort(this.self().sortOrgMembers); - membersList.forEach(member => membersModel.append(qx.data.marshal.Json.createModel(member))); - }); + // Let me go? + const openStudy = osparc.store.Store.getInstance().getCurrentStudy(); + const myGroupId = osparc.store.Groups.getInstance().getMyGroupId(); + if ( + openStudy === null && + canIWrite && + groupMembers.length > 1 && groupMember.getGroupId() === myGroupId + ) { + options.push("leave"); + } + member["options"] = options; + member["showOptions"] = Boolean(options.length); + membersList.push(member); + }); + membersList.sort(this.self().sortOrgMembers); + membersList.forEach(member => membersModel.append(qx.data.marshal.Json.createModel(member))); }, __addMember: async function(orgMemberEmail) { From c8f7c3edbc1257c18ccaa7c6689b7620fa4de965 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 11:27:37 +0100 Subject: [PATCH 31/59] unused --- .../osparc/filter/OrganizationMembers.js | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 services/static-webserver/client/source/class/osparc/filter/OrganizationMembers.js diff --git a/services/static-webserver/client/source/class/osparc/filter/OrganizationMembers.js b/services/static-webserver/client/source/class/osparc/filter/OrganizationMembers.js deleted file mode 100644 index 42e10a8bdb5..00000000000 --- a/services/static-webserver/client/source/class/osparc/filter/OrganizationMembers.js +++ /dev/null @@ -1,70 +0,0 @@ -/* ************************************************************************ - - osparc - the simcore frontend - - https://osparc.io - - Copyright: - 2020 IT'IS Foundation, https://itis.swiss - - License: - MIT: https://opensource.org/licenses/MIT - - Authors: - * Odei Maiz (odeimaiz) - -************************************************************************ */ - -/** - * Filter for members for the given organization. - */ -qx.Class.define("osparc.filter.OrganizationMembers", { - extend: osparc.filter.TagsFilter, - - /** - * Constructor for Organizations creates the filter and builds its menu. - * - * @extends osparc.filter.TagsFilter - */ - construct: function(filterGroupId) { - this.base(arguments, this.tr("Members"), "organizationMembers", filterGroupId); - }, - - properties: { - organizationId: { - check: "Number", - nullable: true, - apply: "_applyOrganizationId", - event: "changeOrganizationId" - } - }, - - members: { - _applyOrganizationId: function(orgId) { - this._removeAllOptions(); - const params = { - url: { - gid: orgId - } - }; - osparc.data.Resources.get("organizationMembers", params) - .then(members => { - members.sort((a, b) => (a["first_name"] > b["first_name"]) ? 1 : -1); - members.forEach(member => { - const name = osparc.utils.Utils.firstsUp(member["first_name"] || member["login"], member["last_name"] || ""); - const bnt = this._addOption(name); - bnt.uid = member["id"]; - }); - }); - }, - - getSelectedOrgMemberIDs: function() { - const selectedOrganizationMemberIDs = []; - const activeMenuButtons = this._getActiveMenuButtons(); - activeMenuButtons.forEach(activeMenuButton => { - selectedOrganizationMemberIDs.push(activeMenuButton.uid); - }); - return selectedOrganizationMemberIDs; - } - } -}); From 4b3d9d1d762804da0d9d14a5f4ec943e1c18ccac Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 11:43:32 +0100 Subject: [PATCH 32/59] listedMember --- .../desktop/organizations/MembersList.js | 163 +++++++----------- 1 file changed, 64 insertions(+), 99 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index a6080e6d216..27f9625086f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -167,36 +167,36 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { "border-radius": "16px" }); item.addListener("promoteToMember", e => { - const clusterMember = e.getData(); - this.__promoteToUser(clusterMember); + const listedMember = e.getData(); + this.__promoteToUser(listedMember); }); item.addListener("promoteToManager", e => { - const orgMember = e.getData(); - this.__promoteToManager(orgMember); + const listedMember = e.getData(); + this.__promoteToManager(listedMember); }); item.addListener("promoteToAdministrator", e => { - const orgMember = e.getData(); - this.__promoteToAdministrator(orgMember); + const listedMember = e.getData(); + this.__promoteToAdministrator(listedMember); }); item.addListener("demoteToUser", e => { - const clusterMember = e.getData(); - this.__demoteToRestrictedUser(clusterMember); + const listedMember = e.getData(); + this.__demoteToRestrictedUser(listedMember); }); item.addListener("demoteToMember", e => { - const orgMember = e.getData(); - this.__demoteToMember(orgMember); + const listedMember = e.getData(); + this.__demoteToMember(listedMember); }); item.addListener("demoteToManager", e => { - const orgMember = e.getData(); - this.__demoteToManager(orgMember); + const listedMember = e.getData(); + this.__demoteToManager(listedMember); }); item.addListener("removeMember", e => { - const orgMember = e.getData(); - this.__deleteMember(orgMember); + const listedMember = e.getData(); + this.__deleteMember(listedMember); }); item.addListener("leaveResource", e => { - const orgMember = e.getData(); - this.__deleteMyself(orgMember); + const listedMember = e.getData(); + this.__deleteMyself(listedMember); }); } }); @@ -307,8 +307,6 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const groupsStore = osparc.store.Groups.getInstance(); - const productEveryone = groupsStore.getEveryoneProductGroup(); const orgId = this.__currentOrg.getGroupId(); const params = { url: { @@ -319,41 +317,14 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { } }; osparc.data.Resources.fetch("organizationMembers", "post", params) - .then(() => { + .then(newMember => { const text = orgMemberEmail + this.tr(" successfully added"); - if (productEveryone && productEveryone["gid"] === parseInt(orgId)) { - // demote the new member to user - const params2 = { - url: { - "gid": orgId - } - }; - osparc.data.Resources.get("organizationMembers", params2) - .then(respOrgMembers => { - const newMember = respOrgMembers.find(m => m["login"] === orgMemberEmail); - if (newMember) { - this.__demoteToRestrictedUser(newMember, text); - } - }); - } else { - osparc.FlashMessenger.getInstance().logAs(text); - osparc.store.Store.getInstance().reset("organizationMembers"); - this.__reloadOrgMembers(); - - // push 'NEW_ORGANIZATION' notification - const params2 = { - url: { - "gid": orgId - } - }; - osparc.data.Resources.get("organizationMembers", params2) - .then(respOrgMembers => { - const newMember = respOrgMembers.find(m => m["login"] === orgMemberEmail); - if (newMember) { - osparc.notification.Notifications.postNewOrganization(newMember["id"], orgId); - } - }); - } + osparc.FlashMessenger.getInstance().logAs(text); + osparc.store.Store.getInstance().reset("organizationMembers"); + this.__reloadOrgMembers(); + + // push 'NEW_ORGANIZATION' notification + osparc.notification.Notifications.postNewOrganization(newMember.getUserId(), orgId); }) .catch(err => { const errorMessage = err["message"] || this.tr("Something went wrong adding the user"); @@ -362,7 +333,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __promoteToUser: function(orgMember) { + __promoteToUser: function(listedMember) { if (this.__currentOrg === null) { return; } @@ -370,7 +341,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": orgMember["id"] + "uid": listedMember["id"] }, data: { "accessRights": this.self().getReadAccess() @@ -388,7 +359,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __demoteToRestrictedUser: function(orgMember, msg) { + __demoteToRestrictedUser: function(listedMember, msg) { if (this.__currentOrg === null) { return; } @@ -396,7 +367,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": "id" in orgMember ? orgMember["id"] : orgMember["key"] + "uid": "id" in listedMember ? listedMember["id"] : listedMember["key"] }, data: { "accessRights": this.self().getNoReadAccess() @@ -417,7 +388,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __promoteToManager: function(orgMember) { + __promoteToManager: function(listedMember) { if (this.__currentOrg === null) { return; } @@ -425,7 +396,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": orgMember["id"] + "uid": listedMember["id"] }, data: { "accessRights": this.self().getWriteAccess() @@ -443,7 +414,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __promoteToAdministrator: function(orgMember) { + __promoteToAdministrator: function(listedMember) { if (this.__currentOrg === null) { return; } @@ -451,7 +422,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": orgMember["id"] + "uid": listedMember["id"] }, data: { "accessRights": this.self().getDeleteAccess() @@ -469,7 +440,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __demoteToMember: function(orgMember) { + __demoteToMember: function(listedMember) { if (this.__currentOrg === null) { return; } @@ -477,7 +448,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": orgMember["id"] + "uid": listedMember["id"] }, data: { "accessRights": this.self().getReadAccess() @@ -495,7 +466,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __demoteToManager: function(orgMember) { + __demoteToManager: function(listedMember) { if (this.__currentOrg === null) { return; } @@ -503,7 +474,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": orgMember["id"] + "uid": listedMember["id"] }, data: { "accessRights": this.self().getWriteAccess() @@ -521,30 +492,31 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __doDeleteMember: function(orgMember) { + __doDeleteMember: function(listedMember) { const params = { url: { "gid": this.__currentOrg.getGroupId(), - "uid": orgMember["id"] + "uid": listedMember["id"] } }; return osparc.data.Resources.fetch("organizationMembers", "delete", params) .then(() => { - osparc.FlashMessenger.getInstance().logAs(orgMember["name"] + this.tr(" successfully removed")); + // OM not sure + osparc.FlashMessenger.getInstance().logAs(listedMember["name"] + this.tr(" successfully removed")); osparc.store.Store.getInstance().reset("organizationMembers"); }) .catch(err => { - osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong removing ") + orgMember["name"], "ERROR"); + osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong removing ") + listedMember["name"], "ERROR"); console.error(err); }); }, - __deleteMember: function(orgMember) { + __deleteMember: function(listedMember) { if (this.__currentOrg === null) { return; } - this.__doDeleteMember(orgMember) + this.__doDeleteMember(listedMember) .then(() => this.__reloadOrgMembers()); }, @@ -553,36 +525,29 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId() + const members = this.__currentOrg.getGroupMembers() + const isThereAnyAdmin = members.some(member => member.getAccessRights()["delete"]); + const isThereAnyManager = members.some(member => member.getAccessRights()["write"]); + let rUSure = this.tr("Are you sure you want to leave?"); + if (isThereAnyAdmin) { + rUSure += `
There is no ${osparc.data.Roles.ORG[2].label} in this Organization.`; + } else if (isThereAnyManager) { + rUSure += `
There is no ${osparc.data.Roles.ORG[3].label} in this Organization.`; + } + rUSure += "

" + this.tr("If you Leave, the page will be reloaded."); + const confirmationWin = new osparc.ui.window.Confirmation(rUSure).set({ + caption: this.tr("Leave Organization"), + confirmText: this.tr("Leave"), + confirmAction: "delete" + }); + confirmationWin.center(); + confirmationWin.open(); + confirmationWin.addListener("close", () => { + if (confirmationWin.getConfirmed()) { + this.__doDeleteMember(orgMember) + .then(() => window.location.reload()); } - }; - osparc.data.Resources.get("organizationMembers", params) - .then(members => { - const isThereAnyAdmin = members.some(member => member["accessRights"]["delete"]); - const isThereAnyManager = members.some(member => member["accessRights"]["write"]); - let rUSure = this.tr("Are you sure you want to leave?"); - if (isThereAnyAdmin) { - rUSure += `
There is no ${osparc.data.Roles.ORG[2].label} in this Organization.`; - } else if (isThereAnyManager) { - rUSure += `
There is no ${osparc.data.Roles.ORG[3].label} in this Organization.`; - } - rUSure += "

" + this.tr("If you Leave, the page will be reloaded."); - const confirmationWin = new osparc.ui.window.Confirmation(rUSure).set({ - caption: this.tr("Leave Organization"), - confirmText: this.tr("Leave"), - confirmAction: "delete" - }); - confirmationWin.center(); - confirmationWin.open(); - confirmationWin.addListener("close", () => { - if (confirmationWin.getConfirmed()) { - this.__doDeleteMember(orgMember) - .then(() => window.location.reload()); - } - }, this); - }); + }, this); } } }); From 4c3149e8976dd3ca18d70b843d5bde8496d83c6f Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 11:58:22 +0100 Subject: [PATCH 33/59] unused --- .../client/source/class/osparc/store/Groups.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 4758c3f9f80..40ac81f8fba 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -230,24 +230,6 @@ qx.Class.define("osparc.store.Groups", { return null; }, - fetchGroup: function(gid) { - return new Promise(resolve => { - if (gid) { - this.getPotentialCollaborators() - .then(potentialCollaborators => { - let group = null; - if (gid in potentialCollaborators) { - group = potentialCollaborators[gid]; - } - resolve(group); - }) - .catch(() => resolve(null)); - } else { - resolve(null); - } - }); - }, - postGroup: function(name, parentGroupId = null, workspaceId = null) { const newGroupData = { name, From 7282d2444c74484d7c473da970f609f6315d58bd Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 12:38:36 +0100 Subject: [PATCH 34/59] postMember --- .../desktop/organizations/MembersList.js | 12 +----- .../source/class/osparc/store/Groups.js | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index 27f9625086f..a4322aa0a52 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -308,19 +308,11 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { } const orgId = this.__currentOrg.getGroupId(); - const params = { - url: { - "gid": orgId - }, - data: { - "email": orgMemberEmail - } - }; - osparc.data.Resources.fetch("organizationMembers", "post", params) + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.postMember(orgId, orgMemberEmail) .then(newMember => { const text = orgMemberEmail + this.tr(" successfully added"); osparc.FlashMessenger.getInstance().logAs(text); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); // push 'NEW_ORGANIZATION' notification diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 40ac81f8fba..920e21be3b3 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -108,11 +108,11 @@ qx.Class.define("osparc.store.Groups", { .then(orgMembers => { const group = this.getOrganization(groupId); if (group) { + // reset group's group members group.setGroupMembers({}); orgMembers.forEach(orgMember => { const user = new osparc.data.model.User(orgMember); - group.getGroupMembers()[orgMember["gid"]] = user; - this.getReachableUsers()[orgMember["gid"]] = user; + this.__addToUsersCache(user, groupId); }); } }); @@ -122,6 +122,7 @@ qx.Class.define("osparc.store.Groups", { return new Promise(resolve => { this.__fetchGroups() .then(orgs => { + // reset Reachable Users this.resetReachableUsers(); const promises = Object.keys(orgs).map(orgId => this.__fetchGroupMembers(orgId)); Promise.all(promises) @@ -286,6 +287,28 @@ qx.Class.define("osparc.store.Groups", { .catch(console.error); }, + postMember: function(orgId, newMemberEmail) { + const params = { + url: { + "gid": orgId + }, + data: { + "email": newMemberEmail + } + }; + osparc.data.Resources.fetch("organizationMembers", "post", params) + .then(newMember => { + const user = new osparc.data.model.User(newMember); + this.__addToUsersCache(user, orgId); + return user; + }) + .catch(err => { + const errorMessage = err["message"] || this.tr("Something went wrong adding the user"); + osparc.FlashMessenger.getInstance().logAs(errorMessage, "ERROR"); + console.error(err); + }); + }, + __addToGroupsCache: function(groupData, groupType) { let group = this.groupsCached.find(f => f.getGroupId() === groupData["gid"]); if (group) { @@ -313,6 +336,16 @@ qx.Class.define("osparc.store.Groups", { return true; } return false; + }, + + __addToUsersCache: function(user, orgId = null) { + if (orgId) { + const organization = this.getOrganization(orgId); + if (organization) { + organization.getGroupMembers()[user.getGroupId()] = user; + } + } + this.getReachableUsers()[user.getGroupId()] = user; } } }); From cd8718de8f283a307391192f07611aa8597f6746 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 12:52:47 +0100 Subject: [PATCH 35/59] removeMember --- .../desktop/organizations/MembersList.js | 17 +++------ .../source/class/osparc/store/Groups.js | 38 ++++++++++++++----- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index a4322aa0a52..36e271f73dc 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -151,8 +151,8 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { membersCtrl.setDelegate({ createItem: () => new osparc.ui.list.MemberListItem(), bindItem: (ctrl, item, id) => { - ctrl.bindProperty("groupId", "model", null, item, id); - ctrl.bindProperty("groupId", "key", null, item, id); + ctrl.bindProperty("userId", "model", null, item, id); + ctrl.bindProperty("userId", "key", null, item, id); ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("name", "title", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); @@ -229,6 +229,7 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { const groupMembers = organization.getGroupMembers(); Object.values(groupMembers).forEach(groupMember => { const member = {}; + member["userId"] = groupMember.getUserId(); member["groupId"] = groupMember.getGroupId(); member["thumbnail"] = groupMember.getThumbnail(); member["name"] = groupMember.getLabel(); @@ -485,17 +486,11 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }, __doDeleteMember: function(listedMember) { - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": listedMember["id"] - } - }; - return osparc.data.Resources.fetch("organizationMembers", "delete", params) + const groupsStore = osparc.store.Groups.getInstance(); + return groupsStore.removeMember(this.__currentOrg.getGroupId(), listedMember["id"]) .then(() => { - // OM not sure osparc.FlashMessenger.getInstance().logAs(listedMember["name"] + this.tr(" successfully removed")); - osparc.store.Store.getInstance().reset("organizationMembers"); + this.__reloadOrgMembers(); }) .catch(err => { osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong removing ") + listedMember["name"], "ERROR"); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 920e21be3b3..717617f0cea 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -290,22 +290,30 @@ qx.Class.define("osparc.store.Groups", { postMember: function(orgId, newMemberEmail) { const params = { url: { - "gid": orgId + "gid": parseInt(orgId) }, data: { "email": newMemberEmail } }; - osparc.data.Resources.fetch("organizationMembers", "post", params) + return osparc.data.Resources.fetch("organizationMembers", "post", params) .then(newMember => { const user = new osparc.data.model.User(newMember); - this.__addToUsersCache(user, orgId); + this.__addToUsersCache(parseInt(user), parseInt(orgId)); return user; - }) - .catch(err => { - const errorMessage = err["message"] || this.tr("Something went wrong adding the user"); - osparc.FlashMessenger.getInstance().logAs(errorMessage, "ERROR"); - console.error(err); + }); + }, + + removeMember: function(orgId, userId) { + const params = { + url: { + "gid": parseInt(orgId), + "uid": parseInt(userId), + } + }; + return osparc.data.Resources.fetch("organizationMembers", "delete", params) + .then(() => { + this.__removeUserFromCache(parseInt(userId), parseInt(orgId)); }); }, @@ -346,6 +354,18 @@ qx.Class.define("osparc.store.Groups", { } } this.getReachableUsers()[user.getGroupId()] = user; - } + }, + + __removeUserFromCache: function(userId, orgId) { + if (orgId) { + const organization = this.getOrganization(orgId); + if (organization) { + const groupMember = Object.values(organization.getGroupMembers()).find(user => user.getUserId() === userId); + if (groupMember) { + delete organization.getGroupMembers()[groupMember.getGroupId()] + } + } + } + }, } }); From 1548cad836daacebb2c1eecc054c05e55f85720a Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 13:30:22 +0100 Subject: [PATCH 36/59] postMember --- .../source/class/osparc/store/Groups.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 717617f0cea..0d6b9e8d855 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -288,19 +288,30 @@ qx.Class.define("osparc.store.Groups", { }, postMember: function(orgId, newMemberEmail) { + const gid = parseInt(orgId); const params = { url: { - "gid": parseInt(orgId) + "gid": gid }, data: { "email": newMemberEmail } }; return osparc.data.Resources.fetch("organizationMembers", "post", params) - .then(newMember => { - const user = new osparc.data.model.User(newMember); - this.__addToUsersCache(parseInt(user), parseInt(orgId)); - return user; + .then(() => { + // the backend doesn't return the user back, + // so fetch them all again and return the user + return this.__fetchGroupMembers(gid); + }) + .then(() => { + const org = this.getOrganization(gid); + if (org) { + const groupMember = Object.values(org.getGroupMembers()).find(user => user.getLogin() === newMemberEmail); + if (groupMember) { + return groupMember; + } + } + return null; }); }, From 4f7d4a7f5c7de3c9e55be2d3ef9b3a526a75ab11 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 13:42:37 +0100 Subject: [PATCH 37/59] patchAccessRights --- .../desktop/organizations/MembersList.js | 14 +---- .../source/class/osparc/store/Groups.js | 56 +++++++++++++++---- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index 36e271f73dc..e49697785e1 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -331,19 +331,11 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": listedMember["id"] - }, - data: { - "accessRights": this.self().getReadAccess() - } - }; - osparc.data.Resources.fetch("organizationMembers", "patch", params) + const newAccessRights = this.self().getReadAccess(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.patchMember(this.__currentOrg.getGroupId(), listedMember["id"], newAccessRights) .then(() => { osparc.FlashMessenger.getInstance().logAs(this.tr(`Successfully promoted to ${osparc.data.Roles.ORG[1].label}`)); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); }) .catch(err => { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 0d6b9e8d855..83ce3c139db 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -231,6 +231,22 @@ qx.Class.define("osparc.store.Groups", { return null; }, + getGroupMemberByUserId: function(orgId, userId) { + const org = this.getGroup(orgId); + if (org) { + return Object.values(org.getGroupMembers()).find(user => user.getUserId() === userId); + } + return null; + }, + + getGroupMemberByLogin: function(orgId, userEmail) { + const org = this.getGroup(orgId); + if (org) { + return Object.values(org.getGroupMembers()).find(user => user.getLogin() === userEmail); + } + return null; + }, + postGroup: function(name, parentGroupId = null, workspaceId = null) { const newGroupData = { name, @@ -304,12 +320,32 @@ qx.Class.define("osparc.store.Groups", { return this.__fetchGroupMembers(gid); }) .then(() => { - const org = this.getOrganization(gid); - if (org) { - const groupMember = Object.values(org.getGroupMembers()).find(user => user.getLogin() === newMemberEmail); - if (groupMember) { - return groupMember; - } + const groupMember = this.getGroupMemberByLogin(gid, newMemberEmail); + if (groupMember) { + return groupMember; + } + return null; + }); + }, + + patchAccessRights: function(orgId, userId, newAccessRights) { + const gid = parseInt(orgId); + const uid = parseInt(userId); + const params = { + url: { + gid, + uid, + }, + data: { + "accessRights": newAccessRights + } + }; + return osparc.data.Resources.fetch("organizationMembers", "patch", params) + .then(() => { + const groupMember = this.getGroupMemberByUserId(gid, uid); + if (groupMember) { + groupMember.setAccessRights(newAccessRights); + return groupMember; } return null; }); @@ -370,11 +406,9 @@ qx.Class.define("osparc.store.Groups", { __removeUserFromCache: function(userId, orgId) { if (orgId) { const organization = this.getOrganization(orgId); - if (organization) { - const groupMember = Object.values(organization.getGroupMembers()).find(user => user.getUserId() === userId); - if (groupMember) { - delete organization.getGroupMembers()[groupMember.getGroupId()] - } + const groupMember = this.getGroupMemberByUserId(orgId, userId) + if (organization && groupMember) { + delete organization.getGroupMembers()[groupMember.getGroupId()] } } }, From e35ecdcf69fc02fdfd184274dfd2ab5ad09897ab Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 13:47:27 +0100 Subject: [PATCH 38/59] patch working --- .../desktop/organizations/MembersList.js | 80 ++++++------------- 1 file changed, 25 insertions(+), 55 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index e49697785e1..b2e8bcda97f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js @@ -349,22 +349,16 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": "id" in listedMember ? listedMember["id"] : listedMember["key"] - }, - data: { - "accessRights": this.self().getNoReadAccess() - } - }; - osparc.data.Resources.fetch("organizationMembers", "patch", params) + const orgId = this.__currentOrg.getGroupId(); + const userId = "id" in listedMember ? listedMember["id"] : listedMember["key"] + const newAccessRights = this.self().getNoReadAccess(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.patchAccessRights(orgId, userId, newAccessRights) .then(() => { if (msg === undefined) { msg = this.tr(`Successfully demoted to ${osparc.data.Roles.ORG[0].label}`); } osparc.FlashMessenger.getInstance().logAs(msg); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); }) .catch(err => { @@ -378,19 +372,13 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": listedMember["id"] - }, - data: { - "accessRights": this.self().getWriteAccess() - } - }; - osparc.data.Resources.fetch("organizationMembers", "patch", params) + const orgId = this.__currentOrg.getGroupId(); + const userId = listedMember["id"]; + const newAccessRights = this.self().getWriteAccess(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.patchAccessRights(orgId, userId, newAccessRights) .then(() => { osparc.FlashMessenger.getInstance().logAs(this.tr(`Successfully promoted to ${osparc.data.Roles.ORG[2].label}`)); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); }) .catch(err => { @@ -404,19 +392,13 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": listedMember["id"] - }, - data: { - "accessRights": this.self().getDeleteAccess() - } - }; - osparc.data.Resources.fetch("organizationMembers", "patch", params) + const orgId = this.__currentOrg.getGroupId(); + const userId = listedMember["id"]; + const newAccessRights = this.self().getDeleteAccess(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.patchAccessRights(orgId, userId, newAccessRights) .then(() => { osparc.FlashMessenger.getInstance().logAs(this.tr(`Successfully promoted to ${osparc.data.Roles.ORG[3].label}`)); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); }) .catch(err => { @@ -430,19 +412,13 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": listedMember["id"] - }, - data: { - "accessRights": this.self().getReadAccess() - } - }; - osparc.data.Resources.fetch("organizationMembers", "patch", params) + const orgId = this.__currentOrg.getGroupId(); + const userId = listedMember["id"]; + const newAccessRights = this.self().getReadAccess(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.patchAccessRights(orgId, userId, newAccessRights) .then(() => { osparc.FlashMessenger.getInstance().logAs(this.tr(`Successfully demoted to ${osparc.data.Roles.ORG[1].label}`)); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); }) .catch(err => { @@ -456,19 +432,13 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGroupId(), - "uid": listedMember["id"] - }, - data: { - "accessRights": this.self().getWriteAccess() - } - }; - osparc.data.Resources.fetch("organizationMembers", "patch", params) + const orgId = this.__currentOrg.getGroupId(); + const userId = listedMember["id"]; + const newAccessRights = this.self().getWriteAccess(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.patchAccessRights(orgId, userId, newAccessRights) .then(() => { osparc.FlashMessenger.getInstance().logAs(this.tr(`Successfully demoted to ${osparc.data.Roles.ORG[3].label}`)); - osparc.store.Store.getInstance().reset("organizationMembers"); this.__reloadOrgMembers(); }) .catch(err => { From 1f4291e79461679175f7e2e4246fea5257b61c39 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 14:35:56 +0100 Subject: [PATCH 39/59] refactor --- .../source/class/osparc/data/model/Group.js | 26 +++++++++++++++++++ .../source/class/osparc/store/Groups.js | 11 ++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index bf7be7b1e0f..7c349179e18 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -87,6 +87,11 @@ qx.Class.define("osparc.data.model.Group", { }, }, + 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)); @@ -94,6 +99,27 @@ qx.Class.define("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(); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 83ce3c139db..08c81c0d247 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -234,7 +234,7 @@ qx.Class.define("osparc.store.Groups", { getGroupMemberByUserId: function(orgId, userId) { const org = this.getGroup(orgId); if (org) { - return Object.values(org.getGroupMembers()).find(user => user.getUserId() === userId); + return org.getGroupMemberByUserId(userId); } return null; }, @@ -242,7 +242,7 @@ qx.Class.define("osparc.store.Groups", { getGroupMemberByLogin: function(orgId, userEmail) { const org = this.getGroup(orgId); if (org) { - return Object.values(org.getGroupMembers()).find(user => user.getLogin() === userEmail); + return org.getGroupMemberByLogin(userEmail); } return null; }, @@ -397,7 +397,7 @@ qx.Class.define("osparc.store.Groups", { if (orgId) { const organization = this.getOrganization(orgId); if (organization) { - organization.getGroupMembers()[user.getGroupId()] = user; + organization.addGroupMember(user); } } this.getReachableUsers()[user.getGroupId()] = user; @@ -406,9 +406,8 @@ qx.Class.define("osparc.store.Groups", { __removeUserFromCache: function(userId, orgId) { if (orgId) { const organization = this.getOrganization(orgId); - const groupMember = this.getGroupMemberByUserId(orgId, userId) - if (organization && groupMember) { - delete organization.getGroupMembers()[groupMember.getGroupId()] + if (organization) { + organization.removeGroupMember(userId) } } }, From c02d07db99b04c5609923ca5d85fa03dd0c1036d Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 14:39:24 +0100 Subject: [PATCH 40/59] nMembers --- .../organizations/OrganizationDetails.js | 33 ++++++++++--------- .../organizations/OrganizationsList.js | 4 +-- .../osparc/ui/list/OrganizationListItem.js | 16 +++++++-- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index 31de19e1541..9675bd83d3f 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -41,27 +41,30 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { __templatesList: null, __servicesList: null, - setCurrentOrg: function(orgModel) { - if (orgModel === null) { + setCurrentOrg: function(organization) { + if (organization === null) { return; } - this.__orgModel = orgModel; + this.__orgModel = organization; const organizationListItem = this.__addOrganizationListItem(); - orgModel.bind("groupId", organizationListItem, "key"); - orgModel.bind("groupId", organizationListItem, "model"); - orgModel.bind("thumbnail", organizationListItem, "thumbnail"); - orgModel.bind("label", organizationListItem, "title"); - orgModel.bind("description", organizationListItem, "subtitle"); - orgModel.bind("groupMembers", organizationListItem, "role", { - converter: groupMembers => groupMembers ? Object.keys(groupMembers).length + this.tr(" members") : "-" - }); - orgModel.bind("accessRights", organizationListItem, "accessRights"); + organization.bind("groupId", organizationListItem, "key"); + organization.bind("groupId", organizationListItem, "model"); + organization.bind("thumbnail", organizationListItem, "thumbnail"); + organization.bind("label", organizationListItem, "title"); + organization.bind("description", organizationListItem, "subtitle"); + organization.bind("groupMembers", organizationListItem, "groupMembers"); + organization.bind("accessRights", organizationListItem, "accessRights"); + organizationListItem.updateNMembers(); + [ + "memberAdded", + "memberRemoved", + ].forEach(ev => organization.addListener(ev, () => organizationListItem.updateNMembers())); // set orgModel to the tab views - this.__membersList.setCurrentOrg(orgModel); - this.__templatesList.setCurrentOrg(orgModel); - this.__servicesList.setCurrentOrg(orgModel); + this.__membersList.setCurrentOrg(organization); + this.__templatesList.setCurrentOrg(organization); + this.__servicesList.setCurrentOrg(organization); }, __getTitleLayout: function() { diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js index 7986fd4b5b7..38b7bde9aae 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js @@ -135,9 +135,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("label", "title", null, item, id); ctrl.bindProperty("description", "subtitle", null, item, id); - ctrl.bindProperty("groupMembers", "role", { - converter: groupMembers => groupMembers ? Object.keys(groupMembers).length + this.tr(" members") : "-" - }, item, id); + ctrl.bindProperty("groupMembers", "groupMembers", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); }, configureItem: item => { diff --git a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js index c13c197e07d..0c6cc5ceef0 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js @@ -24,7 +24,14 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { init: true, nullable: false, event: "changeShowDeleteButton" - } + }, + + groupMembers: { + check: "Object", + nullable: true, + init: null, + event: "changeGroupMembers", + }, }, events: { @@ -39,6 +46,11 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { return; }, + updateNMembers: function() { + const roleText = this.getGroupMembers() ? Object.keys(this.getGroupMembers()).length + this.tr(" members") : "-"; + this.setRole(roleText); + }, + // overridden _getOptionsMenu: function() { let menu = null; @@ -89,6 +101,6 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { thumbnail.setSource(osparc.utils.Icons.everyone(osparc.ui.list.ListItemWithMenu.ICON_SIZE)); } } - } + }, } }); From 0be0661236367f255aea0d523d9518301cfb0f8f Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 14:41:17 +0100 Subject: [PATCH 41/59] working --- .../client/source/class/osparc/ui/list/OrganizationListItem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js index 0c6cc5ceef0..45ce402f79d 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/OrganizationListItem.js @@ -31,6 +31,7 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { nullable: true, init: null, event: "changeGroupMembers", + apply: "updateNMembers", }, }, From 5efca2a1cdf722f9bd80c40ecd646d4631ba353c Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 14:50:36 +0100 Subject: [PATCH 42/59] patchGroup --- .../organizations/OrganizationDetails.js | 18 +--------- .../source/class/osparc/store/Groups.js | 36 +++++++++++-------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index 9675bd83d3f..97819877ab0 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -113,27 +113,11 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - const params = { - url: { - "gid": groupId - }, - data: { - "label": name, - "description": description, - "thumbnail": thumbnail || null - } - }; - osparc.data.Resources.fetch("organizations", "patch", params) + osparc.store.Groups.getInstance().patchGroup(groupId, name, description, thumbnail) .then(() => { osparc.FlashMessenger.getInstance().logAs(name + this.tr(" successfully edited")); button.setFetching(false); win.close(); - osparc.store.Store.getInstance().reset("organizations"); - this.__orgModel.set({ - label: name, - description: description, - thumbnail: thumbnail || null - }); }) .catch(err => { osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong editing ") + name, "ERROR"); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 08c81c0d247..3815d778352 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -247,6 +247,7 @@ qx.Class.define("osparc.store.Groups", { return null; }, + // CRUD GROUP postGroup: function(name, parentGroupId = null, workspaceId = null) { const newGroupData = { name, @@ -281,28 +282,32 @@ qx.Class.define("osparc.store.Groups", { .catch(console.error); }, - putGroup: function(groupId, updateData) { - const group = this.getOrganization(groupId); - const oldParentGroupId = group.getParentGroupId(); + patchGroup: function(groupId, name, description, thumbnail) { const params = { - "url": { - groupId + url: { + "gid": groupId }, - data: updateData + data: { + "label": name, + "description": description, + "thumbnail": thumbnail || null + } }; - return osparc.data.Resources.getInstance().fetch("groups", "update", params) - .then(groupData => { - this.__addToGroupsCache(groupData); - if (updateData.parentGroupId !== oldParentGroupId) { - this.fireDataEvent("groupMoved", { - group, - oldParentGroupId, + return osparc.data.Resources.fetch("organizations", "patch", params) + .then(() => { + const organization = this.getOrganization(groupId); + if (organization) { + organization.set({ + label: name, + description: description, + thumbnail: thumbnail || null }); } - }) - .catch(console.error); + }); }, + // CRUD GROUP + // CRUD GROUP MEMBERS postMember: function(orgId, newMemberEmail) { const gid = parseInt(orgId); const params = { @@ -363,6 +368,7 @@ qx.Class.define("osparc.store.Groups", { this.__removeUserFromCache(parseInt(userId), parseInt(orgId)); }); }, + // CRUD GROUP MEMBERS __addToGroupsCache: function(groupData, groupType) { let group = this.groupsCached.find(f => f.getGroupId() === groupData["gid"]); From 30a0f2d00a08a1f4f55072f6c7db550083553c44 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 14:55:36 +0100 Subject: [PATCH 43/59] patch working --- .../desktop/organizations/OrganizationDetails.js | 2 +- .../desktop/organizations/OrganizationsList.js | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index 97819877ab0..18ef5cdcfe7 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -109,7 +109,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { }, __updateOrganization: function(win, button, orgEditor) { - const groupId = orgEditor.getGroupId(); + const groupId = orgEditor.getGid(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js index 38b7bde9aae..db290c7853c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js @@ -288,27 +288,15 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { }, __updateOrganization: function(win, button, orgEditor) { - const groupId = orgEditor.getGroupId(); + const groupId = orgEditor.getGid(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - const params = { - url: { - "gid": groupId - }, - data: { - "label": name, - "description": description, - "thumbnail": thumbnail || null - } - }; - osparc.data.Resources.fetch("organizations", "patch", params) + osparc.store.Groups.getInstance().patchGroup(groupId, name, description, thumbnail) .then(() => { osparc.FlashMessenger.getInstance().logAs(name + this.tr(" successfully edited")); button.setFetching(false); win.close(); - osparc.store.Store.getInstance().reset("organizations"); - this.reloadOrganizations(); }) .catch(err => { osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong editing ") + name, "ERROR"); From a3c21cbdff9addeb62c5497b667d967bb8e74398 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 16:45:01 +0100 Subject: [PATCH 44/59] post and delete organization --- .../organizations/OrganizationDetails.js | 2 +- .../organizations/OrganizationsList.js | 40 +++----------- .../source/class/osparc/store/Groups.js | 52 ++++++------------- 3 files changed, 25 insertions(+), 69 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js index 18ef5cdcfe7..8b3781d7a12 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js @@ -113,7 +113,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - osparc.store.Groups.getInstance().patchGroup(groupId, name, description, thumbnail) + osparc.store.Groups.getInstance().patchOrganization(groupId, name, description, thumbnail) .then(() => { osparc.FlashMessenger.getInstance().logAs(name + this.tr(" successfully edited")); button.setFetching(false); diff --git a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js index db290c7853c..ff773341ff0 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js @@ -224,19 +224,10 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { win.open(); win.addListener("close", () => { if (win.getConfirmed()) { - const params = { - url: { - "gid": orgKey - } - }; - osparc.data.Resources.fetch("organizations", "delete", params) + const groupsStore = osparc.store.Groups.getInstance(orgKey); + groupsStore.deleteOrganization(orgKey) .then(() => { - osparc.store.Store.getInstance().reset("organizations"); - // reload "profile", "organizations" are part of the information in this endpoint - osparc.data.Resources.getOne("profile", {}, null, false) - .then(() => { - this.reloadOrganizations(); - }); + this.reloadOrganizations(); }) .catch(err => { osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong deleting ") + name, "ERROR"); @@ -250,31 +241,16 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { }, __createOrganization: function(win, button, orgEditor) { - const groupId = orgEditor.getGroupId(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - const params = { - url: { - "gid": groupId - }, - data: { - "label": name, - "description": description, - "thumbnail": thumbnail || null - } - }; - osparc.data.Resources.fetch("organizations", "post", params) + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.postOrganization(name, description, thumbnail) .then(org => { osparc.FlashMessenger.getInstance().logAs(name + this.tr(" successfully created")); button.setFetching(false); - osparc.store.Store.getInstance().reset("organizations"); - // reload "profile", "organizations" are part of the information in this endpoint - osparc.data.Resources.getOne("profile", {}, null, false) - .then(() => { - // open it - this.reloadOrganizations(org["gid"]); - }); + // open it + this.reloadOrganizations(org.getGroupId()); }) .catch(err => { const errorMessage = err["message"] || this.tr("Something went wrong creating ") + name; @@ -292,7 +268,7 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - osparc.store.Groups.getInstance().patchGroup(groupId, name, description, thumbnail) + osparc.store.Groups.getInstance().patchOrganization(groupId, name, description, thumbnail) .then(() => { osparc.FlashMessenger.getInstance().logAs(name + this.tr(" successfully edited")); button.setFetching(false); diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 3815d778352..5d6d6fde858 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -23,7 +23,6 @@ qx.Class.define("osparc.store.Groups", { this.base(arguments); this.groupsCached = []; - this.usersCached = []; }, properties: { @@ -71,7 +70,6 @@ qx.Class.define("osparc.store.Groups", { members: { groupsCached: null, - usersCached: null, __fetchGroups: function() { if (osparc.auth.Data.getInstance().isGuest()) { @@ -248,41 +246,37 @@ qx.Class.define("osparc.store.Groups", { }, // CRUD GROUP - postGroup: function(name, parentGroupId = null, workspaceId = null) { + postOrganization: function(name, description, thumbnail) { const newGroupData = { - name, - parentGroupId, - workspaceId, + "label": name, + "description": description, + "thumbnail": thumbnail || null }; const params = { data: newGroupData }; return osparc.data.Resources.getInstance().fetch("groups", "post", params) .then(groupData => { - const group = this.__addToGroupsCache(groupData); - this.fireDataEvent("groupAdded", group); + const group = this.__addToGroupsCache(groupData, "organization"); + this.getOrganizations()[group.getGroupId()] = group; return group; }); }, - deleteGroup: function(groupId, workspaceId) { + deleteOrganization: function(groupId) { const params = { - "url": { - groupId + url: { + "gid": groupId } }; return osparc.data.Resources.getInstance().fetch("groups", "delete", params) .then(() => { - const group = this.getOrganization(groupId); - if (group) { - this.__deleteFromGroupsCache(groupId, workspaceId); - this.fireDataEvent("groupRemoved", group); - } - }) - .catch(console.error); + this.__deleteFromGroupsCache(groupId); + delete this.getOrganizations()[groupId]; + }); }, - patchGroup: function(groupId, name, description, thumbnail) { + patchOrganization: function(groupId, name, description, thumbnail) { const params = { url: { "gid": groupId @@ -372,16 +366,7 @@ qx.Class.define("osparc.store.Groups", { __addToGroupsCache: function(groupData, groupType) { let group = this.groupsCached.find(f => f.getGroupId() === groupData["gid"]); - if (group) { - const props = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group)); - // put - Object.keys(groupData).forEach(key => { - if (props.includes(key)) { - group.set(key, groupData[key]); - } - }); - } else { - // get and post + if (!group) { group = new osparc.data.model.Group(groupData).set({ groupType }); @@ -390,13 +375,8 @@ qx.Class.define("osparc.store.Groups", { return group; }, - __deleteFromGroupsCache: function(groupId, workspaceId) { - const idx = this.groupsCached.findIndex(f => f.getGroupId() === groupId); - if (idx > -1) { - this.groupsCached.splice(idx, 1); - return true; - } - return false; + __deleteFromGroupsCache: function(groupId) { + delete this.getOrganizations()[groupId]; }, __addToUsersCache: function(user, orgId = null) { From 32b9762e0798f6435425c7b80a77275693b9d7e8 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 16:54:39 +0100 Subject: [PATCH 45/59] [skip ci] working post and delete --- .../client/source/class/osparc/data/model/Group.js | 1 + .../source/class/osparc/editor/OrganizationEditor.js | 2 +- .../client/source/class/osparc/store/Groups.js | 10 +++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index 7c349179e18..4ab5a8da6f4 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -34,6 +34,7 @@ qx.Class.define("osparc.data.model.Group", { description: groupData.description, accessRights: groupData.accessRights, thumbnail: groupData.thumbnail, + groupMembers: {}, }); }, diff --git a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js index c9fbec3f8cd..d54eb22601a 100644 --- a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js +++ b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js @@ -41,7 +41,7 @@ qx.Class.define("osparc.editor.OrganizationEditor", { } else { const groupsStore = osparc.store.Groups.getInstance(); const orgs = groupsStore.getOrganizations(); - const existingNames = orgs.map(org => org.getLabel()); + const existingNames = Object.values(orgs).map(org => org.getLabel()); const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames) title.setValue(defaultName); } diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 5d6d6fde858..119a8886f0a 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -255,10 +255,14 @@ qx.Class.define("osparc.store.Groups", { const params = { data: newGroupData }; - return osparc.data.Resources.getInstance().fetch("groups", "post", params) + let group = null; + return osparc.data.Resources.fetch("organizations", "post", params) .then(groupData => { - const group = this.__addToGroupsCache(groupData, "organization"); + group = this.__addToGroupsCache(groupData, "organization"); this.getOrganizations()[group.getGroupId()] = group; + return this.__fetchGroupMembers(group.getGroupId()); + }) + .then(() => { return group; }); }, @@ -269,7 +273,7 @@ qx.Class.define("osparc.store.Groups", { "gid": groupId } }; - return osparc.data.Resources.getInstance().fetch("groups", "delete", params) + return osparc.data.Resources.fetch("organizations", "delete", params) .then(() => { this.__deleteFromGroupsCache(groupId); delete this.getOrganizations()[groupId]; From 20e35b5dd7e237f8a048de4867df0cad58a95bc5 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Thu, 21 Nov 2024 17:26:17 +0100 Subject: [PATCH 46/59] fix --- .../client/source/class/osparc/store/Groups.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 119a8886f0a..2706a2fe769 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -190,14 +190,9 @@ qx.Class.define("osparc.store.Groups", { potentialCollaborators[gid] = members[gid]; } if (includeMe) { - const myData = osparc.auth.Data.getInstance(); - const myGid = myData.getGroupId(); - potentialCollaborators[myGid] = { - "login": myData.getEmail(), - "first_name": myData.getFirstName(), - "last_name": myData.getLastName(), - "collabType": 2 - }; + const myGroup = this.getGroupMe(); + myGroup["collabType"] = 2; + potentialCollaborators[myGroup.getGroupId()] = myGroup; } if (includeProductEveryone && productEveryone) { productEveryone["collabType"] = 0; From 5cfb0d7cf3085f499bc1bce7df9f44828a92df95 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 09:54:13 +0100 Subject: [PATCH 47/59] wallet members list --- .../source/class/osparc/data/model/User.js | 8 ++++++- .../osparc/desktop/wallets/MembersList.js | 22 +++++++++---------- .../source/class/osparc/store/Groups.js | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index 4fa90dfaab8..7cad182cc1e 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -40,7 +40,7 @@ qx.Class.define("osparc.data.model.User", { groupId: userData.gid, label: label, login: userData.login, - thumbnail: osparc.utils.Avatar.getUrl(userData.login, 32), + thumbnail: this.self().emailToThumbnail(userData.login), accessRights: userData.accessRights, }); }, @@ -87,5 +87,11 @@ qx.Class.define("osparc.data.model.User", { init: "", event: "changeThumbnail", }, + }, + + statics: { + emailToThumbnail: function(email) { + return osparc.utils.Avatar.getUrl(email, 32) + }, } }); diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index 232bd3d21d2..24da6b52ed2 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -217,18 +217,16 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const gid = accessRights["gid"]; if (Object.prototype.hasOwnProperty.call(potentialCollaborators, parseInt(gid))) { const collab = potentialCollaborators[parseInt(gid)]; - // Do not override collaborator object - const collaborator = osparc.utils.Utils.deepCloneObject(collab); - if ("first_name" in collaborator) { - collaborator["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32); - collaborator["name"] = osparc.utils.Utils.firstsUp( - `${"first_name" in collaborator && collaborator["first_name"] != null ? - collaborator["first_name"] : collaborator["login"]}`, - `${"last_name" in collaborator && collaborator["last_name"] != null ? - collaborator["last_name"] : ""}` - ); - } - collaborator["accessRights"] = accessRights; + const collaborator = {}; + collaborator["groupId"] = collab.getGroupId(); + collaborator["thumbnail"] = collab.getThumbnail(); + collaborator["name"] = collab.getLabel(); + collaborator["login"] = "getLogin" in collab ? collab.getLogin() : ""; + collaborator["accessRights"] = { + read: accessRights["read"], + write: accessRights["write"], + delete: accessRights["delete"], + }; let options = []; if (canIWrite) { // accountant... diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 2706a2fe769..c4127d87550 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -90,8 +90,8 @@ qx.Class.define("osparc.store.Groups", { }); this.setEveryoneGroup(everyoneGroup); this.setEveryoneProductGroup(productEveryoneGroup); - this.setGroupMe(groupMe); this.setOrganizations(orgs); + this.setGroupMe(groupMe); return orgs; }); }, From 4d8f5ed5f80a5c7a4cc0a2bdbd2f8102d62bf9b6 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 10:05:13 +0100 Subject: [PATCH 48/59] minor --- .../source/class/osparc/desktop/wallets/MembersList.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index 24da6b52ed2..66094ba380c 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -214,9 +214,9 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(true); const canIWrite = wallet.getMyAccessRights()["write"]; wallet.getAccessRights().forEach(accessRights => { - const gid = accessRights["gid"]; - if (Object.prototype.hasOwnProperty.call(potentialCollaborators, parseInt(gid))) { - const collab = potentialCollaborators[parseInt(gid)]; + const gid = parseInt(accessRights["gid"]); + if (Object.prototype.hasOwnProperty.call(potentialCollaborators, gid)) { + const collab = potentialCollaborators[gid]; const collaborator = {}; collaborator["groupId"] = collab.getGroupId(); collaborator["thumbnail"] = collab.getThumbnail(); From 55ac409a36e2d47e6b037c80f710fbc9602ac9b3 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 10:10:13 +0100 Subject: [PATCH 49/59] Nicer wallet members list --- .../source/class/osparc/data/model/User.js | 19 ++++++++++++------- .../osparc/desktop/wallets/MembersList.js | 2 +- .../osparc/desktop/wallets/WalletListItem.js | 1 + .../source/class/osparc/store/Groups.js | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js index 7cad182cc1e..b3c03d837c6 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/User.js +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -28,13 +28,7 @@ qx.Class.define("osparc.data.model.User", { construct: function(userData) { this.base(arguments); - let label = userData["login"]; - if ("first_name" in userData && userData["first_name"]) { - label = osparc.utils.Utils.firstsUp(userData["first_name"]); - if (userData["last_name"]) { - label += " " + osparc.utils.Utils.firstsUp(userData["last_name"]); - } - } + const label = this.self().namesToLabel(userData["first_name"], userData["last_name"]) || userData["login"]; this.set({ userId: userData.id, groupId: userData.gid, @@ -90,6 +84,17 @@ qx.Class.define("osparc.data.model.User", { }, statics: { + namesToLabel: function(firstName, lastName) { + let label = ""; + if (firstName) { + label = osparc.utils.Utils.firstsUp(firstName); + if (lastName) { + label += " " + osparc.utils.Utils.firstsUp(lastName); + } + } + return label; + }, + emailToThumbnail: function(email) { return osparc.utils.Avatar.getUrl(email, 32) }, diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index 66094ba380c..9d4be3e6885 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -221,7 +221,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { collaborator["groupId"] = collab.getGroupId(); collaborator["thumbnail"] = collab.getThumbnail(); collaborator["name"] = collab.getLabel(); - collaborator["login"] = "getLogin" in collab ? collab.getLogin() : ""; + collaborator["login"] = "getLogin" in collab ? collab.getLogin() : collab.getDescription(); collaborator["accessRights"] = { read: accessRights["read"], write: accessRights["write"], diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletListItem.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletListItem.js index 3e3f0e34e4e..e184975f3a3 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletListItem.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/WalletListItem.js @@ -64,6 +64,7 @@ qx.Class.define("osparc.desktop.wallets.WalletListItem", { }, events: { + "openShareWallet": "qx.event.type.Data", "openEditWallet": "qx.event.type.Data", "buyCredits": "qx.event.type.Data", "toggleFavourite": "qx.event.type.Data" diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index c4127d87550..148bac575d8 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -92,6 +92,12 @@ qx.Class.define("osparc.store.Groups", { this.setEveryoneProductGroup(productEveryoneGroup); this.setOrganizations(orgs); this.setGroupMe(groupMe); + const myAuthData = osparc.auth.Data.getInstance(); + groupMe.set({ + label: osparc.data.model.User.namesToLabel(myAuthData.getFirstName(), myAuthData.getLastName()), + description: myAuthData.getEmail(), + thumbnail: osparc.data.model.User.emailToThumbnail(myAuthData.getEmail()), + }) return orgs; }); }, From bdb72654e23d9cbcd76ab04dcc0d3380cf32f931 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 10:25:08 +0100 Subject: [PATCH 50/59] fix push wallet notifications --- .../osparc/desktop/wallets/MembersList.js | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js index 9d4be3e6885..da72d06c4e1 100644 --- a/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js +++ b/services/static-webserver/client/source/class/osparc/desktop/wallets/MembersList.js @@ -166,9 +166,9 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { membersCtrl.setDelegate({ createItem: () => new osparc.desktop.wallets.MemberListItem(), bindItem: (ctrl, item, id) => { - ctrl.bindProperty("id", "model", null, item, id); - ctrl.bindProperty("id", "key", null, item, id); - ctrl.bindProperty("gid", "gid", null, item, id); + ctrl.bindProperty("userId", "model", null, item, id); + ctrl.bindProperty("userId", "key", null, item, id); + ctrl.bindProperty("groupId", "gid", null, item, id); ctrl.bindProperty("thumbnail", "thumbnail", null, item, id); ctrl.bindProperty("name", "title", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); @@ -183,16 +183,16 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { "border-radius": "16px" }); item.addListener("promoteToAccountant", e => { - const walletMember = e.getData(); - this.__promoteToAccountant(walletMember); + const listedMember = e.getData(); + this.__promoteToAccountant(listedMember); }); item.addListener("demoteToMember", e => { - const walletMember = e.getData(); - this.__demoteToMember(walletMember); + const listedMember = e.getData(); + this.__demoteToMember(listedMember); }); item.addListener("removeMember", e => { - const walletMember = e.getData(); - this.__deleteMember(walletMember); + const listedMember = e.getData(); + this.__deleteMember(listedMember); }); } }); @@ -216,12 +216,14 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { wallet.getAccessRights().forEach(accessRights => { const gid = parseInt(accessRights["gid"]); if (Object.prototype.hasOwnProperty.call(potentialCollaborators, gid)) { + // only users or groupMe const collab = potentialCollaborators[gid]; const collaborator = {}; + collaborator["userId"] = gid === myGroupId ? osparc.auth.Data.getInstance().getUserId() : collab.getUserId(); collaborator["groupId"] = collab.getGroupId(); collaborator["thumbnail"] = collab.getThumbnail(); collaborator["name"] = collab.getLabel(); - collaborator["login"] = "getLogin" in collab ? collab.getLogin() : collab.getDescription(); + collaborator["login"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getLogin(); collaborator["accessRights"] = { read: accessRights["read"], write: accessRights["write"], @@ -287,7 +289,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); // push 'WALLET_SHARED' notification - const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators() + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(); gids.forEach(gid => { if (gid in potentialCollaborators && "getUserId" in potentialCollaborators[gid]) { // it's a user, not an organization @@ -298,7 +300,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); }, - __promoteToAccountant: function(walletMember) { + __promoteToAccountant: function(listedMember) { const wallet = this.__currentModel; if (wallet === null) { return; @@ -307,7 +309,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const params = { url: { "walletId": wallet.getWalletId(), - "groupId": walletMember["gid"] + "groupId": listedMember["gid"], }, data: this.self().getWriteAccess() }; @@ -318,7 +320,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); }, - __demoteToMember: function(walletMember) { + __demoteToMember: function(listedMember) { const wallet = this.__currentModel; if (wallet === null) { return; @@ -327,7 +329,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const params = { url: { "walletId": wallet.getWalletId(), - "groupId": walletMember["gid"] + "groupId": listedMember["gid"], }, data: this.self().getReadAccess() }; @@ -338,7 +340,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); }, - __deleteMember: function(walletMember) { + __deleteMember: function(listedMember) { const wallet = this.__currentModel; if (wallet === null) { return; @@ -347,7 +349,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { const params = { url: { "walletId": wallet.getWalletId(), - "groupId": walletMember["gid"] + "groupId": listedMember["gid"], } }; osparc.data.Resources.fetch("wallets", "deleteAccessRights", params) From cc4d5669bbfd492b37c0327f606a959289fc6427 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 10:34:43 +0100 Subject: [PATCH 51/59] fix notification --- .../source/class/osparc/notification/Notifications.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/notification/Notifications.js b/services/static-webserver/client/source/class/osparc/notification/Notifications.js index a34a0e2886c..788dcb5f79b 100644 --- a/services/static-webserver/client/source/class/osparc/notification/Notifications.js +++ b/services/static-webserver/client/source/class/osparc/notification/Notifications.js @@ -105,7 +105,7 @@ qx.Class.define("osparc.notification.Notifications", { const specNotification = { "category": "WALLET_SHARED", "actionable_path": "wallet/"+walletId, - "resource_id": walletId, + "resource_id": walletId.toString(), "title": "Credits shared", "text": "A Credit Account was shared with you" }; @@ -143,9 +143,9 @@ qx.Class.define("osparc.notification.Notifications", { return osparc.data.Resources.fetch("notifications", "post", params); }, - postNewWallet: function(userId, studyId) { + postNewWallet: function(userId, walletId) { const params = { - data: this.__newWalletObj(userId, studyId) + data: this.__newWalletObj(userId, walletId) }; return osparc.data.Resources.fetch("notifications", "post", params); }, From 4448bff5da0278d832633437f57145cbac7fcb5f Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:09:25 +0100 Subject: [PATCH 52/59] Share with everyone --- .../class/osparc/share/Collaborators.js | 11 +++++---- .../osparc/share/CollaboratorsService.js | 21 +++-------------- .../class/osparc/share/CollaboratorsStudy.js | 21 +++-------------- .../source/class/osparc/store/Groups.js | 23 +++++++++++++++++++ 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 4bb6dbf0787..de02804bf52 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -37,7 +37,7 @@ qx.Class.define("osparc.share.Collaborators", { this.__collaborators = {}; initCollabs.forEach(initCollab => { - this.__collaborators[initCollab["gid"]] = initCollab; + this.__collaborators[initCollab.getGroupId()] = initCollab; }); this.__getCollaborators(); }, @@ -402,15 +402,16 @@ qx.Class.define("osparc.share.Collaborators", { const groupsStore = osparc.store.Groups.getInstance(); const everyoneGIds = [ - groupsStore.getEveryoneProductGroup()["gid"], - groupsStore.getEveryoneGroup()["gid"] + groupsStore.getEveryoneProductGroup().getGroupId(), + groupsStore.getEveryoneGroup().getGroupId() ]; const accessRights = this._serializedDataCopy["accessRights"]; const collaboratorsList = []; const showOptions = this.__canIChangePermissions(); + const allGroupsAndUsers = groupsStore.getAllGroupsAndUsers(); Object.keys(accessRights).forEach(gid => { - if (Object.prototype.hasOwnProperty.call(this.__collaborators, gid)) { - const collab = this.__collaborators[gid]; + if (gid in allGroupsAndUsers) { + const collab = allGroupsAndUsers[gid]; // Do not override collaborator object const collaborator = { "gid": collab.getGroupId(), diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js index f6d2ec531c8..913bcb9a4ae 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js @@ -35,8 +35,9 @@ qx.Class.define("osparc.share.CollaboratorsService", { const serviceDataCopy = osparc.utils.Utils.deepCloneObject(serviceData); const initCollabs = []; - initCollabs.push(this.self().getEveryoneProductObj()); - initCollabs.push(this.self().getEveryoneObj()); + const groupsStore = osparc.store.Groups.getInstance(); + const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); + initCollabs.push(everyoneProductGroup); this.base(arguments, serviceDataCopy, initCollabs); }, @@ -64,22 +65,6 @@ qx.Class.define("osparc.share.CollaboratorsService", { "write": true }; }, - - getEveryoneProductObj: function() { - const groupsStore = osparc.store.Groups.getInstance(); - const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); - const everyone = osparc.utils.Utils.deepCloneObject(everyoneProductGroup); - everyone["accessRights"] = this.getCollaboratorAccessRight(); - return everyone; - }, - - getEveryoneObj: function() { - const groupsStore = osparc.store.Groups.getInstance(); - const everyoneGroup = groupsStore.getEveryoneGroup(); - const everyone = osparc.utils.Utils.deepCloneObject(everyoneGroup); - everyone["accessRights"] = this.getCollaboratorAccessRight(); - return everyone; - } }, members: { diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index 3936b2f2856..3d9b623c78d 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -37,8 +37,9 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { const initCollabs = []; if (osparc.data.Permissions.getInstance().canDo("study.everyone.share")) { - initCollabs.push(this.self().getEveryoneProductObj(this._resourceType === "study")); - initCollabs.push(this.self().getEveryoneObj(this._resourceType === "study")); + const groupsStore = osparc.store.Groups.getInstance(); + const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); + initCollabs.push(everyoneProductGroup); } this.base(arguments, studyDataCopy, initCollabs); @@ -105,22 +106,6 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { } return true; }, - - getEveryoneProductObj: function(isStudy) { - const groupsStore = osparc.store.Groups.getInstance(); - const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); - const everyone = osparc.utils.Utils.deepCloneObject(everyoneProductGroup); - everyone["accessRights"] = isStudy ? this.getCollaboratorAccessRight() : this.getViewerAccessRight(); - return everyone; - }, - - getEveryoneObj: function(isStudy) { - const groupsStore = osparc.store.Groups.getInstance(); - const everyoneGroup = groupsStore.getEveryoneGroup(); - const everyone = osparc.utils.Utils.deepCloneObject(everyoneGroup); - everyone["accessRights"] = isStudy ? this.getCollaboratorAccessRight() : this.getViewerAccessRight(); - return everyone; - } }, members: { diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index 148bac575d8..08ebcc2904c 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -136,6 +136,29 @@ qx.Class.define("osparc.store.Groups", { }) }, + getAllGroupsAndUsers: function() { + const allGroupsAndUsers = {}; + + const groupEveryone = this.getEveryoneGroup(); + allGroupsAndUsers[groupEveryone.getGroupId()] = groupEveryone; + + const groupProductEveryone = this.getEveryoneProductGroup(); + allGroupsAndUsers[groupProductEveryone.getGroupId()] = groupProductEveryone; + + const groupMe = this.getGroupMe(); + allGroupsAndUsers[groupMe.getGroupId()] = groupMe; + + Object.values(this.getOrganizations()).forEach(organization => { + allGroupsAndUsers[organization.getGroupId()] = organization; + }); + + Object.values(this.getReachableUsers()).forEach(reachableUser => { + allGroupsAndUsers[reachableUser.getGroupId()] = reachableUser; + }); + + return allGroupsAndUsers; + }, + getMyGroupId: function() { return this.getGroupMe().getGroupId(); }, From 5ab8d23da7869810fa3e6270eaa2400d4de90c0e Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:14:07 +0100 Subject: [PATCH 53/59] rename --- .../client/source/class/osparc/share/Collaborators.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index de02804bf52..7760de4e284 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -35,9 +35,9 @@ qx.Class.define("osparc.share.Collaborators", { this.__buildLayout(); - this.__collaborators = {}; + this.__potentialCollaborators = {}; initCollabs.forEach(initCollab => { - this.__collaborators[initCollab.getGroupId()] = initCollab; + this.__potentialCollaborators[initCollab.getGroupId()] = initCollab; }); this.__getCollaborators(); }, @@ -158,7 +158,7 @@ qx.Class.define("osparc.share.Collaborators", { _resourceType: null, __addCollaborators: null, __collaboratorsModel: null, - __collaborators: null, + __potentialCollaborators: null, _createChildControlImpl: function(id) { let control; @@ -341,8 +341,8 @@ qx.Class.define("osparc.share.Collaborators", { }, __getCollaborators: function() { - const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators() - this.__collaborators = Object.assign(this.__collaborators, potentialCollaborators); + const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(); + this.__potentialCollaborators = Object.assign(this.__potentialCollaborators, potentialCollaborators); this._reloadCollaboratorsList(); }, From f6855aa8699bf25781745bbb141746a68edf2a05 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:19:11 +0100 Subject: [PATCH 54/59] cleanup --- .../source/class/osparc/share/Collaborators.js | 13 +------------ .../class/osparc/share/CollaboratorsService.js | 7 +------ .../source/class/osparc/share/CollaboratorsStudy.js | 9 +-------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 7760de4e284..7129fb57b5d 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -35,11 +35,7 @@ qx.Class.define("osparc.share.Collaborators", { this.__buildLayout(); - this.__potentialCollaborators = {}; - initCollabs.forEach(initCollab => { - this.__potentialCollaborators[initCollab.getGroupId()] = initCollab; - }); - this.__getCollaborators(); + this._reloadCollaboratorsList(); }, events: { @@ -158,7 +154,6 @@ qx.Class.define("osparc.share.Collaborators", { _resourceType: null, __addCollaborators: null, __collaboratorsModel: null, - __potentialCollaborators: null, _createChildControlImpl: function(id) { let control; @@ -340,12 +335,6 @@ qx.Class.define("osparc.share.Collaborators", { return vBox; }, - __getCollaborators: function() { - const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(); - this.__potentialCollaborators = Object.assign(this.__potentialCollaborators, potentialCollaborators); - this._reloadCollaboratorsList(); - }, - __getLeaveStudyButton: function() { const myGid = osparc.auth.Data.getInstance().getGroupId(); if ( diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js index 913bcb9a4ae..bd16086cb27 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js @@ -34,12 +34,7 @@ qx.Class.define("osparc.share.CollaboratorsService", { this._resourceType = "service"; const serviceDataCopy = osparc.utils.Utils.deepCloneObject(serviceData); - const initCollabs = []; - const groupsStore = osparc.store.Groups.getInstance(); - const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); - initCollabs.push(everyoneProductGroup); - - this.base(arguments, serviceDataCopy, initCollabs); + this.base(arguments, serviceDataCopy); }, statics: { diff --git a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js index 3d9b623c78d..771a4284331 100644 --- a/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js +++ b/services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js @@ -35,14 +35,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { this._resourceType = studyData["resourceType"]; // study or template const studyDataCopy = osparc.data.model.Study.deepCloneStudyObject(studyData); - const initCollabs = []; - if (osparc.data.Permissions.getInstance().canDo("study.everyone.share")) { - const groupsStore = osparc.store.Groups.getInstance(); - const everyoneProductGroup = groupsStore.getEveryoneProductGroup(); - initCollabs.push(everyoneProductGroup); - } - - this.base(arguments, studyDataCopy, initCollabs); + this.base(arguments, studyDataCopy); }, statics: { From 80cf2e57ed1666b8cf9887b32945f760ddd79b74 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:24:59 +0100 Subject: [PATCH 55/59] org notification --- .../client/source/class/osparc/notification/Notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/notification/Notifications.js b/services/static-webserver/client/source/class/osparc/notification/Notifications.js index 788dcb5f79b..2d5a2de9318 100644 --- a/services/static-webserver/client/source/class/osparc/notification/Notifications.js +++ b/services/static-webserver/client/source/class/osparc/notification/Notifications.js @@ -39,7 +39,7 @@ qx.Class.define("osparc.notification.Notifications", { const specNotification = { "category": "NEW_ORGANIZATION", "actionable_path": "organization/"+orgId, - "resource_id": orgId, + "resource_id": orgId.toString(), "title": "New organization", "text": "You're now member of a new Organization" }; From 9f83b4163fbe5e3fbd450717c6d028434d43fa89 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:29:54 +0100 Subject: [PATCH 56/59] default thumbnail for org --- .../client/source/class/osparc/share/Collaborators.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/static-webserver/client/source/class/osparc/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 7129fb57b5d..283cf695ef3 100644 --- a/services/static-webserver/client/source/class/osparc/share/Collaborators.js +++ b/services/static-webserver/client/source/class/osparc/share/Collaborators.js @@ -411,10 +411,13 @@ qx.Class.define("osparc.share.Collaborators", { collaborator["name"] = collab.getLabel(); collaborator["login"] = collab.getLogin(); } else { + // org/group collaborator["label"] = collab.getLabel(); collaborator["description"] = collab.getDescription(); if (everyoneGIds.includes(parseInt(gid))) { collaborator["thumbnail"] = "@FontAwesome5Solid/globe/32"; + } else if (!collaborator["thumbnail"]) { + collaborator["thumbnail"] = "@FontAwesome5Solid/users/26"; } } collaborator["accessRights"] = accessRights[gid]; From 034aadb7205833b4632025301c5bfa6b2a05aa22 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:39:12 +0100 Subject: [PATCH 57/59] aesthetics --- .../source/class/osparc/ui/list/CollaboratorListItem.js | 8 ++++++++ .../client/source/class/osparc/ui/list/ListItem.js | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js index eb881568b38..8d19e51b7b0 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js @@ -18,6 +18,14 @@ qx.Class.define("osparc.ui.list.CollaboratorListItem", { extend: osparc.ui.list.ListItem, + construct: function() { + this.base(arguments); + + this.set({ + minHeight: 48 + }) + }, + properties: { collabType: { check: [0, 1, 2], // 0:all, 1:org, 2:user diff --git a/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js index e046f420805..ad24b0ce56a 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js @@ -50,9 +50,16 @@ qx.Class.define("osparc.ui.list.ListItem", { const layout = new qx.ui.layout.Grid(8, 1); layout.setColumnWidth(0, 32); + layout.setRowFlex(0, 1); layout.setColumnFlex(1, 1); + layout.setColumnAlign(0, "center", "middle"); + layout.setColumnAlign(2, "center", "middle"); this._setLayout(layout); - this.setPadding(5); + + this.set({ + padding: 5, + alignY: "middle", + }); this.addListener("pointerover", this._onPointerOver, this); this.addListener("pointerout", this._onPointerOut, this); From 2b40c9194c0763570959b7a1a8aaff2790c9e444 Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:40:58 +0100 Subject: [PATCH 58/59] last --- .../client/source/class/osparc/ui/list/ListItem.js | 1 + 1 file changed, 1 insertion(+) diff --git a/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js index ad24b0ce56a..5b45f066022 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/ListItem.js @@ -58,6 +58,7 @@ qx.Class.define("osparc.ui.list.ListItem", { this.set({ padding: 5, + minHeight: 48, alignY: "middle", }); From 7409c3caea8cdf24994cbe7ed79f3ff0c4c422bb Mon Sep 17 00:00:00 2001 From: Odei Maiz Date: Fri, 22 Nov 2024 11:41:04 +0100 Subject: [PATCH 59/59] II --- .../source/class/osparc/ui/list/CollaboratorListItem.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js b/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js index 8d19e51b7b0..eb881568b38 100644 --- a/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js +++ b/services/static-webserver/client/source/class/osparc/ui/list/CollaboratorListItem.js @@ -18,14 +18,6 @@ qx.Class.define("osparc.ui.list.CollaboratorListItem", { extend: osparc.ui.list.ListItem, - construct: function() { - this.base(arguments); - - this.set({ - minHeight: 48 - }) - }, - properties: { collabType: { check: [0, 1, 2], // 0:all, 1:org, 2:user