More subscription license work

This commit is contained in:
2022-08-23 03:00:17 +00:00
parent 129586a331
commit 028e7b8818
4 changed files with 70 additions and 15 deletions

View File

@@ -64,8 +64,11 @@ namespace AyaNova.Core
//Scheduleable users
private const string SERVICE_TECHS_FEATURE_NAME = "ServiceTechs";
//Accounting add-on
private const string ACCOUNTING_FEATURE_NAME = "Accounting";
//ActiveInternalUsers subscription license
private const string ACTIVE_INTERNAL_USERS_FEATURE_NAME = "ActiveInternalUsers";
//ActiveCustomerUsers subscription license
private const string ACTIVE_CUSTOMER_USERS_FEATURE_NAME = "ActiveCustomerUsers";
//This feature name means it's a trial key
private const string TRIAL_FEATURE_NAME = "TrialMode";
@@ -756,7 +759,7 @@ namespace AyaNova.Core
}
//Has someone been trying funny business with the active techs in the db?
if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > _ActiveLicense.ActiveNumber)
if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > _ActiveLicense.ActiveNumber)
{
var msg = $"E1020 - Active count exceeded capacity";
apiServerState.SetSystemLock(msg);
@@ -805,16 +808,46 @@ namespace AyaNova.Core
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
}
//TECHCOUNT - new license causes exceeding count?
#if (SUBSCRIPTION_BUILD)
//SUBSCRIPTION USER COUNTS - new license causes exceeding counts?
long NewInsideUserLicensedCount = ParsedNewKey.GetLicenseFeature(ACTIVE_INTERNAL_USERS_FEATURE_NAME).Count;
long ExistingActiveInsideUserCount = await AyaNova.Biz.UserBiz.ActiveInsideUserCountAsync();
long NewCustomerLicensedCount = ParsedNewKey.GetLicenseFeature(ACTIVE_CUSTOMER_USERS_FEATURE_NAME).Count;
long ExistingCustomerUserCount = await AyaNova.Biz.UserBiz.ActiveCustomerContactUserCountAsync();
string err = "E1020 - Can't install license: ";
bool throwit = false;
if (ExistingActiveInsideUserCount > NewInsideUserLicensedCount)
{
throwit = true;
err += $"{ExistingActiveInsideUserCount} active internal users of {NewInsideUserLicensedCount} permitted";
}
if (ExistingCustomerUserCount > NewCustomerLicensedCount)
{
throwit = true;
err += $"{ExistingCustomerUserCount} active Customer login users of {NewCustomerLicensedCount} permitted";
}
if (throwit)
throw new ApplicationException(err);
#else
//PERPETUAL, vet the TECHCOUNT - new license causes exceeding count?
long NewTechCount = ParsedNewKey.GetLicenseFeature(SERVICE_TECHS_FEATURE_NAME).Count;
if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > NewTechCount)
if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > NewTechCount)
{
//attempt to set enough of the eldest last login techs to inactive
await AyaNova.Biz.UserBiz.DeActivateExcessiveTechs(NewTechCount, log);
if (await AyaNova.Biz.UserBiz.ActiveCountAsync() > NewTechCount)
if (await AyaNova.Biz.UserBiz.ActiveTechUserCountAsync() > NewTechCount)
throw new ApplicationException("E1020 - Can't install key, too many active techs and / or subcontractors in database. Deactivate enough to install key.");
}
#endif
//Update current license
CurrentInDbKeyRecord.Key = RawTextNewKey;