Skip to content

Commit 5b1868c

Browse files
committed
added changes to the user flow
1 parent 0bb329c commit 5b1868c

File tree

14 files changed

+1138
-137
lines changed

14 files changed

+1138
-137
lines changed

ExamplesApiTypeExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ public enum ExamplesApiType
4444
[Description("con")]
4545
Connect = 5,
4646

47+
/// <summary>
48+
/// Web Forms API
49+
/// </summary>
50+
[Description("web")]
51+
WebForms = 6,
4752

4853
/// <summary>
4954
/// Maestro API
5055
/// </summary>
5156
[Description("mae")]
52-
Maestro = 6,
57+
Maestro = 7,
5358
}
5459

5560
public static class ExamplesApiTypeExtensions

launcher-csharp/Common/LocalsFilter.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ public void OnActionExecuting(ActionExecutingContext context)
9797
BasePath = identity.FindFirst(x => x.Type.Equals("base_uri")).Value,
9898
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
9999
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
100-
MaestroManageApiBasePath = this.configuration["DocuSign:MaestroManageApiEndpoint"],
101-
MaestroAuthApiBasePath = this.configuration["DocuSign:MaestroAuthApiEndpoint"],
100+
MaestroApiBasePath = this.configuration["DocuSign:MaestroApiEndpoint"],
102101
}
103102
:
104103
new Session
@@ -108,8 +107,7 @@ public void OnActionExecuting(ActionExecutingContext context)
108107
BasePath = this.requestItemsService.Session.BasePath,
109108
RoomsApiBasePath = this.configuration["DocuSign:RoomsApiEndpoint"],
110109
AdminApiBasePath = this.configuration["DocuSign:AdminApiEndpoint"],
111-
MaestroManageApiBasePath = this.configuration["DocuSign:MaestroManageApiEndpoint"],
112-
MaestroAuthApiBasePath = this.configuration["DocuSign:MaestroAuthApiEndpoint"],
110+
MaestroApiBasePath = this.configuration["DocuSign:MaestroApiEndpoint"],
113111
};
114112

115113
this.requestItemsService.Session = locals.Session;

launcher-csharp/Common/RequestItemsService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ public void UpdateUserFromJwt()
224224
BasePath = account.BaseUri,
225225
RoomsApiBasePath = this.Configuration["DocuSign:RoomsApiEndpoint"],
226226
AdminApiBasePath = this.Configuration["DocuSign:AdminApiEndpoint"],
227-
MaestroManageApiBasePath = this.Configuration["DocuSign:MaestroManageApiEndpoint"],
228-
MaestroAuthApiBasePath = this.Configuration["DocuSign:MaestroAuthApiEndpoint"],
227+
MaestroApiBasePath = this.Configuration["DocuSign:MaestroApiEndpoint"],
229228
};
230229
}
231230

launcher-csharp/Maestro/Controllers/CancelWorkflow.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ public override IActionResult Get()
4949

5050
var accessToken = this.RequestItemsService.User.AccessToken;
5151
var accountId = this.RequestItemsService.Session.AccountId;
52-
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroManageApiBasePath);
52+
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
5353
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
5454
bool isInProgressStatus = false;
5555
if (this.RequestItemsService.InstanceId != null)
5656
{
57-
var instance = GetWorkflowService.GetWorkFlowInstance(docuSignClient, accountId, this.RequestItemsService.WorkflowId, this.RequestItemsService.InstanceId);
58-
isInProgressStatus = instance.InstanceState == WorkflowInstance.WorkflowInstanceState.InProgress;
57+
var instance = GetWorkflowService.GetWorkFlowInstance(
58+
docuSignClient,
59+
accountId,
60+
this.RequestItemsService.WorkflowId,
61+
this.RequestItemsService.InstanceId);
62+
isInProgressStatus = instance.InstanceState == WorkflowInstanceState.InProgress;
5963
}
6064

