Skip to content

Commit 11572c0

Browse files
meihDSpaigesrossi
andauthored
Devdocs 8760 (#96)
* new file * whereIsDocumentData - incomplete * update Click to v1.2.2 * remove version_number * create page * create new html page * update from eg002 to eg006 * update from activate to embed * add Click 6 * indent * revert indent * delete b/c I'm getting an error * change from activate to embed * from activate to embed * add click 6 * removed 2 lines from Update a clickwrap using SDK if I need to put them back, they are lines 55, 56 https://github.com/docusign/code-examples-python-private/blob/e5530c462e9f9d4d6f11fed777515fc555d3f835/app/click/examples/eg002_activate_clickwrap.py#L55 * revert the 2 lines * add get a list of active clickwraps, removed clickwrap_request https://github.com/docusign/code-examples-python-private/blob/7cdc7222049c78b989a1032d6294a6be18afd809/app/click/examples/eg002_activate_clickwrap.py#L61 * removed 'in' in comment * debug with just get_clickwraps * not worker * back to create_has_agreed * add user agreement request model * puts parens around dict * replace colon with comma * replace with inbar's snippet * add document_data= * import UserAgreementRequest * removed document_data.update * remove parens * add user_agreement_request * hardcode other document data fields * add full * debug just full_name * test full name only * test all params renamed * fullName only debugging * test email again * change email address * remove spaces * sub in email - may not work b/c where am I getting email var from? * try with args to auto update * add email to render template * add to get_args * added form from ruby * update form * add remaining doc data fields * indenting * get inactive clickwraps * add error handling for inactive clickwraps * import eg002 * length() * update length condition to correct reserved words * made it undefined instead * is defined * add condition for only inactive clickwraps * remove text from Click 2 * update results page text * try to open agreementUrl automatically * added comma * agreement_url * url= * removing webbrowser which gives error * create_has_agreed_with_http_info * input type = date * reverted to create_has_agreed without http b/c I'm not sure how to json.dumps with tuples instead of dictionary * embedding clickwrap in page * error handling * email validation * fixing client user id * error message Co-authored-by: Paige Rossi <paige.rossi@docusign.com>
1 parent 51b8f56 commit 11572c0

7 files changed

Lines changed: 274 additions & 2 deletions

File tree

app/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
app.register_blueprint(click_views.eg003)
8181
app.register_blueprint(click_views.eg004)
8282
app.register_blueprint(click_views.eg005)
83-
83+
app.register_blueprint(click_views.eg006)
84+
8485
else:
8586
app.register_blueprint(esignature_views.eg001)
8687
app.register_blueprint(esignature_views.eg002)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from docusign_click import AccountsApi, UserAgreementRequest
2+
from flask import session, request
3+
import ast
4+
5+
from ..utils import create_click_api_client
6+
7+
8+
class Eg006EmbedClickwrapController:
9+
@staticmethod
10+
def get_args():
11+
"""Get required session and request arguments"""
12+
return {
13+
"account_id": session.get("ds_account_id"), # Represents your {ACCOUNT_ID}
14+
"access_token": session.get("ds_access_token"), # Represents your {ACCESS_TOKEN}
15+
"clickwrap": request.form.get("clickwrap"),
16+
"fullName": request.form.get("fullName"),
17+
"email": request.form.get("email"),
18+
"company": request.form.get("company"),
19+
"title": request.form.get("title"),
20+
"date": request.form.get("date"),
21+
}
22+
23+
@staticmethod
24+
def get_active_clickwraps(args):
25+
"""
26+
1. Create an API client with hheaders
27+
2. Get a list of active clickwraps
28+
"""
29+
# Step 1. Create an API client with headers
30+
api_client = create_click_api_client(
31+
access_token=args["access_token"]
32+
)
33+
34+
# Step 2. Get a list of active clickwraps
35+
accounts_api = AccountsApi(api_client)
36+
response = accounts_api.get_clickwraps(
37+
account_id=args["account_id"],
38+
status="active"
39+
)
40+
41+
return response
42+
43+
@staticmethod
44+
def worker(args):
45+
"""
46+
1. Create an API client with headers
47+
2. Create a clickwrap request model
48+
3. Update a clickwrap using SDK
49+
"""
50+
# Create an API client with headers
51+
api_client = create_click_api_client(
52+
access_token=args["access_token"]
53+
)
54+
55+
# Create a user agreement request model
56+
user_agreement_request = UserAgreementRequest(
57+
client_user_id=args["email"],
58+
document_data={
59+
"fullName": args["fullName"],
60+
"email": args["email"],
61+
"company": args["company"],
62+
"title": args["title"],
63+
"date": args["date"]
64+
},
65+
)
66+
67+
# Retrieve Agreement Url using SDK
68+
accounts_api = AccountsApi(api_client)
69+
clickwrap = ast.literal_eval(args["clickwrap"])
70+
print(type(clickwrap))
71+
response = accounts_api.create_has_agreed(
72+
account_id=args["account_id"],
73+
clickwrap_id=clickwrap["clickwrap_id"],
74+
user_agreement_request=user_agreement_request,
75+
)
76+
77+
return response
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
3+
<h2>{{ h1 }}</h2>
4+
<p>{{ message | safe }}</p>
5+
{% if link %}
6+
<br>
7+
<a href="{{ link }}" target="_blank">{{ link_text }}</a>
8+
<br>
9+
{% endif %}
10+
11+
<p>Agreement URL received back from the API call: <code>{{agreementUrl}}</code></p>
12+
13+
<p id="agreementStatus">
14+
{{ session["manifest"]["SupportingTexts"]["HelpingTexts"]["NOTAGREED"] }}
15+
</p>
16+
17+
{% if changed_settings %}
18+
<ul>
19+
{% for k, v in changed_settings.items() %}
20+
<li><b>{{ k }}:</b> {{ v }}</li>
21+
{% endfor %}
22+
</ul>
23+
{% endif %}
24+
25+
<div id="ds-terms-of-service"></div>
26+
<script src="https://demo.docusign.net/clickapi/sdk/latest/docusign-click.js"></script>
27+
<script>docuSignClick.Clickwrap.render({
28+
agreementUrl: "{{ agreementUrl }}",
29+
onAgreed: function() {
30+
// Triggered if the user has just agreed
31+
document.getElementById("agreementStatus").innerHTML = "{{ session['manifest']['SupportingTexts']['HelpingTexts']['AGREED'] }}";
32+
}
33+
}, "#ds-terms-of-service");
34+
</script>
35+
36+
<p><a href="/">Continue</a></p>
37+
38+
{% endblock %}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
3+
<div class="container">
4+
5+
{% include 'example_info.html' %}
6+
{% set form_index = 0 %}
7+
{% set click_index = 0 %}
8+
{% set full_name_index = 1 %}
9+
{% set email_index = 2 %}
10+
{% set company_index = 3 %}
11+
{% set title_index = 4 %}
12+
{% set date_index = 5 %}
13+
{% set redirect_to1_index = 0 %}
14+
{% set redirect_to2_index = 1 %}
15+
16+
17+
{% if inactive_clickwraps_data['clickwraps'][0] is defined and clickwraps_data['clickwraps'][0] is undefined %}
18+
{{ example['RedirectsToOtherCodeExamples'][redirect_to2_index]['RedirectText'].format('href="eg002"') | safe }}
19+
{% elif clickwraps_data['clickwraps'][0] is undefined %}
20+
{{ example['RedirectsToOtherCodeExamples'][redirect_to1_index]['RedirectText'].format('href="eg001"') | safe }}
21+
{% else %}
22+
23+
<form class="eg" action="" method="post" data-busy="form-download">
24+
{% if 'FormName' in example['Forms'][form_index] %}
25+
<p>{{ example['Forms'][form_index]['FormName'] | safe }}</p>
26+
{% endif %}
27+
28+
<div class="form-group">
29+
<label for="clickwrap">{{ example['Forms'][form_index]['Inputs'][click_index]['InputName'] }}</label>
30+
<select class="custom-select" id="clickwrap"
31+
name="clickwrap">
32+
{% for clickwrap in clickwraps_data['clickwraps'] %}
33+
<option value="{{ clickwrap }}">{{ clickwrap['clickwrap_name'] }}</option>
34+
{% endfor %}
35+
</select>
36+
</div>
37+
38+
<div class="form-group">
39+
<label for="fullName">{{ example['Forms'][form_index]['Inputs'][full_name_index]['InputName'] }}</label>
40+
<input type="text" class="form-control" id="fullName"
41+
name="fullName" required>
42+
</div>
43+
44+
<div class="form-group">
45+
<label for="email">{{ example['Forms'][form_index]['Inputs'][email_index]['InputName'] }}</label>
46+
<input type="email" class="form-control" id="email"
47+
name="email" required>
48+
</div>
49+
50+
<div class="form-group">
51+
<label for="company">{{ example['Forms'][form_index]['Inputs'][company_index]['InputName'] }}</label>
52+
<input type="text" class="form-control" id="company"
53+
name="company" required>
54+
</div>
55+
56+
<div class="form-group">
57+
<label for="title">{{ example['Forms'][form_index]['Inputs'][title_index]['InputName'] }}</label>
58+
<input type="text" class="form-control" id="title"
59+
name="title" required>
60+
</div>
61+
62+
<div class="form-group">
63+
<label for="date">{{ example['Forms'][form_index]['Inputs'][date_index]['InputName'] }}</label>
64+
<input type="date" class="form-control" id="date"
65+
name="date" required>
66+
</div>
67+
68+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
69+
{% include 'submit_button.html' %}
70+
</form>
71+
{% endif %}
72+
73+
</div>
74+
75+
{% endblock %}

app/click/views/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
from .eg003_create_new_clickwrap_version import eg003
44
from .eg004_list_clickwraps import eg004
55
from .eg005_clickwrap_responses import eg005
6+
from .eg006_embed_clickwrap import eg006
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""Example 006: Embed a clickwrap"""
2+
3+
from os import path
4+
import json
5+
import webbrowser
6+
7+
from docusign_click.client.api_exception import ApiException
8+
from flask import render_template, current_app, Blueprint, session
9+
10+
from ..examples.eg006_embed_clickwrap import Eg006EmbedClickwrapController
11+
from ..examples.eg002_activate_clickwrap import Eg002ActivateClickwrapController
12+
from app.docusign import authenticate, get_example_by_number, ensure_manifest
13+
from app.ds_config import DS_CONFIG
14+
from app.error_handlers import process_error
15+
16+
example_number = 6
17+
eg = f"eg00{example_number}" # Reference (and URL) for this example
18+
eg006 = Blueprint(eg, __name__)
19+
20+
21+
@eg006.route(f"/{eg}", methods=["POST"])
22+
@ensure_manifest(manifest_url=DS_CONFIG["click_manifest_url"])
23+
@authenticate(eg=eg)
24+
def embed_clickwrap():
25+
"""
26+
1. Get required arguments
27+
2. Call the worker method
28+
3. Render the response
29+
"""
30+
example = get_example_by_number(session["manifest"], example_number)
31+
32+
# 1. Get required arguments
33+
args = Eg006EmbedClickwrapController.get_args()
34+
35+
try:
36+
# 2. Call the worker method to create a new clickwrap
37+
results = Eg006EmbedClickwrapController.worker(args)
38+
current_app.logger.info(
39+
f"""See the embedded clickwrap in the dialog box."""
40+
)
41+
except ApiException as err:
42+
return process_error(err)
43+
44+
# Save for use by other examples which need an clickwrap params.
45+
session["clickwrap_is_active"] = True
46+
47+
if results.to_dict()["agreement_url"] == None:
48+
return render_template(
49+
"error.html",
50+
error_code="200",
51+
error_message="The email address was already used to agree to this elastic template. Provide a different email address if you want to view the agreement and agree to it."
52+
)
53+
54+
# 3. Render the response
55+
return render_template(
56+
"eg006_done.html",
57+
title=example["ExampleName"],
58+
message=f"""See the embedded clickwrap in the dialog box.""",
59+
json=json.dumps(json.dumps(results.to_dict(), default=str)),
60+
agreementUrl= results.to_dict()["agreement_url"]
61+
)
62+
63+
64+
@eg006.route(f"/{eg}", methods=["GET"])
65+
@ensure_manifest(manifest_url=DS_CONFIG["click_manifest_url"])
66+
@authenticate(eg=eg)
67+
def get_view():
68+
"""responds with the form for the example"""
69+
example = get_example_by_number(session["manifest"], example_number)
70+
71+
args = Eg006EmbedClickwrapController.get_args()
72+
return render_template(
73+
"eg006_embed_clickwrap.html",
74+
title=example["ExampleName"],
75+
example=example,
76+
clickwraps_data=Eg006EmbedClickwrapController.get_active_clickwraps(args),
77+
inactive_clickwraps_data=Eg002ActivateClickwrapController.get_inactive_clickwraps(args),
78+
source_file= "eg006_embed_clickwrap.py",
79+
source_url=DS_CONFIG["click_github_url"] + "eg006_embed_clickwrap.py",
80+
)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cryptography==3.3.2
77
docusign-esign==3.16.0
88
docusign-rooms==1.1.0
99
docusign-monitor==1.1.0
10-
docusign-click==1.1.0
10+
docusign-click==1.2.2
1111
docusign-admin==1.1.1
1212
Flask==1.1.1
1313
Flask-OAuthlib==0.9.6

0 commit comments

Comments
 (0)