Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
30ce563
AB#26877 - Add Notifications Settings and Management Interface
plavoie-BC Dec 3, 2024
0350e20
UI Tag Helper Bugfix
plavoie-BC Dec 4, 2024
3abe879
Change notification settings form
plavoie-BC Dec 4, 2024
304af23
Merge remote-tracking branch 'origin/dev' into feature/AB#26877-email…
plavoie-BC Dec 5, 2024
d184907
Merge branch 'dev' into feature/AB#26877-email-settings-management
plavoie-BC Dec 5, 2024
bd81c4f
Add null handling for externalUserLookupServiceProvider bugfixes
plavoie-BC Dec 5, 2024
a193a65
Change from email configuration to notificaiton setting provider for …
plavoie-BC Dec 10, 2024
f587f50
Add feature gate for Notifications Setting Page
plavoie-BC Dec 10, 2024
7e665b0
Add Notifications setting permissions
plavoie-BC Dec 10, 2024
85c347d
SonarQube fixes
plavoie-BC Dec 10, 2024
830300f
Add Notification Setting Management UI JavaScript
plavoie-BC Dec 10, 2024
647a21b
Fix Notification Settings Virtual File System references
plavoie-BC Dec 10, 2024
dd2b88d
Add email address validation
plavoie-BC Dec 10, 2024
0a211eb
AB#27129 - Remove default TimeZone and Emailing settings management UI
plavoie-BC Dec 11, 2024
0d51fa4
Update settings topbar user and feature requirements
plavoie-BC Dec 11, 2024
9ea2af7
Remove DefaultFromDisplayName setting property
plavoie-BC Dec 11, 2024
2e064e0
Merge branch 'dev' into feature/AB#26877-email-settings-management
plavoie-BC Dec 11, 2024
9ae71ea
Set default fallback NoReply email address
plavoie-BC Dec 11, 2024
9810c58
Merge branch 'feature/AB#26877-email-settings-management' of https://…
plavoie-BC Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Unity.Notifications.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;
using Volo.Abp.SettingManagement;

namespace Unity.Notifications.Permissions;

Expand All @@ -9,6 +10,9 @@ public class NotificationsPermissionDefinitionProvider : PermissionDefinitionPro
public override void Define(IPermissionDefinitionContext context)
{
context.AddGroup(NotificationsPermissions.GroupName, L("Permission:Notifications"));

var settingManagement = context.GetGroup(SettingManagementPermissions.GroupName);
settingManagement.AddPermission(NotificationsPermissions.Settings, L("Permission:NotificationsPermissions.Settings"));
}

