case 4310

This commit is contained in:
2022-11-20 23:58:03 +00:00
parent 7496c1b8e7
commit 334e00ba43
6 changed files with 118 additions and 34 deletions

View File

@@ -542,6 +542,7 @@ namespace AyaNova.Api.Controllers
// ReturnList.Add(new NameIdItem() { Name = LT["NotifyEventCopyOfCustomerNotification"], Id = (long)NotifyEventType.CopyOfCustomerNotification });
ReturnList.Add(new NameIdItem() { Name = LT["NotifyEventWorkorderCreatedForCustomer"], Id = (long)NotifyEventType.WorkorderCreatedForCustomer });
ReturnList.Add(new NameIdItem() { Name = LT["NotifyEventPMGenerationFailed"], Id = (long)NotifyEventType.PMGenerationFailed });
ReturnList.Add(new NameIdItem() { Name = LT["NotifyEventDirectSMTPMessage"], Id = (long)NotifyEventType.DirectSMTPMessage });
}
else if (keyNameInLowerCase == StringUtil.TrimTypeName(typeof(NotifyDeliveryMethod).ToString()).ToLowerInvariant())

View File

@@ -11,6 +11,7 @@ using System.Linq;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using AyaNova.Util;
namespace AyaNova.Api.Controllers
{
@@ -227,6 +228,93 @@ namespace AyaNova.Api.Controllers
[Required]
public List<long> Users { get; set; }
}
/// <summary>
/// Send direct SMTP message notification so single object / address
/// Note: adds to queue, not instantly sent
/// </summary>
/// <returns>NoContent on success or error</returns>
[HttpPost("direct-smtp")]
public async Task<IActionResult> SendNotifySmtpDirectMessage([FromBody] NotifyDirectSMTP notifyDirectSMTP)
{
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
//validate
if (string.IsNullOrWhiteSpace(notifyDirectSMTP.ToAddress))
{
//We need to fetch the address from the object type and id
//if no id then can skip the rest here
if (notifyDirectSMTP.ObjectId == 0)
{
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, "ObjectId", "No address or object id specified, no where to send this"));
}
//get the address
switch (notifyDirectSMTP.AType)
{
case AyaType.NoType:
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, "ToAddress", "No address or object type and id specified no where to send this"));
case AyaType.Customer:
var CustomerInfo = await ct.Customer.AsNoTracking().Where(x => x.Id == notifyDirectSMTP.ObjectId).Select(x => new { x.Name, x.EmailAddress, x.Active }).FirstAsync();
if (string.IsNullOrWhiteSpace(CustomerInfo.EmailAddress))
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, "EmailAddress", $"Customer {CustomerInfo.Name} doesn't have an email address no where to send this"));
if (CustomerInfo.Active == false)
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "Active", $"Customer {CustomerInfo.Name} is not active, only active customers can be emailed directly"));
notifyDirectSMTP.ToAddress = CustomerInfo.EmailAddress;
break;
default:
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, "AType", "Specified Type not supported for 'on request' smtp"));
}
}
var UserId = UserIdFromContext.Id(HttpContext.Items);
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
try
{
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
{
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification,
$"Email notifications are set to OFF at server, unable to send 'on request' type SMTP notification subject:{notifyDirectSMTP.Subject}",
"Error",
null,
UserId);
log.LogInformation($"** WARNING: SMTP notification is currently set to Active=False; unable to send 'on request' type SMTP notification subject:{notifyDirectSMTP.Subject} **");
}
else
await m.SendEmailAsync(notifyDirectSMTP.ToAddress, "Test from Notification system", "This is a test to confirm notification system is working", ServerGlobalOpsSettingsCache.Notify);
}
catch (Exception ex)
{
await NotifyEventHelper.AddOpsProblemEvent("SMTP direct message failed", ex);
return StatusCode(500, new ApiErrorResponse(ApiErrorCode.API_SERVER_ERROR, null, ExceptionUtil.ExtractAllExceptionMessages(ex)));
}
return NoContent();
}
public class NotifyDirectSMTP
{
public NotifyDirectSMTP()
{
}
public long ObjectId { get; set; } = 0;
public AyaType AType { get; set; } = AyaType.NoType;
public string ToAddress { get; set; }
public string Subject { get; set; }
public string TextBody { get; set; }
public string HTMLBody { get; set; }
}
//------------

View File

@@ -26,7 +26,8 @@ namespace AyaNova.Biz
AttachmentModified = 11,
EraseAllData = 12,
ResetSerial = 13,
UtilityFileDownload = 14
UtilityFileDownload = 14,
DirectSMTP = 15//NotifyEventDirectSMTPMessage key can work for this too
//NEW ITEMS REQUIRE translation KEYS and update CLIENT ay-history.vue code in eventypes list and translation fetcher

View File

@@ -60,7 +60,7 @@ Inspiring quotes used to help complete this huge project by myself
PMGenerationFailed = 32, //indicates there was a failure during PM generation with error
//SendUserCredentials = 33, //XXXXXXX Internal System use only: When user generates new credentials and sends them this is the notification type for that see UserBiz GenerateCredsAndEmailUser
ReviewImminent = 34,//*Review object, Advance notice setting tag conditional
DirectSMTPMessage= 35 //Used internally when sending a message via email directly to a Customer (initially) and possibly other objects in future. Shows in sent log but not user subscribable

View File

@@ -20,7 +20,7 @@ namespace AyaNova.Util
/////////// CHANGE THIS ON NEW SCHEMA UPDATE ////////////////////
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 11;
private const int DESIRED_SCHEMA_LEVEL = 12;
internal const long EXPECTED_COLUMN_COUNT = 1380;
internal const long EXPECTED_INDEX_COUNT = 161;
@@ -1685,6 +1685,31 @@ CREATE OR REPLACE VIEW public.viewpartinventorylist
await SetSchemaLevelAsync(++currentSchema);
}
//////////////////////////////////////////////////
//
// case 4173
//
if (currentSchema < 12)
{
LogUpdateMessage(log);
//english translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'NotifyEventDirectSMTPMessage', 'On request SMTP' FROM atranslation t where t.baselanguage = 'en'");
//spanish translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'NotifyEventDirectSMTPMessage', 'Bajo petición SMTP' FROM atranslation t where t.baselanguage = 'es'");
//french translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'NotifyEventDirectSMTPMessage', 'SMTP demandé' FROM atranslation t where t.baselanguage = 'fr'");
//german translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'NotifyEventDirectSMTPMessage', 'Auf Anfrage SMTP' FROM atranslation t where t.baselanguage = 'de'");
await SetSchemaLevelAsync(++currentSchema);
}
//#########################################