Skip to content

Commit

Permalink
Merge branch 'develop' into feature/eCommerce
Browse files Browse the repository at this point in the history
  • Loading branch information
scoxen1 authored May 23, 2024
2 parents 34e2864 + f48d184 commit 9851e92
Show file tree
Hide file tree
Showing 11 changed files with 28,693 additions and 9 deletions.
3 changes: 3 additions & 0 deletions api/CESMII.Marketplace.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<IMongoRepository<JobLog>, MongoRepository<JobLog>>();
services.AddScoped<IMongoRepository<JobDefinition>, MongoRepository<JobDefinition>>();

//one off tables
services.AddScoped<IMongoRepository<JobManager.Models.BlockedEmailDomain>, MongoRepository<JobManager.Models.BlockedEmailDomain>>();

//DAL objects
services.AddScoped<UserDAL>(); //this one has extra methods outside of the IDal interface
services.AddScoped<IUserSignUpData, UserSignUpData>();
Expand Down
5 changes: 4 additions & 1 deletion api/CESMII.Marketplace.Common/HttpApiFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public async Task<string> Run(HttpApiConfig config)
HttpClient client = _httpClientFactory.CreateClient();
try
{
client.BaseAddress = new Uri(config.BaseAddress);
if (!string.IsNullOrEmpty(config.BaseAddress))
{
client.BaseAddress = new Uri(config.BaseAddress);
}

// Add an bearer token if necessary
if (!string.IsNullOrEmpty(config.BearerToken))
Expand Down
4 changes: 4 additions & 0 deletions api/CESMII.Marketplace.Data/Entities/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace CESMII.Marketplace.Data.Entities
{
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

[BsonIgnoreExtraElements]
public class Organization : AbstractEntity
{
public string Name { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions api/CESMII.Marketplace.JobManager/JobFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task<string> ExecuteJob(JobPayloadModel model, UserModel user)
{
Messages = new List<JobLogMessage>() {
new JobLogMessage() {
Message = $"Starting job '{jobDef.Name}' for '{item.DisplayName}'...",
Message = $"Starting '{jobDef.DisplayName}' for '{item.DisplayName}'...",
Created = DateTime.UtcNow
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ private async Task ExecuteJobInternal(JobDefinitionModel jobDef, string payload,
try
{
//instantiate job class
var job = InstantiateJob(jobDef.TypeName, logger, httpFactory, dalJobLog, dalUser, configuration, mailRelay);
var job = InstantiateJob(jobDef.TypeName, _serviceScopeFactory, logger, httpFactory, dalJobLog, dalUser, configuration, mailRelay);

//initialize job
job.Initialize(jobDef, payload, logId, user);
Expand Down
4 changes: 4 additions & 0 deletions api/CESMII.Marketplace.JobManager/Jobs/JobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
using CESMII.Marketplace.Common;
using CESMII.Marketplace.Common.Enums;
using CESMII.Common.SelfServiceSignUp.Services;
using Microsoft.Extensions.DependencyInjection;

namespace CESMII.Marketplace.JobManager.Jobs
{
public abstract class JobBase : IJob, IDisposable
{
protected readonly IServiceScopeFactory _serviceScopeFactory;
protected readonly ILogger<IJob> _logger;
protected bool _disposed = false;
protected readonly IHttpApiFactory _httpFactory;
Expand All @@ -29,13 +31,15 @@ public abstract class JobBase : IJob, IDisposable
public event JobRunEventHandler JobRun; // event

public JobBase(
IServiceScopeFactory serviceScopeFactory,
ILogger<IJob> logger,
IHttpApiFactory httpFactory,
IDal<JobLog, JobLogModel> dalJobLog,
UserDAL dalUser,
IConfiguration configuration,
MailRelayService mailRelayService)
{
_serviceScopeFactory = serviceScopeFactory;
_logger = logger;
_httpFactory = httpFactory;
_dalJobLog = dalJobLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using System.Net.Http;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
Expand All @@ -25,13 +26,14 @@ namespace CESMII.Marketplace.JobManager.Jobs
public class JobBorgConnectActivate : JobBase
{
public JobBorgConnectActivate(
IServiceScopeFactory serviceScopeFactory,
ILogger<IJob> logger,
IHttpApiFactory httpFactory,
IDal<JobLog, JobLogModel> dalJobLog,
UserDAL dalUser,
IConfiguration configuration,
MailRelayService mailRelayService) :
base(logger, httpFactory, dalJobLog, dalUser, configuration, mailRelayService)
base(serviceScopeFactory, logger, httpFactory, dalJobLog, dalUser, configuration, mailRelayService)
{
//wire up run async event
base.JobRun += JobRunBorg;
Expand Down
49 changes: 47 additions & 2 deletions api/CESMII.Marketplace.JobManager/Jobs/JobOntimeEdgeTrial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
using System.Linq;
using System.Threading.Tasks;
using System.Net.Mail;
using System.Net.Http;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

using CESMII.Marketplace.Data.Repositories;
using CESMII.Marketplace.Data.Entities;
using CESMII.Marketplace.DAL;
using CESMII.Marketplace.DAL.Models;
Expand All @@ -17,7 +20,7 @@
using CESMII.Common.SelfServiceSignUp.Services;
using CESMII.Marketplace.SmipGraphQlClient;
using CESMII.Marketplace.SmipGraphQlClient.Models;
using System.Net.Http;
using CESMII.Marketplace.JobManager.Models;

namespace CESMII.Marketplace.JobManager.Jobs
{
Expand All @@ -28,13 +31,14 @@ namespace CESMII.Marketplace.JobManager.Jobs
public class JobOnTimeEdgeTrial : JobBase
{
public JobOnTimeEdgeTrial(
IServiceScopeFactory serviceScopeFactory,
ILogger<IJob> logger,
IHttpApiFactory httpFactory,
IDal<JobLog, JobLogModel> dalJobLog,
UserDAL dalUser,
IConfiguration configuration,
MailRelayService mailRelayService) :
base(logger, httpFactory, dalJobLog, dalUser, configuration, mailRelayService)
base(serviceScopeFactory, logger, httpFactory, dalJobLog, dalUser, configuration, mailRelayService)
{
//wire up run async event
base.JobRun += JobInitiateTrial;
Expand Down Expand Up @@ -90,6 +94,7 @@ private async Task<string> JobInitiateTrial(object sender, JobEventArgs e)
//call the Zapier catch hook API to intialize start trial flow
var config = new HttpApiConfig()
{
BaseAddress = "",
Url = jobConfig.ApogeanApi.Url,
Body = new StringContent(JsonConvert.SerializeObject(req)),
ContentType = "application/json",
Expand Down Expand Up @@ -234,6 +239,14 @@ private bool ValidatePayload(JobOnTimeEdgePayload payload, out string message)
sbResult.AppendLine("Email is required.");
_logger.LogInformation($"JobOnTimeEdgeTrial|ValidatePayload|Email is required.");
}
else
{
var msgEmailDomain = "";
if (!ValidateEmailDomain(payload.FormData?.Email, out msgEmailDomain))
{
sbResult.AppendLine(msgEmailDomain);
}
}
if (string.IsNullOrEmpty(payload.FormData?.Phone))
{
sbResult.AppendLine("Phone is required.");
Expand All @@ -244,6 +257,38 @@ private bool ValidatePayload(JobOnTimeEdgePayload payload, out string message)
return sbResult.Length == 0;
}

private bool ValidateEmailDomain(string email, out string message)
{
var sbResult = new System.Text.StringBuilder();
if (string.IsNullOrEmpty(email))
{
sbResult.AppendLine("Email is required.");
_logger.LogError($"JobOnTimeEdgeTrial|ValidateEmailDomain|Email is required.");
}
else
{
//wrap in scope so that we don't lose the scope of the dependency injected objects once the
//web api request completes and disposes of the import service object (and its module vars)
using (var scope = _serviceScopeFactory.CreateScope())
{
//initialize scoped services for DI, initialize job class
var repoBlockedDomains = scope.ServiceProvider.GetService<IMongoRepository<BlockedEmailDomain>>();
var numMatches = repoBlockedDomains.Count(x => email.Trim().ToLower().EndsWith(x.domain.ToLower()));

if (numMatches > 0)
{
//var matches = repoBlockedDomains.FindByCondition(x => email.Trim().ToLower().EndsWith(x.domain.ToLower())).Select(x => x.domain).ToList();
sbResult.AppendLine("Signing up for this trial prohibits use of free email domains. Please use a different email.");
_logger.LogWarning($"JobOnTimeEdgeTrial|ValidateEmailDomain|Blocked|Email '{email}' has a blocked email domain and is not permitted.");
}
}
}

message = sbResult.ToString();
return sbResult.Length == 0;
}


[System.Obsolete("ValidateSmipSettings de-scoped")]
private bool ValidateSmipSettings(SmipSettingsOnTimeEdge settings, out string message)
{
Expand Down
13 changes: 13 additions & 0 deletions api/CESMII.Marketplace.JobManager/Models/BlockedEmailDomain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CESMII.Marketplace.Data.Entities;

namespace CESMII.Marketplace.JobManager.Models
{
/// <summary>
/// This is a one off table used to check for blocked email domains on the Apogean blocked list.
/// </summary>
/// <seealso cref="CESMII.Marketplace.JobManager.Jobs.OnTimeEdgeApiConfig"/>
public class BlockedEmailDomain : AbstractEntity
{
public string domain { get; set; }
}
}
6 changes: 3 additions & 3 deletions frontend/src/views/custom/ApogeanStartTrial.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function ApogeanStartTrial(props) {
}

const renderForm = () => {
const disabled = !(_jobStatus === AppSettings.JobLogStatus.NotStarted);
const disabled = !(_jobStatus === AppSettings.JobLogStatus.NotStarted || _jobStatus === AppSettings.JobLogStatus.Failed);
return (
<Form noValidate className="mx-3" >
<div className="row mb-2">
Expand Down Expand Up @@ -338,14 +338,14 @@ function ApogeanStartTrial(props) {
}

const renderMainContent = () => {
if (_jobStatus === AppSettings.JobLogStatus.Failed) return;
//if (_jobStatus === AppSettings.JobLogStatus.Failed) return;

return (
<>
<div className="marketplace-list-item border" >
<div className="card mb-0 border-0">
<div className="card-body">
{(_jobStatus !== AppSettings.JobLogStatus.Completed && _jobStatus !== AppSettings.JobLogStatus.Failed) &&
{(_jobStatus !== AppSettings.JobLogStatus.Completed) &&
<>
{renderForm()}
</>
Expand Down
Loading

0 comments on commit 9851e92

Please sign in to comment.