Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Email Notifications #450

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion BLAZAM/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
global using BLAZAM.Logger;
global using BLAZAM.FileSystem;
global using BLAZAM.Helpers;
global using BLAZAM.Common.Exceptions;
global using BLAZAM.Services.Background;


1 change: 0 additions & 1 deletion BLAZAM/Pages/Error/UnhandledExceptionPage.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@using BLAZAM.Email.Services;
@inject EmailService email
@inject ApplicationInfo ApplicationInfo
@inject IAppDatabaseFactory factory
Expand Down
12 changes: 0 additions & 12 deletions BLAZAM/ProgramHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@

using BLAZAM.Common.Data.Services;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Localization;
using MudBlazor.Services;
using System.Globalization;
using MudBlazor;
using BLAZAM.Server.Data;
using BLAZAM.Update.Services;
using BLAZAM.Update;
using BLAZAM.Database.Context;
using BLAZAM.ActiveDirectory.Interfaces;
using BLAZAM.ActiveDirectory;
using BLAZAM.Session.Interfaces;
using BLAZAM.Notifications.Services;
using BLAZAM.Common.Data;
using BLAZAM.Services.Background;
using BLAZAM.Email.Services;
using BLAZAM.Services;
using BLAZAM.Services.Duo;
using BLAZAM.Server.Data.Services;
using System.Diagnostics;
using System.Reflection;
using BLAZAM.Services.Chat;
using BLAZAM.Services.Audit;
using BLAZAM.Common;
using BLAZAM.Nav;
using BLAZAM.Session;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Org.BouncyCastle.Ocsp;
using System.Management;

namespace BLAZAM.Server
Expand Down
1 change: 1 addition & 0 deletions BLAZAMActiveDirectory/BLAZAMActiveDirectory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ProjectReference Include="..\BLAZAMDatabase\BLAZAMDatabase.csproj" />
<ProjectReference Include="..\BLAZAMJobs\BLAZAMJobs.csproj" />
<ProjectReference Include="..\BLAZAMLocalization\BLAZAMLocalization.csproj" />
<ProjectReference Include="..\BLAZAMNotifications\BLAZAMNotifications.csproj" />
<ProjectReference Include="..\BLAZAMSession\BLAZAMSession.csproj" />
</ItemGroup>

Expand Down
3 changes: 0 additions & 3 deletions BLAZAMDatabase/Context/DatabaseContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
using BLAZAM.Logger;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Configuration;
using BLAZAM.Database.Models.Chat;
using BLAZAM.Server.Data;
using Microsoft.IdentityModel.Tokens;
using System.Data;
using BLAZAM.FileSystem;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using BLAZAM.Database.Models.Notifications;

namespace BLAZAM.Database.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using BLAZAM.Database.Models.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLAZAM.Database.Models.Notifications
{
Expand Down
4 changes: 4 additions & 0 deletions BLAZAMEmail/BLAZAMEmail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
<ProjectReference Include="..\BLAZAMEmailMessage\BLAZAMEmailMessage.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@using BLAZAM.Helpers
@using System.Security
@inherits NotificationTemplateComponent

<EmailTemplateHeader>
<strong>@AppLocalization["Active Directory object created"]</strong>
</EmailTemplateHeader>

<EmailTemplateBody>
EntryName + AppLocalization[" has been created."])
<br/>


</EmailTemplateBody>


