Skip to content

Commit 0a541ed

Browse files
committed
Merge pull request #66 from Frencil/shared_link_password
Adding support for shared_link password parameter
2 parents 36b010b + ef31c96 commit 0a541ed

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

boxsdk/object/item.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def move(self, parent_folder):
159159
}
160160
return self.update_info(data)
161161

162-
def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None):
162+
def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None, password=None):
163163
"""Get a shared link for the item with the given access permissions.
164164
165165
:param access:
@@ -186,6 +186,11 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo
186186
If this parameter is None, the default setting will be used.
187187
:type allow_preview:
188188
`bool` or None
189+
:param password:
190+
The password required to view this link. If no password is specified then no password will be set.
191+
Please notice that this is a premium feature, which might not be available to your app.
192+
:type password:
193+
`unicode` or None
189194
:returns:
190195
The URL of the shared link.
191196
:rtype:
@@ -208,6 +213,9 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo
208213
if allow_preview is not None:
209214
permissions['can_preview'] = allow_preview
210215

216+
if password is not None:
217+
data['shared_link']['password'] = password
218+
211219
item = self.update_info(data, etag=etag)
212220
return item.shared_link['url']
213221

test/unit/object/test_item.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ def shared_link_access(request):
7171
return request.param
7272

7373

74+
@pytest.fixture(params=('hunter2', None))
75+
def shared_link_password(request):
76+
return request.param
77+
78+
7479
@pytest.fixture(params=(date(2015, 5, 5), None))
7580
def shared_link_unshared_at(request):
7681
return request.param
@@ -81,6 +86,7 @@ def test_get_shared_link(
8186
mock_box_session,
8287
shared_link_access,
8388
shared_link_unshared_at,
89+
shared_link_password,
8490
shared_link_can_download,
8591
shared_link_can_preview,
8692
test_url,
@@ -96,6 +102,8 @@ def test_get_shared_link(
96102
expected_data['shared_link']['access'] = shared_link_access
97103
if shared_link_unshared_at is not None:
98104
expected_data['shared_link']['unshared_at'] = shared_link_unshared_at.isoformat()
105+
if shared_link_password is not None:
106+
expected_data['shared_link']['password'] = shared_link_password
99107
if shared_link_can_download is not None or shared_link_can_preview is not None:
100108
expected_data['shared_link']['permissions'] = permissions = {}
101109
if shared_link_can_download is not None:
@@ -106,6 +114,7 @@ def test_get_shared_link(
106114
etag=etag,
107115
access=shared_link_access,
108116
unshared_at=shared_link_unshared_at,
117+
password=shared_link_password,
109118
allow_download=shared_link_can_download,
110119
allow_preview=shared_link_can_preview,
111120
)

0 commit comments

Comments
 (0)