Skip to content

Commit 29e5c1f

Browse files
fix merge conflicts
2 parents 7cfafb6 + 2b57d38 commit 29e5c1f

11 files changed

Lines changed: 275 additions & 13 deletions

app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
app.register_blueprint(admin_views.eg006)
7373
app.register_blueprint(admin_views.eg007)
7474
app.register_blueprint(admin_views.eg008)
75+
app.register_blueprint(admin_views.eg009)
7576

7677
elif EXAMPLES_API_TYPE["Click"]:
7778
app.register_blueprint(click_views.eg001)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from docusign_admin import (
2+
ApiClient,
3+
ProductPermissionProfilesApi,
4+
UserProductProfileDeleteRequest)
5+
from flask import session, request
6+
7+
from ...ds_config import DS_CONFIG
8+
from app.admin.utils import get_organization_id
9+
10+
class Eg009DeleteUserProductPermissionProfileController:
11+
@staticmethod
12+
def get_args():
13+
"""Get required session and request arguments"""
14+
organization_id = get_organization_id()
15+
return {
16+
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
17+
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
18+
"organization_id": organization_id, # Represents your {ORGANIZATION_ID}
19+
"product_id": request.form.get("product_id"),
20+
"clm_email": session["clm_email"],
21+
}
22+
23+
@staticmethod
24+
def get_permission_profiles_by_email():
25+
"""Get permission profiles"""
26+
27+
api_client = ApiClient(host=DS_CONFIG["admin_api_client_host"])
28+
api_client.set_default_header(
29+
header_name="Authorization",
30+
header_value=f"Bearer {session['ds_access_token']}"
31+
)
32+
# Step 3 start
33+
product_permission_profiles_api = ProductPermissionProfilesApi(api_client=api_client)
34+
profiles = product_permission_profiles_api.get_user_product_permission_profiles_by_email(
35+
organization_id=get_organization_id(),
36+
account_id=session["ds_account_id"],
37+
email=session["clm_email"]
38+
)
39+
profiles_list = profiles.to_dict()["product_permission_profiles"]
40+
# Step 3 end
41+
return profiles_list
42+
43+
@staticmethod
44+
def worker(self, args):
45+
"""
46+
1. Create an API client with headers
47+
2. Get your monitor data via SDK
48+
"""
49+
50+
access_token = args["access_token"]
51+
account_id = args["account_id"]
52+
org_id = args["organization_id"]
53+
email = args["clm_email"]
54+
product_id = args["product_id"]
55+
56+
# Create an API client with headers
57+
# Step 2 start
58+
api_client = ApiClient(host=DS_CONFIG["admin_api_client_host"])
59+
api_client.set_default_header(
60+
header_name="Authorization",
61+
header_value=f"Bearer {access_token}"
62+
)
63+
# Step 2 end
64+
65+
# Step 4 start
66+
user_product_profile_delete_request = UserProductProfileDeleteRequest(
67+
user_email=email,
68+
product_ids=[product_id]
69+
)
70+
# Step 4 end
71+
72+
# Step 5 start
73+
product_permission_profiles_api = ProductPermissionProfilesApi(api_client=api_client)
74+
response = product_permission_profiles_api.remove_user_product_permission(
75+
organization_id=org_id,
76+
account_id=account_id,
77+
user_product_permission_profiles_request=user_product_profile_delete_request
78+
)
79+
# Step 5 end
80+
81+
return response.to_dict()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- extend base layout --> {% extends "base.html" %} {% block content %}
2+
3+
{% include 'example_info.html' %}
4+
5+
{% set form_index = 0 %}
6+
{% set product_index = 0 %}
7+
{% set redirect_to2_index = 0 %}
8+
9+
{% if email_ok %}
10+
<form class="eg" action="" method="post" data-busy="form">
11+
{% if permission_profile_list %}
12+
<div class="form-group">
13+
<label for="product_id">{{ example['Forms'][form_index]['Inputs'][product_index]['InputName'] }}</label>
14+
<select class="form-control" id="product_id" name="product_id">
15+
{% for profile in permission_profile_list %}
16+
<option value="{{profile.product_id}}">{{profile.permission_name}}</option>
17+
{% endfor %}
18+
</select>
19+
</div>
20+
{% else %}
21+
<p>Problem: Please first create a user with permission profile.
22+
</br>Thank you.</p>
23+
{% endif %}
24+
25+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
26+
{% include 'continue_button.html' %}
27+
</form>
28+
{% else %}
29+
{{ example['RedirectsToOtherCodeExamples'][redirect_to2_index]['RedirectText'].format('href="eg002"') | safe }}
30+
31+
<form class="eg" action="eg002" method="get">
32+
{% include 'continue_button.html' %}
33+
</form>
34+
{% endif %}
35+
{% endblock %}

