Skip to content

Commit

Permalink
NXDRIVE-2942: Improve folder selection on Direct Transfer screen --Fi…
Browse files Browse the repository at this point in the history
…xed expansion
  • Loading branch information
gitofanindya committed Sep 4, 2024
1 parent f6e3e7f commit 27190ff
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
7 changes: 6 additions & 1 deletion nxdrive/gui/folders_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ def run(self) -> None:

try:
if info:
children = list(self.tree.client.get_children(info))
if not info.is_expandable() and not info.get_path().startswith(

Check warning on line 49 in nxdrive/gui/folders_loader.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_loader.py#L49

Added line #L49 was not covered by tests
"/default-domain/UserWorkspaces/"
):
children = []

Check warning on line 52 in nxdrive/gui/folders_loader.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_loader.py#L52

Added line #L52 was not covered by tests
else:
children = list(self.tree.client.get_children(info))

Check warning on line 54 in nxdrive/gui/folders_loader.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_loader.py#L54

Added line #L54 was not covered by tests
else:
children = list(self.tree.client.get_top_documents())
except Exception:
Expand Down
57 changes: 33 additions & 24 deletions nxdrive/gui/folders_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,23 @@ def get_path(self) -> str:
class Doc(FileInfo):
"""A folderish document. Used by the Direct Transfer feature."""

def __init__(self, doc: Document, /, *, parent: FileInfo = None) -> None:
def __init__(
self, doc: Document, expandable: bool = True, /, *, parent: FileInfo = None
) -> None:
super().__init__(parent=parent)
self.doc = doc
self.expandable = expandable

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

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L89

Added line #L89 was not covered by tests

def __repr__(self) -> str:
return (
f"{type(self).__name__}<id={self.get_id()}, label={self.get_label()}, "
f"{type(self).__name__}<id={self.get_id()}, label={self.get_label()}, admin={self.is_expandable()!r}, "
f"parent={self.get_path()!r}, enable={self.enable()!r}, selectable={self.selectable()!r}>"
)

def is_expandable(self) -> bool:
"""Returns if the current user is an Admin"""
return self.expandable

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

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L99

Added line #L99 was not covered by tests

def folderish(self) -> bool:
"""Only folders are used, so it is always True."""
return True
Expand Down Expand Up @@ -281,30 +288,32 @@ def _get_root_folders(self) -> List["Documents"]:
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 = []
try:
roots = self.get_roots()
for root in roots:
if (
root["type"] == "Folder"
and root["uid"] != self.personal_space_uid
and root["parentRef"] != self.personal_space_uid
):
doc = self.remote.fetch(
root["uid"],
enrichers=["permissions"],
)
if (
"Write" in doc["contextParameters"]["permissions"]
or "ReadWrite" in doc["contextParameters"]["permissions"]
or "Everything" in doc["contextParameters"]["permissions"]
):
yield Doc(doc)
root = self.remote.documents.get(path="/")
return [Doc(doc) for doc in self._get_children(root.uid)]
except Exception:
log.warning("Error while retrieving documents on '/'", exc_info=True)
context = {"permissions": [], "hasFolderishChild": False}
root_details.append([Doc(Document(title="/", contextParameters=context))])
return root_details
if Options.direct_transfer_folder_only_view:
roots = self.get_roots()
ret_list = []
for root in roots:
if root["type"] == "Folder" and not root["path"].startswith(

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

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L295-L299

Added lines #L295 - L299 were not covered by tests
"/default-domain/UserWorkspaces/"
):
doc = self.remote.fetch(

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
root["uid"],
enrichers=["permissions"],
)
if (

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

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L306

Added line #L306 was not covered by tests
"Write" in doc["contextParameters"]["permissions"]
or "ReadWrite" in doc["contextParameters"]["permissions"]
or "Everything" in doc["contextParameters"]["permissions"]
):
ret_list.append(Doc(doc, False))
return ret_list

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

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L311-L312

Added lines #L311 - L312 were not covered by tests
else:
log.warning("Error while retrieving documents on '/'", exc_info=True)
context = {"permissions": [], "hasFolderishChild": False}
return [Doc(Document(title="/", contextParameters=context))]

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

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_model.py#L314-L316

Added lines #L314 - L316 were not covered by tests

def get_top_documents(self) -> Iterator["Documents"]:
"""Fetch all documents at the root."""
Expand Down
14 changes: 7 additions & 7 deletions nxdrive/gui/folders_treeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ def __init__(self, parent: "FoldersDialog", client: FoldersOnly, /) -> None:

def on_selection_changed(self, current: QModelIndex, _: QModelIndex, /) -> None:
"""Actions to do when a folder is selected."""
item = self.model().itemFromIndex(current).data(qt.UserRole)
self.parent.remote_folder.setText(item.get_path())
self.parent.remote_folder_ref = item.get_id()
self.parent.remote_folder_title = item.get_label()
self.current = current
self.parent.button_ok_state()
self.parent.update_file_group()
if item := self.model().itemFromIndex(current).data(qt.UserRole):
self.parent.remote_folder.setText(item.get_path())
self.parent.remote_folder_ref = item.get_id()
self.parent.remote_folder_title = item.get_label()
self.current = current
self.parent.button_ok_state()
self.parent.update_file_group()

Check warning on line 193 in nxdrive/gui/folders_treeview.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/folders_treeview.py#L187-L193

Added lines #L187 - L193 were not covered by tests

def refresh_selected(self) -> None:
"""Force reload the the current selected index."""
Expand Down
1 change: 1 addition & 0 deletions nxdrive/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class MetaOptions(type):
"debug_pydev": (False, "default"),
"delay": (30, "default"),
"deletion_behavior": ("unsync", "default"),
"direct_transfer_folder_only_view": (False, "default"),
"disabled_file_integrity_check": (False, "default"),
"disallowed_types_for_dt": (__doctypes_no_dt, "default"),
"dt_hide_personal_space": (False, "default"),
Expand Down

0 comments on commit 27190ff

Please sign in to comment.