Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion boxsdk/object/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, allow_download=None, allow_preview=None, password=None):
"""Get a shared link for the item with the given access permissions.

:param access:
Expand All @@ -186,6 +186,11 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo
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.
:type password:
`unicode` or None
:returns:
The URL of the shared link.
:rtype:
Expand All @@ -208,6 +213,9 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo
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']

Expand Down
9 changes: 9 additions & 0 deletions test/unit/object/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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,
)
Expand Down