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 1b7a8fe6e82..acb3fe35386 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 store = osparc.store.Store.getInstance(); const everyoneGroupIds = [ - store.getEveryoneProductGroup()["gid"], - store.getEveryoneGroup()["gid"] + groupsStore.getEveryoneProductGroup().getGroupId(), + groupsStore.getEveryoneGroup().getGroupId(), ]; const found = Object.keys(checks).some(gId => everyoneGroupIds.includes(parseInt(gId))); return !found; @@ -168,7 +168,7 @@ qx.Class.define("osparc.dashboard.CardBase", { if (gid === myGroupId) { continue; } - const grp = groups[i].find(group => group["gid"] === gid); + const grp = groups[i].find(group => group.getGroupId() === gid); if (grp) { sharedGrp.push(grp); } @@ -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); } @@ -216,25 +216,13 @@ qx.Class.define("osparc.dashboard.CardBase", { // groups -> [orgMembs, orgs, [productEveryone], [everyone]]; populateShareIcon: function(shareIcon, accessRights) { - const store = osparc.store.Store.getInstance(); - Promise.all([ - store.getGroupEveryone(), - store.getProductEveryone(), - store.getReachableMembers(), - store.getGroupsOrganizations() - ]) - .then(values => { - const everyone = values[0] ? [values[0]] : []; - const productEveryone = values[1] ? [values[1]] : []; - const orgMembs = []; - const orgMembers = values[2]; - for (const gid of Object.keys(orgMembers)) { - orgMembs.push(orgMembers[gid]); - } - const orgs = values.length === 4 ? values[3] : []; - const groups = [orgMembs, orgs, productEveryone, everyone]; - osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups); - }); + const groupsStore = osparc.store.Groups.getInstance(); + const orgMembs = Object.values(groupsStore.getReachableUsers()); + const orgs = Object.values(groupsStore.getOrganizations()); + const productEveryone = [groupsStore.getEveryoneProductGroup()]; + const everyone = [groupsStore.getEveryoneGroup()]; + const groups = [orgMembs, orgs, productEveryone, everyone]; + osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups); }, }, 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..77595025bc4 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.fetchGroupsAndMembers()); 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..ba1485f024f 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceContainerManager.js @@ -474,29 +474,28 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", { let groupContainer = this.__getGroupContainer(orgId); if (groupContainer === null) { groupContainer = this.__createGroupContainer(orgId, "loading-label"); - osparc.store.Store.getInstance().getOrganizationOrUser(orgId) - .then(org => { - if (org && org["collabType"] !== 2) { - let icon = ""; - if (org.thumbnail) { - icon = org.thumbnail; - } else if (org["collabType"] === 0) { - icon = "@FontAwesome5Solid/globe/24"; - } else if (org["collabType"] === 1) { - icon = "@FontAwesome5Solid/users/24"; - } - groupContainer.set({ - headerIcon: icon, - headerLabel: org.label - }); - } else { - groupContainer.exclude(); - } - }) - .finally(() => { - this._add(groupContainer); - this.__moveNoGroupToLast(); + const groupsStore = osparc.store.Groups.getInstance(); + const group = groupsStore.getGroup(orgId); + if (group) { + let icon = ""; + if (group.getThumbnail()) { + icon = group.getThumbnail(); + } else if (group["collabType"] === 0) { + icon = "@FontAwesome5Solid/globe/24"; + } else if (group["collabType"] === 1) { + icon = "@FontAwesome5Solid/users/24"; + } else if (group["collabType"] === 2) { + icon = "@FontAwesome5Solid/user/24"; + } + groupContainer.set({ + headerIcon: icon, + headerLabel: group.getLabel(), }); + } else { + groupContainer.exclude(); + } + this._add(groupContainer); + this.__moveNoGroupToLast(); } const card = this.__createCard(resourceData); this.__addCardToContainer(card, groupContainer); 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", 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..4ab5a8da6f4 --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -0,0 +1,133 @@ +/* ************************************************************************ + + osparc - the simcore frontend + + https://osparc.io + + Copyright: + 2024 IT'IS Foundation, https://itis.swiss + + License: + MIT: https://opensource.org/licenses/MIT + + Authors: + * Odei Maiz (odeimaiz) + +************************************************************************ */ + +/** + * Class that stores Group data. + */ + +qx.Class.define("osparc.data.model.Group", { + extend: qx.core.Object, + + /** + * @param groupData {Object} Object containing the serialized Group Data + */ + construct: function(groupData) { + this.base(arguments); + + this.set({ + groupId: groupData.gid, + label: groupData.label, + description: groupData.description, + accessRights: groupData.accessRights, + thumbnail: groupData.thumbnail, + groupMembers: {}, + }); + }, + + properties: { + groupId: { + check: "Number", + nullable: false, + init: null, + event: "changeGroupId", + }, + + label: { + check: "String", + nullable: false, + init: null, + event: "changeLabel", + }, + + description: { + check: "String", + nullable: true, + init: null, + event: "changeDescription", + }, + + accessRights: { + check: "Object", + nullable: false, + init: null, + event: "changeAccessRights", + }, + + thumbnail: { + check: "String", + nullable: true, + init: "", + event: "changeThumbnail", + }, + + groupMembers: { + check: "Object", + nullable: true, + init: null, + event: "changeGroupMembers", + }, + + groupType: { + check: ["me", "organization", "productEveryone", "everyone"], + nullable: false, + init: null, + }, + }, + + events: { + "memberAdded": "qx.event.type.Event", + "memberRemoved": "qx.event.type.Event", + }, + + statics: { + getProperties: function() { + return Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Group)); + } + }, + + members: { + getGroupMemberByUserId: function(userId) { + return Object.values(this.getGroupMembers()).find(user => user.getUserId() === userId); + }, + + getGroupMemberByLogin: function(userEmail) { + return Object.values(this.getGroupMembers()).find(user => user.getLogin() === userEmail); + }, + + addGroupMember: function(user) { + this.getGroupMembers()[user.getGroupId()] = user; + this.fireEvent("memberAdded"); + }, + + removeGroupMember: function(userId) { + const groupMember = this.getGroupMemberByUserId(userId); + if (groupMember) { + delete this.getGroupMembers()[groupMember.getGroupId()]; + this.fireEvent("memberRemoved"); + } + }, + + serialize: function() { + const jsonObject = {}; + const propertyKeys = this.self().getProperties(); + propertyKeys.forEach(key => { + jsonObject[key] = this.get(key); + }); + return jsonObject; + } + } +}); 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/data/model/User.js b/services/static-webserver/client/source/class/osparc/data/model/User.js new file mode 100644 index 00000000000..b3c03d837c6 --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/data/model/User.js @@ -0,0 +1,102 @@ +/* ************************************************************************ + + 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); + + const label = this.self().namesToLabel(userData["first_name"], userData["last_name"]) || userData["login"]; + this.set({ + userId: userData.id, + groupId: userData.gid, + label: label, + login: userData.login, + thumbnail: this.self().emailToThumbnail(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", + }, + + thumbnail: { + check: "String", + nullable: true, + init: "", + event: "changeThumbnail", + }, + }, + + 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/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/credits/BuyCreditsStepper.js b/services/static-webserver/client/source/class/osparc/desktop/credits/BuyCreditsStepper.js index 37e4a351a8b..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 @@ -10,12 +10,11 @@ qx.Class.define("osparc.desktop.credits.BuyCreditsStepper", { construct(paymentMethods) { this.base(arguments); this.__paymentMethods = paymentMethods; + const groupsStore = osparc.store.Groups.getInstance(); + const myGid = groupsStore.getMyGroupId() const store = osparc.store.Store.getInstance(); - store.getGroupsMe() - .then(personalGroup => { - this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid) - this.__buildLayout() - }); + 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 93a2ee3dcae..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 @@ -31,13 +31,12 @@ qx.Class.define("osparc.desktop.credits.Transactions", { } } + const groupsStore = osparc.store.Groups.getInstance(); + const myGid = groupsStore.getMyGroupId() const store = osparc.store.Store.getInstance(); - store.getGroupsMe() - .then(personalGroup => { - this.__personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid); - this.__personalWalletId = this.__personalWallet.getWalletId(); - this.__buildLayout(); - }); + 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/organizations/MembersList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/MembersList.js index eb694304233..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 @@ -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("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); @@ -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); }); } }); @@ -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.") : @@ -225,83 +225,82 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { enabled: canIWrite }); - const params = { - url: { - "gid": orgModel.getGid() + const 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(); + 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) { @@ -309,53 +308,16 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const productEveryone = await osparc.store.Store.getInstance().getProductEveryone(); - - const orgId = this.__currentOrg.getGid(); - const params = { - url: { - "gid": orgId - }, - data: { - "email": orgMemberEmail - } - }; - osparc.data.Resources.fetch("organizationMembers", "post", params) - .then(() => { + const orgId = this.__currentOrg.getGroupId(); + const groupsStore = osparc.store.Groups.getInstance(); + groupsStore.postMember(orgId, orgMemberEmail) + .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); + 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"); @@ -364,24 +326,16 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __promoteToUser: function(orgMember) { + __promoteToUser: function(listedMember) { if (this.__currentOrg === null) { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": orgMember["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 => { @@ -390,27 +344,21 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __demoteToRestrictedUser: function(orgMember, msg) { + __demoteToRestrictedUser: function(listedMember, msg) { if (this.__currentOrg === null) { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": "id" in orgMember ? orgMember["id"] : orgMember["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 => { @@ -419,24 +367,18 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __promoteToManager: function(orgMember) { + __promoteToManager: function(listedMember) { if (this.__currentOrg === null) { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": orgMember["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 => { @@ -445,24 +387,18 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __promoteToAdministrator: function(orgMember) { + __promoteToAdministrator: function(listedMember) { if (this.__currentOrg === null) { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": orgMember["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 => { @@ -471,24 +407,18 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __demoteToMember: function(orgMember) { + __demoteToMember: function(listedMember) { if (this.__currentOrg === null) { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": orgMember["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 => { @@ -497,24 +427,18 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __demoteToManager: function(orgMember) { + __demoteToManager: function(listedMember) { if (this.__currentOrg === null) { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": orgMember["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 => { @@ -523,30 +447,25 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { }); }, - __doDeleteMember: function(orgMember) { - const params = { - url: { - "gid": this.__currentOrg.getGid(), - "uid": orgMember["id"] - } - }; - return osparc.data.Resources.fetch("organizationMembers", "delete", params) + __doDeleteMember: function(listedMember) { + const groupsStore = osparc.store.Groups.getInstance(); + return groupsStore.removeMember(this.__currentOrg.getGroupId(), listedMember["id"]) .then(() => { - osparc.FlashMessenger.getInstance().logAs(orgMember["name"] + this.tr(" successfully removed")); - osparc.store.Store.getInstance().reset("organizationMembers"); + osparc.FlashMessenger.getInstance().logAs(listedMember["name"] + this.tr(" successfully removed")); + this.__reloadOrgMembers(); }) .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()); }, @@ -555,36 +474,29 @@ qx.Class.define("osparc.desktop.organizations.MembersList", { return; } - const params = { - url: { - "gid": this.__currentOrg.getGid() + 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); } } }); 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..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 @@ -41,25 +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("gid", organizationListItem, "key"); - orgModel.bind("gid", organizationListItem, "model"); - orgModel.bind("thumbnail", organizationListItem, "thumbnail"); - orgModel.bind("label", organizationListItem, "title"); - orgModel.bind("description", organizationListItem, "subtitle"); - orgModel.bind("nMembers", organizationListItem, "role"); - 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() { @@ -104,31 +109,15 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", { }, __updateOrganization: function(win, button, orgEditor) { - const orgKey = orgEditor.getGid(); + const groupId = orgEditor.getGid(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - const params = { - url: { - "gid": orgKey - }, - data: { - "label": name, - "description": description, - "thumbnail": thumbnail || null - } - }; - osparc.data.Resources.fetch("organizations", "patch", params) + osparc.store.Groups.getInstance().patchOrganization(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/desktop/organizations/OrganizationsList.js b/services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js index c2f8656ed83..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 @@ -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,12 +130,12 @@ 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); - ctrl.bindProperty("nMembers", "role", null, item, id); + ctrl.bindProperty("groupMembers", "groupMembers", null, item, id); ctrl.bindProperty("accessRights", "accessRights", null, item, id); }, configureItem: item => { @@ -180,28 +177,14 @@ 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()); + orgs.sort(this.self().sortOrganizations); + orgs.forEach(org => orgsModel.append(org)); + this.setOrganizationsLoaded(true); + if (orgId) { + this.fireDataEvent("organizationSelected", orgId); + } }, __openEditOrganization: function(orgId) { @@ -222,7 +205,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; } }); @@ -241,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"); @@ -267,31 +241,16 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { }, __createOrganization: function(win, button, orgEditor) { - const orgKey = orgEditor.getGid(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - const params = { - url: { - "gid": orgKey - }, - 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; @@ -305,27 +264,15 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", { }, __updateOrganization: function(win, button, orgEditor) { - const orgKey = orgEditor.getGid(); + const groupId = orgEditor.getGid(); const name = orgEditor.getLabel(); const description = orgEditor.getDescription(); const thumbnail = orgEditor.getThumbnail(); - const params = { - url: { - "gid": orgKey - }, - data: { - "label": name, - "description": description, - "thumbnail": thumbnail || null - } - }; - osparc.data.Resources.fetch("organizations", "patch", params) + osparc.store.Groups.getInstance().patchOrganization(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"); 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/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/desktop/paymentMethods/PaymentMethods.js b/services/static-webserver/client/source/class/osparc/desktop/paymentMethods/PaymentMethods.js index 2e7032aa694..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 @@ -23,13 +23,12 @@ qx.Class.define("osparc.desktop.paymentMethods.PaymentMethods", { this._setLayout(new qx.ui.layout.VBox(20)); + const groupsStore = osparc.store.Groups.getInstance(); + const myGid = groupsStore.getMyGroupId(); const store = osparc.store.Store.getInstance(); - store.getGroupsMe() - .then(personalGroup => { - const personalWallet = store.getWallets().find(wallet => wallet.getOwner() === personalGroup.gid) - this.__personalWalletId = personalWallet.getWalletId() - this.__buildLayout() - }); + 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 e68f7f7577f..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 @@ -265,50 +265,42 @@ 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); - } + const groupsStore = osparc.store.Groups.getInstance(); + 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.Store.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 = clusterMember.getGroupId(); + if (gid in potentialCollaborators) { + const collaborator = potentialCollaborators[gid]; + const collabObj = {}; + if (collaborator["collabType"] === 1) { + // group + collabObj["thumbnail"] = collaborator.getThumbnail() || "@FontAwesome5Solid/users/24"; + collabObj["login"] = collaborator.getDescription(); + } else if (collaborator["collabType"] === 2) { + // user + collabObj["thumbnail"] = collaborator.getThumbnail() || "@FontAwesome5Solid/user/24"; + collabObj["login"] = collaborator.getLogin(); + } + if (Object.keys(collabObj).length) { + collabObj["id"] = collaborator.getGroupId(); + collabObj["name"] = collaborator.getLabel(); + collabObj["accessRights"] = clusterMember.getAccessRights(); + collabObj["showOptions"] = canWrite; + membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj)); + } + } + }); }, __openEditCluster: function(clusterId) { 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..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); }); } }); @@ -211,24 +211,24 @@ 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 = 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)]; - // 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 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"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getLogin(); + collaborator["accessRights"] = { + read: accessRights["read"], + write: accessRights["write"], + delete: accessRights["delete"], + }; let options = []; if (canIWrite) { // accountant... @@ -289,21 +289,18 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); // push 'WALLET_SHARED' notification - osparc.store.Store.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()); + } + }); }); }, - __promoteToAccountant: function(walletMember) { + __promoteToAccountant: function(listedMember) { const wallet = this.__currentModel; if (wallet === null) { return; @@ -312,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() }; @@ -323,7 +320,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); }, - __demoteToMember: function(walletMember) { + __demoteToMember: function(listedMember) { const wallet = this.__currentModel; if (wallet === null) { return; @@ -332,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() }; @@ -343,7 +340,7 @@ qx.Class.define("osparc.desktop.wallets.MembersList", { }); }, - __deleteMember: function(walletMember) { + __deleteMember: function(listedMember) { const wallet = this.__currentModel; if (wallet === null) { return; @@ -352,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) 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/editor/AnnotationNoteCreator.js b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js index 1073c1b7faf..4ff7706695f 100644 --- a/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js +++ b/services/static-webserver/client/source/class/osparc/editor/AnnotationNoteCreator.js @@ -142,10 +142,11 @@ qx.Class.define("osparc.editor.AnnotationNoteCreator", { __setRecipientGid: function(gid) { this.setRecipientGid(gid); - osparc.store.Store.getInstance().getGroup(gid) - .then(user => { - this.getChildControl("selected-recipient").setValue(user.label); - }); + // only users were proposed + 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/editor/OrganizationEditor.js b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js index b528e760c01..d54eb22601a 100644 --- a/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js +++ b/services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js @@ -32,23 +32,18 @@ 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", { converter: val => val ? val : "" }); } else { - osparc.store.Store.getInstance().getGroupsOrganizations() - .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 groupsStore = osparc.store.Groups.getInstance(); + const orgs = groupsStore.getOrganizations(); + const existingNames = Object.values(orgs).map(org => org.getLabel()); + 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/filter/CollaboratorToggleButton.js b/services/static-webserver/client/source/class/osparc/filter/CollaboratorToggleButton.js index 31d3aef3512..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["label"]; + 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/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; - } - } -}); 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..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; }, @@ -69,7 +64,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(); @@ -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 62871860da6..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,11 +117,10 @@ 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().getUserByUserId(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 67194c84418..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.Store.getInstance().getGroup(resourceId) - .then(group => descriptionLabel.setValue("You're now member of '" + group["label"] + "'")) - .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": @@ -157,9 +160,9 @@ 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().getUserByUserId(userFromId); if (user) { - descriptionLabel.setValue("was shared by " + user["label"]); + descriptionLabel.setValue("was shared by " + user.getLabel()); } } break; @@ -177,9 +180,9 @@ qx.Class.define("osparc.notification.NotificationUI", { } } if (userFromId) { - const user = osparc.store.Store.getInstance().getUser(userFromId); + const user = osparc.store.Groups.getInstance().getUserByUserId(userFromId); if (user) { - descriptionLabel.setValue("was shared by " + user["label"]); + descriptionLabel.setValue("was shared by " + user.getLabel()); } } break; @@ -196,9 +199,9 @@ 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().getUserByUserId(userFromId); if (user) { - descriptionLabel.setValue("was added by " + user["label"]); + descriptionLabel.setValue("was added by " + user.getLabel()); } } break; @@ -264,16 +267,14 @@ qx.Class.define("osparc.notification.NotificationUI", { __openOrganizationDetails: function(orgId) { // make sure org is available - osparc.store.Store.getInstance().getGroup(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/notification/Notifications.js b/services/static-webserver/client/source/class/osparc/notification/Notifications.js index a34a0e2886c..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" }; @@ -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); }, 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/share/Collaborators.js b/services/static-webserver/client/source/class/osparc/share/Collaborators.js index 66e75202ce6..283cf695ef3 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.__collaborators = {}; - initCollabs.forEach(initCollab => { - this.__collaborators[initCollab["gid"]] = initCollab; - }); - this.__getCollaborators(); + this._reloadCollaboratorsList(); }, events: { @@ -158,7 +154,6 @@ qx.Class.define("osparc.share.Collaborators", { _resourceType: null, __addCollaborators: null, __collaboratorsModel: null, - __collaborators: null, _createChildControlImpl: function(id) { let control; @@ -340,14 +335,6 @@ qx.Class.define("osparc.share.Collaborators", { return vBox; }, - __getCollaborators: function() { - osparc.store.Store.getInstance().getPotentialCollaborators() - .then(potentialCollaborators => { - this.__collaborators = Object.assign(this.__collaborators, potentialCollaborators); - this._reloadCollaboratorsList(); - }); - }, - __getLeaveStudyButton: function() { const myGid = osparc.auth.Data.getInstance().getGroupId(); if ( @@ -402,32 +389,35 @@ 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().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 = 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"] = 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"] : ""}` - ); - } else if (everyoneGIds.includes(parseInt(gid))) { - // everyone product or everyone - if (collaborator["thumbnail"] === null) { + 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]; 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..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,11 +34,7 @@ qx.Class.define("osparc.share.CollaboratorsService", { this._resourceType = "service"; const serviceDataCopy = osparc.utils.Utils.deepCloneObject(serviceData); - const initCollabs = []; - initCollabs.push(this.self().getEveryoneProductObj()); - initCollabs.push(this.self().getEveryoneObj()); - - this.base(arguments, serviceDataCopy, initCollabs); + this.base(arguments, serviceDataCopy); }, statics: { @@ -64,20 +60,6 @@ qx.Class.define("osparc.share.CollaboratorsService", { "write": true }; }, - - getEveryoneProductObj: function() { - const everyoneProductGroup = osparc.store.Store.getInstance().getEveryoneProductGroup(); - const everyone = osparc.utils.Utils.deepCloneObject(everyoneProductGroup); - everyone["accessRights"] = this.getCollaboratorAccessRight(); - return everyone; - }, - - getEveryoneObj: function() { - const everyoneGroup = osparc.store.Store.getInstance().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 58f47059cd6..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,13 +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")) { - initCollabs.push(this.self().getEveryoneProductObj(this._resourceType === "study")); - initCollabs.push(this.self().getEveryoneObj(this._resourceType === "study")); - } - - this.base(arguments, studyDataCopy, initCollabs); + this.base(arguments, studyDataCopy); }, statics: { @@ -105,20 +99,6 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { } return true; }, - - getEveryoneProductObj: function(isStudy) { - const everyoneProductGroup = osparc.store.Store.getInstance().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 everyone = osparc.utils.Utils.deepCloneObject(everyoneGroup); - everyone["accessRights"] = isStudy ? this.getCollaboratorAccessRight() : this.getViewerAccessRight(); - return everyone; - } }, members: { @@ -224,9 +204,8 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { ); }; - const groupData = await osparc.store.Store.getInstance().getGroup(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"), @@ -257,24 +236,21 @@ qx.Class.define("osparc.share.CollaboratorsStudy", { __pushNotifications: function(gids) { // push 'STUDY_SHARED'/'TEMPLATE_SHARED' notification - osparc.store.Store.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/CollaboratorsWorkspace.js b/services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js index d8bb906794c..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.Store.getInstance().getGroup(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/NewCollaboratorsManager.js b/services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js index 65510ea9142..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(); @@ -112,20 +112,18 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { // all users can share services with ProductEveryone includeProductEveryone = true; } - osparc.store.Store.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) { @@ -133,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); @@ -154,7 +152,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; @@ -175,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) { @@ -189,13 +187,8 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", { this.__collabButtonsContainer.setEnabled(false); this.__shareButton.setFetching(true); - const addCollabs = []; - for (let i=0; i { const gids = e.getData(); if (gids.length) { - osparc.store.Store.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]["label"], "@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); }, 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..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 new file mode 100644 index 00000000000..08ebcc2904c --- /dev/null +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -0,0 +1,429 @@ +/* ************************************************************************ + + 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 = []; + }, + + properties: { + everyoneGroup: { + check: "osparc.data.model.Group", + init: {} + }, + + everyoneProductGroup: { + check: "osparc.data.model.Group", + init: {} + }, + + organizations: { + check: "Object", + init: {} + }, + + groupMe: { + check: "osparc.data.model.Group", + init: {} + }, + + reachableUsers: { + check: "Object", + init: {} + }, + }, + + events: { + "groupAdded": "qx.event.type.Data", + "groupRemoved": "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([]); + }); + } + const useCache = false; + return osparc.data.Resources.get("organizations", {}, useCache) + .then(resp => { + const everyoneGroup = this.__addToGroupsCache(resp["all"], "everyone"); + const productEveryoneGroup = this.__addToGroupsCache(resp["product"], "productEveryone"); + const groupMe = this.__addToGroupsCache(resp["me"], "me"); + const orgs = {}; + resp["organizations"].forEach(organization => { + const org = this.__addToGroupsCache(organization, "organization"); + orgs[org.getGroupId()] = org; + }); + this.setEveryoneGroup(everyoneGroup); + 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; + }); + }, + + __fetchGroupMembers: function(groupId) { + const params = { + url: { + gid: groupId + } + }; + return osparc.data.Resources.get("organizationMembers", params) + .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); + this.__addToUsersCache(user, groupId); + }); + } + }); + }, + + fetchGroupsAndMembers: function() { + 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) + .then(() => resolve()) + .catch(err => console.error(err)); + }); + }) + }, + + 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(); + }, + + getOrganizationIds: function() { + return Object.keys(this.getOrganizations()); + }, + + getGroup: function(groupId) { + const groups = []; + + const groupMe = this.getGroupMe(); + groupMe["collabType"] = 2; + groups.push(groupMe); + + Object.values(this.getReachableUsers()).forEach(member => { + member["collabType"] = 2; + groups.push(member); + }); + + Object.values(this.getOrganizations()).forEach(org => { + org["collabType"] = 1; + groups.push(org); + }); + + const groupProductEveryone = this.getEveryoneProductGroup(); + groupProductEveryone["collabType"] = 0; + groups.push(groupProductEveryone); + + const groupEveryone = this.getEveryoneGroup(); + groupEveryone["collabType"] = 0; + groups.push(groupEveryone); + const idx = groups.findIndex(group => group.getGroupId() === parseInt(groupId)); + if (idx > -1) { + return groups[idx]; + } + return null; + }, + + getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { + 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 members = this.getReachableUsers(); + for (const gid of Object.keys(members)) { + members[gid]["collabType"] = 2; + potentialCollaborators[gid] = members[gid]; + } + if (includeMe) { + const myGroup = this.getGroupMe(); + myGroup["collabType"] = 2; + potentialCollaborators[myGroup.getGroupId()] = myGroup; + } + if (includeProductEveryone && productEveryone) { + productEveryone["collabType"] = 0; + potentialCollaborators[productEveryone.getGroupId()] = productEveryone; + } + return potentialCollaborators; + }, + + getOrganization: function(groupId) { + if (groupId && groupId in this.getOrganizations()) { + return this.getOrganizations()[groupId]; + } + return null; + }, + + getUserByUserId: function(userId) { + if (userId) { + const visibleMembers = this.getReachableUsers(); + return Object.values(visibleMembers).find(member => member.getUserId() === userId); + } + return null; + }, + + getUserByGroupId: function(groupId) { + if (groupId) { + const visibleMembers = this.getReachableUsers(); + return Object.values(visibleMembers).find(member => member.getGroupId() === groupId); + } + return null; + }, + + getGroupMemberByUserId: function(orgId, userId) { + const org = this.getGroup(orgId); + if (org) { + return org.getGroupMemberByUserId(userId); + } + return null; + }, + + getGroupMemberByLogin: function(orgId, userEmail) { + const org = this.getGroup(orgId); + if (org) { + return org.getGroupMemberByLogin(userEmail); + } + return null; + }, + + // CRUD GROUP + postOrganization: function(name, description, thumbnail) { + const newGroupData = { + "label": name, + "description": description, + "thumbnail": thumbnail || null + }; + const params = { + data: newGroupData + }; + let group = null; + return osparc.data.Resources.fetch("organizations", "post", params) + .then(groupData => { + group = this.__addToGroupsCache(groupData, "organization"); + this.getOrganizations()[group.getGroupId()] = group; + return this.__fetchGroupMembers(group.getGroupId()); + }) + .then(() => { + return group; + }); + }, + + deleteOrganization: function(groupId) { + const params = { + url: { + "gid": groupId + } + }; + return osparc.data.Resources.fetch("organizations", "delete", params) + .then(() => { + this.__deleteFromGroupsCache(groupId); + delete this.getOrganizations()[groupId]; + }); + }, + + patchOrganization: function(groupId, name, description, thumbnail) { + const params = { + url: { + "gid": groupId + }, + data: { + "label": name, + "description": description, + "thumbnail": thumbnail || null + } + }; + 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 + }); + } + }); + }, + // CRUD GROUP + + // CRUD GROUP MEMBERS + postMember: function(orgId, newMemberEmail) { + const gid = parseInt(orgId); + const params = { + url: { + "gid": gid + }, + data: { + "email": newMemberEmail + } + }; + return osparc.data.Resources.fetch("organizationMembers", "post", params) + .then(() => { + // the backend doesn't return the user back, + // so fetch them all again and return the user + return this.__fetchGroupMembers(gid); + }) + .then(() => { + 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; + }); + }, + + 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)); + }); + }, + // CRUD GROUP MEMBERS + + __addToGroupsCache: function(groupData, groupType) { + let group = this.groupsCached.find(f => f.getGroupId() === groupData["gid"]); + if (!group) { + group = new osparc.data.model.Group(groupData).set({ + groupType + }); + this.groupsCached.unshift(group); + } + return group; + }, + + __deleteFromGroupsCache: function(groupId) { + delete this.getOrganizations()[groupId]; + }, + + __addToUsersCache: function(user, orgId = null) { + if (orgId) { + const organization = this.getOrganization(orgId); + if (organization) { + organization.addGroupMember(user); + } + } + this.getReachableUsers()[user.getGroupId()] = user; + }, + + __removeUserFromCache: function(userId, orgId) { + if (orgId) { + const organization = this.getOrganization(orgId); + if (organization) { + organization.removeGroupMember(userId) + } + } + }, + } +}); 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..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: {} - }, - reachableMembers: { - check: "Object", - init: {} - }, - everyoneProductGroup: { - check: "Object", - init: {} - }, - everyoneGroup: { - check: "Object", - init: {} - }, clusters: { check: "Array", init: [], @@ -457,193 +437,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,38 +575,37 @@ qx.Class.define("osparc.store.Store", { resolve(oldClassifiers); return; } - this.getGroupsOrganizations() - .then(orgs => { - if (orgs.length === 0) { + const groupsStore = osparc.store.Groups.getInstance(); + 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); }); }); } 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..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 @@ -50,9 +50,17 @@ 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, + minHeight: 48, + alignY: "middle", + }); this.addListener("pointerover", this._onPointerOver, this); this.addListener("pointerout", this._onPointerOut, this); 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 { 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..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 @@ -24,7 +24,15 @@ qx.Class.define("osparc.ui.list.OrganizationListItem", { init: true, nullable: false, event: "changeShowDeleteButton" - } + }, + + groupMembers: { + check: "Object", + nullable: true, + init: null, + event: "changeGroupMembers", + apply: "updateNMembers", + }, }, events: { @@ -39,11 +47,16 @@ 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; const accessRights = this.getAccessRights(); - if (accessRights.getWrite()) { + if (accessRights["write"]) { const optionsMenu = this.getChildControl("options"); optionsMenu.show(); @@ -51,7 +64,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 +72,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" @@ -83,14 +96,12 @@ 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() - .then(groupProductEveryone => { - if (groupProductEveryone && parseInt(this.getKey()) === groupProductEveryone["gid"]) { - thumbnail.setSource(osparc.utils.Icons.everyone(osparc.ui.list.ListItemWithMenu.ICON_SIZE)); - } - }); + const groupsStore = osparc.store.Groups.getInstance(); + const groupProductEveryone = groupsStore.getEveryoneProductGroup(); + if (groupProductEveryone && parseInt(this.getKey()) === groupProductEveryone.getGroupId()) { + 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..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.Store.getInstance().getGroup(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": 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..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.Store.getInstance().getGroup(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") {