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 8b466d0608b..b6b6b029203 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/CardBase.js @@ -148,54 +148,56 @@ qx.Class.define("osparc.dashboard.CardBase", { return false; }, - // groups -> [orgMembs, orgs, [productEveryone], [everyone]]; - setIconAndTooltip: function(shareIcon, accessRights, groups) { - shareIcon.setSource(osparc.dashboard.CardBase.SHARE_ICON); - if (osparc.data.model.Study.canIWrite(accessRights)) { - shareIcon.set({ - toolTipText: qx.locale.Manager.tr("Share") - }); + populateShareIcon: async function(shareIcon, accessRights) { + const gids = Object.keys(accessRights).map(key => parseInt(key)); + + const groupsStore = osparc.store.Groups.getInstance(); + + // Icon + const groupEveryone = groupsStore.getEveryoneGroup(); + const groupProductEveryone = groupsStore.getEveryoneProductGroup(); + const organizations = groupsStore.getOrganizations(); + const organizationIds = Object.keys(organizations).map(key => parseInt(key)); + if (gids.includes(groupEveryone.getGroupId()) || gids.includes(groupProductEveryone.getGroupId())) { + shareIcon.setSource(osparc.dashboard.CardBase.SHARED_ALL); + } else if (organizationIds.filter(value => gids.includes(value)).length) { // find intersection + shareIcon.setSource(osparc.dashboard.CardBase.SHARED_ORGS); + } else if (gids.length === 1) { + shareIcon.setSource(osparc.dashboard.CardBase.SHARE_ICON); + } else { + shareIcon.setSource(osparc.dashboard.CardBase.SHARED_USER); } - let sharedGrps = []; - const myGroupId = osparc.auth.Data.getInstance().getGroupId(); - for (let i=0; i { + const idx = gids.indexOf(group.getGroupId()); + if (idx > -1) { + sharedGrps.push(group); + gids.splice(idx, 1); } - const sharedGrp = []; - const gids = Object.keys(accessRights); - for (let j=0; j group.getGroupId() === gid); - if (grp) { - sharedGrp.push(grp); + }); + // once the groups were removed, the remaining group ids are users' primary groups ids + const usersStore = osparc.store.Users.getInstance(); + const myGroupId = osparc.auth.Data.getInstance().getGroupId(); + for (let i=0; i hint.show(), this); shareIcon.addListener("mouseout", () => hint.exclude(), this); }, - - // groups -> [users, orgs, [productEveryone], [everyone]]; - populateShareIcon: function(shareIcon, accessRights) { - const groupsStore = osparc.store.Groups.getInstance(); - const usersStore = osparc.store.Users.getInstance(); - const users = usersStore.getUsers(); - const orgs = Object.values(groupsStore.getOrganizations()); - const productEveryone = [groupsStore.getEveryoneProductGroup()]; - const everyone = [groupsStore.getEveryoneGroup()]; - const groups = [users, orgs, productEveryone, everyone]; - osparc.dashboard.CardBase.setIconAndTooltip(shareIcon, accessRights, groups); - }, }, properties: { 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 4466c23099a..bc9068bca8c 100644 --- a/services/static-webserver/client/source/class/osparc/data/Resources.js +++ b/services/static-webserver/client/source/class/osparc/data/Resources.js @@ -884,6 +884,10 @@ qx.Class.define("osparc.data.Resources", { "users": { useCache: false, // osparc.store.Groups handles the cache endpoints: { + get: { + method: "GET", + url: statics.API + "/groups/{gid}/users" + }, search: { method: "POST", url: statics.API + "/users:search" diff --git a/services/static-webserver/client/source/class/osparc/store/Users.js b/services/static-webserver/client/source/class/osparc/store/Users.js index 652eaf68b79..59da1a2fb9a 100644 --- a/services/static-webserver/client/source/class/osparc/store/Users.js +++ b/services/static-webserver/client/source/class/osparc/store/Users.js @@ -28,6 +28,29 @@ qx.Class.define("osparc.store.Users", { }, members: { + fetchUser: function(groupId) { + const params = { + url: { + gid: groupId + } + }; + return osparc.data.Resources.fetch("users", "get", params) + .then(userData => { + const user = this.addUser(userData[0]); + return user; + }); + }, + + getUser: function(groupId, fetchIfNotFound = true) { + const userFound = this.getUsers().find(user => user.getGroupId() === groupId); + if (userFound) { + return new Promise(resolve => resolve(userFound)); + } else if (fetchIfNotFound) { + return this.fetchUser(groupId); + } + return new Promise(reject => reject()); + }, + addUser: function(userData) { const user = new osparc.data.model.User(userData); const userFound = this.getUsers().find(usr => usr.getGroupId() === user.getGroupId());