@@ -129,18 +129,27 @@ def get_share_time(self):
129
129
return datetime .datetime .fromtimestamp (
130
130
self .__get_int ('stime' )
131
131
)
132
-
133
- def get_expiration (self ):
132
+
133
+ def get_expiration_datetime (self ):
134
134
"""Returns the expiration date.
135
135
136
136
:returns: expiration date
137
137
:rtype: datetime object
138
138
"""
139
- exp = self .__get_int ( 'expiration' )
139
+ exp = self .share_info [ 'expiration' ]
140
140
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
144
153
return None
145
154
146
155
def get_token (self ):
@@ -730,9 +739,10 @@ def update_share(self, share_id, **kwargs):
730
739
perms = kwargs .get ('perms' , None )
731
740
password = kwargs .get ('password' , None )
732
741
public_upload = kwargs .get ('public_upload' , None )
742
+ expiration = kwargs .get ('expiration' , None )
733
743
if (isinstance (perms , int )) and (perms > self .OCS_PERMISSION_ALL ):
734
744
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 ) ):
736
746
return False
737
747
if not isinstance (share_id , int ):
738
748
return False
@@ -744,6 +754,8 @@ def update_share(self, share_id, **kwargs):
744
754
data ['password' ] = password
745
755
if (public_upload is not None ) and (isinstance (public_upload , bool )):
746
756
data ['publicUpload' ] = str (public_upload ).lower ()
757
+ if expiration is not None :
758
+ data ['expireDate' ] = self .__parse_expiration_date (expiration )
747
759
748
760
res = self .__make_ocs_request (
749
761
'PUT' ,
@@ -794,7 +806,8 @@ def share_file_with_link(self, path, **kwargs):
794
806
"""
795
807
perms = kwargs .get ('perms' , None )
796
808
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 )
798
811
799
812
800
813
path = self .__normalize_path (path )
@@ -808,6 +821,8 @@ def share_file_with_link(self, path, **kwargs):
808
821
post_data ['password' ] = password
809
822
if perms :
810
823
post_data ['permissions' ] = perms
824
+ if expiration is not None :
825
+ post_data ['expireDate' ] = self .__parse_expiration_date (expiration )
811
826
812
827
res = self .__make_ocs_request (
813
828
'POST' ,
@@ -819,12 +834,25 @@ def share_file_with_link(self, path, **kwargs):
819
834
tree = ET .fromstring (res .content )
820
835
self .__check_ocs_status (tree )
821
836
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
+
822
848
return ShareInfo (
823
849
{
824
850
'id' : data_el .find ('id' ).text ,
825
851
'path' :path ,
826
852
'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
828
856
}
829
857
)
830
858
raise HTTPResponseError (res )
@@ -968,8 +996,8 @@ def user_exists(self, user_name):
968
996
"""Checks a user via provisioning API.
969
997
If you get back an error 999, then the provisioning API is not enabled.
970
998
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
973
1001
974
1002
"""
975
1003
users = self .search_users (user_name )
@@ -995,7 +1023,7 @@ def search_users(self, user_name):
995
1023
tree = ET .fromstring (res .text )
996
1024
users = [x .text for x in tree .findall ('data/users/element' )]
997
1025
998
- return users
1026
+ return users
999
1027
1000
1028
raise HTTPResponseError (res )
1001
1029
@@ -1685,7 +1713,7 @@ def __strip_dav_path(self, path):
1685
1713
if path .startswith (self .__davpath ):
1686
1714
return path [len (self .__davpath ):]
1687
1715
return path
1688
-
1716
+
1689
1717
def __webdav_move_copy (self ,remote_path_source ,remote_path_target ,operation ):
1690
1718
"""Copies or moves a remote file or directory
1691
1719
@@ -1733,6 +1761,21 @@ def __xml_to_dict(self, element):
1733
1761
else :
1734
1762
return_dict [el .tag ] = el .text
1735
1763
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
1736
1779
1737
1780
def __get_shareinfo (self , data_el ):
1738
1781
"""Simple helper which returns instance of ShareInfo class
0 commit comments