@code{
[Parameter]
public string EntryName { get; set; }

public override string Render() => new ComponentRenderer<EntryCreatedEmailMessage>()
.UseLayout<DefaultEmailLayout>()
.AddServiceProvider(ApplicationInfo.services)
.Set(c => c.EntryName, EntryName).Render();
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@using BLAZAM.Helpers
@using System.Security
@inherits NotificationTemplateComponent

<EmailTemplateHeader>
<strong>@AppLocalization["Object deleted"]</strong>
</EmailTemplateHeader>

<EmailTemplateBody>
@( EntryName + AppLocalization[" has been deltted."])
<br/>


</EmailTemplateBody>


@code{
[Parameter]
public string EntryName { get; set; }

public override string Render() => new ComponentRenderer<EntryDeletedEmailMessage>()
.UseLayout<DefaultEmailLayout>()
.AddServiceProvider(ApplicationInfo.services)
.Set(c => c.EntryName, EntryName).Render();
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@using BLAZAM.Helpers
@using System.Security
@inherits NotificationTemplateComponent

<EmailTemplateHeader>
<strong>@AppLocalization["Entry modified"]</strong>
</EmailTemplateHeader>

<EmailTemplateBody>
@(EntryName + AppLocalization[" has been modified."])
<br/>


</EmailTemplateBody>


@code{
[Parameter]
public string EntryName { get; set; }

public override string Render() => new ComponentRenderer<EntryEditedEmailMessage>()
.UseLayout<DefaultEmailLayout>()
.AddServiceProvider(ApplicationInfo.services)
.Set(c => c.EntryName, EntryName).Render();
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@using BLAZAM.Helpers
@using System.Security
@inherits NotificationTemplateComponent

<EmailTemplateHeader>
<strong>@AppLocalization["Group membership changed"]</strong>
</EmailTemplateHeader>

<EmailTemplateBody>
@(AppLocalization["he password for "] + EntryName + AppLocalization[" has been changed."])
<br/>


</EmailTemplateBody>


@code{
[Parameter]
public string EntryName { get; set; }

public override string Render() => new ComponentRenderer<EntryGroupAssignmentEmailMessage>()
.UseLayout<DefaultEmailLayout>()
.AddServiceProvider(ApplicationInfo.services)
.Set(c => c.EntryName, EntryName).Render();
}



10 changes: 2 additions & 8 deletions BLAZAMGui/UI/AppComponentBase.razor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

using BLAZAM.ActiveDirectory;
using BLAZAM.Email.Services;
using BLAZAM.Services.Audit;
using BLAZAM.Services.Chat;
using BLAZAM.Common;
using BLAZAM.Nav;

namespace BLAZAM.Gui.UI
Expand Down Expand Up @@ -44,8 +42,7 @@ public class AppComponentBase : ComponentBase,IDisposable
[Inject]
public ICurrentUserStateService CurrentUser { get; set; }

// protected IApplicationUserState? CurrentUser => UserStateService.CurrentUserState;


[Inject]
protected AuditLogger AuditLogger { get; set; }

Expand Down Expand Up @@ -85,7 +82,6 @@ public class AppComponentBase : ComponentBase,IDisposable
protected override void OnInitialized()
{
base.OnInitialized();
//Nav = new AppNavigationManager(BaseNav);
try
{
Context = DbFactory.CreateDbContext();
Expand Down Expand Up @@ -151,9 +147,7 @@ protected void Refresh(bool forceReload = false)

public virtual void Dispose()
{
//Remove for issue #235, Dependency Injection automatically
//disposes of objects after they are no longer needed.
//Context?.Dispose();
//This object requires no further disposal
}

public async Task CopyToClipboard(string? text)
Expand Down
3 changes: 1 addition & 2 deletions BLAZAMGui/UI/AppModalContentBase.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using BLAZAM.Email.Services;
@using BLAZAM.Services.Chat;
@using BLAZAM.Services.Chat;
@code {


Expand Down
1 change: 0 additions & 1 deletion BLAZAMGui/UI/Settings/ManualApplicationUpdater.razor
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@
{
MessageService.ShowMessage<JobResultDialog>(output.ToDialogParameters(), AppLocalization["Update"]);
await output.RunAsync();
// SnackBarService.Success("Update started successfully. The web application will restart and update momentarily.");

}
await InvokeAsync(StateHasChanged);
Expand Down
5 changes: 5 additions & 0 deletions BLAZAMJobs/BLAZAMJobs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<RootNamespace>BLAZAM.Jobs</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.20.0" />
<PackageReference Include="PreMailer.Net" Version="2.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BLAZAMDatabase\BLAZAMDatabase.csproj" />
<ProjectReference Include="..\BLAZAMSession\BLAZAMSession.csproj" />
Expand Down
5 changes: 1 addition & 4 deletions BLAZAMJobs/Job.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using BLAZAM.Common.Data;
using BLAZAM.Database.Models.User;
using BLAZAM.Session.Interfaces;
using Microsoft.AspNetCore.Components;


namespace BLAZAM.Jobs
{
Expand Down
18 changes: 13 additions & 5 deletions BLAZAMNotifications/Notifications/NotificationTypeExtentions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using BLAZAM.Database.Models.Notifications;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLAZAM.Notifications.Notifications
{
Expand All @@ -17,6 +12,19 @@ public static class NotificationTypeExtentions
case NotificationType.PasswordChange:
notificationTemplate = new PasswordChangedEmailMessage();
break;
case NotificationType.Create:
notificationTemplate = new EntryCreatedEmailMessage();
break;
case NotificationType.Delete:
notificationTemplate = new EntryDeletedEmailMessage();
break;
case NotificationType.Modify:
notificationTemplate = new EntryEditedEmailMessage();
break;
case NotificationType.GroupAssignment:
notificationTemplate = new EntryGroupAssignmentEmailMessage();
break;

}
if(notificationTemplate != null)
{
Expand Down
1 change: 1 addition & 0 deletions BLAZAMServices/BLAZAMServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="MailKit" Version="4.6.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="PreMailer.Net" Version="2.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading