Skip to content

Commit

Permalink
Merge pull request #920 from bcgov/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jimmyPasta authored Dec 5, 2024
2 parents 694207d + 39ce465 commit 2107343
Show file tree
Hide file tree
Showing 22 changed files with 305 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static string Convert(string currentValue, QuestionType type)
QuestionType.Number => JsonSerializer.Serialize(new NumericValue(currentValue)),
QuestionType.YesNo => JsonSerializer.Serialize(new YesNoValue(ValueConverterHelpers.ConvertYesNo(currentValue))),
QuestionType.SelectList => JsonSerializer.Serialize(new SelectListValue(currentValue)),
QuestionType.TextArea => JsonSerializer.Serialize(new TextAreaValue(currentValue)),
_ => throw new NotImplementedException()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
minlength="@Model.MinLength"
maxlength="@Model.MaxLength"
disabled="@Model.IsDisabled"
id="answer-text[email protected]"
id="answer-textarea[email protected]"
name="[email protected]"
data-original-value="@Model.Answer"
oninput="handleInputChange('@Model.QuestionId','answer-text-')">@Model.Answer</textarea>
oninput="handleInputChange('@Model.QuestionId','answer-textarea-')">@Model.Answer</textarea>
<span id="[email protected]" class="text-danger field-validation-error"></span>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ $(function () {
<div class="mb-3">
<label for="answer-text-${item.dataset.id}" class="form-label unt-form-label">Answer</label>
<textarea rows="${item.dataset.rows}" type="text" ${req} class="form-control answer-text-input" minlength="${item.dataset.minlength}" maxlength="${item.dataset.maxlength}"
id="answer-text-${item.dataset.id}" name="Answer-Textarea-${item.dataset.id}" value="" data-original-value=""
oninput="handleInputChange('${item.dataset.id}','answer-text-')"></textarea>
id="answer-textarea-${item.dataset.id}" name="Answer-Textarea-${item.dataset.id}" value="" data-original-value=""
oninput="handleInputChange('${item.dataset.id}','answer-textarea-')"></textarea>
<span id="error-message-${item.dataset.id}" class="text-danger field-validation-error"></span>
</div>`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using Volo.Abp.Application.Dtos;

namespace Unity.Notifications.Emails;

[Serializable]
public class EmailHistoryDto : ExtensibleAuditedEntityDto<Guid>
{
public string Subject { get; set; } = string.Empty;
public DateTime? SentDateTime { get; set; }
public string Body { get; set; } = string.Empty;
public EmailHistoryUserDto? SentBy { get; set; }
}

public class EmailHistoryUserDto : EntityDto<Guid>
{
public string UserName { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Surname { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
Expand All @@ -14,9 +14,11 @@
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Users;

namespace Unity.Notifications.EmailNotifications;

[Authorize]
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(EmailNotificationService), typeof(IEmailNotificationService))]
public class EmailNotificationService : ApplicationService, IEmailNotificationService
Expand All @@ -25,18 +27,21 @@ public class EmailNotificationService : ApplicationService, IEmailNotificationSe
private readonly IConfiguration _configuration;
private readonly EmailQueueService _emailQueueService;
private readonly IEmailLogsRepository _emailLogsRepository;
private readonly IExternalUserLookupServiceProvider _externalUserLookupServiceProvider;

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

private const string approvalBody =
Expand Down Expand Up @@ -73,15 +78,15 @@ public string GetDeclineBody()
}

public async Task<EmailLog?> InitializeEmailLog(string emailTo, string body, string subject, Guid applicationId, string? emailFrom)
{
{
if (string.IsNullOrEmpty(emailTo))
{
return null;
}
var emailObject = GetEmailObject(emailTo, body, subject, emailFrom);
EmailLog emailLog = GetMappedEmailLog(emailObject);
emailLog.ApplicationId = applicationId;

// When being called here the current tenant is in context - verified by looking at the tenant id
EmailLog loggedEmail = await _emailLogsRepository.InsertAsync(emailLog, autoSave: true);
return loggedEmail;
Expand Down Expand Up @@ -133,20 +138,55 @@ public async Task<RestResponse> SendEmailNotification(string emailTo, string bod
try
{
emailLog = await _emailLogsRepository.GetAsync(id);
}
catch (EntityNotFoundException ex) {
}
catch (EntityNotFoundException ex)
{
string ExceptionMessage = ex.Message;
Logger.LogInformation(ex, "Entity Not found for Email Log Must be in wrong context: {ExceptionMessage}", ExceptionMessage);
}
return emailLog;
}

public virtual async Task<List<EmailHistoryDto>> GetHistoryByApplicationId(Guid applicationId)
{
var entityList = await _emailLogsRepository.GetByApplicationIdAsync(applicationId);
var dtoList = ObjectMapper.Map<List<EmailLog>, List<EmailHistoryDto>>(entityList);

var sentByUserIds = dtoList
.Where(d => d.CreatorId.HasValue)
.Select(d => d.CreatorId!.Value)
.Distinct()
.ToList();

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

foreach (var userId in sentByUserIds)
{
var userInfo = await _externalUserLookupServiceProvider.FindByIdAsync(userId);
if (userInfo != null)
{
userDictionary[userId] = ObjectMapper.Map<IUserData, EmailHistoryUserDto>(userInfo);
}

}

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

return dtoList;
}

/// <summary>
/// Send Email To Queue
/// </summary>
/// <param name="EmailLog">The email log to send to q</param>
public async Task SendEmailToQueue(EmailLog emailLog)
{
{
EmailNotificationEvent emailNotificationEvent = new EmailNotificationEvent();
emailNotificationEvent.Id = emailLog.Id;
emailNotificationEvent.TenantId = emailLog.TenantId;
Expand All @@ -159,10 +199,11 @@ protected virtual dynamic GetEmailObject(string emailTo, string body, string sub
List<string> toList = new();
string[] emails = emailTo.Split([',', ';'], StringSplitOptions.RemoveEmptyEntries);

foreach (string email in emails) {
foreach (string email in emails)
{
toList.Add(email.Trim());
}

var emailObject = new
{
body,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using RestSharp;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Notifications.Emails;
using Volo.Abp.Application.Services;

namespace Unity.Notifications.EmailNotifications
{
public interface IEmailNotificationService: IApplicationService
public interface IEmailNotificationService : IApplicationService
{
Task<EmailLog?> InitializeEmailLog(string emailTo, string body, string subject, Guid applicationId, string? emailFrom);
Task<EmailLog?> GetEmailLogById(Guid id);
Task<RestResponse> SendEmailNotification(string emailTo, string body, string subject, string? emailFrom);
Task SendEmailToQueue(EmailLog emailLog);
string GetApprovalBody();
string GetDeclineBody();
Task<List<EmailHistoryDto>> GetHistoryByApplicationId(Guid applicationId);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using AutoMapper;
using Unity.Notifications.Emails;
using Volo.Abp.Users;

namespace Unity.Notifications;

public class NotificationsApplicationAutoMapperProfile : Profile
{
public NotificationsApplicationAutoMapperProfile()
{
/* You can configure your AutoMapper mapping configuration here.
* Alternatively, you can split your mapping configurations
* into multiple profile classes for a better organization. */
CreateMap<EmailLog, EmailHistoryDto>()
.ForMember(x => x.SentBy, map => map.Ignore());
CreateMap<IUserData, EmailHistoryUserDto>();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AutoMapper;
using Volo.Abp.Modularity;
using Volo.Abp.Application;
Expand All @@ -12,6 +12,7 @@
using Unity.Shared.MessageBrokers.RabbitMQ;
using Unity.Notifications.Integrations.RabbitMQ;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Http.Client;

namespace Unity.Notifications;

Expand All @@ -21,16 +22,27 @@ namespace Unity.Notifications;
typeof(AbpDddApplicationModule),
typeof(AbpAutoMapperModule),
typeof(AbpBackgroundJobsModule),
typeof(AbpBackgroundWorkersQuartzModule)
typeof(AbpBackgroundWorkersQuartzModule),
typeof(AbpHttpClientModule)
)]
public class NotificationsApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();

context.Services.AddAutoMapperObjectMapper<NotificationsApplicationModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<NotificationsApplicationModule>(validate: true);
});

context.Services.AddScoped<IChesClientService, ChesClientService>();

context.Services.AddHttpClientProxies(
typeof(NotificationsApplicationContractsModule).Assembly
);

Configure<EmailBackgroundJobsOptions>(options =>
{
options.IsJobExecutionEnabled = configuration.GetValue<bool>("BackgroundJobs:IsJobExecutionEnabled");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Volo.Abp.BackgroundWorkers.Quartz" Version="8.3.0" />
<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" />
<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,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

Expand All @@ -7,5 +8,6 @@ namespace Unity.Notifications.Emails
public interface IEmailLogsRepository : IBasicRepository<EmailLog, Guid>
{
Task<EmailLog?> GetByIdAsync(Guid id, bool includeDetails = false);
Task<List<EmailLog>> GetByApplicationIdAsync(Guid applicationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Unity.Notifications.Emails;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using System.Collections.Generic;


namespace Unity.Notifications.Repositories
Expand All @@ -14,12 +15,18 @@ public class EmailLogsRepository : EfCoreRepository<NotificationsDbContext, Emai
{
public EmailLogsRepository(IDbContextProvider<NotificationsDbContext> dbContextProvider) : base(dbContextProvider)
{
}

}

public async Task<EmailLog?> GetByIdAsync(Guid id, bool includeDetails = false)
{
var dbSet = await GetDbSetAsync();
return await dbSet.FirstOrDefaultAsync(s => s.Id == id);
}

public async Task<List<EmailLog>> GetByApplicationIdAsync(Guid applicationId)
{
var dbSet = await GetDbSetAsync();
return await dbSet.Where(x => x.ApplicationId == applicationId).ToListAsync();
}

public override async Task<IQueryable<EmailLog>> WithDetailsAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
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)
Expand All @@ -28,6 +30,11 @@ public override void PreConfigureServices(ServiceConfigurationContext context)
options.AddAssemblyResource(typeof(NotificationsResource), typeof(NotificationsWebModule).Assembly);
});

Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(NotificationsApplicationModule).Assembly);
});

PreConfigure<IMvcBuilder>(mvcBuilder =>
{
mvcBuilder.AddApplicationPartIfNotExists(typeof(NotificationsWebModule).Assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Unity.Notifications.Application\Unity.Notifications.Application.csproj" />
<ProjectReference Include="..\Unity.Notifications.Application.Contracts\Unity.Notifications.Application.Contracts.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,22 @@ input.form-control.disabled:read-only, textarea.form-control.disabled:read-only,

.multi-line {
white-space: pre-wrap !important;
}

table.dataTable td.dt-control:before {
display: inline-block;
box-sizing: border-box;
content: "" !important;
border-top: 5px solid transparent;
border-left: 10px solid rgba(0, 0, 0, 0.5);
border-bottom: 5px solid transparent;
border-right: 0px solid transparent;
}

table.dataTable tr.dt-hasChild td.dt-control:before {
border-top: 10px solid rgba(0, 0, 0, 0.5);
border-left: 5px solid transparent;
content: "" !important;
border-bottom: 0px solid transparent;
border-right: 5px solid transparent;
}
Loading

0 comments on commit 2107343

Please sign in to comment.