Skip to content

Commit e6429ac

Browse files
committed
42660 V14: Integrations (Dynamics)
- Add new project for Dynamics Integration - Introduce new management API - Add Client folder for front end implementation
1 parent d43cffd commit e6429ac

36 files changed

+1655
-332
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ src/Testsite/umbraco
77
src/Testsite/Views
88
src/Testsite/wwwroot
99
src/Umbraco.Cms.Integrations.Commerce.Shopify/wwwroot
10+
src/Umbraco.Cms.Integrations.Crm.Hubspot/wwwroot
11+
src/Umbraco.Cms.Integrations.Crm.Dynamics/wwwroot
1012

1113

1214
# User-specific files
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const outputPath = 'Release' !== 'Release' ? '../wwwroot' : '../obj/Release/net8.0/clientassets'
1+
export const outputPath = 'Debug' !== 'Release' ? '../wwwroot' : '../obj/Debug/net8.0/clientassets'

src/Umbraco.Cms.Integrations.Commerce.Shopify/wwwroot/App_Plugins/Shopify/umbraco-package.json

Lines changed: 0 additions & 14 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Options;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
10+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.Dtos;
11+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
12+
13+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
14+
{
15+
public class CheckOAuthConfigurationController : FormsControllerBase
16+
{
17+
public CheckOAuthConfigurationController(IOptions<DynamicsSettings> options, DynamicsService dynamicsService, DynamicsConfigurationService dynamicsConfigurationService, DynamicsComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, dynamicsService, dynamicsConfigurationService, authorizationImplementationFactory)
18+
{
19+
}
20+
21+
[HttpGet("check-oauth-configuration")]
22+
[ProducesResponseType(typeof(OAuthConfigurationDto), StatusCodes.Status200OK)]
23+
[ProducesResponseType(StatusCodes.Status404NotFound)]
24+
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
25+
public async Task<IActionResult> CheckOAuthConfiguration()
26+
{
27+
var oauthConfiguration = DynamicsConfigurationService.GetOAuthConfiguration();
28+
29+
if (oauthConfiguration == null) return NotFound(new OAuthConfigurationDto { Message = string.Empty });
30+
31+
var identity = await DynamicsService.GetIdentity(oauthConfiguration.AccessToken);
32+
33+
if (!identity.IsAuthorized) return Unauthorized(new OAuthConfigurationDto { Message = identity.Error != null ? identity.Error.Message : string.Empty });
34+
35+
oauthConfiguration.IsAuthorized = true;
36+
37+
return Ok(oauthConfiguration);
38+
}
39+
}
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using Umbraco.Cms.Api.Common.Attributes;
8+
using Umbraco.Cms.Web.Common.Routing;
9+
10+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
11+
{
12+
[ApiController]
13+
[BackOfficeRoute($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}")]
14+
[MapToApi(Constants.ManagementApi.ApiName)]
15+
public class DynamicsControllerBase : Controller
16+
{
17+
}
18+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.Extensions.Options;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
9+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.Dtos;
10+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models;
11+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
12+
using static Umbraco.Cms.Integrations.Crm.Dynamics.DynamicsComposer;
13+
using Asp.Versioning;
14+
using Microsoft.AspNetCore.Http;
15+
16+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
17+
{
18+
[ApiVersion("1.0")]
19+
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
20+
[Route($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}/forms")]
21+
public class FormsControllerBase : DynamicsControllerBase
22+
{
23+
// Using a static HttpClient (see: https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/).
24+
//private readonly static HttpClient s_client = new HttpClient();
25+
26+
// Access to the client within the class is via ClientFactory(), allowing us to mock the responses in tests.
27+
//public static Func<HttpClient> ClientFactory = () => s_client;
28+
29+
protected readonly DynamicsSettings DynamicsSettings;
30+
31+
protected readonly IDynamicsAuthorizationService AuthorizationService;
32+
33+
protected readonly DynamicsService DynamicsService;
34+
35+
protected readonly DynamicsConfigurationService DynamicsConfigurationService;
36+
37+
public FormsControllerBase(IOptions<DynamicsSettings> options,
38+
DynamicsService dynamicsService,
39+
DynamicsConfigurationService dynamicsConfigurationService,
40+
AuthorizationImplementationFactory authorizationImplementationFactory)
41+
{
42+
43+
DynamicsSettings = options.Value;
44+
45+
AuthorizationService = authorizationImplementationFactory(DynamicsSettings.UseUmbracoAuthorization);
46+
47+
DynamicsService = dynamicsService;
48+
49+
DynamicsConfigurationService = dynamicsConfigurationService;
50+
}
51+
}
52+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Options;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
10+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.Dtos;
11+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
12+
13+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
14+
{
15+
public class GetAccessTokenController : FormsControllerBase
16+
{
17+
public GetAccessTokenController(IOptions<DynamicsSettings> options, DynamicsService dynamicsService, DynamicsConfigurationService dynamicsConfigurationService, DynamicsComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, dynamicsService, dynamicsConfigurationService, authorizationImplementationFactory)
18+
{
19+
}
20+
21+
[HttpPost("get-access-token")]
22+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
23+
public async Task<IActionResult> GetAccessToken([FromBody] OAuthRequestDto authRequestDto) =>
24+
Ok(await AuthorizationService.GetAccessTokenAsync(authRequestDto.Code));
25+
}
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Options;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
10+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
11+
12+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
13+
{
14+
public class GetAuthorizationUrlController : FormsControllerBase
15+
{
16+
public GetAuthorizationUrlController(IOptions<DynamicsSettings> options, DynamicsService dynamicsService, DynamicsConfigurationService dynamicsConfigurationService, DynamicsComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, dynamicsService, dynamicsConfigurationService, authorizationImplementationFactory)
17+
{
18+
}
19+
20+
[HttpGet("authorization-url")]
21+
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
22+
public IActionResult GetAuthorizationUrl() => Ok(AuthorizationService.GetAuthorizationUrl());
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Options;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
10+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
11+
12+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
13+
{
14+
public class GetEmbedCodeController : FormsControllerBase
15+
{
16+
public GetEmbedCodeController(IOptions<DynamicsSettings> options, DynamicsService dynamicsService, DynamicsConfigurationService dynamicsConfigurationService, DynamicsComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, dynamicsService, dynamicsConfigurationService, authorizationImplementationFactory)
17+
{
18+
}
19+
20+
[HttpGet("get-embed-code")]
21+
[ProducesResponseType(typeof(Task<string>), StatusCodes.Status200OK)]
22+
public async Task<IActionResult> GetEmbedCode(string formId) => Ok(await DynamicsService.GetEmbedCode(formId));
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models.Dtos;
9+
using Umbraco.Cms.Integrations.Crm.Dynamics.Models;
10+
using Umbraco.Cms.Integrations.Crm.Dynamics.Services;
11+
using Microsoft.Extensions.Options;
12+
using Umbraco.Cms.Integrations.Crm.Dynamics.Configuration;
13+
14+
namespace Umbraco.Cms.Integrations.Crm.Dynamics.Api.Management.Controllers
15+
{
16+
public class GetFormsController : FormsControllerBase
17+
{
18+
public GetFormsController(IOptions<DynamicsSettings> options, DynamicsService dynamicsService, DynamicsConfigurationService dynamicsConfigurationService, DynamicsComposer.AuthorizationImplementationFactory authorizationImplementationFactory) : base(options, dynamicsService, dynamicsConfigurationService, authorizationImplementationFactory)
19+
{
20+
}
21+
22+
[HttpGet]
23+
[ProducesResponseType(typeof(IEnumerable<FormDto>), StatusCodes.Status200OK)]
24+
public async Task<IActionResult> GetForms(string module) =>
25+
Ok(await DynamicsService.GetForms((DynamicsModule)Enum.Parse(typeof(DynamicsModule), module)));
26+
}
27+
}

0 commit comments

Comments
 (0)