From 7f6e7dbee53dade350479a3bfb0d57508f0f1629 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 13 Jan 2023 23:02:54 +0000 Subject: [PATCH] --- server/biz/TrialLicenseRequestBiz.cs | 73 ++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/server/biz/TrialLicenseRequestBiz.cs b/server/biz/TrialLicenseRequestBiz.cs index d6a4dbd..19558a3 100644 --- a/server/biz/TrialLicenseRequestBiz.cs +++ b/server/biz/TrialLicenseRequestBiz.cs @@ -87,7 +87,7 @@ namespace Sockeye.Biz { var err = "TrialLicenseRequest sending email confirmation request: SMTP direct message failed"; await NotifyEventHelper.AddOpsProblemEvent(err, ex); - AddError(ApiErrorCode.API_SERVER_ERROR, null, ExceptionUtil.ExtractAllExceptionMessages(ex)); + AddError(ApiErrorCode.API_SERVER_ERROR, null, err + ExceptionUtil.ExtractAllExceptionMessages(ex)); return null; } @@ -133,7 +133,12 @@ namespace Sockeye.Biz if (HasErrors) return null; - //IF WE HAVE APPROVED A REQUEST THEN GENERATE TRIAL LICENSE, NOTIFY USER + //IF WE HAVE APPROVED A REQUEST THEN GENERATE TRIAL LICENSE, NOTIFY USER + //Notice to future coders who might see this or anything else in Sockeye that seems a bit ugly and spaghetti coded: + //I'm writing this in early January of 2023 in the time I get to work on it while my wife of 25 years sleeps off her palliative chemotherapy for terminal pancreatic cancer + //I'm fully aware this code is bodged together and just don't care right now, if it works it works. + //I need this up and running so I can spend more time with my wife and less time managing the detailed fuckery of the business + //that can be automated away while still keeping things going for now if (dbObject.Status == TrialRequestStatus.AwaitingApproval && putObject.Status == TrialRequestStatus.Approved) { //APPROVED, generate and save key to be approved for release by us @@ -171,13 +176,13 @@ namespace Sockeye.Biz putObject.LicenseId = newLicense.Id; //Notify User - /* - var body = $"Your trial license request has been approved.\r\nThe license will fetch and install automatically shortly or you can fetch it now in the License form menu."; - //send confirmation email - RfMail.SendMessage("support@ayanova.com", trial.Email, "AyaNova trial request approved", body, false); + /* + var body = $"Your trial license request has been approved.\r\nThe license will fetch and install automatically shortly or you can fetch it now in the License form menu."; + //send confirmation email + RfMail.SendMessage("support@ayanova.com", trial.Email, "AyaNova trial request approved", body, false); - */ - var notifyDirectSMTP = new Sockeye.Api.Controllers.NotifyController.NotifyDirectSMTP() + */ + var notifyDirectSMTP = new Sockeye.Api.Controllers.NotifyController.NotifyDirectSMTP() { ToAddress = putObject.Email, Subject = "AyaNova trial request approved",//todo move to global settings @@ -194,33 +199,59 @@ namespace Sockeye.Biz { var err = "TrialLicenseRequest sending approved email: SMTP direct message failed"; await NotifyEventHelper.AddOpsProblemEvent(err, ex); - AddError(ApiErrorCode.API_SERVER_ERROR, null, ExceptionUtil.ExtractAllExceptionMessages(ex)); + AddError(ApiErrorCode.API_SERVER_ERROR, null, err + ExceptionUtil.ExtractAllExceptionMessages(ex)); return null; - } - } - - if (dbObject.Status == TrialRequestStatus.AwaitingApproval && putObject.Status == TrialRequestStatus.Rejected) { //REJECTED, send email putObject.Processed = DateTime.UtcNow; + + /* + string reason = string.Empty; + if (!string.IsNullOrWhiteSpace(rejectReason)) + { + reason = $"The request was rejected due to:\r\n{rejectReason}"; + } + var body = $"Your trial license request was not approved.\r\n{reason}"; + //send confirmation email + RfMail.SendMessage("support@ayanova.com", trial.Email, "AyaNova trial request not approved", body, false); + */ + + string reason = string.Empty; + if (!string.IsNullOrWhiteSpace(putObject.RejectReason)) + { + reason = $"The request was rejected due to:\r\n{putObject.RejectReason}"; + } + var notifyDirectSMTP = new Sockeye.Api.Controllers.NotifyController.NotifyDirectSMTP() + { + ToAddress = putObject.Email, + Subject = "AyaNova trial request not approved",//todo move to global settings + TextBody = ServerGlobalBizSettings.Cache.RavenTrialRejected.Replace("{reason}", reason) + }; + + IMailer m = Sockeye.Util.ServiceProviderProvider.Mailer; + try + { + await m.SendEmailAsync(notifyDirectSMTP.ToAddress, notifyDirectSMTP.Subject, notifyDirectSMTP.TextBody, ServerGlobalOpsSettingsCache.Notify, null, null, null); + await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, notifyDirectSMTP.ObjectId, notifyDirectSMTP.SockType, SockEvent.DirectSMTP, $"\"{notifyDirectSMTP.Subject}\"->{notifyDirectSMTP.ToAddress}"), ct); + } + catch (Exception ex) + { + var err = "TrialLicenseRequest sending rejected email: SMTP direct message failed"; + await NotifyEventHelper.AddOpsProblemEvent(err, ex); + AddError(ApiErrorCode.API_SERVER_ERROR, null, err + ExceptionUtil.ExtractAllExceptionMessages(ex)); + return null; + } } ct.Replace(dbObject, putObject); try - { - - //first save request *then* license if all is well - + { await ct.SaveChangesAsync(); - - - - } catch (DbUpdateConcurrencyException) {