Skip to content

Commit

Permalink
[skip ci] refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Dec 18, 2024
1 parent c1f1b5c commit 29223c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ qx.Class.define("osparc.dashboard.CardBase", {
// groups -> [users, orgs, [productEveryone], [everyone]];
populateShareIcon: function(shareIcon, accessRights) {
const groupsStore = osparc.store.Groups.getInstance();
const users = Object.values(groupsStore.getUsers());
const usersStore = osparc.store.Users.getInstance();
const users = usersStore.getUsers();
const orgs = Object.values(groupsStore.getOrganizations());
const productEveryone = [groupsStore.getEveryoneProductGroup()];
const everyone = [groupsStore.getEveryoneGroup()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ qx.Class.define("osparc.store.Groups", {
check: "osparc.data.model.Group",
init: {}
},

users: {
check: "Object",
init: {}
},
},

events: {
Expand Down Expand Up @@ -126,7 +121,8 @@ qx.Class.define("osparc.store.Groups", {
this.__fetchGroups()
.then(orgs => {
// reset Users
this.resetUsers();
const usersStore = osparc.store.Users.getInstance();
usersStore.resetUsers();
const promises = Object.keys(orgs).map(orgId => this.__fetchGroupMembers(orgId));
Promise.all(promises)
.then(() => resolve())
Expand All @@ -151,7 +147,8 @@ qx.Class.define("osparc.store.Groups", {
allGroupsAndUsers[organization.getGroupId()] = organization;
});

Object.values(this.getUsers()).forEach(user => {
const users = osparc.store.Users.getInstance().getUsers();
users.forEach(user => {
allGroupsAndUsers[user.getGroupId()] = user;
});

Expand All @@ -173,7 +170,9 @@ qx.Class.define("osparc.store.Groups", {
groupMe["collabType"] = 2;
groups.push(groupMe);

Object.values(this.getUsers()).forEach(user => {
const usersStore = osparc.store.Users.getInstance();
const users = usersStore.getUsers();
users.forEach(user => {
user["collabType"] = 2;
groups.push(user);
});
Expand Down Expand Up @@ -201,6 +200,12 @@ qx.Class.define("osparc.store.Groups", {
const potentialCollaborators = {};
const orgs = this.getOrganizations();
const productEveryone = this.getEveryoneProductGroup();

if (includeProductEveryone && productEveryone) {
productEveryone["collabType"] = 0;
potentialCollaborators[productEveryone.getGroupId()] = productEveryone;
}

Object.values(orgs).forEach(org => {
if (org.getAccessRights()["read"]) {
// maybe because of migration script, some users have access to the product everyone group
Expand All @@ -212,20 +217,20 @@ qx.Class.define("osparc.store.Groups", {
potentialCollaborators[org.getGroupId()] = org;
}
});
const users = this.getUsers();
for (const gid of Object.keys(users)) {
users[gid]["collabType"] = 2;
potentialCollaborators[gid] = users[gid];
}

if (includeMe) {
const myGroup = this.getGroupMe();
myGroup["collabType"] = 2;
potentialCollaborators[myGroup.getGroupId()] = myGroup;
}
if (includeProductEveryone && productEveryone) {
productEveryone["collabType"] = 0;
potentialCollaborators[productEveryone.getGroupId()] = productEveryone;
}

const usersStore = osparc.store.Users.getInstance();
const users = usersStore.getUsers();
users.forEach(user => {
user["collabType"] = 2;
potentialCollaborators[user.getGroupId()] = user;
});

return potentialCollaborators;
},

Expand All @@ -239,16 +244,18 @@ qx.Class.define("osparc.store.Groups", {

getUserByUserId: function(userId) {
if (userId) {
const users = this.getUsers();
return Object.values(users).find(member => member.getUserId() === userId);
const usersStore = osparc.store.Users.getInstance();
const users = usersStore.getUsers();
return users.find(user => user.getUserId() === userId);
}
return null;
},

getUserByGroupId: function(groupId) {
if (groupId) {
const users = this.getUsers();
return Object.values(users).find(member => member.getGroupId() === groupId);
const usersStore = osparc.store.Users.getInstance();
const users = usersStore.getUsers();
return users.find(user => user.getGroupId() === groupId);
}
return null;
},
Expand Down Expand Up @@ -426,7 +433,6 @@ qx.Class.define("osparc.store.Groups", {
organization.addGroupMember(userMember);
}
}
this.getUsers()[userMember.getGroupId()] = userMember;
osparc.store.Users.getInstance().addUser(orgMember);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ qx.Class.define("osparc.store.Users", {
extend: qx.core.Object,
type: "singleton",

construct: function() {
this.base(arguments);

this.__usersCached = [];
properties: {
users: {
check: "Array",
init: [],
nullable: false,
},
},

members: {
addUser: function(userData) {
const user = new osparc.data.model.User(userData);
const userFound = this.__usersCached.find(usr => usr.getGroupId() === user.getGroupId());
const userFound = this.getUsers().find(usr => usr.getGroupId() === user.getGroupId());
if (!userFound) {
this.__usersCached.push(user);
this.getUsers().push(user);
}
return user;
},
Expand Down

0 comments on commit 29223c6

Please sign in to comment.