Skip to content

Commit

Permalink
feat: Add redirect_url fields to Sign Request
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 committed Jul 26, 2022
1 parent 78d2dbb commit b60c4d4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
14 changes: 12 additions & 2 deletions boxsdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,9 @@ def create_sign_request(
email_message: Optional[Iterable] = None,
email_subject: Optional[str] = None,
external_id: Optional[str] = None,
is_document_preparation_needed: Optional[bool] = None
is_document_preparation_needed: Optional[bool] = None,
redirect_url: Optional[str] = None,
declined_redirect_url: Optional[str] = None,
) -> dict:
"""
Used to create a new sign request.
Expand Down Expand Up @@ -1537,6 +1539,11 @@ def create_sign_request(
This can be used to reference an ID in an external system that the sign request is related to.
:param is_document_preparation_needed:
Indicates if the sender should receive a prepare_url in the response to complete document preparation via UI.
:param redirect_url:
The URL that a signer will be redirected to after signing a document.
If no declined redirect URL is specified, this URL will be used for decline actions as well.
:param declined_redirect_url:
The URL that a signer will be redirected to after declining to sign a document.
:returns:
A dictionary representing a created SignRequest
"""
Expand Down Expand Up @@ -1567,7 +1574,10 @@ def create_sign_request(
body['external_id'] = external_id
if is_document_preparation_needed:
body['is_document_preparation_needed'] = is_document_preparation_needed

if redirect_url:
body['redirect_url'] = redirect_url
if declined_redirect_url:
body['declined_redirect_url'] = declined_redirect_url
box_response = self._session.post(url, data=json.dumps(body))
response = box_response.json()
return self.translator.translate(
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/sign_requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A Sign Request can refer to one or more Box Files and can be sent to one or more
Create Sign Request
------------------------

The [`client.create_sign_request(files, signers, parent_folder_id, prefill_tags=None, are_reminders_enabled=None, are_text_signatures_enabled=None, days_valid=None, email_message=None, email_subject=None, external_id=None, is_document_preparation_needed=None)`][create-sign-request]
The [`client.create_sign_request(files, signers, parent_folder_id, prefill_tags=None, are_reminders_enabled=None, are_text_signatures_enabled=None, days_valid=None, email_message=None, email_subject=None, external_id=None, is_document_preparation_needed=None, redirect_url=None, declined_redirect_url=None)`][create-sign-request]
method will create a Sign Request. You need to provide at least one file (from which the signing document will be created) and at least one signer to receive the Sign Request.

<!-- sample post_sign_requests -->
Expand Down
14 changes: 11 additions & 3 deletions test/unit/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,8 @@ def mock_sign_request_response():
'email_subject': 'Sign Request from Acme',
'external_id': '123',
'is_document_preparation_needed': 'true',
'redirect_url': 'https://www.box.com/accepted',
'declined_redirect_url': 'https://www.box.com/declined',
'parent_folder': {
'id': '12345',
'type': 'folder',
Expand Down Expand Up @@ -1666,7 +1668,8 @@ def test_get_sign_requests(mock_client, mock_box_session, mock_sign_request_resp

def test_create_sign_request(mock_client, mock_box_session, mock_sign_request_response):
expected_url = f'{API.BASE_API_URL}/sign_requests'

redirect_url = 'https://www.box.com/accepted'
declined_redirect_url = 'https://www.box.com/declined'
source_file = {
'id': '12345',
'type': 'file'
Expand Down Expand Up @@ -1695,18 +1698,23 @@ def test_create_sign_request(mock_client, mock_box_session, mock_sign_request_re
{
'id': parent_folder_id,
'type': 'folder'
}
},
'redirect_url': redirect_url,
'declined_redirect_url': declined_redirect_url,
})
mock_box_session.post.return_value.json.return_value = mock_sign_request_response

new_sign_request = mock_client.create_sign_request(
files, signers, parent_folder_id)
files, signers, parent_folder_id,
redirect_url=redirect_url, declined_redirect_url=declined_redirect_url)

mock_box_session.post.assert_called_once_with(expected_url, data=data)
assert isinstance(new_sign_request, SignRequest)
assert new_sign_request['source_files'][0]['id'] == source_file['id']
assert new_sign_request['signers'][0]['email'] == signer['email']
assert new_sign_request['parent_folder']['id'] == parent_folder_id
assert new_sign_request['redirect_url'] == redirect_url
assert new_sign_request['declined_redirect_url'] == declined_redirect_url


def test_file_request(mock_client):
Expand Down
2 changes: 2 additions & 0 deletions test/unit/object/test_sign_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def mock_sign_request_response():
'email_subject': 'Sign Request from Acme',
'external_id': '123',
'is_document_preparation_needed': 'true',
'redirect_url': 'https://www.box.com/accepted',
'declined_redirect_url': 'https://www.box.com/declined',
'parent_folder': {
'id': '12345',
'type': 'folder',
Expand Down

0 comments on commit b60c4d4

Please sign in to comment.