-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(summary): Az function task owner report sender (#722)
- [x] New feature - [ ] Bug fix - [ ] High impact **Description of work:** <!--- Please give a description of the work ---> AB57452 Similar to the weekly resource owner report sender this is the equivalent sender for the task owner report. Due to the report format being more complex, I had to do some manual transformation of the adaptive card html. Without these changes the layout would look fine in new outlook and browser, but would look very bad in classic outlook. AZ func is disabled in FQA and FPRD. A seperate PR will enable them once testing of the solution has been performed. **Testing:** - [x] Can be tested - [x] Automatic tests created / updated - [x] Local tests are passing <!--- Please give a description of how this can be tested ---> **Checklist:** - [x] Considered automated tests - [x] Considered updating specification / documentation - [x] Considered work items - [x] Considered security - [x] Performed developer testing - [x] Checklist finalized / ready for review <!--- Other comments --->
- Loading branch information
1 parent
516e7db
commit ab0c33a
Showing
23 changed files
with
919 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Fusion.Resources.Functions.Common/ApiClients/ApiModels/Contexts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
|
||
public class ApiContext | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string? ExternalId { get; set; } | ||
|
||
public ApiContextType Type { get; set; } = null!; | ||
|
||
public Dictionary<string, object?> Value { get; set; } = null!; | ||
|
||
public string Title { get; set; } = null!; | ||
|
||
public string? Source { get; set; } | ||
|
||
public bool IsActive { get; set; } | ||
} | ||
|
||
public class ApiContextType | ||
{ | ||
public string Id { get; set; } = null!; | ||
|
||
public bool IsChildType { get; set; } | ||
|
||
public string[]? ParentTypeIds { get; set; } | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Fusion.Resources.Functions.Common/ApiClients/ApiModels/Mails.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
|
||
public class SendEmailRequest | ||
{ | ||
public required string[] Recipients { get; set; } | ||
public required string Subject { get; set; } | ||
public required string Body { get; set; } | ||
public string? FromDisplayName { get; set; } | ||
} | ||
|
||
public class SendEmailWithTemplateRequest | ||
{ | ||
public required string Subject { get; set; } | ||
|
||
public required string[] Recipients { get; set; } | ||
|
||
/// <summary> | ||
/// Specify the content that is to be displayed in the mail | ||
/// </summary> | ||
public required MailBody MailBody { get; set; } | ||
} | ||
|
||
public class MailBody | ||
{ | ||
/// <summary> | ||
/// The main content in the mail placed between the header and footer | ||
/// </summary> | ||
public required string HtmlContent { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. If not specified, the footer template will be used | ||
/// </summary> | ||
public string? HtmlFooter { get; set; } | ||
|
||
/// <summary> | ||
/// Optional. A text that is displayed inside the header. Will default to 'Mail from Fusion' | ||
/// </summary> | ||
public string? HeaderTitle { get; set; } | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Fusion.Resources.Functions.Common/ApiClients/ContextApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
using Fusion.Resources.Functions.Common.Integration.Http; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public class ContextApiClient : IContextApiClient | ||
{ | ||
private readonly HttpClient client; | ||
|
||
public ContextApiClient(IHttpClientFactory httpClientFactory) | ||
{ | ||
client = httpClientFactory.CreateClient(HttpClientNames.Application.Context); | ||
} | ||
|
||
public async Task<ICollection<ApiContext>> GetContextsAsync(string? contextType = null, CancellationToken cancellationToken = default) | ||
{ | ||
var url = contextType is null ? "/contexts" : $"/contexts?$filter=type eq '{contextType}'"; | ||
return await client.GetAsJsonAsync<ICollection<ApiContext>>(url, cancellationToken); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Fusion.Resources.Functions.Common/ApiClients/IContextApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public interface IContextApiClient | ||
{ | ||
public Task<ICollection<ApiContext>> GetContextsAsync(string? contextType = null, CancellationToken cancellationToken = default); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Fusion.Resources.Functions.Common/ApiClients/IMailApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public interface IMailApiClient | ||
{ | ||
public Task SendEmailAsync(SendEmailRequest request, CancellationToken cancellationToken = default); | ||
|
||
public Task SendEmailWithTemplateAsync(SendEmailWithTemplateRequest request, string? templateName = "default", CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/Fusion.Resources.Functions.Common/ApiClients/MailApiClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Text; | ||
using Fusion.Resources.Functions.Common.ApiClients.ApiModels; | ||
using Fusion.Resources.Functions.Common.Extensions; | ||
using Fusion.Resources.Functions.Common.Integration.Errors; | ||
using Fusion.Resources.Functions.Common.Integration.Http; | ||
using Newtonsoft.Json; | ||
|
||
namespace Fusion.Resources.Functions.Common.ApiClients; | ||
|
||
public class MailApiClient : IMailApiClient | ||
{ | ||
private readonly HttpClient mailClient; | ||
|
||
public MailApiClient(IHttpClientFactory httpClientFactory) | ||
{ | ||
mailClient = httpClientFactory.CreateClient(HttpClientNames.Application.Mail); | ||
mailClient.Timeout = TimeSpan.FromMinutes(2); | ||
} | ||
|
||
public async Task SendEmailAsync(SendEmailRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
var json = JsonConvert.SerializeObject(request); | ||
var content = new StringContent(json, Encoding.UTF8, "application/json"); | ||
|
||
using var response = await mailClient.PostAsync("/mails", content, cancellationToken); | ||
|
||
await ThrowIfNotSuccess(response); | ||
} | ||
|
||
public async Task SendEmailWithTemplateAsync(SendEmailWithTemplateRequest request, string? templateName = "default", CancellationToken cancellationToken = default) | ||
{ | ||
var json = JsonConvert.SerializeObject(request); | ||
var content = new StringContent(json, Encoding.UTF8, "application/json"); | ||
|
||
using var response = await mailClient.PostAsync($"templates/{templateName}/mails", content, cancellationToken); | ||
|
||
await ThrowIfNotSuccess(response); | ||
} | ||
|
||
private async Task ThrowIfNotSuccess(HttpResponseMessage response) | ||
{ | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
var body = await response.Content.ReadAsStringAsync(); | ||
throw new ApiError(response.RequestMessage!.RequestUri!.ToString(), response.StatusCode, body, "Response from API call indicates error"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Fusion.Resources.Functions.Common/Integration/Http/Handlers/ContextHttpHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Fusion.Resources.Functions.Common.Integration.Authentication; | ||
using Fusion.Resources.Functions.Common.Integration.ServiceDiscovery; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Fusion.Resources.Functions.Common.Integration.Http.Handlers; | ||
|
||
public class ContextHttpHandler : FunctionHttpMessageHandler | ||
{ | ||
private readonly IOptions<HttpClientsOptions> options; | ||
|
||
public ContextHttpHandler(ILoggerFactory logger, ITokenProvider tokenProvider, IServiceDiscovery serviceDiscovery, IOptions<HttpClientsOptions> options) | ||
: base(logger.CreateLogger<ContextHttpHandler>(), tokenProvider, serviceDiscovery) | ||
{ | ||
this.options = options; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
await SetEndpointUriForRequestAsync(request, ServiceEndpoint.Context); | ||
await AddAuthHeaderForRequestAsync(request, options.Value.Fusion); | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Fusion.Resources.Functions.Common/Integration/Http/Handlers/MailHttpHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Fusion.Resources.Functions.Common.Integration.Authentication; | ||
using Fusion.Resources.Functions.Common.Integration.ServiceDiscovery; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Fusion.Resources.Functions.Common.Integration.Http.Handlers; | ||
|
||
public class MailHttpHandler : FunctionHttpMessageHandler | ||
{ | ||
private readonly IOptions<HttpClientsOptions> options; | ||
|
||
public MailHttpHandler(ILoggerFactory loggerFactory, ITokenProvider tokenProvider, IServiceDiscovery serviceDiscovery, IOptions<HttpClientsOptions> options) | ||
: base(loggerFactory.CreateLogger<MailHttpHandler>(), tokenProvider, serviceDiscovery) | ||
{ | ||
this.options = options; | ||
} | ||
|
||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
await SetEndpointUriForRequestAsync(request, ServiceEndpoint.Mail); | ||
await AddAuthHeaderForRequestAsync(request, options.Value.Fusion); | ||
|
||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.