From 8467470c1d0b19be5ba03626acb14a2c9e10798e Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 10 Jan 2023 00:44:33 +0000 Subject: [PATCH] --- server/biz/GlobalBizSettingsBiz.cs | 78 +++++++++++++++++++--------- server/biz/LicenseBiz.cs | 14 ++--- server/biz/TrialLicenseRequestBiz.cs | 1 - server/util/AySchema.cs | 8 +-- 4 files changed, 65 insertions(+), 36 deletions(-) diff --git a/server/biz/GlobalBizSettingsBiz.cs b/server/biz/GlobalBizSettingsBiz.cs index 208aab6..a409664 100644 --- a/server/biz/GlobalBizSettingsBiz.cs +++ b/server/biz/GlobalBizSettingsBiz.cs @@ -476,6 +476,7 @@ namespace Sockeye.Biz } */ var l = new License(); + l.Active = true; l.RegTo = jLicense["regTo"].Value(); //try to match customer; rockfish didn't track customer id in the license so this is a bit wishy washy @@ -489,6 +490,9 @@ namespace Sockeye.Biz var KeyText = jLicense["key"].Value(); + + l.Key = KeyText; + LicenseBiz.ParseKeySetDTOFields(l); if (KeyText.Contains("AyaNovaLicenseKey")) { //v7 key @@ -548,8 +552,8 @@ namespace Sockeye.Biz if (jKey["AyaNovaLicenseKey"]["LockDate"] != null) l.LicenseExpire = jKey["AyaNovaLicenseKey"]["LockDate"].Value().ToUniversalTime(); - l.MaintenanceExpire = jKey["AyaNovaLicenseKey"]["Expires"].Value().ToUniversalTime(); + //l.Users=jKey["AyaNovaLicenseKey"]["TotalScheduleableUsers"].Value(); l.PGroup = ProductGroup.AyaNova7; l.FetchCode = jLicense["code"].Value(); l.Tags.Add("v7"); @@ -572,6 +576,7 @@ namespace Sockeye.Biz l.LicenseExpire = jKey["AyaNovaLiteLicenseKey"]["LockDate"].Value().ToUniversalTime(); l.MaintenanceExpire = jKey["AyaNovaLiteLicenseKey"]["Expires"].Value().ToUniversalTime(); + l.PGroup = ProductGroup.AyaNova7; l.FetchCode = jLicense["code"].Value(); l.Tags.Add("v7"); @@ -615,7 +620,7 @@ namespace Sockeye.Biz l.Created = (DateTime)DateUtil.EpochToDateNullIsNull(jLicense["dtcreated"].Value()); l.FetchedOn = DateUtil.EpochToDateNullIsNull(jLicense["dtfetched"].Value()); l.FetchEmail = jLicense["email"].Value(); - l.Key = jLicense["key"].Value(); + // l.Key = jLicense["key"].Value(); l.Active = true;//active here means it's been fully prepared and is viable for use, all prior licenses fit this description so all are active l.NotificationSent = true; @@ -662,31 +667,54 @@ namespace Sockeye.Biz //Save Key first then can set keyid on tlr + long? TrialKeyId = null; { - License l = new License(); - l.TrialMode = true; - l.Key = jTrialRequestItem["key"].Value(); + string sKey = jTrialRequestItem["key"].Value(); + if (!string.IsNullOrWhiteSpace(sKey)) + { + License l = new License(); + l.TrialMode = true; - //Parse key as we need the expiry dates and they are only stored in the key not the trial request - string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(l.Key, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); - var jKey = JObject.Parse(keyNoWS); - l.DbId = jKey["Key"]["DBID"].Value(); - l.LicenseExpire = jKey["Key"]["LicenseExpiration"].Value().ToUniversalTime(); - if ((bool?)jKey["Key"]["Perpetual"] ?? true) - l.PGroup = ProductGroup.RavenPerpetual; - else - l.PGroup = ProductGroup.RavenSubscription; - l.MaintenanceExpire = jKey["Key"]["MaintenanceExpiration"].Value().ToUniversalTime(); - l.Tags.Add("raven"); - l.Tags.Add("trial"); - l.Created = DateUtil.EpochToDateNullIsMin(jTrialRequestItem["dtProcessed"].Value()); - l.FetchedOn = DateUtil.EpochToDateNullIsNull(jTrialRequestItem["dtFetched"].Value()); - l.FetchEmail = jTrialRequestItem["email"].Value(); + l.Key = sKey; + //Parse key as we need the expiry dates and they are only stored in the key not the trial request + string keyNoWS = System.Text.RegularExpressions.Regex.Replace(StringUtil.Extract(l.Key, "[KEY", "KEY]").Trim(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); + var jKey = JObject.Parse(keyNoWS); - l.Active = true;//active here means it's been fully prepared and is viable for use, all prior licenses fit this description so all are active - l.NotificationSent = true; - LicenseBiz lbiz = LicenseBiz.GetBiz(ct); - await lbiz.CreateAsync(l, true); + + l.RegTo = jKey["Key"]["RegisteredTo"].Value(); + + //try to match customer; rockfish didn't track customer id in the license so this is a bit wishy washy + Customer cust = null; + cust = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.Name == l.RegTo); + if (cust == null)//email? + cust = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.EmailAddress.Contains(jTrialRequestItem["email"].Value())); + if (cust != null) + l.CustomerId = cust.Id; + + + l.DbId = jKey["Key"]["DBID"].Value(); + l.LicenseExpire = jKey["Key"]["LicenseExpiration"].Value().ToUniversalTime(); + if ((bool?)jKey["Key"]["Perpetual"] ?? true) + l.PGroup = ProductGroup.RavenPerpetual; + else + l.PGroup = ProductGroup.RavenSubscription; + l.MaintenanceExpire = jKey["Key"]["MaintenanceExpiration"].Value().ToUniversalTime(); + l.Tags.Add("raven"); + l.Tags.Add("trial"); + l.Created = DateUtil.EpochToDateNullIsMin(jTrialRequestItem["dtProcessed"].Value()); + l.FetchedOn = DateUtil.EpochToDateNullIsNull(jTrialRequestItem["dtFetched"].Value()); + l.FetchEmail = jTrialRequestItem["email"].Value(); + + l.Active = true;//active here means it's been fully prepared and is viable for use, all prior licenses fit this description so all are active + l.NotificationSent = true; + LicenseBiz lbiz = LicenseBiz.GetBiz(ct); + var newLicenseObject = await lbiz.CreateAsync(l, true); + if (newLicenseObject == null) + ; + else + TrialKeyId = newLicenseObject.Id; + + } } { @@ -702,7 +730,7 @@ namespace Sockeye.Biz tlr.Processed = DateUtil.EpochToDateNullIsNull(jTrialRequestItem["dtProcessed"].Value()); tlr.Status = (TrialRequestStatus)jTrialRequestItem["status"].Value(); tlr.RejectReason = jTrialRequestItem["rejectReason"].Value(); - + tlr.KeyId = TrialKeyId; var biz = TrialLicenseRequestBiz.GetBiz(ct); await biz.CreateAsync(tlr); } diff --git a/server/biz/LicenseBiz.cs b/server/biz/LicenseBiz.cs index bb172c3..a57fd7d 100644 --- a/server/biz/LicenseBiz.cs +++ b/server/biz/LicenseBiz.cs @@ -78,7 +78,7 @@ namespace Sockeye.Biz #region PARSE KEY SET DTO FIELDS //Read the license key text, parse it and set the dto fields accordingly - internal License ParseKeySetDTOFields(License l) + public static License ParseKeySetDTOFields(License l) { if (l == null || string.IsNullOrWhiteSpace(l.Key)) @@ -411,11 +411,12 @@ namespace Sockeye.Biz var feature = jFeature["Name"].Value(); int count = 0; - if (feature != "TrialMode") - count = jFeature["Count"].Value(); - else + if (feature == "TrialMode") l.TrialMode = true; + if (jFeature["Count"] != null) + count = jFeature["Count"].Value(); + if (feature == "ActiveInternalUsers") l.Users = count; @@ -600,14 +601,15 @@ namespace Sockeye.Biz bool isNew = currentObj == null; //fetched keys are never editable, must be duped if re-issue - if (currentObj.FetchedOn != null) + //I'LL PROBABLY NEED TO CHANGE THIS LATER FOR SOME REASON BUT FOR NOW IT'S DEFENSIVE + if (!isNew && currentObj.FetchedOn != null) { AddError(ApiErrorCode.VALIDATION_NOT_CHANGEABLE, "generalerror", "Fetched, not changeable, duplicate instead"); return; } //MISC product group is not valid for keys - if (currentObj.PGroup == ProductGroup.Misc) + if (proposedObj.PGroup == ProductGroup.Misc) { AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "pGroup"); return; diff --git a/server/biz/TrialLicenseRequestBiz.cs b/server/biz/TrialLicenseRequestBiz.cs index d9a31dd..d510651 100644 --- a/server/biz/TrialLicenseRequestBiz.cs +++ b/server/biz/TrialLicenseRequestBiz.cs @@ -195,7 +195,6 @@ namespace Sockeye.Biz .AddText(obj.Email) .AddText(obj.EmailConfirmCode) .AddText(obj.RejectReason) - .AddText(obj.Key) .AddText(obj.Tags); } diff --git a/server/util/AySchema.cs b/server/util/AySchema.cs index ef7a650..919aeeb 100644 --- a/server/util/AySchema.cs +++ b/server/util/AySchema.cs @@ -22,16 +22,16 @@ namespace Sockeye.Util //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!! private const int DESIRED_SCHEMA_LEVEL = 17; - internal const long EXPECTED_COLUMN_COUNT = 504; + internal const long EXPECTED_COLUMN_COUNT = 505; internal const long EXPECTED_INDEX_COUNT = 74; - internal const long EXPECTED_CHECK_CONSTRAINTS = 240; - internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 32; + internal const long EXPECTED_CHECK_CONSTRAINTS = 242; + internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 33; internal const long EXPECTED_VIEWS = 0; internal const long EXPECTED_ROUTINES = 2; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!! - ///////////////////////////////////////// C504:I74:CC241:FC32:V0:R2) + ///////////////////////////////////////// (C505:I74:CC242:FC33:V0:R2) /* MAXIMUM POSTGRES OBJECT NAME LENGTH: 63 CHARACTERS