app/admin/views/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
from .eg006_get_user_profile_by_email import eg006
77
from .eg007_get_user_profile_by_user_id import eg007
88
from .eg008_update_user_product_permission_profile import eg008
9+
from .eg009_delete_user_product_permission_profile import eg009
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
"""Example 009: Delete user product permission profiles using an email address. """
2+
3+
import json
4+
5+
from docusign_admin.client.api_exception import ApiException
6+
from flask import Blueprint, render_template, current_app, session
7+
8+
from app.docusign import authenticate, ensure_manifest, get_example_by_number
9+
from app.error_handlers import process_error
10+
from ..examples.eg009_delete_user_product_permission_profile import Eg009DeleteUserProductPermissionProfileController
11+
from ...ds_config import DS_CONFIG
12+
from ..utils import check_user_exists_by_email
13+
14+
example_number = 9
15+
eg = f"eg00{example_number}" # Reference (and URL) for this example
16+
eg009 = Blueprint(eg, __name__)
17+
18+
@eg009.route(f"/{eg}", methods=["POST"])
19+
@ensure_manifest(manifest_url=DS_CONFIG["admin_manifest_url"])
20+
@authenticate(eg=eg)
21+
def create_active_clm_esign_user():
22+
"""
23+
1. Get required arguments
24+
2. Call the worker method
25+
3. Render the response
26+
"""
27+
example = get_example_by_number(session["manifest"], example_number)
28+
29+
if "clm_email" in session and check_user_exists_by_email(session["clm_email"]):
30+
controller = Eg009DeleteUserProductPermissionProfileController()
31+
32+
# 1. Get required arguments
33+
args = Eg009DeleteUserProductPermissionProfileController.get_args()
34+
try:
35+
# 2. Call the worker method
36+
results = Eg009DeleteUserProductPermissionProfileController.worker(controller, args)
37+
except ApiException as err:
38+
return process_error(err)
39+
40+
template = render_template(
41+
"example_done.html",
42+
title=example["ExampleName"],
43+
message="Results from MultiProductUserManagement:removeUserProductPermission method:",
44+
json=json.dumps(json.dumps(results, default=str))
45+
)
46+
else:
47+
template = render_template(
48+
f"{eg}_delete_user_product_permission_profile.html",
49+
title=example["ExampleName"],
50+
example=example,
51+
source_file=f"{eg}_delete_user_product_permission_profile.py",
52+
source_url=DS_CONFIG["admin_github_url"] + f"{eg}_delete_user_product_permission_profile.py",
53+
documentation=DS_CONFIG["documentation"] + eg
54+
)
55+
56+
return template
57+
58+
@eg009.route(f"/{eg}", methods=["GET"])
59+
@ensure_manifest(manifest_url=DS_CONFIG["admin_manifest_url"])
60+
@authenticate(eg=eg)
61+
def get_view():
62+
""" Responds with the form for the example"""
63+
example = get_example_by_number(session["manifest"], example_number)
64+
65+
if "clm_email" in session and check_user_exists_by_email(session["clm_email"]):
66+
try:
67+
profiles = Eg009DeleteUserProductPermissionProfileController.get_permission_profiles_by_email()
68+
permission_profile_list = []
69+
clm_product_id = None
70+
clm_permission_profile_name = None
71+
esign_product_id = None
72+
esign_permission_profile_name = None
73+
for profile in profiles:
74+
permission_profiles = profile["permission_profiles"]
75+
for permission_profile in permission_profiles:
76+
if profile["product_name"] == "CLM":
77+
clm_permission_profile_name = permission_profile["permission_profile_name"]
78+
clm_product_id = profile["product_id"]
79+
else:
80+
esign_permission_profile_name = permission_profile["permission_profile_name"]
81+
esign_product_id = profile["product_id"]
82+
83+
if clm_product_id is not None:
84+
permission_profile_list.append({"product_id": clm_product_id, "permission_name": f"CLM - {clm_permission_profile_name}"})
85+
86+
if esign_product_id is not None:
87+
permission_profile_list.append({"product_id": esign_product_id, "permission_name": f"eSignature - {esign_permission_profile_name}"})
88+
89+
except ApiException as err:
90+
return process_error(err)
91+
92+
template = render_template(
93+
f"{eg}_delete_user_product_permission_profile.html",
94+
title=example["ExampleName"],
95+
example=example,
96+
email_ok="clm_email" in session,
97+
source_file=f"{eg}_delete_user_product_permission_profile.py",
98+
source_url=DS_CONFIG["admin_github_url"] + f"{eg}_delete_user_product_permission_profile.py",
99+
documentation=DS_CONFIG["documentation"] + eg,
100+
email=session["clm_email"],
101+
permission_profile_list=permission_profile_list
102+
)
103+
else:
104+
template = render_template(
105+
f"{eg}_delete_user_product_permission_profile.html",
106+
title=example["ExampleName"],
107+
example=example,
108+
source_file=f"{eg}_delete_user_product_permission_profile.py",
109+
source_url=DS_CONFIG["admin_github_url"] + f"{eg}_delete_user_product_permission_profile.py",
110+
documentation=DS_CONFIG["documentation"] + eg
111+
)
112+
113+
return template

