Skip to content

Commit 3dce21e

Browse files
author
Vincent Petry
committed
Merge pull request #117 from SergioBertolinSG/extra_args_sharing_with_link
Extra args sharing with link
2 parents 75ac7f2 + 4afbd5c commit 3dce21e

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

owncloud/owncloud.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,25 +652,41 @@ def copy(self, remote_path_source, remote_path_target):
652652
"""
653653
return self.__webdav_move_copy(remote_path_source,remote_path_target,"COPY")
654654

655-
def share_file_with_link(self, path):
655+
def share_file_with_link(self, path, **kwargs):
656656
"""Shares a remote file with link
657657
658658
:param path: path to the remote file to share
659+
:param perms (optional): permission of the shared object
660+
defaults to read only (1)
661+
:param public_upload (optional): allows users to upload files or folders
662+
:param password (optional): sets a password
663+
http://doc.owncloud.org/server/6.0/admin_manual/sharing_api/index.html
659664
:returns: instance of :class:`PublicShare` with the share info
660665
or False if the operation failed
661666
:raises: HTTPResponseError in case an HTTP error status was returned
662667
"""
668+
perms = kwargs.get('perms', None)
669+
public_upload = kwargs.get('public_upload', 'false')
670+
password = kwargs.get('password', None)
671+
672+
663673
path = self.__normalize_path(path)
664674
post_data = {
665675
'shareType': self.OCS_SHARE_TYPE_LINK,
666-
'path': self.__encode_string(path)
676+
'path': self.__encode_string(path),
667677
}
678+
if (public_upload is not None) and (isinstance(public_upload, bool)):
679+
post_data['publicUpload'] = str(public_upload).lower()
680+
if isinstance(password, basestring):
681+
post_data['password'] = password
682+
if perms:
683+
post_data['permissions'] = perms
668684

669685
res = self.__make_ocs_request(
670686
'POST',
671687
self.OCS_SERVICE_SHARE,
672688
'shares',
673-
data=post_data
689+
data = post_data
674690
)
675691
if res.status_code == 200:
676692
tree = ET.fromstring(res.content)

owncloud/test/test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ def test_share_with_link(self, file_name):
562562
path = self.test_root + file_name
563563
self.assertTrue(self.client.put_file_contents(path, 'hello world!'))
564564

565-
share_info = self.client.share_file_with_link(path)
565+
share_info = self.client.share_file_with_link(path, public_upload=True, password='1234')
566566

567567
self.assertTrue(self.client.is_shared(path))
568568
self.assertTrue(isinstance(share_info, owncloud.PublicShare))
@@ -571,6 +571,8 @@ def test_share_with_link(self, file_name):
571571
self.assertTrue(type(share_info.link) is str)
572572
self.assertTrue(type(share_info.token) is str)
573573

574+
575+
574576
def test_share_with_link_non_existing_file(self):
575577
"""Test sharing a file with link"""
576578
with self.assertRaises(owncloud.ResponseError) as e:
@@ -592,6 +594,8 @@ def test_share_with_user(self, file_name):
592594
self.assertTrue(type(share_info.share_id) is int)
593595
self.assertTrue(share_info.perms, 31)
594596
self.assertTrue(self.client.delete(path))
597+
598+
595599

596600
@data_provider(files)
597601
def test_delete_share(self, file_name):

0 commit comments

Comments
 (0)