case 4173

This commit is contained in:
2023-05-08 22:54:18 +00:00
parent 2116534503
commit ca82375bca
8 changed files with 354 additions and 218 deletions

View File

@@ -252,7 +252,66 @@ namespace AyaNova.Api.Controllers
return Accepted(new { JobId = j.GId });
}
/// <summary>
/// Batch Send direct SMTP message notification to selected objects
/// Server notification settings must be set and active
/// User must have MODIFY role for the object type in question to be allowed to bulk message
/// this typically means full manager type roles only
/// Currently supported types are Customer, HeadOffice, Vendor, User
/// WARNING: be careful using this method; high volume emailing or spam-like behavior
/// could result in a ban or block of your mail account or mail server or domain
/// Use of this method is logged to AyaNova event log on successful attempted delivery
/// </summary>
/// <param name="batchDirectSMTPParams"></param>
/// <returns>Job Id</returns>
[HttpPost("batch-direct-smtp")]
public async Task<IActionResult> BatchDirectSMTPObjects([FromBody] BatchDirectSMTPParams batchDirectSMTPParams)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
if (!Util.ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, null, "Email notifications are set to OFF at server, unable to send 'on request' type SMTP notification"));
if (batchDirectSMTPParams == null)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "batchDirectSMTPParams is required"));
if (batchDirectSMTPParams.SelectedRequest == null)
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_REQUIRED, null, "batchDirectSMTPParams.DataListSelectedRequest is required"));
if (!Authorized.HasModifyRole(HttpContext.Items, batchDirectSMTPParams.SelectedRequest.AType))
return StatusCode(403, new ApiNotAuthorizedResponse());
//Rehydrate id list if necessary
if (batchDirectSMTPParams.SelectedRequest.SelectedRowIds.Length == 0)
batchDirectSMTPParams.SelectedRequest.SelectedRowIds = await DataListSelectedProcessingOptions.RehydrateIdList(
batchDirectSMTPParams.SelectedRequest,
ct,
UserRolesFromContext.Roles(HttpContext.Items),
log,
UserIdFromContext.Id(HttpContext.Items),
UserTranslationIdFromContext.Id(HttpContext.Items));
var JobName = $"LT:BatchDirectSMTP - LT:{batchDirectSMTPParams.SelectedRequest.AType} ({batchDirectSMTPParams.SelectedRequest.SelectedRowIds.LongLength}) LT:User {UserNameFromContext.Name(HttpContext.Items)}";
JObject o = JObject.FromObject(new
{
idList = batchDirectSMTPParams.SelectedRequest.SelectedRowIds
});
OpsJob j = new OpsJob();
j.Name = JobName;
j.AType = batchDirectSMTPParams.SelectedRequest.AType;
j.JobType = JobType.BatchCoreObjectOperation;
j.SubType = JobSubType.DirectSMTP;
j.Exclusive = false;
j.JobInfo = o.ToString();
await JobsBiz.AddJobAsync(j);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerJob, AyaEvent.Created, JobName), ct);
return Accepted(new { JobId = j.GId });
}
/// <summary>
/// Request cancellation of Job. Not all jobs can be cancelled.

View File

@@ -31,7 +31,8 @@ namespace AyaNova.Biz
TagRemoveAny = 4,
TagReplace = 5,
TagReplaceAny = 6,
Delete = 7
Delete = 7,
DirectSMTP = 8
}
}//eons

View File

@@ -0,0 +1,17 @@
using AyaNova.Biz;
namespace AyaNova.Models
{
/// <summary>
/// Parameters for bulk operation batch-direct-smtp
/// </summary>
public class BatchDirectSMTPParams
{
public DataListSelectedRequest SelectedRequest { get; set; }
public string Subject { get; set; }
public string TextBody { get; set; }
public string HTMLBody { get; set; }
}
}

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 = 18;
private const int DESIRED_SCHEMA_LEVEL = 19;
internal const long EXPECTED_COLUMN_COUNT = 1389;
internal const long EXPECTED_INDEX_COUNT = 160;
@@ -1850,6 +1850,42 @@ CREATE OR REPLACE VIEW public.viewpartinventorylist
}
//////////////////////////////////////////////////
//
// case 4173
//
if (currentSchema < 19)
{
LogUpdateMessage(log);
//english translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'BatchDirectSMTP', 'Batch email job' FROM atranslation t where t.baselanguage = 'en'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SendEmail', 'Send email' FROM atranslation t where t.baselanguage = 'en'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'EmailMultipleObjectsWarning', 'Warning: you are about to send an email to multiple objects.\r\nAre you sure?' FROM atranslation t where t.baselanguage = 'en'");
//spanish translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'BatchDirectSMTP', 'Trabajo de correo electrónico por lotes' FROM atranslation t where t.baselanguage = 'es'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SendEmail', 'Enviar correo electrónico' FROM atranslation t where t.baselanguage = 'es'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'EmailMultipleObjectsWarning', 'Advertencia: está a punto de enviar un correo electrónico a varios objetos.\r\n¿Está seguro?' FROM atranslation t where t.baselanguage = 'es'");
//french translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'BatchDirectSMTP', 'Tâche d''e-mail par lots' FROM atranslation t where t.baselanguage = 'fr'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SendEmail', 'Envoyer un e-mail' FROM atranslation t where t.baselanguage = 'fr'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'EmailMultipleObjectsWarning', 'Avertissement : vous êtes sur le point d''envoyer un e-mail à plusieurs objets.\r\nÊtes-vous sûr?' FROM atranslation t where t.baselanguage = 'fr'");
//german translations
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'BatchDirectSMTP', 'Batch-E-Mail-Job' FROM atranslation t where t.baselanguage = 'de'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'SendEmail', 'E-Mail senden' FROM atranslation t where t.baselanguage = 'de'");
await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'EmailMultipleObjectsWarning', 'Warnung: Sie sind im Begriff, eine E-Mail an mehrere Objekte zu senden.\r\nSind Sie sicher?' FROM atranslation t where t.baselanguage = 'de'");
await SetSchemaLevelAsync(++currentSchema);
}
//#########################################