Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explorer): normalize folder path #2329

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import typing as t
import uuid
from datetime import datetime, timedelta
from pathlib import Path, PurePath
from pathlib import Path, PurePath, PurePosixPath

from antares.study.version import StudyVersion
from pydantic import BeforeValidator, ConfigDict, Field, PlainSerializer, computed_field, field_validator
Expand Down Expand Up @@ -358,7 +358,7 @@ class NonStudyFolderDTO(AntaresBaseModel):
so the user can navigate in the hierarchy
"""

path: Path
path: PurePosixPath
workspace: str
name: str
has_children: bool = Field(
Expand All @@ -368,18 +368,25 @@ class NonStudyFolderDTO(AntaresBaseModel):
model_config = ConfigDict(populate_by_name=True)

@computed_field(alias="parentPath")
def parent_path(self) -> Path:
def parent_path(self) -> PurePosixPath:
"""
This computed field is convenient for the front.

This field is also aliased as parentPath to match the front-end naming convention.

Returns: the parent path of the current directory. Starting with the workspace as a root directory (we want /workspafe/folder1/sub... and not workspace/folder1/fsub... ).
"""
workspace_path = Path(f"/{self.workspace}")
workspace_path = PurePosixPath(f"/{self.workspace}")
full_path = workspace_path.joinpath(self.path)
return full_path.parent

@field_validator("path", mode="before")
def to_posix(cls, path: Path) -> PurePosixPath:
"""
Always convert path to posix path.
"""
return PurePosixPath(path)


class WorkspaceMetadata(AntaresBaseModel):
"""
Expand Down
3 changes: 2 additions & 1 deletion antarest/study/storage/explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This file is part of the Antares project.

import logging
from pathlib import PurePosixPath
from typing import List

from antarest.core.config import Config
Expand Down Expand Up @@ -48,7 +49,7 @@ def list_dir(
try:
if is_non_study_folder(child, workspace.filter_in, workspace.filter_out):
# we don't want to expose the full absolute path on the server
child_rel_path = child.relative_to(workspace.path)
child_rel_path = PurePosixPath(child.relative_to(workspace.path))
has_children = has_non_study_folder(child, workspace.filter_in, workspace.filter_out)
directories.append(
NonStudyFolderDTO(
Expand Down
Loading