private static LocalizableString L(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Unity.Notifications.Permissions;
public static class NotificationsPermissions
{
public const string GroupName = "Notifications";
public const string Settings = "SettingManagement.Notifications";

public static string[] GetAll()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="Volo.Abp.Ddd.Application.Contracts" Version="8.3.0" />
<PackageReference Include="Volo.Abp.Authorization" Version="8.3.0" />
<PackageReference Include="Volo.Abp.SettingManagement.Application.Contracts" Version="8.3.0" />
<ProjectReference Include="..\Unity.Notifications.Domain.Shared\Unity.Notifications.Domain.Shared.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Users;
using Volo.Abp.SettingManagement;
using Unity.Notifications.Settings;
using Unity.Notifications.Permissions;

namespace Unity.Notifications.EmailNotifications;

Expand All @@ -28,20 +31,23 @@ public class EmailNotificationService : ApplicationService, IEmailNotificationSe
private readonly EmailQueueService _emailQueueService;
private readonly IEmailLogsRepository _emailLogsRepository;
private readonly IExternalUserLookupServiceProvider _externalUserLookupServiceProvider;
private readonly ISettingManager _settingManager;

public EmailNotificationService(
IEmailLogsRepository emailLogsRepository,
IConfiguration configuration,
IChesClientService chesClientService,
EmailQueueService emailQueueService,
IExternalUserLookupServiceProvider externalUserLookupServiceProvider
IExternalUserLookupServiceProvider externalUserLookupServiceProvider,
ISettingManager settingManager
)
{
_emailLogsRepository = emailLogsRepository;
_configuration = configuration;
_chesClientService = chesClientService;
_emailQueueService = emailQueueService;
_externalUserLookupServiceProvider = externalUserLookupServiceProvider;
_settingManager = settingManager;
}

private const string approvalBody =
Expand Down Expand Up @@ -83,7 +89,7 @@ public string GetDeclineBody()
{
return null;
}
var emailObject = GetEmailObject(emailTo, body, subject, emailFrom);
var emailObject = await GetEmailObjectAsync(emailTo, body, subject, emailFrom);
EmailLog emailLog = GetMappedEmailLog(emailObject);
emailLog.ApplicationId = applicationId;

Expand Down Expand Up @@ -116,7 +122,7 @@ public async Task<RestResponse> SendEmailNotification(string emailTo, string bod
{
if (!string.IsNullOrEmpty(emailTo))
{
var emailObject = GetEmailObject(emailTo, body, subject, emailFrom);
var emailObject = await GetEmailObjectAsync(emailTo, body, subject, emailFrom);
response = await _chesClientService.SendAsync(emailObject);
}
else
Expand Down Expand Up @@ -155,8 +161,7 @@ public virtual async Task<List<EmailHistoryDto>> GetHistoryByApplicationId(Guid
var sentByUserIds = dtoList
.Where(d => d.CreatorId.HasValue)
.Select(d => d.CreatorId!.Value)
.Distinct()
.ToList();
.Distinct();

var userDictionary = new Dictionary<Guid, EmailHistoryUserDto>();

Expand All @@ -172,9 +177,9 @@ public virtual async Task<List<EmailHistoryDto>> GetHistoryByApplicationId(Guid

foreach (var item in dtoList)
{
if (item.CreatorId.HasValue)
if (item.CreatorId.HasValue && userDictionary.TryGetValue(item.CreatorId.Value, out var userDto))
{
item.SentBy = userDictionary[item.CreatorId.Value];
item.SentBy = userDto;
}
}

Expand All @@ -194,7 +199,7 @@ public async Task SendEmailToQueue(EmailLog emailLog)
await _emailQueueService.SendToEmailEventQueueAsync(emailNotificationEvent);
}

protected virtual dynamic GetEmailObject(string emailTo, string body, string subject, string? emailFrom)
protected virtual async Task<dynamic> GetEmailObjectAsync(string emailTo, string body, string subject, string? emailFrom)
{
List<string> toList = new();
string[] emails = emailTo.Split([',', ';'], StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -204,12 +209,14 @@ protected virtual dynamic GetEmailObject(string emailTo, string body, string sub
toList.Add(email.Trim());
}

var defaultFromAddress = await SettingProvider.GetOrNullAsync(NotificationsSettings.Mailing.DefaultFromAddress);

var emailObject = new
{
body,
bodyType = "html",
encoding = "utf-8",
from = emailFrom ?? _configuration["Notifications:ChesFromEmail"] ?? "unity@gov.bc.ca",
from = emailFrom ?? defaultFromAddress ?? "NoReply@gov.bc.ca",
priority = "normal",
subject,
tag = "tag",
Expand All @@ -228,4 +235,13 @@ protected virtual EmailLog GetMappedEmailLog(dynamic emailDynamicObject)
emailLog.ToAddress = ((List<string>)emailDynamicObject.to).FirstOrDefault() ?? "";
return emailLog;
}

[Authorize(NotificationsPermissions.Settings)]
public async Task UpdateSettings(NotificationsSettingsDto settingsDto)
{
if (!settingsDto.DefaultFromAddress.IsNullOrWhiteSpace())
{
await _settingManager.SetForCurrentTenantAsync(NotificationsSettings.Mailing.DefaultFromAddress, settingsDto.DefaultFromAddress);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Notifications.Emails;
using Unity.Notifications.Settings;
using Volo.Abp.Application.Services;

namespace Unity.Notifications.EmailNotifications
Expand All @@ -16,5 +17,6 @@ public interface IEmailNotificationService : IApplicationService
string GetApprovalBody();
string GetDeclineBody();
Task<List<EmailHistoryDto>> GetHistoryByApplicationId(Guid applicationId);
Task UpdateSettings(NotificationsSettingsDto settingsDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<PackageReference Include="Volo.Abp.EventBus.RabbitMQ" Version="8.3.0" />
<PackageReference Include="Volo.Abp.Ddd.Application" Version="8.3.0" />
<PackageReference Include="Volo.Abp.Http.Client" Version="8.3.0" />
<PackageReference Include="Volo.Abp.SettingManagement.Application" Version="8.3.0" />
<ProjectReference Include="..\..\..\..\Unity.Shared\MessageBrokers\RabbitMQ\Unity.Shared.csproj" />
<ProjectReference Include="..\..\..\..\src\Unity.GrantManager.Application.Contracts\Unity.GrantManager.Application.Contracts.csproj" />
<ProjectReference Include="..\Unity.Notifications.Application.Contracts\Unity.Notifications.Application.Contracts.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"culture": "en",
"texts": {
"MyAccount": "My account",
"SamplePageMessage": "A sample page for the Notifications module"
"MyAccount": "My account",
"SamplePageMessage": "A sample page for the Notifications module",
"Permission:NotificationsPermissions.Settings": "Configure Notifications",
"Setting:Notifications": "Notifications",
"Setting:Notifications.Mailing.DefaultFromAddress.DisplayName": "From Address",
"Setting:Notifications.Mailing.DefaultFromAddress.Description": "The default From sender address"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
using Volo.Abp.Settings;
using Unity.Notifications.Localization;
using Volo.Abp.Localization;
using Volo.Abp.Settings;

namespace Unity.Notifications.Settings;

public class NotificationsSettingDefinitionProvider : SettingDefinitionProvider
{
public override void Define(ISettingDefinitionContext context)
{
/* Define module settings here.
* Use names from NotificationsSettings class.
*/
context.Add(
new SettingDefinition(
NotificationsSettings.Mailing.DefaultFromAddress,
"NoReply.Econ.Unity@gov.bc.ca",
L($"Setting:{NotificationsSettings.Mailing.DefaultFromAddress}.DisplayName"),
L($"Setting:{NotificationsSettings.Mailing.DefaultFromAddress}.Description"),
isVisibleToClients: false,
isInherited: false)
);
}

private static LocalizableString L(string name)
{
return LocalizableString.Create<NotificationsResource>(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

public static class NotificationsSettings
{
public const string GroupName = "Notifications";
public const string GroupName = "GrantManager.Notifications";

/* Add constants for setting names. Example: public const string MySettingName = GroupName + ".MySettingName" */
public static class Mailing
{
public const string Default = "GrantManager.Notifications.Mailing";
public const string DefaultFromAddress = "GrantManager.Notifications.Mailing.DefaultFromAddress";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Unity.Notifications.Settings;
public class NotificationsSettingsDto
{
public string DefaultFromAddress { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@
using Microsoft.Extensions.DependencyInjection;
using Unity.Notifications.Localization;
using Unity.Notifications.Web.Menus;
using Unity.Notifications.Web.Views.Settings;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AutoMapper;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.BackgroundWorkers.Quartz;
using Volo.Abp.Modularity;
using Volo.Abp.SettingManagement.Web;
using Volo.Abp.SettingManagement.Web.Pages.SettingManagement;
using Volo.Abp.UI.Navigation;
using Volo.Abp.VirtualFileSystem;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.BackgroundWorkers.Quartz;
using Volo.Abp.AspNetCore.Mvc;

namespace Unity.Notifications.Web;

[DependsOn(
typeof(NotificationsApplicationModule),
typeof(NotificationsApplicationContractsModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpAutoMapperModule)
typeof(AbpAutoMapperModule),
typeof(AbpSettingManagementWebModule)
)]
public class NotificationsWebModule : AbpModule
{
Expand Down Expand Up @@ -64,6 +68,11 @@ public override void ConfigureServices(ServiceConfigurationContext context)
options.FileSets.AddEmbedded<NotificationsWebModule>();
});

Configure<SettingManagementPageOptions>(options =>
{
options.Contributors.Add(new NotificationsSettingPageContributor());
});

context.Services.AddAutoMapperObjectMapper<NotificationsWebModule>();
Configure<AbpAutoMapperOptions>(options =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<IsPackable>true</IsPackable>
<OutputType>Library</OutputType>
<RootNamespace>Unity.Notifications.Web</RootNamespace>
<GenerateEmbeddedFilesManifest>false</GenerateEmbeddedFilesManifest>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,6 +18,7 @@
<PackageReference Include="Volo.Abp.BackgroundJobs" Version="8.3.0" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Quartz" Version="8.3.0" />
<PackageReference Include="Volo.Abp.BackgroundWorkers.Quartz" Version="8.3.0" />
<PackageReference Include="Volo.Abp.SettingManagement.Web" Version="8.3.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -34,14 +35,24 @@
<EmbeddedResource Include="Pages\**\*.js" />
<EmbeddedResource Include="Components\**\*.js" />
<EmbeddedResource Include="Components\**\*.css" />
<EmbeddedResource Include="Views\**\*.js" />
<EmbeddedResource Include="Views\**\*.css" />
<EmbeddedResource Include="wwwroot\**\*.*" />
<Content Remove="Pages\**\*.css" />
<Content Remove="Pages\**\*.js" />
<Content Remove="Components\**\*.js" />
<Content Remove="Components\**\*.css" />
<Content Remove="Views\**\*.js" />
<Content Remove="Views\**\*.css" />
<Content Remove="wwwroot\**\*.*" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Views\Settings\NotificationsSettingGroup\Default.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<PackageReference Update="ConfigureAwait.Fody" Version="3.3.2" />
<PackageReference Update="Fody" Version="6.8.1">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@model Unity.Notifications.Web.Views.Settings.NotificationsSettingGroup.NotificationsSettingViewModel

<abp-script src="/Views/Settings/NotificationsSettingGroup/Default.js" />

<div class="container-fluid px-0">
<div class="unity-page-titlebar">
<h4 class="m-0">Notifications Configuration</h4>
</div>
<div class="p-3">
<form id="NotificationsSettingsForm">
<abp-row>
<abp-column size-md="_12" class="mx-2 fw-bold">
<abp-input asp-for="@Model.DefaultFromAddress" />
</abp-column>
</abp-row>
<abp-row>
<hr class="my-4" />
<div class="d-flex p-2">
<abp-button id="NotificationsSaveButton"
text="Save Changes"
button-type="Primary" class="me-2"
type="submit" />
<abp-button id="NotificationsDiscardButton"
text="Discard Changes"
button-type="Light" class="me-2"
disabled="true"/>
</div>
</abp-row>
</form>
</div>
</div>
Loading