forked from docusign/code-examples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
75 lines (65 loc) · 2.67 KB
/
controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from docusign_esign import AccountsApi, PermissionProfile
from docusign_esign.client.api_exception import ApiException
from flask import request, session
from ....consts import settings
from ....docusign import create_api_client
from ....error_handlers import process_error
class Eg026Controller:
@staticmethod
def get_args():
"""Get required session and request arguments"""
permission_profile_id = request.form.get("permission_profile")
args = {
"account_id": session["ds_account_id"], # Represents your {ACCOUNT_ID}
"base_path": session["ds_base_path"],
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN}
"permission_profile_id": permission_profile_id,
"settings": settings
}
return args
@staticmethod
def worker(args):
"""
1. Create an API client
2. Create a permission profile object
3. Get existing profile settings
4. Change the permission profile setting using the SDK
"""
# Step 2. Construct your API headers
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
# Step 3. Construct your request body
permission_profile = PermissionProfile(
settings=args["settings"]
)
account_api = AccountsApi(api_client)
previous_settings = account_api.get_permission_profile(
account_id=args["account_id"],
permission_profile_id=args["permission_profile_id"]
).settings.to_dict()
# Step 4. Call the eSignature REST API
response = account_api.update_permission_profile(
account_id=args["account_id"],
permission_profile_id=args["permission_profile_id"],
permission_profile=permission_profile
)
new_settings = response.settings.to_dict()
changed_settings = {}
# Save only changed settings
for k, v in new_settings.items():
if v != previous_settings[k]:
key = " ".join(k.split("_"))
changed_settings[key] = v
return response, changed_settings
@staticmethod
def get_permissions_profiles(args):
"""Retrieve all permissions profiles"""
api_client = create_api_client(
base_path=args["base_path"],
access_token=args["access_token"]
)
try:
account_api = AccountsApi(api_client)
response = account_api.list_permissions(account_id=args["account_id"])
return response.permission_profiles
except ApiException as err:
return process_error(err)