app/eSignature/examples/eg010_send_binary_docs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ def worker(cls, args):
102102

103103
# Step 2. call Envelopes::create API method
104104
# Exceptions will be caught by the calling function
105-
results = requests.post(
106-
url=f"{args['base_path']}/v2.1/accounts/{args['account_id']}/envelopes",
107-
headers={
105+
headers = {
108106
"Authorization": "bearer " + args['access_token'],
109107
"Accept": "application/json",
110108
"Content-Type": f"multipart/form-data; boundary={boundary.decode('utf-8')}"
111-
},
109+
}
110+
111+
results = requests.post(
112+
url=f"{args['base_path']}/v2.1/accounts/{args['account_id']}/envelopes",
113+
headers=headers,
112114
data=req_body
113115
)
114116
return {"status_code": results.status_code, "results": results.json()}

app/eSignature/examples/eg039_in_person_signer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def get_args():
3333
return args
3434

3535
@classmethod
36+
# Step 3 start
3637
def worker(cls, args):
3738
"""
3839
1. Create the envelope request object
@@ -52,26 +53,33 @@ def worker(cls, args):
5253
results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
5354

5455
envelope_id = results.envelope_id
56+
# Step 3 end
5557

5658
# 3. Create the Recipient View request object
59+
# Step 4 start
5760
recipient_view_request = RecipientViewRequest(
5861
authentication_method=authentication_method,
5962
recipient_id="1",
6063
return_url=envelope_args["ds_return_url"],
6164
user_name=envelope_args["host_name"],
6265
email=envelope_args["host_email"]
6366
)
67+
# Step 4 end
68+
69+
# Step 5 start
6470
# 4. Obtain the recipient_view_url for the embedded signing session
6571
# Exceptions will be caught by the calling function
6672
results = envelope_api.create_recipient_view(
6773
account_id=args["account_id"],
6874
envelope_id=envelope_id,
6975
recipient_view_request=recipient_view_request
7076
)
77+
# Step 5 end
7178

7279
return {"envelope_id": envelope_id, "redirect_url": results.url}
7380

7481
@classmethod
82+
# Step 2 start
7583
def make_envelope(cls, args):
7684
"""
7785
Creates envelope
@@ -130,3 +138,6 @@ def make_envelope(cls, args):
130138
)
131139

132140
return envelope_definition
141+
# Step 2 end
142+
143+
# End

app/eSignature/examples/eg040_document_visibility.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def get_args():
4848
}
4949
return args
5050

51-
# Step 3 start
5251
@classmethod
5352
def worker(cls, args, doc_docx_path, doc_pdf_path):
5453
"""
@@ -58,21 +57,24 @@ def worker(cls, args, doc_docx_path, doc_pdf_path):
5857
envelope_args = args["envelope_args"]
5958
# 1. Create the envelope request object
6059
envelope_definition = cls.make_envelope(envelope_args, doc_docx_path, doc_pdf_path)
61-
60+
6261
# 2. call Envelopes::create API method
6362
# Exceptions will be caught by the calling function
63+
# Step 2 start
6464
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
65+
# Step 2 end
6566

67+
# Step 4 start
6668
envelope_api = EnvelopesApi(api_client)
6769
results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
68-
70+
# Step 4 end
71+
6972
envelope_id = results.envelope_id
7073

7174
return {"envelope_id": envelope_id}
72-
# Step 3 end
73-
74-
# Step 2 start
75+
7576
@classmethod
77+
# Step 3 start
7678
def make_envelope(cls, args, doc_docx_path, doc_pdf_path):
7779
"""
7880
Creates envelope
@@ -212,4 +214,7 @@ def create_document1(cls, args):
212214
<h3 style="margin-top:3em;">Agreed: <span style="color:white;">**signature_1**/</span></h3>
213215
</body>
214216
</html>
215-
"""
217+
"""
218+
# Step 3 end
219+
220+
# End

app/rooms/views/eg009_assign_form_to_form_group.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def assign_form_to_form_group():
5151
h1="Creating a form group",
5252
message=f"""Form "{args['form_id']}" has been assigned to
5353
Form Group "{args['form_group_id']}"!""",
54-
json=json.dumps(json.dumps(results, default=str))
5554
)
5655

5756

connect_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def validateHMAC():
2+
import hmac
3+
import hashlib
4+
import base64
5+
file = open("payload.txt", "rb") # Read the payload from a file named payload.txt
6+
payload = file.read()
7+
secret = "4+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxuE=" # Replace this value with your own secret
8+
signature = "e4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhg=" # Replace this value with your own signature
9+
10+
hashBytes = hmac.new(str.encode(secret), msg=payload, digestmod=hashlib.sha256).digest()
11+
base64Hash = base64.b64encode(hashBytes)
12+
return hmac.compare_digest(str.encode(signature), base64Hash)
13+
14+
print(validateHMAC())

0 commit comments

Comments
 (0)