Skip to content

Commit

Permalink
back to uid
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jan 16, 2025
1 parent afa016e commit 47c5c0a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..basic_types import IDStr
from ..folders import FolderID
from ..groups import GroupID
from ..users import UserID
from ..utils.common_validators import null_or_none_str_to_none_validator
from ..workspaces import WorkspaceID
from ._base import InputSchema, OutputSchema
Expand All @@ -19,7 +20,7 @@ class FolderGet(OutputSchema):
created_at: datetime
modified_at: datetime
trashed_at: datetime | None
trashed_by: GroupID | None
trashed_by: UserID | None
owner: GroupID
workspace_id: WorkspaceID | None
my_access_rights: AccessRights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
PlainSerializer,
field_validator,
)
from simcore_service_webserver.models import UserID

from ..api_schemas_long_running_tasks.tasks import TaskGet
from ..basic_types import LongTruncatedStr, ShortTruncatedStr
from ..emails import LowerCaseEmailStr
from ..folders import FolderID
from ..groups import GroupID
from ..projects import ClassifierID, DateTimeStr, NodesDict, ProjectID
from ..projects_access import AccessRights, GroupIDStr
from ..projects_state import ProjectState
Expand Down Expand Up @@ -99,7 +99,7 @@ class ProjectGet(OutputSchema):
folder_id: FolderID | None

trashed_at: datetime | None
trashed_by: GroupID | None
trashed_by: UserID | None

_empty_description = field_validator("description", mode="before")(
none_to_empty_str_pre_validator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
copy_data_folders_from_project,
get_project_total_size_simcore_s3,
)
from ..users._users_service import get_user_primary_group_id
from ..users.api import get_user_fullname
from ..workspaces.api import check_user_workspace_access, get_user_workspace
from ..workspaces.errors import WorkspaceAccessForbiddenError
Expand Down Expand Up @@ -421,7 +422,16 @@ async def create_project( # pylint: disable=too-many-arguments,too-many-branche
}

# Ensures is like ProjectGet
data = ProjectGet.from_domain_model(new_project).data(exclude_unset=True)
if trashed_by_uid := new_project.get("trashed_by"):
trashed_by_primary_gid = await get_user_primary_group_id(
request.app, trashed_by_uid
)
else:
trashed_by_primary_gid = None

data = ProjectGet.from_domain_model(
new_project, trashed_by_primary_gid=trashed_by_primary_gid
).data(exclude_unset=True)

raise web.HTTPCreated(
text=json_dumps({"data": data}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
projects.c.hidden,
projects.c.workspace_id,
projects.c.trashed,
projects.c.trashed_by,
projects.c.trashed_explicitly,
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from . import projects_api
from ._access_rights_api import check_user_project_permission
from .exceptions import ProjectRunningConflictError
from .models import ProjectPatchExtended
from .models import ProjectPatchInternalExtended

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -94,8 +94,10 @@ async def _schedule():
user_id=user_id,
product_name=product_name,
project_uuid=project_id,
project_patch=ProjectPatchExtended(
trashed_at=arrow.utcnow().datetime, trashed_explicitly=explicit
project_patch=ProjectPatchInternalExtended(
trashed_at=arrow.utcnow().datetime,
trashed_explicitly=explicit,
trashed_by=user_id,
),
)

Expand All @@ -113,5 +115,7 @@ async def untrash_project(
user_id=user_id,
product_name=product_name,
project_uuid=project_id,
project_patch=ProjectPatchExtended(trashed_at=None, trashed_explicitly=False),
project_patch=ProjectPatchInternalExtended(
trashed_at=None, trashed_explicitly=False, trashed_by=None
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ProjectDB(BaseModel):
hidden: bool
workspace_id: WorkspaceID | None
trashed: datetime | None
trashed_by: UserID | None
trashed_explicitly: bool = False

model_config = ConfigDict(from_attributes=True, arbitrary_types_allowed=True)
Expand Down Expand Up @@ -94,9 +95,10 @@ class UserProjectAccessRightsWithWorkspace(BaseModel):
model_config = ConfigDict(from_attributes=True)


class ProjectPatchExtended(ProjectPatch):
class ProjectPatchInternalExtended(ProjectPatch):
# ONLY used internally
trashed_at: datetime | None
trashed_by: UserID | None
trashed_explicitly: bool

model_config = ConfigDict(populate_by_name=True, extra="forbid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
ProjectTooManyProjectOpenedError,
)
from .lock import get_project_locked_state, is_project_locked, lock_project
from .models import ProjectDict, ProjectPatchExtended
from .models import ProjectDict, ProjectPatchInternalExtended
from .settings import ProjectsSettings, get_plugin_settings
from .utils import extract_dns_without_default_port

Expand Down Expand Up @@ -252,7 +252,7 @@ async def patch_project(
*,
user_id: UserID,
project_uuid: ProjectID,
project_patch: ProjectPatch | ProjectPatchExtended,
project_patch: ProjectPatch | ProjectPatchInternalExtended,
product_name: ProductName,
):
patch_project_data = project_patch.to_domain_model()
Expand Down
12 changes: 6 additions & 6 deletions services/web/server/tests/unit/with_dbs/03/test_trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def test_trash_projects( # noqa: PLR0915
assert got.trashed_at
assert trashing_at < got.trashed_at
assert got.trashed_at < arrow.utcnow().datetime
assert got.trashed_by == logged_user["primary_gid"]
assert got.trashed_by == logged_user["id"]

# LIST trashed
resp = await client.get("/v0/projects", params={"filters": '{"trashed": true}'})
Expand Down Expand Up @@ -233,7 +233,7 @@ async def test_trash_single_folder(client: TestClient, logged_user: UserInfoDict
assert got.trashed_at
assert trashing_at < got.trashed_at
assert got.trashed_at < arrow.utcnow().datetime
assert got.trashed_by == logged_user["primary_gid"]
assert got.trashed_by == logged_user["id"]
assert got.owner == logged_user["primary_gid"]

# LIST trashed
Expand Down Expand Up @@ -350,19 +350,19 @@ async def test_trash_folder_with_content(
data, _ = await assert_status(resp, status.HTTP_200_OK)
got = FolderGet.model_validate(data)
assert got.trashed_at is not None
assert got.trashed_by == logged_user["primary_gid"]
assert got.trashed_by == logged_user["id"]

resp = await client.get(f"/v0/folders/{subfolder.folder_id}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
got = FolderGet.model_validate(data)
assert got.trashed_at is not None
assert got.trashed_by == logged_user["primary_gid"]
assert got.trashed_by == logged_user["id"]

resp = await client.get(f"/v0/projects/{project_uuid}")
data, _ = await assert_status(resp, status.HTTP_200_OK)
got = ProjectGet.model_validate(data)
assert got.trashed_at is not None
assert got.trashed_by == logged_user["primary_gid"]
assert got.trashed_by == logged_user["id"]

# UNTRASH folder
resp = await client.post(f"/v0/folders/{folder.folder_id}:untrash")
Expand Down Expand Up @@ -477,7 +477,7 @@ async def test_trash_empty_workspace(
)
assert page.data[0].trashed_at is not None
assert before_trash < page.data[0].trashed_at
assert page.data[0].trashed_by == logged_user["primary_gid"]
assert page.data[0].trashed_by == logged_user["id"]

# --------

Expand Down

0 comments on commit 47c5c0a

Please sign in to comment.