Skip to content

Commit

Permalink
Plugin optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrWichlinskiSoftwaremind authored and diocas committed May 19, 2023
1 parent e291dbe commit dd9ddbc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cs3api4lab/api/cs3_file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added cs3api4lab/api/lock_manager.py
Empty file.
1 change: 1 addition & 0 deletions cs3api4lab/config/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def _file_config(self, key):
"oauth_file": None,
"oauth_token": None,
"locks_api": "metadata",
"oauth_token": None,
"dev_env": False
}

Expand Down
9 changes: 6 additions & 3 deletions cs3api4lab/locks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 34 additions & 0 deletions cs3api4lab/tests/test_cs3apismanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit dd9ddbc

Please sign in to comment.