python-o365
python-o365 copied to clipboard
more parameters for onedrive share_with_link()
I am wondering if someone can add supports for more parameters, esp password, and expiration date for share_with_link() at https://github.com/O365/python-o365/blob/412d5b7dc521328ceb84a0086f1d89036bc09bd8/O365/drive.py#L830 The api doc is at https://docs.microsoft.com/en-us/graph/api/listitem-createlink?view=graph-rest-beta&tabs=http
Also, is it possible to update expiration date of a shared link without recreating a new link?
Thanks!
I don't have the time to implement this. PR are very welcome
Also, is it possible to update expiration date of a shared link without recreating a new link?
If it's possible on MS Graph it should be possible on O365
Here is the updated function. Can you merge it to the base? I have tested it and it works as expected.
def share_with_link(self, share_type='view', share_scope='anonymous', share_password=None, share_expiration_date=None):
""" Creates or returns a link you can share with others
:param str share_type: 'view' to allow only view access,
'edit' to allow editions, and
'embed' to allow the DriveItem to be embedded
:param str share_scope: 'anonymous': anyone with the link can access.
'organization' Only organization members can access
:param str share_password: sharing link password that is set by the creator. Optional.
:param str share_expiration_date: format of yyyy-MM-dd (e.g., 2022-02-14) that indicates the expiration date of the permission. Optional.
:return: link to share
:rtype: DriveItemPermission
"""
if not self.object_id:
return None
url = self.build_url(
self._endpoints.get('share_link').format(id=self.object_id))
data = {
'type': share_type,
'scope': share_scope
}
if share_password is not None: data['password']=share_password
if share_expiration_date is not None: data['expirationDateTime']=share_expiration_date
response = self.con.post(url, data=data)
if not response:
return None
data = response.json()
# return data.get('link', {}).get('webUrl')
return DriveItemPermission(parent=self, **{self._cloud_data_key: data})
Great thanks!