Skip to content

Commit

Permalink
User model
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Nov 20, 2024
1 parent 296df6f commit 575eaaa
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2024 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

/**
* Class that stores User data.
*/

qx.Class.define("osparc.data.model.User", {
extend: qx.core.Object,

/**
* @param userData {Object} Object containing the serialized User Data
*/
construct: function(userData) {
this.base(arguments);

let label = userData["login"];
if ("first_name" in userData && userData["first_name"]) {
label = osparc.utils.Utils.firstsUp(userData["first_name"]);
if (userData["last_name"]) {
label += " " + osparc.utils.Utils.firstsUp(userData["last_name"]);
}
}
this.set({
userId: userData.id,
groupId: userData.gid,
label: label,
login: userData.login,
accessRights: userData.accessRights,
});
},

properties: {
userId: {
check: "Number",
nullable: false,
init: null,
event: "changeUserId",
},

groupId: {
check: "Number",
nullable: false,
init: null,
event: "changeGroupId",
},

label: {
check: "String",
nullable: false,
init: null,
event: "changeLabel",
},

login: {
check: "String",
nullable: true,
init: null,
event: "changeLogin",
},

accessRights: {
check: "Object",
nullable: false,
init: null,
event: "changeAccessRights",
},
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -277,36 +277,34 @@ qx.Class.define("osparc.desktop.preferences.pages.ClustersPage", {
this.__organizationsAndMembers.reloadVisibleCollaborators(memberKeys);
}

osparc.store.Groups.getInstance().getPotentialCollaborators()
.then(potentialCollaborators => {
clusterMembers.forEach(clusterMember => {
const gid = clusterMember.gid;
if (gid in potentialCollaborators) {
const collaborator = potentialCollaborators[gid];
const collabObj = {};
if (collaborator["collabType"] === 1) {
collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24";
collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]);
collabObj["login"] = collaborator["description"];
} else if (collaborator["collabType"] === 2) {
collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32);
collaborator["name"] = osparc.utils.Utils.firstsUp(
`${"first_name" in collaborator && collaborator["first_name"] != null ?
collaborator["first_name"] : collaborator["login"]}`,
`${"last_name" in collaborator && collaborator["last_name"] ?
collaborator["last_name"] : ""}`
);
collabObj["login"] = collaborator["login"];
}
if (Object.keys(collabObj).length) {
collabObj["id"] = collaborator["gid"];
collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember));
collabObj["showOptions"] = canWrite;
membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj));
}
}
});
});
const potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators();
clusterMembers.forEach(clusterMember => {
const gid = "gid" in clusterMember ? clusterMember["gid"] : clusterMember.getGroupId();
if (gid in potentialCollaborators) {
const collaborator = potentialCollaborators[gid];
const collabObj = {};
if (collaborator["collabType"] === 1) {
collabObj["thumbnail"] = collaborator["thumbnail"] || "@FontAwesome5Solid/users/24";
collabObj["name"] = osparc.utils.Utils.firstsUp(collaborator["label"]);
collabObj["login"] = collaborator["description"];
} else if (collaborator["collabType"] === 2) {
collabObj["thumbnail"] = osparc.utils.Avatar.getUrl(collaborator["login"], 32);
collaborator["name"] = osparc.utils.Utils.firstsUp(
`${"first_name" in collaborator && collaborator["first_name"] != null ?
collaborator["first_name"] : collaborator["login"]}`,
`${"last_name" in collaborator && collaborator["last_name"] ?
collaborator["last_name"] : ""}`
);
collabObj["login"] = collaborator["login"];
}
if (Object.keys(collabObj).length) {
collabObj["id"] = collaborator["gid"];
collabObj["accessRights"] = JSON.parse(qx.util.Serializer.toJson(clusterMember));
collabObj["showOptions"] = canWrite;
membersArrayModel.append(qx.data.marshal.Json.createModel(collabObj));
}
}
});
},

__openEditCluster: function(clusterId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ qx.Class.define("osparc.store.Groups", {
if (group) {
group.setGroupMembers({});
orgMembers.forEach(orgMember => {
orgMember["label"] = osparc.utils.Utils.firstsUp(
`${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`,
`${orgMember["last_name"] ? orgMember["last_name"] : ""}`
);
group.getGroupMembers()[orgMember["gid"]] = orgMember;
this.getReachableMembers()[orgMember["gid"]] = orgMember;
const user = new osparc.data.model.User(orgMember)
group.getGroupMembers()[orgMember["gid"]] = user;
this.getReachableMembers()[orgMember["gid"]] = user;
});
}
});
Expand Down Expand Up @@ -180,42 +177,40 @@ qx.Class.define("osparc.store.Groups", {
},

getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) {
return new Promise((resolve, reject) => {
const potentialCollaborators = {};
const orgs = this.getOrganizations();
const productEveryone = this.getEveryoneProductGroup();
Object.values(orgs).forEach(org => {
if (org.getAccessRights()["read"]) {
// maybe because of migration script, some users have access to the product everyone group
// rely on the includeProductEveryone argument to exclude it if necessary
if (org.getGroupId() === productEveryone.getGroupId() && !includeProductEveryone) {
return;
}
org["collabType"] = 1;
potentialCollaborators[org.getGroupId()] = org;
const potentialCollaborators = {};
const orgs = this.getOrganizations();
const productEveryone = this.getEveryoneProductGroup();
Object.values(orgs).forEach(org => {
if (org.getAccessRights()["read"]) {
// maybe because of migration script, some users have access to the product everyone group
// rely on the includeProductEveryone argument to exclude it if necessary
if (org.getGroupId() === productEveryone.getGroupId() && !includeProductEveryone) {
return;
}
});
const members = this.getReachableMembers();
for (const gid of Object.keys(members)) {
members[gid]["collabType"] = 2;
potentialCollaborators[gid] = members[gid];
}
if (includeMe) {
const myData = osparc.auth.Data.getInstance();
const myGid = myData.getGroupId();
potentialCollaborators[myGid] = {
"login": myData.getEmail(),
"first_name": myData.getFirstName(),
"last_name": myData.getLastName(),
"collabType": 2
};
}
if (includeProductEveryone && productEveryone) {
productEveryone["collabType"] = 0;
potentialCollaborators[productEveryone.getGroupId()] = productEveryone;
org["collabType"] = 1;
potentialCollaborators[org.getGroupId()] = org;
}
resolve(potentialCollaborators);
});
const members = this.getReachableMembers();
for (const gid of Object.keys(members)) {
members[gid]["collabType"] = 2;
potentialCollaborators[gid] = members[gid];
}
if (includeMe) {
const myData = osparc.auth.Data.getInstance();
const myGid = myData.getGroupId();
potentialCollaborators[myGid] = {
"login": myData.getEmail(),
"first_name": myData.getFirstName(),
"last_name": myData.getLastName(),
"collabType": 2
};
}
if (includeProductEveryone && productEveryone) {
productEveryone["collabType"] = 0;
potentialCollaborators[productEveryone.getGroupId()] = productEveryone;
}
return potentialCollaborators;
},

getGroup: function(groupId = null) {
Expand Down

0 comments on commit 575eaaa

Please sign in to comment.