@@ -43,15 +43,17 @@ def __init__(self, res):
4343class PublicShare ():
4444 """Public share information"""
4545
46- def __init__ (self , share_id , target_file , link , token ):
46+ def __init__ (self , share_id , target_file , link , token , ** kwargs ):
4747 self .share_id = share_id
4848 self .target_file = target_file
4949 self .link = link
5050 self .token = token
51+ self .permissions = kwargs .get ('permissions' , 1 )
52+ self .expiration_date = kwargs .get ('expiration_date' , None )
5153
5254 def __str__ (self ):
53- return 'PublicShare(id=%i,path=%s,link=%s,token=%s)' % \
54- (self .share_id , self .target_file , self .link , self .token )
55+ return 'PublicShare(id=%i,path=%s,link=%s,token=%s,permissions=%s,expiration_date=%s )' % \
56+ (self .share_id , self .target_file , self .link , self .token , self . permissions , self . expiration_date )
5557
5658
5759class UserShare ():
@@ -596,6 +598,7 @@ def update_share(self, share_id, **kwargs):
596598 :param perms: (int) update permissions (see share_file_with_user() below)
597599 :param password: (string) updated password for public link Share
598600 :param public_upload: (boolean) enable/disable public upload for public shares
601+ :param expiration_date: (optional) expiration date object, or string in format 'YYYY-MM-DD'
599602 :returns: True if the operation succeeded, False otherwise
600603 :raises: HTTPResponseError in case an HTTP error status was returned
601604 """
@@ -609,6 +612,9 @@ def update_share(self, share_id, **kwargs):
609612 return False
610613 if not isinstance (share_id , int ):
611614 return False
615+ expiration = kwargs .get ('expiration_date' , None )
616+ if expiration is not None :
617+ post_data ['expireDate' ] = self .__parse_expiration_date (expiration )
612618
613619 data = {}
614620 if perms :
@@ -660,6 +666,7 @@ def share_file_with_link(self, path, **kwargs):
660666 defaults to read only (1)
661667 :param public_upload (optional): allows users to upload files or folders
662668 :param password (optional): sets a password
669+ :param expiration_date: (optional) expiration date object, or string in format 'YYYY-MM-DD'
663670 http://doc.owncloud.org/server/6.0/admin_manual/sharing_api/index.html
664671 :returns: instance of :class:`PublicShare` with the share info
665672 or False if the operation failed
@@ -668,7 +675,7 @@ def share_file_with_link(self, path, **kwargs):
668675 perms = kwargs .get ('perms' , None )
669676 public_upload = kwargs .get ('public_upload' , 'false' )
670677 password = kwargs .get ('password' , None )
671-
678+ expiration = kwargs . get ( 'expiration_date' , None )
672679
673680 path = self .__normalize_path (path )
674681 post_data = {
@@ -681,6 +688,8 @@ def share_file_with_link(self, path, **kwargs):
681688 post_data ['password' ] = password
682689 if perms :
683690 post_data ['permissions' ] = perms
691+ if expiration is not None :
692+ post_data ['expiration' ] = self .__parse_expiration_date (expiration )
684693
685694 res = self .__make_ocs_request (
686695 'POST' ,
@@ -692,11 +701,19 @@ def share_file_with_link(self, path, **kwargs):
692701 tree = ET .fromstring (res .content )
693702 self .__check_ocs_status (tree )
694703 data_el = tree .find ('data' )
704+
705+ expiration = None
706+ exp_el = data_el .find ('expiration' )
707+ if exp_el is not None and exp_el .text is not None and len (exp_el .text ) > 0 :
708+ expiration = int (exp_el .text )
709+
695710 return PublicShare (
696711 int (data_el .find ('id' ).text ),
697712 path ,
698713 data_el .find ('url' ).text ,
699- data_el .find ('token' ).text
714+ data_el .find ('token' ).text ,
715+ permissions = int (data_el .find ('permissions' ).text ),
716+ expiration = expiration
700717 )
701718 raise HTTPResponseError (res )
702719
@@ -1371,6 +1388,22 @@ def __encode_string(s):
13711388 return s .encode ('utf-8' )
13721389 return s
13731390
1391+ @staticmethod
1392+ def __parse_expiration_date (date ):
1393+ """Converts the given datetime object into the format required
1394+ by the share API
1395+
1396+ :param date: datetime object
1397+ :returns: string encoded to use as expireDate parameter in the share API
1398+ """
1399+ if date is None :
1400+ return None
1401+
1402+ if isinstance (date , datetime .datetime ):
1403+ return date .strftime ('YYYY-MM-DD' )
1404+
1405+ return date
1406+
13741407 @staticmethod
13751408 def __check_ocs_status (tree , accepted_codes = [100 ]):
13761409 """Checks the status code of an OCS request
@@ -1491,7 +1524,7 @@ def __strip_dav_path(self, path):
14911524 if path .startswith (self .__davpath ):
14921525 return path [len (self .__davpath ):]
14931526 return path
1494-
1527+
14951528 def __webdav_move_copy (self ,remote_path_source ,remote_path_target ,operation ):
14961529 """Copies or moves a remote file or directory
14971530
0 commit comments