Skip to content

Commit

Permalink
Merge branch 'master' into fix-file-deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo authored Dec 11, 2024
2 parents 85d1577 + 92ddd6c commit a361b74
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Annotated, Any, Self, TypeVar

from common_library.basic_types import DEFAULT_FACTORY
from models_library.groups import EVERYONE_GROUP_ID
from pydantic import (
AnyHttpUrl,
AnyUrl,
Expand All @@ -14,16 +15,16 @@
model_validator,
)

from ..basic_types import IDStr
from ..emails import LowerCaseEmailStr
from ..groups import (
AccessRightsDict,
Group,
GroupID,
GroupMember,
StandardGroupCreate,
StandardGroupUpdate,
)
from ..users import UserID
from ..users import UserID, UserNameID
from ..utils.common_validators import create__check_only_one_is_set__root_validator
from ._base import InputSchema, OutputSchema

Expand Down Expand Up @@ -55,7 +56,7 @@ class GroupAccessRights(BaseModel):


class GroupGet(OutputSchema):
gid: int = Field(..., description="the group ID")
gid: GroupID = Field(..., description="the group ID")
label: str = Field(..., description="the group name")
description: str = Field(..., description="the group description")
thumbnail: AnyUrl | None = Field(
Expand Down Expand Up @@ -114,7 +115,7 @@ def from_model(cls, group: Group, access_rights: AccessRightsDict) -> Self:
"accessRights": {"read": True, "write": False, "delete": False},
},
{
"gid": "0",
"gid": "1",
"label": "All",
"description": "Open to all users",
"accessRights": {"read": True, "write": True, "delete": True},
Expand Down Expand Up @@ -214,7 +215,7 @@ class MyGroupsGet(OutputSchema):
},
],
"all": {
"gid": "0",
"gid": EVERYONE_GROUP_ID,
"label": "All",
"description": "Open to all users",
"accessRights": {"read": True, "write": False, "delete": False},
Expand All @@ -228,13 +229,11 @@ class GroupUserGet(BaseModel):
# OutputSchema

# Identifiers
id: Annotated[
str | None, Field(description="the user id", coerce_numbers_to_str=True)
] = None
user_name: Annotated[IDStr, Field(alias="userName")]
id: Annotated[UserID | None, Field(description="the user's id")] = None
user_name: Annotated[UserNameID, Field(alias="userName")]
gid: Annotated[
str | None,
Field(description="the user primary gid", coerce_numbers_to_str=True),
GroupID | None,
Field(description="the user primary gid"),
] = None

# Private Profile
Expand Down Expand Up @@ -296,7 +295,7 @@ class GroupUserAdd(InputSchema):
"""

uid: UserID | None = None
user_name: Annotated[IDStr | None, Field(alias="userName")] = None
user_name: Annotated[UserNameID | None, Field(alias="userName")] = None
email: Annotated[
LowerCaseEmailStr | None,
Field(
Expand Down
3 changes: 3 additions & 0 deletions packages/models-library/src/models_library/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
EVERYONE_GROUP_ID: Final[int] = 1


__all__: tuple[str, ...] = ("GroupID",)


class GroupTypeInModel(str, enum.Enum):
"""
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@ qx.Class.define("osparc.auth.Data", {
event: "changeUsername",
},

/**
* Email of logged in user, otherwise null
*/
email: {
init: null,
nullable: true,
nullable: true, // email of logged in user, otherwise null
check: "String"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ qx.Class.define("osparc.auth.Manager", {
authData.set({
email: profile["login"],
username: profile["userName"],
firstName: profile["first_name"] || profile["login"],
lastName: profile["last_name"] || "",
firstName: profile["first_name"],
lastName: profile["last_name"],
expirationDate: "expirationDate" in profile ? new Date(profile["expirationDate"]) : null
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
__showBlockedCardFromStatus: function(lockedStatus) {
const status = lockedStatus["status"];
const owner = lockedStatus["owner"];
let toolTip = osparc.utils.Utils.firstsUp(owner["first_name"] || this.tr("A user"), owner["last_name"] || "");
let toolTip = osparc.utils.Utils.firstsUp(owner["first_name"] || this.tr("A user"), owner["last_name"] || ""); // it will be replaced by "userName"
let image = null;
switch (status) {
case "CLOSING":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ qx.Class.define("osparc.data.model.Group", {
return Object.values(this.getGroupMembers()).find(user => user.getUserId() === userId);
},

getGroupMemberByUsername: function(username) {
return Object.values(this.getGroupMembers()).find(user => user.getUsername() === username);
},

getGroupMemberByLogin: function(userEmail) {
return Object.values(this.getGroupMembers()).find(user => user.getEmail() === userEmail);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ qx.Class.define("osparc.data.model.User", {
construct: function(userData) {
this.base(arguments);

let label = userData["login"];
let description = "";
if (userData["first_name"]) {
label = qx.lang.String.firstUp(userData["first_name"]);
description = userData["first_name"];
if (userData["last_name"]) {
label += " " + qx.lang.String.firstUp(userData["last_name"]);
description += " " + userData["last_name"];
}
description += " - ";
}
if (userData["login"]) {
description += userData["login"];
}
const thumbnail = osparc.utils.Avatar.emailToThumbnail(userData["login"]);
this.set({
userId: userData["id"],
groupId: userData["gid"],
label: label,
username: userData["username"] || "",
userId: parseInt(userData["id"]),
groupId: parseInt(userData["gid"]),
username: userData["userName"],
firstName: userData["first_name"],
lastName: userData["last_name"],
email: userData["login"],
label: userData["userName"],
description,
thumbnail,
});
},
Expand All @@ -70,24 +75,31 @@ qx.Class.define("osparc.data.model.User", {
event: "changeLabel",
},

username: {
description: {
check: "String",
nullable: true,
init: null,
event: "changeDescription",
},

username: {
check: "String",
nullable: false,
init: null,
event: "changeUsername",
},

firstName: {
init: "",
nullable: true,
check: "String",
nullable: true,
init: "",
event: "changeFirstName"
},

lastName: {
init: "",
nullable: true,
check: "String",
nullable: true,
init: "",
event: "changeLastName"
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
lockedBy = studyData["state"]["locked"]["owner"];
}
if (locked && lockedBy["user_id"] !== osparc.auth.Data.getInstance().getUserId()) {
const msg = `${studyAlias} ${qx.locale.Manager.tr("is already open by")} ${
const msg = `${studyAlias} ${qx.locale.Manager.tr("is already open by")} ${ // it will be replaced "userName"
"first_name" in lockedBy && lockedBy["first_name"] != null ?
lockedBy["first_name"] :
qx.locale.Manager.tr("another user.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
if (sorted !== 0) {
return sorted;
}
if (("email" in a) && ("email" in b)) {
return a["email"].localeCompare(b["email"]);
if (("label" in a) && ("label" in b)) {
return a["label"].localeCompare(b["label"]);
}
return 0;
}
Expand Down Expand Up @@ -105,22 +105,17 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
alignY: "middle"
}));

const userEmail = new qx.ui.form.TextField().set({
const newMemberUserName = new qx.ui.form.TextField().set({
required: true,
placeholder: this.tr(" New Member's email")
placeholder: this.tr(" New Member's username")
});
hBox.add(userEmail, {
hBox.add(newMemberUserName, {
flex: 1
});

const validator = new qx.ui.form.validation.Manager();
validator.add(userEmail, qx.util.Validate.email());

const addBtn = new qx.ui.form.Button(this.tr("Add"));
addBtn.addListener("execute", function() {
if (validator.validate()) {
this.__addMember(userEmail.getValue());
}
this.__addMember(newMemberUserName.getValue());
}, this);
hBox.add(addBtn);

Expand Down Expand Up @@ -154,9 +149,9 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
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("label", "title", null, item, id);
ctrl.bindProperty("description", "subtitleMD", null, item, id);
ctrl.bindProperty("accessRights", "accessRights", null, item, id);
ctrl.bindProperty("email", "subtitleMD", null, item, id);
ctrl.bindProperty("options", "options", null, item, id);
ctrl.bindProperty("showOptions", "showOptions", null, item, id);
},
Expand Down Expand Up @@ -217,23 +212,25 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
const canIDelete = organization.getAccessRights()["delete"];

const introText = canIWrite ?
this.tr("You can add new members and promote or demote existing ones.") :
this.tr("You can add new members and promote or demote existing ones.<br>In order to add new members, type their username or email if this is public.") :
this.tr("You can't add new members to this Organization. Please contact an Administrator or Manager.");
this.__introLabel.setValue(introText);

this.__memberInvitation.set({
enabled: canIWrite
});

const myGroupId = osparc.auth.Data.getInstance().getGroupId();
const membersList = [];
const groupMembers = organization.getGroupMembers();
Object.values(groupMembers).forEach(groupMember => {
const gid = parseInt(groupMember.getGroupId());
const member = {};
member["userId"] = groupMember.getUserId();
member["groupId"] = groupMember.getGroupId();
member["userId"] = gid === myGroupId ? osparc.auth.Data.getInstance().getUserId() : groupMember.getUserId();
member["groupId"] = gid;
member["thumbnail"] = groupMember.getThumbnail();
member["name"] = groupMember.getLabel();
member["email"] = groupMember.getEmail();
member["label"] = groupMember.getLabel();
member["description"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : groupMember.getDescription();
member["accessRights"] = groupMember.getAccessRights();
let options = [];
if (canIDelete) {
Expand Down Expand Up @@ -287,7 +284,6 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
}
// Let me go?
const openStudy = osparc.store.Store.getInstance().getCurrentStudy();
const myGroupId = osparc.store.Groups.getInstance().getMyGroupId();
if (
openStudy === null &&
canIWrite &&
Expand All @@ -303,16 +299,18 @@ qx.Class.define("osparc.desktop.organizations.MembersList", {
membersList.forEach(member => membersModel.append(qx.data.marshal.Json.createModel(member)));
},

__addMember: async function(orgMemberEmail) {
__addMember: async function(newMemberIdentifier) {
if (this.__currentOrg === null) {
return;
}

const orgId = this.__currentOrg.getGroupId();
const groupsStore = osparc.store.Groups.getInstance();
groupsStore.postMember(orgId, orgMemberEmail)
const isEmail = osparc.utils.Utils.isEmail(newMemberIdentifier);
const request = isEmail ? groupsStore.addMember(orgId, null, newMemberIdentifier) : groupsStore.addMember(orgId, newMemberIdentifier);
request
.then(newMember => {
const text = orgMemberEmail + this.tr(" successfully added");
const text = newMemberIdentifier + this.tr(" successfully added");
osparc.FlashMessenger.getInstance().logAs(text);
this.__reloadOrgMembers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
if (sorted !== 0) {
return sorted;
}
if (("email" in a) && ("email" in b)) {
return a["email"].localeCompare(b["email"]);
if (("label" in a) && ("label" in b)) {
return a["label"].localeCompare(b["label"]);
}
return 0;
}
Expand Down Expand Up @@ -170,9 +170,9 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
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("label", "title", null, item, id);
ctrl.bindProperty("description", "subtitleMD", null, item, id);
ctrl.bindProperty("accessRights", "accessRights", null, item, id);
ctrl.bindProperty("email", "subtitleMD", null, item, id);
ctrl.bindProperty("options", "options", null, item, id);
ctrl.bindProperty("showOptions", "showOptions", null, item, id);
},
Expand Down Expand Up @@ -222,8 +222,8 @@ qx.Class.define("osparc.desktop.wallets.MembersList", {
collaborator["userId"] = gid === myGroupId ? osparc.auth.Data.getInstance().getUserId() : collab.getUserId();
collaborator["groupId"] = collab.getGroupId();
collaborator["thumbnail"] = collab.getThumbnail();
collaborator["name"] = collab.getLabel();
collaborator["email"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getEmail();
collaborator["label"] = collab.getLabel();
collaborator["description"] = gid === myGroupId ? osparc.auth.Data.getInstance().getEmail() : collab.getDescription();
collaborator["accessRights"] = {
read: accessRights["read"],
write: accessRights["write"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ qx.Class.define("osparc.filter.CollaboratorToggleButton", {
});

let label = collaborator.getLabel();
if ("getEmail" in collaborator) {
// user
if ("getEmail" in collaborator && collaborator.getEmail()) {
label += ` (${collaborator.getEmail()})`;
this.setToolTipText(collaborator.getEmail());
}
this.setLabel(label);

if (collaborator.getDescription()) {
const ttt = collaborator.getLabel() + "<br>" + collaborator.getDescription();
this.setToolTipText(ttt);
}

let iconPath = null;
switch (collaborator["collabType"]) {
case 0:
Expand Down
Loading

0 comments on commit a361b74

Please sign in to comment.