6165
this.ViewBag.WorkflowId = this.RequestItemsService.WorkflowId;
@@ -84,7 +88,7 @@ public ActionResult CancelFlow()
8488
{
8589
var accessToken = this.RequestItemsService.User.AccessToken;
8690
var accountId = this.RequestItemsService.Session.AccountId;
87-
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroManageApiBasePath);
91+
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
8892
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
8993
var result = CancelWorkflowService.CancelWorkflow(docuSignClient, accountId, this.RequestItemsService.InstanceId);
9094

launcher-csharp/Maestro/Controllers/GetWorkflow.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ public ActionResult GetFlow()
7373
{
7474
var accessToken = this.RequestItemsService.User.AccessToken;
7575
var accountId = this.RequestItemsService.Session.AccountId;
76-
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroManageApiBasePath);
76+
var docuSignClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
7777
docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
78-
var result = GetWorkflowService.GetWorkFlowInstance(docuSignClient, accountId, this.RequestItemsService.WorkflowId, this.RequestItemsService.InstanceId);
78+
var result = GetWorkflowService.GetWorkFlowInstance(
79+
docuSignClient,
80+
accountId,
81+
this.RequestItemsService.WorkflowId,
82+
this.RequestItemsService.InstanceId);
7983

8084
this.ViewBag.h1 = this.CodeExampleText.ExampleName;
8185
this.ViewBag.message = string.Format(this.CodeExampleText.ResultsPageText, result.InstanceState);

