From 2c35d50fab35302187ea5a5525efa06b9f98ac1c Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Fri, 21 Aug 2015 11:28:47 -0400 Subject: [PATCH 1/3] adding support for shared_link password parameter --- boxsdk/object/item.py | 9 ++++++++- test/unit/object/test_item.py | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/boxsdk/object/item.py b/boxsdk/object/item.py index 2a7d9f017..2294a65b1 100644 --- a/boxsdk/object/item.py +++ b/boxsdk/object/item.py @@ -159,7 +159,7 @@ def move(self, parent_folder): } return self.update_info(data) - def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None): + def get_shared_link(self, access=None, etag=None, unshared_at=None, password=None, allow_download=None, allow_preview=None): """Get a shared link for the item with the given access permissions. :param access: @@ -176,6 +176,10 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo and has permission to set expiration dates. :type unshared_at: :class:`datetime.date` or None + :param password: + The password required to view this link. If no password is specified, the default password will be used. + :type password: + `unicode` or None :param allow_download: Whether or not the item being shared can be downloaded when accessed via the shared link. If this parameter is None, the default setting will be used. @@ -201,6 +205,9 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo if unshared_at is not None: data['shared_link']['unshared_at'] = unshared_at.isoformat() + if password is not None: + data['shared_link']['password'] = password + if allow_download is not None or allow_preview is not None: data['shared_link']['permissions'] = permissions = {} if allow_download is not None: diff --git a/test/unit/object/test_item.py b/test/unit/object/test_item.py index 4b485c6e3..5a468ed77 100644 --- a/test/unit/object/test_item.py +++ b/test/unit/object/test_item.py @@ -71,6 +71,11 @@ def shared_link_access(request): return request.param +@pytest.fixture(params=('hunter2', None)) +def shared_link_password(request): + return request.param + + @pytest.fixture(params=(date(2015, 5, 5), None)) def shared_link_unshared_at(request): return request.param @@ -81,6 +86,7 @@ def test_get_shared_link( mock_box_session, shared_link_access, shared_link_unshared_at, + shared_link_password, shared_link_can_download, shared_link_can_preview, test_url, @@ -96,6 +102,8 @@ def test_get_shared_link( expected_data['shared_link']['access'] = shared_link_access if shared_link_unshared_at is not None: expected_data['shared_link']['unshared_at'] = shared_link_unshared_at.isoformat() + if shared_link_password is not None: + expected_data['shared_link']['password'] = shared_link_password if shared_link_can_download is not None or shared_link_can_preview is not None: expected_data['shared_link']['permissions'] = permissions = {} if shared_link_can_download is not None: @@ -106,6 +114,7 @@ def test_get_shared_link( etag=etag, access=shared_link_access, unshared_at=shared_link_unshared_at, + password=shared_link_password, allow_download=shared_link_can_download, allow_preview=shared_link_can_preview, ) From d33c64b321094afe8a39349e05fed1a0dabf5e1b Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Fri, 21 Aug 2015 12:00:25 -0400 Subject: [PATCH 2/3] addressing feedback from @Jeff-Meadows: - moved password argument to end of argument list - updated param doc to be correct in the event of no password - updated param doc to notify that this is a premium feature --- boxsdk/object/item.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/boxsdk/object/item.py b/boxsdk/object/item.py index 2294a65b1..8bc6c9826 100644 --- a/boxsdk/object/item.py +++ b/boxsdk/object/item.py @@ -159,7 +159,7 @@ def move(self, parent_folder): } return self.update_info(data) - def get_shared_link(self, access=None, etag=None, unshared_at=None, password=None, allow_download=None, allow_preview=None): + def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None, password=None): """Get a shared link for the item with the given access permissions. :param access: @@ -176,8 +176,6 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, password=Non and has permission to set expiration dates. :type unshared_at: :class:`datetime.date` or None - :param password: - The password required to view this link. If no password is specified, the default password will be used. :type password: `unicode` or None :param allow_download: @@ -190,6 +188,9 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, password=Non If this parameter is None, the default setting will be used. :type allow_preview: `bool` or None + :param password: + The password required to view this link. If no password is specified then no password will be set. + Please notice that this is a premium feature, which might not be available to your app. :returns: The URL of the shared link. :rtype: @@ -205,9 +206,6 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, password=Non if unshared_at is not None: data['shared_link']['unshared_at'] = unshared_at.isoformat() - if password is not None: - data['shared_link']['password'] = password - if allow_download is not None or allow_preview is not None: data['shared_link']['permissions'] = permissions = {} if allow_download is not None: @@ -215,6 +213,9 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, password=Non if allow_preview is not None: permissions['can_preview'] = allow_preview + if password is not None: + data['shared_link']['password'] = password + item = self.update_info(data, etag=etag) return item.shared_link['url'] From ef31c9651c4d7cecc32c9df6ccfd8649999f98f9 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Fri, 21 Aug 2015 13:17:44 -0400 Subject: [PATCH 3/3] fix positioning of type doc on password for get_shared_link --- boxsdk/object/item.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boxsdk/object/item.py b/boxsdk/object/item.py index 8bc6c9826..38835463a 100644 --- a/boxsdk/object/item.py +++ b/boxsdk/object/item.py @@ -176,8 +176,6 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo and has permission to set expiration dates. :type unshared_at: :class:`datetime.date` or None - :type password: - `unicode` or None :param allow_download: Whether or not the item being shared can be downloaded when accessed via the shared link. If this parameter is None, the default setting will be used. @@ -191,6 +189,8 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo :param password: The password required to view this link. If no password is specified then no password will be set. Please notice that this is a premium feature, which might not be available to your app. + :type password: + `unicode` or None :returns: The URL of the shared link. :rtype: