From 0b9dd8dd5795d27a760988014f6af62d72e3fc2d Mon Sep 17 00:00:00 2001 From: mr-shekhar <85621953+mr-shekhar@users.noreply.github.com> Date: Wed, 21 Sep 2022 20:27:19 +0530 Subject: [PATCH] Revert "NXDRIVE-2667: direct transfer allow to select folderish type (#3416)" (#3611) This reverts commit f8556976e5bac7b9e7f0c4b3c18a874fe64604fa. --- docs/changes/5.3.0.md | 1 - nxdrive/client/remote_client.py | 30 +--------- nxdrive/engine/engine.py | 46 +--------------- nxdrive/gui/folders_dialog.py | 6 -- nxdrive/objects.py | 34 ------------ tests/unit/test_objects.py | 97 +-------------------------------- 6 files changed, 5 insertions(+), 209 deletions(-) diff --git a/docs/changes/5.3.0.md b/docs/changes/5.3.0.md index b841a107bc..8515803a94 100644 --- a/docs/changes/5.3.0.md +++ b/docs/changes/5.3.0.md @@ -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 diff --git a/nxdrive/client/remote_client.py b/nxdrive/client/remote_client.py index 584f9185e9..5f511f75e9 100644 --- a/nxdrive/client/remote_client.py +++ b/nxdrive/client/remote_client.py @@ -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 ( @@ -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) @@ -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 diff --git a/nxdrive/engine/engine.py b/nxdrive/engine/engine.py index 64fb566757..dd3c0cbf22 100644 --- a/nxdrive/engine/engine.py +++ b/nxdrive/engine/engine.py @@ -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], @@ -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.""" @@ -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"] @@ -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( @@ -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( @@ -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 @@ -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) diff --git a/nxdrive/gui/folders_dialog.py b/nxdrive/gui/folders_dialog.py index f93d52c868..e84e037903 100644 --- a/nxdrive/gui/folders_dialog.py +++ b/nxdrive/gui/folders_dialog.py @@ -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() @@ -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")) @@ -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: diff --git a/nxdrive/objects.py b/nxdrive/objects.py index d0324671f3..a17dd60832 100644 --- a/nxdrive/objects.py +++ b/nxdrive/objects.py @@ -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) diff --git a/tests/unit/test_objects.py b/tests/unit/test_objects.py index 7b9f09c321..60a112e3b1 100644 --- a/tests/unit/test_objects.py +++ b/tests/unit/test_objects.py @@ -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") @@ -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", [ @@ -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