Skip to content

Commit

Permalink
feature(studies): add has_children flag to non study folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Jan 6, 2025
1 parent 8b0ac51 commit 6baf05d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class NonStudyFolderDTO(AntaresBaseModel):
path: Path
workspace: str
name: str
has_children: bool # true when has non study folder children (false when has no children or only study children)

@computed_field(alias="parentPath")
def parent_path(self) -> Path:
Expand Down
13 changes: 9 additions & 4 deletions antarest/study/storage/explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from antarest.study.storage.utils import (
get_folder_from_workspace,
get_workspace_from_config,
is_study_folder,
should_ignore_folder_for_scan,
has_non_study_folder,
is_non_study_folder,
)

logger = logging.getLogger(__name__)
Expand All @@ -41,10 +41,15 @@ def list_dir(
directory_path = get_folder_from_workspace(workspace, workspace_directory_path)
directories = []
for child in directory_path.iterdir():
if child.is_dir() and not is_study_folder(child) and not should_ignore_folder_for_scan(child):
if is_non_study_folder(child):
# we don't want to expose the full absolute path on the server
child_rel_path = child.relative_to(workspace.path)
directories.append(NonStudyFolderDTO(path=child_rel_path, workspace=workspace_name, name=child.name))
has_children = has_non_study_folder(child)
directories.append(
NonStudyFolderDTO(
path=child_rel_path, workspace=workspace_name, name=child.name, has_children=has_children
)
)
return directories

def list_workspaces(
Expand Down
11 changes: 11 additions & 0 deletions antarest/study/storage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,14 @@ def should_ignore_folder_for_scan(path: Path) -> bool:
return True

return False


def has_non_study_folder(path: Path) -> bool:
for sub_path in path.iterdir():
if is_non_study_folder(sub_path):
return True
return False


def is_non_study_folder(path: Path) -> bool:
return path.is_dir() and not is_study_folder(path) and not should_ignore_folder_for_scan(path)
6 changes: 1 addition & 5 deletions tests/integration/explorer_blueprint/test_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ def test_explorer(client: TestClient, admin_access_token: str, study_tree: Path)
directories_res = res.json()
directories_res = [NonStudyFolderDTO(**d) for d in directories_res]
directorires_expected = [
NonStudyFolderDTO(
path=Path("folder/trash"),
workspace="ext",
name="trash",
)
NonStudyFolderDTO(path=Path("folder/trash"), workspace="ext", name="trash", has_children=False)
]
assert directories_res == directorires_expected

Expand Down
17 changes: 13 additions & 4 deletions tests/storage/business/test_explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_list_dir_empty_string(config_scenario_a: Config):
result = explorer.list_dir("diese", "")

assert len(result) == 1
assert result[0] == NonStudyFolderDTO(path=Path("folder"), workspace="diese", name="folder")
assert result[0] == NonStudyFolderDTO(path=Path("folder"), workspace="diese", name="folder", has_children=True)


@pytest.mark.unit_test
Expand All @@ -95,9 +95,18 @@ def test_list_dir_several_subfolders(config_scenario_a: Config):

assert len(result) == 3
folder_path = Path("folder")
assert NonStudyFolderDTO(path=(folder_path / "subfolder1"), workspace="diese", name="subfolder1") in result
assert NonStudyFolderDTO(path=(folder_path / "subfolder2"), workspace="diese", name="subfolder2") in result
assert NonStudyFolderDTO(path=(folder_path / "subfolder3"), workspace="diese", name="subfolder3") in result
assert (
NonStudyFolderDTO(path=(folder_path / "subfolder1"), workspace="diese", name="subfolder1", has_children=False)
in result
)
assert (
NonStudyFolderDTO(path=(folder_path / "subfolder2"), workspace="diese", name="subfolder2", has_children=False)
in result
)
assert (
NonStudyFolderDTO(path=(folder_path / "subfolder3"), workspace="diese", name="subfolder3", has_children=False)
in result
)


@pytest.mark.unit_test
Expand Down

0 comments on commit 6baf05d

Please sign in to comment.