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

NXDRIVE-2942: Improve folder selection on Direct Transfer screen #5189

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions nxdrive/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
errno.ERANGE, # Result too large
}

QUERY_ENDPOINT = "/api/v1/search/lang/NXQL/execute?query="

# OSError indicating the incapacity to do anything because of too long file name or deep tree
LONG_FILE_ERRORS = {errno.ENAMETOOLONG}
if WINDOWS:
Expand Down
72 changes: 59 additions & 13 deletions nxdrive/gui/folders_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import getLogger
from typing import Iterator, List, Union
from typing import Any, Iterator, List, Union

from nuxeo.models import Document

Expand Down Expand Up @@ -97,29 +97,48 @@

def enable(self) -> bool:
"""Allow to select the folder only if the user can effectively create documents inside."""
return (
"HiddenInCreation" not in self.doc.facets
and self.doc.type not in Options.disallowed_types_for_dt
and "AddChildren" in self.doc.contextParameters["permissions"]
)
try:
return (

Check warning on line 101 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L100-L101

Added lines #L100 - L101 were not covered by tests
"HiddenInCreation" not in self.doc.facets
and self.doc.type not in Options.disallowed_types_for_dt
and "AddChildren" in self.doc.contextParameters["permissions"]
)
except Exception:
return (

Check warning on line 107 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L106-L107

Added lines #L106 - L107 were not covered by tests
"HiddenInCreation" not in self.doc["facets"]
and self.doc["type"] not in Options.disallowed_types_for_dt
and "AddChildren" in self.doc["contextParameters"]["permissions"]
)

def get_id(self) -> str:
"""The document's UID."""
return self.doc.uid
try:
return self.doc.uid
except Exception:
return self.doc["uid"]

Check warning on line 118 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L115-L118

Added lines #L115 - L118 were not covered by tests

def get_label(self) -> str:
"""The document's name as it is showed in the tree."""
return self.doc.title
try:
return self.doc.title
except Exception:
return self.doc["title"]

Check warning on line 125 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L122-L125

Added lines #L122 - L125 were not covered by tests

def get_path(self) -> str:
"""Guess the document's path on the server."""
return self.doc.path
try:
return self.doc.path
except Exception:
return self.doc["path"]

Check warning on line 132 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L129-L132

Added lines #L129 - L132 were not covered by tests

def selectable(self) -> bool:
"""Allow to fetch its children only if the user has at least the "Read" permission
and if it contains at least one subfolder.
"""
return "Read" in self.doc.contextParameters["permissions"]
try:
return "Read" in self.doc.contextParameters["permissions"]
except Exception:
return "Read" in self.doc["contextParameters"]["permissions"]

Check warning on line 141 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L138-L141

Added lines #L138 - L141 were not covered by tests


class FilteredDoc(FileInfo):
Expand Down Expand Up @@ -213,10 +232,12 @@

def __init__(self, remote: Remote, /) -> None:
self.remote = remote
self.personal_space_uid = ""

Check warning on line 235 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L235

Added line #L235 was not covered by tests

def get_personal_space(self) -> "Documents":
"""Retrieve the "Personal space" special folder."""
personal_space = self.remote.personal_space()
self.personal_space_uid = personal_space.uid

Check warning on line 240 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L240

Added line #L240 was not covered by tests

# Alter the title to use "Personal space" instead of "Firstname Lastname"
personal_space.title = Translator.get("PERSONAL_SPACE")
Expand Down Expand Up @@ -247,18 +268,43 @@
)
)

def get_roots(self) -> List[Any]:
from ..constants import QUERY_ENDPOINT

Check warning on line 272 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L272

Added line #L272 was not covered by tests

url = (

Check warning on line 274 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L274

Added line #L274 was not covered by tests
f"{QUERY_ENDPOINT}select * from Document WHERE ecm:mixinType = 'Folderish'"
)
return self.remote.client.request("GET", url).json()["entries"]

Check warning on line 277 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L277

Added line #L277 was not covered by tests

def _get_root_folders(self) -> List["Documents"]:
"""Get root folders.
Use a try...except block to prevent loading error on the root,
else it will also show a loading error for the personal space.
"""
root_details = []

Check warning on line 284 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L284

Added line #L284 was not covered by tests
try:
root = self.remote.documents.get(path="/")
return [Doc(doc) for doc in self._get_children(root.uid)]
roots = self.get_roots()
for root in roots:
if (

Check warning on line 288 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L286-L288

Added lines #L286 - L288 were not covered by tests
root["type"] == "Folder"
and root["uid"] != self.personal_space_uid
and root["parentRef"] != self.personal_space_uid
):
doc = self.remote.fetch(

Check warning on line 293 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L293

Added line #L293 was not covered by tests
root["uid"],
enrichers=["permissions"],
)
if (

Check warning on line 297 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L297

Added line #L297 was not covered by tests
"Write" in doc["contextParameters"]["permissions"]
or "ReadWrite" in doc["contextParameters"]["permissions"]
or "Everything" in doc["contextParameters"]["permissions"]
):
yield Doc(doc)

Check warning on line 302 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L302

Added line #L302 was not covered by tests
except Exception:
log.warning("Error while retrieving documents on '/'", exc_info=True)
context = {"permissions": [], "hasFolderishChild": False}
return [Doc(Document(title="/", contextParameters=context))]
root_details.append([Doc(Document(title="/", contextParameters=context))])
return root_details

Check warning on line 307 in nxdrive/gui/folders_model.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L306-L307

Added lines #L306 - L307 were not covered by tests

def get_top_documents(self) -> Iterator["Documents"]:
"""Fetch all documents at the root."""
Expand Down
Loading