@@ -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 ):
@@ -727,9 +736,10 @@ def update_share(self, share_id, **kwargs):
727
736
perms = kwargs .get ('perms' , None )
728
737
password = kwargs .get ('password' , None )
729
738
public_upload = kwargs .get ('public_upload' , None )
739
+ expiration = kwargs .get ('expiration' , None )
730
740
if (isinstance (perms , int )) and (perms > self .OCS_PERMISSION_ALL ):
731
741
perms = None
732
- if not (perms or password or (public_upload is not None )):
742
+ if not (perms or password or (public_upload is not None ) or ( expiration is not None ) ):
733
743
return False
734
744
if not isinstance (share_id , int ):
735
745
return False
@@ -741,6 +751,8 @@ def update_share(self, share_id, **kwargs):
741
751
data ['password' ] = password
742
752
if (public_upload is not None ) and (isinstance (public_upload , bool )):
743
753
data ['publicUpload' ] = str (public_upload ).lower ()
754
+ if expiration is not None :
755
+ data ['expireDate' ] = self .__parse_expiration_date (expiration )
744
756
745
757
res = self .__make_ocs_request (
746
758
'PUT' ,
@@ -791,7 +803,8 @@ def share_file_with_link(self, path, **kwargs):
791
803
"""
792
804
perms = kwargs .get ('perms' , None )
793
805
public_upload = kwargs .get ('public_upload' , 'false' )
794
- password = kwargs .get ('password' , None )
806
+ password = kwargs .get ('password' , None )
807
+ expiration = kwargs .get ('expiration' , None )
795
808
796
809
797
810
path = self .__normalize_path (path )
@@ -805,6 +818,8 @@ def share_file_with_link(self, path, **kwargs):
805
818
post_data ['password' ] = password
806
819
if perms :
807
820
post_data ['permissions' ] = perms
821
+ if expiration is not None :
822
+ post_data ['expireDate' ] = self .__parse_expiration_date (expiration )
808
823
809
824
res = self .__make_ocs_request (
810
825
'POST' ,
@@ -816,12 +831,25 @@ def share_file_with_link(self, path, **kwargs):
816
831
tree = ET .fromstring (res .content )
817
832
self .__check_ocs_status (tree )
818
833
data_el = tree .find ('data' )
834
+
835
+ expiration = None
836
+ exp_el = data_el .find ('expiration' )
837
+ if exp_el is not None and exp_el .text is not None and len (exp_el .text ) > 0 :
838
+ expiration = exp_el .text
839
+
840
+ permissions = None
841
+ perms_el = data_el .find ('permissions' )
842
+ if perms_el is not None and perms_el .text is not None and len (perms_el .text ) > 0 :
843
+ permissions = int (perms_el .text )
844
+
819
845
return ShareInfo (
820
846
{
821
847
'id' : data_el .find ('id' ).text ,
822
848
'path' :path ,
823
849
'link' : data_el .find ('url' ).text ,
824
- 'token' : data_el .find ('token' ).text
850
+ 'token' : data_el .find ('token' ).text ,
851
+ 'expiration' : expiration ,
852
+ 'permissions' :permissions
825
853
}
826
854
)
827
855
raise HTTPResponseError (res )
@@ -965,8 +993,8 @@ def user_exists(self, user_name):
965
993
"""Checks a user via provisioning API.
966
994
If you get back an error 999, then the provisioning API is not enabled.
967
995
968
- :param user_name: name of user to be checked
969
- :returns: True if user found
996
+ :param user_name: name of user to be checked
997
+ :returns: True if user found
970
998
971
999
"""
972
1000
users = self .search_users (user_name )
@@ -992,7 +1020,7 @@ def search_users(self, user_name):
992
1020
tree = ET .fromstring (res .text )
993
1021
users = [x .text for x in tree .findall ('data/users/element' )]
994
1022
995
- return users
1023
+ return users
996
1024
997
1025
raise HTTPResponseError (res )
998
1026
@@ -1701,7 +1729,7 @@ def __strip_dav_path(self, path):
1701
1729
if path .startswith (self .__davpath ):
1702
1730
return path [len (self .__davpath ):]
1703
1731
return path
1704
-
1732
+
1705
1733
def __webdav_move_copy (self ,remote_path_source ,remote_path_target ,operation ):
1706
1734
"""Copies or moves a remote file or directory
1707
1735
@@ -1749,6 +1777,21 @@ def __xml_to_dict(self, element):
1749
1777
else :
1750
1778
return_dict [el .tag ] = el .text
1751
1779
return return_dict
1780
+
1781
+ @staticmethod
1782
+ def __parse_expiration_date (date ):
1783
+ """Converts the given datetime object into the format required
1784
+ by the share API
1785
+ :param date: datetime object
1786
+ :returns: string encoded to use as expireDate parameter in the share API
1787
+ """
1788
+ if date is None :
1789
+ return None
1790
+
1791
+ if isinstance (date , datetime .datetime ):
1792
+ return date .strftime ('YYYY-MM-DD' )
1793
+
1794
+ return date
1752
1795
1753
1796
def __get_shareinfo (self , data_el ):
1754
1797
"""Simple helper which returns instance of ShareInfo class
0 commit comments