Skip to content

Commit

Permalink
Revert "NXDRIVE-2667: direct transfer allow to select folderish type (#…
Browse files Browse the repository at this point in the history
…3416)" (#3611)

This reverts commit f855697.
  • Loading branch information
mr-shekhar authored Sep 21, 2022
1 parent c95e337 commit 0b9dd8d
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 209 deletions.
1 change: 0 additions & 1 deletion docs/changes/5.3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Release date: `2022-xx-xx`
## GUI

- [NXDRIVE-2765](https://jira.nuxeo.com/browse/NXDRIVE-2765): Fix upgrade/downgrade mechanism
- [NXDRIVE-2667](https://jira.nuxeo.com/browse/NXDRIVE-2667): [Direct Transfer] Allow to select folderish type when using the new remote folder capability
- [NXDRIVE-2735](https://jira.nuxeo.com/browse/NXDRIVE-2735): Uncheck items in Share Debug dialog box

## Packaging / Build
Expand Down
30 changes: 1 addition & 29 deletions nxdrive/client/remote_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@
)
from ..metrics.poll_metrics import CustomPollMetrics
from ..metrics.utils import current_os, user_agent
from ..objects import (
Download,
Metrics,
NuxeoDocumentInfo,
RemoteFileInfo,
SubTypeEnricher,
)
from ..objects import Download, Metrics, NuxeoDocumentInfo, RemoteFileInfo
from ..options import Options
from ..qt.imports import QApplication
from ..utils import (
Expand Down Expand Up @@ -571,15 +565,6 @@ def upload_folder(
res: Dict[str, Any] = self.execute(**kwargs)
return res

def upload_folder_type(
self, parent: str, params: Dict[str, str], /, *, headers: Dict[str, Any] = None
) -> Dict[str, Any]:
"""Create a folder using REST api."""
resp = self.client.request(
"POST", f"{self.client.api_path}/path{parent}", headers=headers, data=params
)
return resp

def cancel_batch(self, batch_details: Dict[str, Any], /) -> None:
"""Cancel an uploaded Batch."""
batch = Batch(service=self.uploads, **batch_details)
Expand Down Expand Up @@ -983,16 +968,3 @@ def _get_trash_condition(self) -> str:
if version_lt(self.client.server_version, "10.2"):
return "AND ecm:currentLifeCycleState != 'deleted'"
return "AND ecm:isTrashed = 0"

def get_doc_enricher(
self, parent: str, enricherType: str = "subtypes"
) -> SubTypeEnricher:

headers: Dict[str, str] = {}
headers = {"enrichers.document": enricherType}

enricherList = SubTypeEnricher.from_dict(
self.fetch(parent, headers=headers, enrichers=[enricherType])
)

return enricherList
46 changes: 3 additions & 43 deletions nxdrive/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,33 +492,6 @@ def _create_remote_folder(
self.directTransferNewFolderError.emit()
return {}

def _create_remote_folder_with_enricher(
self,
remote_parent_path: str,
new_folder: str,
new_folder_type: str,
session_id: int,
/,
) -> Dict[str, Any]:
try:
payload = {
"entity-type": "document",
"name": new_folder,
"type": new_folder_type,
"properties{'dc:title'}": new_folder,
}
res = self.remote.upload_folder_type(remote_parent_path, payload)
new_path = remote_parent_path + "/" + new_folder
self.directTransferNewFolderSuccess.emit(new_path)
return res
except Exception:
log.warning(
f"Could not create the {new_folder!r} folder with type {new_folder_type!r} in {remote_parent_path!r}",
exc_info=True,
)
self.directTransferNewFolderError.emit()
return {}

def _direct_transfer(
self,
local_paths: Dict[Path, int],
Expand All @@ -530,7 +503,6 @@ def _direct_transfer(
duplicate_behavior: str = "create",
last_local_selected_location: Optional[Path] = None,
new_folder: Optional[str] = None,
new_folder_type: Optional[str] = None,
) -> None:
"""Plan the Direct Transfer."""

Expand All @@ -545,17 +517,9 @@ def _direct_transfer(
if new_folder:
self.send_metric("direct_transfer", "new_folder", "1")
expected_session_uid = self.dao.get_count("uid != 0", table="Sessions") + 1
if not new_folder_type or new_folder_type == "Automatic":
item = self._create_remote_folder(
remote_parent_path, new_folder, expected_session_uid
)
else:
item = self._create_remote_folder_with_enricher(
remote_parent_path,
new_folder,
new_folder_type,
expected_session_uid,
)
item = self._create_remote_folder(
remote_parent_path, new_folder, expected_session_uid
)
if not item:
return
remote_parent_path = item["path"]
Expand Down Expand Up @@ -640,7 +604,6 @@ def direct_transfer(
duplicate_behavior: str = "create",
last_local_selected_location: Optional[Path] = None,
new_folder: Optional[str] = None,
new_folder_type: Optional[str] = None,
) -> None:
"""Plan the Direct Transfer."""
self._direct_transfer(
Expand All @@ -651,7 +614,6 @@ def direct_transfer(
duplicate_behavior=duplicate_behavior,
last_local_selected_location=last_local_selected_location,
new_folder=new_folder,
new_folder_type=new_folder_type,
)

def direct_transfer_async(
Expand All @@ -665,7 +627,6 @@ def direct_transfer_async(
duplicate_behavior: str = "create",
last_local_selected_location: Optional[Path] = None,
new_folder: Optional[str] = None,
new_folder_type: Optional[str] = None,
) -> None:
"""Plan the Direct Transfer. Async to not freeze the GUI."""
from .workers import Runner
Expand All @@ -679,7 +640,6 @@ def direct_transfer_async(
duplicate_behavior=duplicate_behavior,
last_local_selected_location=last_local_selected_location,
new_folder=new_folder,
new_folder_type=new_folder_type,
)
self._threadpool.start(runner)

Expand Down
6 changes: 0 additions & 6 deletions nxdrive/gui/folders_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,6 @@ def __init__(self, parent: FoldersDialog, /) -> None:

layout = QVBoxLayout()

self.facetList = self.parent.engine.remote.get_doc_enricher(
self.parent.remote_folder_ref, "subtypes"
)

self.folder_creation_frame = QFrame()
self.operation_result_frame = QFrame()

Expand Down Expand Up @@ -636,7 +632,6 @@ def _add_folder_creation_layout(self) -> None:

self.cb = QComboBox()
self.cb.addItem("Automatic", "create")
self.cb.addItems(self.facetList.facets)

folder_label = QLabel(Translator.get("FOLDER_NAME"))
type_label = QLabel(Translator.get("FOLDER_TYPE"))
Expand Down Expand Up @@ -681,7 +676,6 @@ def accept(self) -> None:
duplicate_behavior=self.parent.cb.currentData(),
last_local_selected_location=self.parent.last_local_selected_location,
new_folder=self.new_folder_name.text(),
new_folder_type=self.cb.currentText(),
)

def close_success(self) -> None:
Expand Down
34 changes: 0 additions & 34 deletions nxdrive/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,37 +507,3 @@ class Session:
completed_on: str
description: str
planned_items: int


# Subtype Enricher Object for doctype info on the Remote Nuxeo repository
@dataclass
class SubTypeEnricher:
uid: str # ref of the document that serves as sync root
path: Optional[str] # title of the document (not guaranteed to be locally unique)
title: str # ref of the parent document
facets: List[str] # subTypes facet
properties: Dict[str, Any] # properties

@staticmethod
def from_dict(
enricher: Dict[str, Any], /, *, parent_uid: str = None
) -> "SubTypeEnricher":
"""Convert Subtype Document enricher to SubTypeEnricher"""
try:
uid = enricher["uid"]
path = enricher["path"]
props = enricher["properties"]
subTypes = enricher["contextParameters"]["subtypes"]
facets = []
for iter in subTypes:
folderish = "Folderish" in iter["facets"]
hiddenInCreation = "HiddenInCreation" in iter["facets"]
if folderish and not hiddenInCreation:
facets.append(iter["type"])

except (KeyError, TypeError):
raise DriveError(
f"This Doctype is missing mandatory information: {enricher!r}"
)

return SubTypeEnricher(uid, parent_uid, path, facets, props)
97 changes: 1 addition & 96 deletions tests/unit/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from nxdrive.exceptions import DriveError
from nxdrive.objects import Blob, NuxeoDocumentInfo, RemoteFileInfo, SubTypeEnricher
from nxdrive.objects import Blob, NuxeoDocumentInfo, RemoteFileInfo


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -116,84 +116,6 @@ def remote_doc_dict() -> Dict[str, Any]:
}


@pytest.fixture(scope="function")
def enricher() -> Dict[str, Any]:
now = datetime.now()
return {
"uid": "fake_id",
"parentId": "fake_id",
"path": "fake/path",
"properties": {"dc:title": "fake"},
"name": "Testing",
"lastModificationDate": "string",
"creationDate": now,
"lockInfo": {"owner": "jdoe", "created": datetime.timestamp(now)},
"contextParameters": {
"subtypes": [
{
"type": "OrderedFolder",
"facets": ["Folderish", "NXTag", "Orderable"],
},
{
"type": "Picture",
"facets": [
"Versionable",
"NXTag",
"Publishable",
"Picture",
"Commentable",
"HasRelatedText",
],
},
{
"type": "Video",
"facets": [
"Versionable",
"NXTag",
"Publishable",
"Video",
"HasStoryboard",
"Commentable",
"HasVideoPreview",
],
},
{
"type": "Note",
"facets": [
"Versionable",
"NXTag",
"Publishable",
"Commentable",
"HasRelatedText",
],
},
{"type": "Folder", "facets": ["Folderish", "NXTag"]},
{
"type": "Audio",
"facets": [
"Versionable",
"NXTag",
"Publishable",
"Commentable",
"Audio",
],
},
{
"type": "File",
"facets": [
"Versionable",
"NXTag",
"Publishable",
"Commentable",
"HasRelatedText",
"Downloadable",
],
},
]
},
}


@pytest.mark.parametrize(
"xpath",
[
Expand Down Expand Up @@ -271,20 +193,3 @@ def test_remote_doc_raise_drive_error(remote_doc_dict):
del remote_doc_dict["id"]
with pytest.raises(DriveError):
RemoteFileInfo.from_dict(remote_doc_dict)


def test_subtype_enricher(enricher):
enricher["uid"] = "MTYxMTIyODA1ODUzNA"
enricherList = SubTypeEnricher.from_dict(enricher)
assert enricherList.facets is not None
assert any("Folder" in s for s in enricherList.facets)


def test_without_subtype_enricher(enricher):
with pytest.raises(DriveError) as exec_info:
enricher["contextParameters"] = None
enricherList = SubTypeEnricher.from_dict(enricher)
assert str(exec_info.value.args[0]).startswith(
"nxdrive.exceptions.DriveError: This Doctype is missing mandatory information:"
)
assert enricherList.facets is None

0 comments on commit 0b9dd8d

Please sign in to comment.