forked from docusign/code-examples-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEg024PermissionCreateController.cs
104 lines (89 loc) · 5.4 KB
/
Eg024PermissionCreateController.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;
using eg_03_csharp_auth_code_grant_core.Models;
using Microsoft.AspNetCore.Mvc;
namespace eg_03_csharp_auth_code_grant_core.Controllers
{
[Route("Eg024")]
public class Eg024PermissionCreateController : EgController
{
public Eg024PermissionCreateController(DSConfiguration config, IRequestItemsService requestItemsService) :
base(config, requestItemsService)
{
}
public override string EgName => "Eg024";
[BindProperty]
public PermissionProfileModel ProfileModel { get; set; }
protected override void InitializeInternal() => ProfileModel = new PermissionProfileModel();
[HttpPost]
[Route("Create")]
public IActionResult Create(PermissionProfileModel permissionProfileModel)
{
// Check the token with minimal buffer time.
bool tokenOk = CheckToken(3);
if (!tokenOk)
{
// We could store the parameters of the requested operation so it could be
// restarted automatically. But since it should be rare to have a token issue
// here, we'll make the user re-enter the form data after authentication.
RequestItemsService.EgName = EgName;
return Redirect("/ds/mustAuthenticate");
}
// Data for this method
// signerEmail
// signerName
var basePath = RequestItemsService.Session.BasePath + "/restapi";
// Step 1. Obtain your OAuth token
var accessToken = RequestItemsService.User.AccessToken; // Represents your {ACCESS_TOKEN}
var accountId = RequestItemsService.Session.AccountId; // Represents your {ACCOUNT_ID}
// Step 2. Construct your API headers
var config = new Configuration(new ApiClient(basePath));
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
AccountsApi accountsApi = new AccountsApi(config);
// Step 3. Construct your request
var accountRoleSettings = new AccountRoleSettingsExtension();
accountRoleSettings.UseNewDocuSignExperienceInterface = "1";
accountRoleSettings.EnableSequentialSigningInterface = true.ToString();
accountRoleSettings.PowerFormRole = "admin";
accountRoleSettings.VaultingMode = "none";
accountRoleSettings.AllowTaggingInSendAndCorrect = true.ToString();
accountRoleSettings.AllowedAddressBookAccess = "personalAndShared";
accountRoleSettings.AllowedTemplateAccess = "share";
accountRoleSettings.SigningUiVersion = "2";
// Present on PermissionProfileView.
accountRoleSettings.AllowBulkSending = permissionProfileModel.AccountRoleSettingsModel.AllowBulkSending.ToString();
accountRoleSettings.AllowEnvelopeSending = permissionProfileModel.AccountRoleSettingsModel.AllowEnvelopeSending.ToString();
accountRoleSettings.AllowSignerAttachments = permissionProfileModel.AccountRoleSettingsModel.AllowSignerAttachments.ToString();
accountRoleSettings.AllowApiAccess = permissionProfileModel.AccountRoleSettingsModel.AllowApiAccess.ToString();
accountRoleSettings.AllowApiAccessToAccount = permissionProfileModel.AccountRoleSettingsModel.AllowApiAccessToAccount.ToString();
accountRoleSettings.AllowApiSequentialSigning = permissionProfileModel.AccountRoleSettingsModel.AllowApiSequentialSigning.ToString();
accountRoleSettings.EnableApiRequestLogging = permissionProfileModel.AccountRoleSettingsModel.EnableApiRequestLogging.ToString();
accountRoleSettings.AllowApiSendingOnBehalfOfOthers = permissionProfileModel.AccountRoleSettingsModel.AllowApiSendingOnBehalfOfOthers.ToString();
accountRoleSettings.AllowWetSigningOverride = permissionProfileModel.AccountRoleSettingsModel.AllowWetSigningOverride.ToString();
accountRoleSettings.EnableRecipientViewingNotifications = permissionProfileModel.AccountRoleSettingsModel.EnableRecipientViewingNotifications.ToString();
accountRoleSettings.ReceiveCompletedSelfSignedDocumentsAsEmailLinks = permissionProfileModel.AccountRoleSettingsModel.ReceiveCompletedSelfSignedDocumentsAsEmailLinks.ToString();
accountRoleSettings.UseNewSendingInterface = permissionProfileModel.AccountRoleSettingsModel.UseNewSendingInterface.ToString();
accountRoleSettings.AllowDocuSignDesktopClient = permissionProfileModel.AccountRoleSettingsModel.AllowDocuSignDesktopClient.ToString();
accountRoleSettings.AllowSendersToSetRecipientEmailLanguage = permissionProfileModel.AccountRoleSettingsModel.AllowSendersToSetRecipientEmailLanguage.ToString();
accountRoleSettings.AllowVaulting = permissionProfileModel.AccountRoleSettingsModel.AllowVaulting.ToString();
accountRoleSettings.AllowedToBeEnvelopeTransferRecipient = permissionProfileModel.AccountRoleSettingsModel.AllowedToBeEnvelopeTransferRecipient.ToString();
accountRoleSettings.EnableTransactionPointIntegration = permissionProfileModel.AccountRoleSettingsModel.EnableTransactionPointIntegration.ToString();
var newPermimssionProfile = new PermissionProfile(PermissionProfileName: permissionProfileModel.ProfileName, Settings: accountRoleSettings);
try
{
// Step 4. Call the eSignature REST API
var result = accountsApi.CreatePermissionProfile(accountId, newPermimssionProfile);
ViewBag.h1 = "The permission profile was updated";
ViewBag.message = $"The permission profile was created!<br />Permission profile ID: {result.PermissionProfileId}, name:{result.PermissionProfileName}.";
return View("example_done");
}
catch (ApiException apiException)
{
ViewBag.errorCode = apiException.ErrorCode;
ViewBag.errorMessage = apiException.Message;
return View("Error");
}
}
}
}