From dd9ddbcca8a9233eb610e4fb61ee9a32e98f8955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wichli=C5=84ski?= Date: Wed, 5 Oct 2022 16:50:35 +0200 Subject: [PATCH] Plugin optimization --- cs3api4lab/api/cs3_file_api.py | 2 +- cs3api4lab/api/lock_manager.py | 0 cs3api4lab/config/config_manager.py | 1 + cs3api4lab/locks/base.py | 9 ++++--- cs3api4lab/tests/test_cs3apismanager.py | 34 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 cs3api4lab/api/lock_manager.py diff --git a/cs3api4lab/api/cs3_file_api.py b/cs3api4lab/api/cs3_file_api.py index 930e24ed..34081a02 100644 --- a/cs3api4lab/api/cs3_file_api.py +++ b/cs3api4lab/api/cs3_file_api.py @@ -16,7 +16,7 @@ import cs3.storage.provider.v1beta1.provider_api_pb2 as cs3sp from google.protobuf.json_format import MessageToDict -from cs3api4lab.exception.exceptions import ResourceNotFoundError +from cs3api4lab.exception.exceptions import ResourceNotFoundError, FileLockedError from cs3api4lab.utils.file_utils import FileUtils from cs3api4lab.api.storage_api import StorageApi diff --git a/cs3api4lab/api/lock_manager.py b/cs3api4lab/api/lock_manager.py new file mode 100644 index 00000000..e69de29b diff --git a/cs3api4lab/config/config_manager.py b/cs3api4lab/config/config_manager.py index b06e5773..82ffb31c 100644 --- a/cs3api4lab/config/config_manager.py +++ b/cs3api4lab/config/config_manager.py @@ -244,6 +244,7 @@ def _file_config(self, key): "oauth_file": None, "oauth_token": None, "locks_api": "metadata", + "oauth_token": None, "dev_env": False } diff --git a/cs3api4lab/locks/base.py b/cs3api4lab/locks/base.py index d9b1377e..0ada2739 100644 --- a/cs3api4lab/locks/base.py +++ b/cs3api4lab/locks/base.py @@ -38,9 +38,12 @@ def get_current_user(self): metadata=[('x-access-token', self.auth.authenticate())]) return self.user.user - def resolve_file_path(self, path): - file_name = path.split('/')[-1] - return self._get_conflict_filename(file_name) + def resolve_file_path(self, stat): + if self.is_valid_external_lock(stat): + file_name = stat['filepath'].split('/')[-1] + file_dir = '/'.join(stat['filepath'].split('/')[0:-1]) + return self._resolve_directory(file_dir, self.config.endpoint) + self._get_conflict_filename(file_name) + return stat['filepath'] @abstractmethod def is_valid_external_lock(self, stat): diff --git a/cs3api4lab/tests/test_cs3apismanager.py b/cs3api4lab/tests/test_cs3apismanager.py index 8dd2a93b..57481102 100644 --- a/cs3api4lab/tests/test_cs3apismanager.py +++ b/cs3api4lab/tests/test_cs3apismanager.py @@ -248,6 +248,40 @@ def test_is_editor_shared_as_viewer(self): pass #we don't need any actions here + def test_is_editor(self): + file_path = '/home/test_is_editor_file.txt' + message = "Lorem ipsum dolor sit amet..." + try: + self.file_api.write_file(file_path, message, self.endpoint) + stat = self.file_api.stat_info(file_path, self.config.endpoint) + result = self.contents_manager._is_editor(stat) + self.assertEqual(result, True, 'Incorrect check if file is editor') + finally: + try: + self.contents_manager.delete_file(file_path) + except Exception: + pass + + def test_is_editor_shared_as_viewer(self): + self.content = "Lorem ipsum dolor sit amet..." + file_path = '/home/test_is_editor_file.txt' + remote_path = '/reva/richard/test_is_editor_file.txt' + einstein_id = '4c510ada-c86b-4815-8820-42cdf82c3d51' + einstein_idp = 'cernbox.cern.ch' + try: + richards_share = self.create_share('richard', einstein_id, einstein_idp, file_path, 'viewer') + self.share_id = richards_share['opaque_id'] + stat = self.file_api.stat_info(remote_path, self.config.endpoint) + result = self.contents_manager._is_editor(stat) + self.assertEqual(result, False, 'Is editor should be false') + finally: + try: + self.remove_test_share('richard', self.share_id) + self.remove_test_file('richard', file_path) + except Exception: + pass #we don't need any actions here + + def test_delete_non_exits_file(self): file_path = "/test_delete_non_exits_file.txt" with self.assertRaises(web.HTTPError):