More subscription license work allow logins addition

This commit is contained in:
2022-08-23 22:42:05 +00:00
parent 01e821c8c5
commit 3d6758c1d0
6 changed files with 74 additions and 31 deletions

View File

@@ -22,7 +22,7 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 6;
internal const long EXPECTED_COLUMN_COUNT = 1376;
internal const long EXPECTED_COLUMN_COUNT = 1377;
internal const long EXPECTED_INDEX_COUNT = 161;
internal const long EXPECTED_CHECK_CONSTRAINTS = 561;
internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 204;
@@ -31,7 +31,7 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!!
///////////////////////////////////////// (C1376:I161:CC561:FC204:V11:R2)
///////////////////////////////////////// C1377:I161:CC561:FC204:V11:R2
/*
@@ -1521,7 +1521,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
LogUpdateMessage(log);
await ExecQueryAsync("ALTER TABLE auser ADD column allowlogin BOOL");
await ExecQueryAsync("UPDTE TABLE auser SET allowlogin=true WHERE active=true");
await ExecQueryAsync("UPDATE auser SET allowlogin=true WHERE active=true");
//english translations

View File

@@ -686,6 +686,48 @@ namespace AyaNova.Core
}
/// <summary>
/// Minimal no side effects check if ok to proceed with boot
/// and do schema updates etc, this is like a pre license initialize
/// called from startup.cs to ensure the safety of the db in case
/// the user has installed a version they are not entitled to
/// which would permanently change their db
/// </summary>
internal static void BootSafetyCheck(AyContext ct, ILogger log)
{
//this is necessary to accomodate checking build date against subscription or perpetual / subscription vs build type and preventing schema update if they upgrade but are not entitled to
//so they don't damage their database saving us having to walk them through a potentially flawed restore
//if there is a build date issue or a license type mismatch issue it will fail with an exception, log to log file, log to console and not go beyond the license check preserving the db
//Note: case 4160 is to build an external license fetcher utility to allow a user to upgrade without uninstalling the newer version by purchasing a new sub and installing the key out of AyaNova
//If they don't want to purchase then they must downgrade HOWEVER they can do the case 4170 thing with the flag AYANOVA_REMOVE_LICENSE_FROM_DB
//verify the build date and version match this build
log.LogDebug("Boot database safety check");
//NOTE: a completely missing db will trigger an exception on this line, we expect that and will be fine as the caller in startup will understand this scenario
//and proceed with the first boot schema update
var schema = ct.SchemaVersion.AsNoTracking().SingleOrDefault();
var ldb = ct.License.AsNoTracking().SingleOrDefault();
if (schema == null || ldb == null || string.IsNullOrWhiteSpace(schema.Id))
return;//no key record at all or no schema, no need to prevent the normal boot up
//is there an actual license in the key?
if (ldb.Key == "none")
return;//nope, let it do it's thing and schema update if necessary
//we have a schema and a license, check it now for build date vs maintenance expiry check
//parse will try to parse the key and will check the build type and maint date so if it bombs here it will throw and startup.cs will properly understand that
ServerDbId = schema.Id;
Parse(ldb.Key, log);
// AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog).Wait();
}
/// <summary>
/// Initialize the license
///
@@ -698,7 +740,6 @@ namespace AyaNova.Core
{
//First fetch the schema db id for the servers database, the license must match
var schema = await ct.SchemaVersion.AsNoTracking().SingleOrDefaultAsync();
//if (schema == null || schema.Id == Guid.Empty)
if (schema == null || string.IsNullOrWhiteSpace(schema.Id))
{
//cryptic message deliberately, this is probably caused by someone trying to circumvent licensing
@@ -923,7 +964,7 @@ namespace AyaNova.Core
{
AyaNovaLicenseKey key = new AyaNovaLicenseKey();
log.LogDebug("Validating license");
log.LogDebug("Parsing and validating license");
if (string.IsNullOrWhiteSpace(k))
{