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.