|
| 1 | +from docusign_admin import ApiClient, ProvisionAssetGroupApi, AssetGroupAccountClone, \ |
| 2 | + AssetGroupAccountCloneSourceAccount, AssetGroupAccountCloneTargetAccount, \ |
| 3 | + AssetGroupAccountCloneTargetAccountAdmin |
| 4 | +from flask import session, request |
| 5 | + |
| 6 | +from ..utils import get_organization_id |
| 7 | +from ...ds_config import DS_CONFIG |
| 8 | + |
| 9 | + |
| 10 | +class Eg012CloneAccountController: |
| 11 | + @staticmethod |
| 12 | + def get_args(): |
| 13 | + """Get required session and request arguments""" |
| 14 | + organization_id = get_organization_id() |
| 15 | + |
| 16 | + return { |
| 17 | + "access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN} |
| 18 | + "organization_id": organization_id, |
| 19 | + "source_account_id": request.form.get("source_account_id"), |
| 20 | + "target_account_name": request.form.get("target_account_name"), |
| 21 | + "target_account_user_name": request.form.get("target_account_user_name"), |
| 22 | + "target_account_first_name": request.form.get("target_account_first_name"), |
| 23 | + "target_account_last_name": request.form.get("target_account_last_name"), |
| 24 | + "target_account_email": request.form.get("target_account_email"), |
| 25 | + } |
| 26 | + |
| 27 | + @staticmethod |
| 28 | + def worker(args): |
| 29 | + """ |
| 30 | + 1. Create an API client with headers |
| 31 | + 2. Get the list of eligible accounts |
| 32 | + 3. Construct the request body |
| 33 | + 4. Clone the account |
| 34 | + """ |
| 35 | + |
| 36 | + access_token = args["access_token"] |
| 37 | + |
| 38 | + # Create an API client with headers |
| 39 | + #ds-snippet-start:Admin12Step2 |
| 40 | + api_client = ApiClient(host=DS_CONFIG["admin_api_client_host"]) |
| 41 | + api_client.set_default_header( |
| 42 | + header_name="Authorization", |
| 43 | + header_value=f"Bearer {access_token}" |
| 44 | + ) |
| 45 | + #ds-snippet-end:Admin12Step2 |
| 46 | + |
| 47 | + #ds-snippet-start:Admin12Step4 |
| 48 | + account_data = AssetGroupAccountClone( |
| 49 | + source_account=AssetGroupAccountCloneSourceAccount( |
| 50 | + id=args["source_account_id"] |
| 51 | + ), |
| 52 | + target_account=AssetGroupAccountCloneTargetAccount( |
| 53 | + name=args["target_account_name"], |
| 54 | + admin=AssetGroupAccountCloneTargetAccountAdmin( |
| 55 | + first_name=args["target_account_first_name"], |
| 56 | + last_name=args["target_account_last_name"], |
| 57 | + email=args["target_account_email"] |
| 58 | + ), |
| 59 | + country_code="US" |
| 60 | + ) |
| 61 | + ) |
| 62 | + #ds-snippet-end:Admin12Step4 |
| 63 | + |
| 64 | + #ds-snippet-start:Admin12Step5 |
| 65 | + asset_group_api = ProvisionAssetGroupApi(api_client=api_client) |
| 66 | + results = asset_group_api.clone_asset_group_account(args["organization_id"], account_data) |
| 67 | + #ds-snippet-end:Admin12Step5 |
| 68 | + |
| 69 | + return results |
| 70 | + |
| 71 | + @staticmethod |
| 72 | + def get_accounts(args): |
| 73 | + access_token = args["access_token"] |
| 74 | + api_client = ApiClient(host=DS_CONFIG["admin_api_client_host"]) |
| 75 | + api_client.set_default_header( |
| 76 | + header_name="Authorization", |
| 77 | + header_value=f"Bearer {access_token}" |
| 78 | + ) |
| 79 | + |
| 80 | + #ds-snippet-start:Admin12Step3 |
| 81 | + asset_group_api = ProvisionAssetGroupApi(api_client=api_client) |
| 82 | + accounts = asset_group_api.get_asset_group_accounts(args["organization_id"], compliant=True) |
| 83 | + #ds-snippet-end:Admin12Step3 |
| 84 | + |
| 85 | + return accounts |
0 commit comments