|
1 | | -import base64 |
2 | | -from os import path |
3 | | - |
4 | | -from app.ds_config import ( |
5 | | - TPL_PATH, |
6 | | - CLICKWRAP_BASE_HOST, |
7 | | - CLICKWRAP_BASE_URI |
8 | | -) |
9 | | -from app.ds_client import DsClient |
10 | | - |
| 1 | +from app.ds_config import CLICKWRAP_ID |
11 | 2 |
|
12 | 3 | class Clickwrap: # pylint: disable=too-few-public-methods |
13 | 4 | @staticmethod |
14 | | - def create(args, session): |
15 | | - """Creates a clickwrap for an account |
16 | | - Parameters: |
17 | | - args (dict): Parameters for the clickwrap. |
| 5 | + def get(args, session): |
| 6 | + """Gets a clickwrap and account data |
18 | 7 | Returns: |
19 | | - JSON structure of the created clickwrap. |
| 8 | + JSON structure of the clickwrap. |
20 | 9 | """ |
21 | | - terms_name = args.get('terms_name') |
22 | | - file_name = 'terms-renewal.docx' |
23 | 10 | account_id = session.get('account_id') |
24 | 11 |
|
25 | | - with open(path.join(TPL_PATH, file_name), 'rb') as binary_file: |
26 | | - binary_file_data = binary_file.read() |
27 | | - base64_encoded_data = base64.b64encode(binary_file_data) |
28 | | - base64_terms = base64_encoded_data.decode('utf-8') |
29 | | - |
30 | | - # Construct clickwrap JSON body |
31 | | - body = { |
32 | | - 'displaySettings': { |
33 | | - 'consentButtonText': 'I Agree', |
34 | | - 'displayName': args.get('display_name'), |
35 | | - 'downloadable': True, |
36 | | - 'format': 'modal', |
37 | | - 'hasAccept': True, |
38 | | - 'mustRead': True, |
39 | | - 'requireAccept': True, |
40 | | - 'size': 'medium', |
41 | | - 'documentDisplay': 'document', |
42 | | - }, |
43 | | - 'documents': [ |
44 | | - { |
45 | | - 'documentBase64': base64_terms, |
46 | | - 'documentName': terms_name, |
47 | | - 'fileExtension': file_name[file_name.rfind('.')+1:], |
48 | | - 'order': 0 |
49 | | - } |
50 | | - ], |
51 | | - 'name': terms_name, |
52 | | - 'requireReacceptance': True |
| 12 | + clickwrap = { |
| 13 | + 'accountId': account_id, |
| 14 | + 'clickwrapId': CLICKWRAP_ID |
53 | 15 | } |
54 | 16 |
|
55 | | - # Make a POST call to the clickwraps endpoint to create a clickwrap for an account |
56 | | - ds_client = DsClient.get_configured_instance( |
57 | | - session.get('access_token'), |
58 | | - CLICKWRAP_BASE_HOST |
59 | | - ) |
60 | | - |
61 | | - uri = f"{CLICKWRAP_BASE_URI}/{account_id}/clickwraps" |
62 | | - response = ds_client.call_api( |
63 | | - uri, 'POST', body=body, response_type='object' |
64 | | - ) |
65 | | - |
66 | | - clickwrap_id = response[0].get('clickwrapId') |
67 | | - |
68 | | - # Make a PUT call to the clickwraps endpoint to activate created clickwrap |
69 | | - uri = f"{CLICKWRAP_BASE_URI}/{account_id}/clickwraps/{clickwrap_id}/versions/1" |
70 | | - response_active = ds_client.call_api( |
71 | | - uri, 'PUT', body={'status': 'active'}, response_type='object' |
72 | | - ) |
73 | | - return response_active[0] |
| 17 | + return clickwrap |
0 commit comments