@@ -129,18 +129,27 @@ def get_share_time(self):
129129 return datetime .datetime .fromtimestamp (
130130 self .__get_int ('stime' )
131131 )
132-
133- def get_expiration (self ):
132+
133+ def get_expiration_datetime (self ):
134134 """Returns the expiration date.
135135
136136 :returns: expiration date
137137 :rtype: datetime object
138138 """
139- exp = self .__get_int ( 'expiration' )
139+ exp = self .share_info [ 'expiration' ]
140140 if exp is not None :
141- return datetime .datetime .fromtimestamp (
142- exp
143- )
141+ return datetime .datetime .strptime (exp , '%Y-%m-%d %H:%M:%S' )
142+ return None
143+
144+ def get_expiration (self ):
145+ """Returns the expiration date.
146+
147+ :returns: expiration date in YYYY-MM-DD hh:mm:ss format
148+ :rtype: string
149+ """
150+ exp = self .share_info ['expiration' ]
151+ if exp is not None :
152+ return exp
144153 return None
145154
146155 def get_token (self ):
@@ -730,9 +739,10 @@ def update_share(self, share_id, **kwargs):
730739 perms = kwargs .get ('perms' , None )
731740 password = kwargs .get ('password' , None )
732741 public_upload = kwargs .get ('public_upload' , None )
742+ expiration = kwargs .get ('expiration' , None )
733743 if (isinstance (perms , int )) and (perms > self .OCS_PERMISSION_ALL ):
734744 perms = None
735- if not (perms or password or (public_upload is not None )):
745+ if not (perms or password or (public_upload is not None ) or ( expiration is not None ) ):
736746 return False
737747 if not isinstance (share_id , int ):
738748 return False
@@ -744,6 +754,8 @@ def update_share(self, share_id, **kwargs):
744754 data ['password' ] = password
745755 if (public_upload is not None ) and (isinstance (public_upload , bool )):
746756 data ['publicUpload' ] = str (public_upload ).lower ()
757+ if expiration is not None :
758+ data ['expireDate' ] = self .__parse_expiration_date (expiration )
747759
748760 res = self .__make_ocs_request (
749761 'PUT' ,
@@ -794,7 +806,8 @@ def share_file_with_link(self, path, **kwargs):
794806 """
795807 perms = kwargs .get ('perms' , None )
796808 public_upload = kwargs .get ('public_upload' , 'false' )
797- password = kwargs .get ('password' , None )
809+ password = kwargs .get ('password' , None )
810+ expiration = kwargs .get ('expiration' , None )
798811
799812
800813 path = self .__normalize_path (path )
@@ -808,6 +821,8 @@ def share_file_with_link(self, path, **kwargs):
808821 post_data ['password' ] = password
809822 if perms :
810823 post_data ['permissions' ] = perms
824+ if expiration is not None :
825+ post_data ['expireDate' ] = self .__parse_expiration_date (expiration )
811826
812827 res = self .__make_ocs_request (
813828 'POST' ,
@@ -819,12 +834,25 @@ def share_file_with_link(self, path, **kwargs):
819834 tree = ET .fromstring (res .content )
820835 self .__check_ocs_status (tree )
821836 data_el = tree .find ('data' )
837+
838+ expiration = None
839+ exp_el = data_el .find ('expiration' )
840+ if exp_el is not None and exp_el .text is not None and len (exp_el .text ) > 0 :
841+ expiration = exp_el .text
842+
843+ permissions = None
844+ perms_el = data_el .find ('permissions' )
845+ if perms_el is not None and perms_el .text is not None and len (perms_el .text ) > 0 :
846+ permissions = int (perms_el .text )
847+
822848 return ShareInfo (
823849 {
824850 'id' : data_el .find ('id' ).text ,
825851 'path' :path ,
826852 'link' : data_el .find ('url' ).text ,
827- 'token' : data_el .find ('token' ).text
853+ 'token' : data_el .find ('token' ).text ,
854+ 'expiration' : expiration ,
855+ 'permissions' :permissions
828856 }
829857 )
830858 raise HTTPResponseError (res )
@@ -968,8 +996,8 @@ def user_exists(self, user_name):
968996 """Checks a user via provisioning API.
969997 If you get back an error 999, then the provisioning API is not enabled.
970998
971- :param user_name: name of user to be checked
972- :returns: True if user found
999+ :param user_name: name of user to be checked
1000+ :returns: True if user found
9731001
9741002 """
9751003 users = self .search_users (user_name )
@@ -995,7 +1023,7 @@ def search_users(self, user_name):
9951023 tree = ET .fromstring (res .text )
9961024 users = [x .text for x in tree .findall ('data/users/element' )]
9971025
998- return users
1026+ return users
9991027
10001028 raise HTTPResponseError (res )
10011029
@@ -1685,7 +1713,7 @@ def __strip_dav_path(self, path):
16851713 if path .startswith (self .__davpath ):
16861714 return path [len (self .__davpath ):]
16871715 return path
1688-
1716+
16891717 def __webdav_move_copy (self ,remote_path_source ,remote_path_target ,operation ):
16901718 """Copies or moves a remote file or directory
16911719
@@ -1733,6 +1761,21 @@ def __xml_to_dict(self, element):
17331761 else :
17341762 return_dict [el .tag ] = el .text
17351763 return return_dict
1764+
1765+ @staticmethod
1766+ def __parse_expiration_date (date ):
1767+ """Converts the given datetime object into the format required
1768+ by the share API
1769+ :param date: datetime object
1770+ :returns: string encoded to use as expireDate parameter in the share API
1771+ """
1772+ if date is None :
1773+ return None
1774+
1775+ if isinstance (date , datetime .datetime ):
1776+ return date .strftime ('YYYY-MM-DD' )
1777+
1778+ return date
17361779
17371780 def __get_shareinfo (self , data_el ):
17381781 """Simple helper which returns instance of ShareInfo class
0 commit comments