Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions owncloud/owncloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def from_public_link(cls, public_link, folder_password='', **kwargs):
public_link_components = parse.urlparse(public_link)
url = public_link_components.scheme + '://' + public_link_components.hostname
if public_link_components.port:
url += ":" + public_link_components.port
url += ":" + str(public_link_components.port)
folder_token = public_link_components.path.split('/')[-1]
anon_session = cls(url, **kwargs)
anon_session.anon_login(folder_token, folder_password=folder_password)
Expand Down Expand Up @@ -868,6 +868,7 @@ def share_file_with_link(self, path, **kwargs):
defaults to read only (1)
:param public_upload (optional): allows users to upload files or folders
:param password (optional): sets a password
:param expire_date (optional): sets an expiration date for the shared link
https://doc.owncloud.com/server/next/admin_manual/configuration/files/file_sharing_configuration.html
:param name (optional): display name for the link
:returns: instance of :class:`ShareInfo` with the share info
Expand All @@ -877,6 +878,7 @@ def share_file_with_link(self, path, **kwargs):
perms = kwargs.get('perms', None)
public_upload = kwargs.get('public_upload', 'false')
password = kwargs.get('password', None)
expire_date = kwargs.get('expire_date', None)
name = kwargs.get('name', None)

path = self._normalize_path(path)
Expand All @@ -888,6 +890,8 @@ def share_file_with_link(self, path, **kwargs):
post_data['publicUpload'] = str(public_upload).lower()
if isinstance(password, six.string_types):
post_data['password'] = password
if isinstance(expire_date, datetime.date):
post_data['expireDate'] = expire_date
if name is not None:
post_data['name'] = self._encode_string(name)
if perms:
Expand All @@ -903,13 +907,25 @@ def share_file_with_link(self, path, **kwargs):
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
data_el = tree.find('data')
exp_el = data_el.find('expiration')
expiration = None
if exp_el is not None:
if exp_el.text is not None:
expiration = int(
round(
datetime.datetime.strptime(
exp_el.text, "%Y-%m-%d %H:%M:%S"
).timestamp()
)
)
return ShareInfo(
{
'id': data_el.find('id').text,
'path': path,
'url': data_el.find('url').text,
'token': data_el.find('token').text,
'name': data_el.find('name').text
'name': data_el.find('name').text,
"expiration": expiration,
}
)
raise HTTPResponseError(res)
Expand Down
5 changes: 4 additions & 1 deletion owncloud/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ def test_share_with_link(self, file_name):
path = self.test_root + file_name
self.assertTrue(self.client.put_file_contents(path, 'hello world!'))

share_info = self.client.share_file_with_link(path, public_upload=False, password='AnvvsP1234', name='Test Link')
tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
share_info = self.client.share_file_with_link(path, public_upload=False, password='AnvvsP1234', name='Test Link', expire_date=tomorrow.date())

self.assertTrue(self.client.is_shared(path))
self.assertTrue(isinstance(share_info, owncloud.ShareInfo))
Expand All @@ -722,6 +723,8 @@ def test_share_with_link(self, file_name):
self.assertEqual(share_info.get_name(), 'Test Link')
self.assertTrue(type(share_info.get_link()) is str)
self.assertTrue(type(share_info.get_token()) is str)
self.assertTrue(type(share_info.get_expiration()) is datetime.datetime)


def test_share_with_link_non_existing_file(self):
"""Test sharing a file with link"""
Expand Down