launcher-csharp/Maestro/Controllers/TriggerWorkflow.cs

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
namespace DocuSign.Maestro.Controllers
66
{
77
using System;
8+
using System.Linq;
89
using DocuSign.CodeExamples;
910
using DocuSign.CodeExamples.Common;
1011
using DocuSign.CodeExamples.Controllers;
1112
using DocuSign.CodeExamples.Maestro.Models;
1213
using DocuSign.CodeExamples.Models;
1314
using DocuSign.Maestro.Client;
15+
using DocuSign.Maestro.Model;
1416
using DocuSign.WebForms.Examples;
1517
using Microsoft.AspNetCore.Mvc;
1618
using Microsoft.Extensions.Configuration;
@@ -20,6 +22,8 @@ namespace DocuSign.Maestro.Controllers
2022
[Route("mae001")]
2123
public class TriggerWorkflow : EgController
2224
{
25+
private const string WORKFLOWNAME = "Example workflow - send invite to signer";
26+
2327
private IConfiguration configuration;
2428

2529
public TriggerWorkflow(
@@ -32,6 +36,7 @@ public TriggerWorkflow(
3236
this.configuration = configuration;
3337
this.CodeExampleText = this.GetExampleText(this.EgName, ExamplesApiType.Maestro);
3438
this.ViewBag.title = this.CodeExampleText.ExampleName;
39+
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
3540
}
3641

3742
public override string EgName => "mae001";
@@ -40,15 +45,70 @@ public TriggerWorkflow(
4045
[HttpGet]
4146
public override IActionResult Get()
4247
{
48+
var actionResult = base.Get();
49+
if (this.RequestItemsService.EgName == this.EgName)
50+
{
51+
return actionResult;
52+
}
53+
54+
var accessToken = this.RequestItemsService.User.AccessToken;
55+
var accountId = this.RequestItemsService.Session.AccountId;
56+
4357
try
4458
{
45-
var actionResult = base.Get();
46-
if (this.RequestItemsService.EgName == this.EgName)
59+
var docuSignManageClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
60+
docuSignManageClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
61+
var workflows = TriggerWorkflowService.GetWorkFlowDefinitions(docuSignManageClient, accountId);
62+
63+
if (workflows.Count > 0)
64+
{
65+
var workflow = workflows.Value
66+
.Where(x => x.Name == WORKFLOWNAME)
67+
.OrderByDescending(x => x.LastUpdatedDate)
68+
.FirstOrDefault();
69+
this.RequestItemsService.WorkflowId = workflow != null ? workflow.Id : null;
70+
}
71+
72+
if (this.RequestItemsService.WorkflowId == null && this.RequestItemsService.TemplateId != null)
4773
{
48-
return actionResult;
74+
NewOrUpdatedWorkflowDefinitionResponse workflow = CreateWorkflowService.CreateWorkflowDefinition(
75+
docuSignManageClient,
76+
accountId,
77+
this.RequestItemsService.TemplateId);
78+
this.RequestItemsService.WorkflowId = workflow.WorkflowDefinitionId;
79+
80+
string publishLink = TriggerWorkflowService.PublishWorkFlow(
81+
docuSignManageClient,
82+
accountId,
83+
workflow.WorkflowDefinitionId);
84+
this.RequestItemsService.IsWorkflowPublished = true;
85+
this.ViewBag.ConsentLink = this.CodeExampleText.AdditionalPages[0].ResultsPageText
86+
.Replace("{0}", publishLink);
87+
88+
return this.View("publishWorkflow");
4989
}
5090

51-
this.RequestItemsService.WorkflowId = this.configuration["DocuSign:WorkflowId"];
91+
if (this.RequestItemsService.IsWorkflowPublished)
92+
{
93+
string publishLink = TriggerWorkflowService.PublishWorkFlow(
94+
docuSignManageClient,
95+
accountId,
96+
this.RequestItemsService.WorkflowId);
97+
if (publishLink != string.Empty)
98+
{
99+
this.ViewBag.ConsentLink = this.CodeExampleText.AdditionalPages[0].ResultsPageText
100+
.Replace("{0}", publishLink);
101+
102+
return this.View("publishWorkflow");
103+
}
104+
else
105+
{
106+
this.RequestItemsService.IsWorkflowPublished = false;
107+
}
108+
}
109+
110+
this.ViewBag.WorkflowId = this.RequestItemsService.WorkflowId;
111+
this.ViewBag.TemplateId = this.RequestItemsService.TemplateId;
52112
this.ViewBag.Config = this.Config;
53113
var workflowTriggerModel = new WorkflowTriggerModel();
54114

@@ -57,7 +117,9 @@ public override IActionResult Get()
57117
catch (ApiException apiException)
58118
{
59119
this.ViewBag.errorCode = apiException.ErrorCode;
60-
this.ViewBag.errorMessage = apiException.Message;
120+
this.ViewBag.errorMessage = apiException.ErrorCode == 403 ?
121+
this.LauncherTexts.ManifestStructure.SupportingTexts.ContactSupportToEnableFeature.Replace("{0}", "Maestro")
122+
: apiException.Message;
61123
this.ViewBag.SupportingTexts = this.LauncherTexts.ManifestStructure.SupportingTexts;
62124

63125
return this.View("Error");
@@ -74,13 +136,19 @@ public ActionResult SubmitForm(WorkflowTriggerModel model)
74136
{
75137
var accessToken = this.RequestItemsService.User.AccessToken;
76138
var accountId = this.RequestItemsService.Session.AccountId;
77-
var docuSignManageClient = new DocuSignClient(this.RequestItemsService.Session.MaestroManageApiBasePath);
139+
var docuSignManageClient = new DocuSignClient(this.RequestItemsService.Session.MaestroApiBasePath);
78140
docuSignManageClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
79-
var workflow = TriggerWorkflowService.GetWorkFlowDefinition(docuSignManageClient, accountId, this.RequestItemsService.WorkflowId);
80141

81-
var docuSignAuthClient = new DocuSignClient(this.RequestItemsService.Session.MaestroAuthApiBasePath);
82-
docuSignAuthClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
83-
var result = TriggerWorkflowService.TriggerWorkflow(docuSignAuthClient, accountId, new Uri(workflow.TriggerUrl), model);
142+
var workflow = TriggerWorkflowService.GetWorkFlowDefinition(
143+
docuSignManageClient,
144+
accountId,
145+
this.RequestItemsService.WorkflowId);
146+
147+
var result = TriggerWorkflowService.TriggerWorkflow(
148+
docuSignManageClient,
149+
accountId,
150+
new Uri(workflow.TriggerUrl),
151+
model);
84152

85153
this.RequestItemsService.InstanceId = result.InstanceId;
86154

0 commit comments

Comments
 (0)