Allow login checked properly for license in subscription customer contact count check

This commit is contained in:
2022-08-29 14:55:24 +00:00
parent 808aa574d7
commit 9b7508afe3
3 changed files with 23 additions and 40 deletions

View File

@@ -37,7 +37,7 @@ namespace AyaNova.Biz
}
}
//This is where SUBSCRIPTION active internal (non customer) license consumers are accounted for
//This is where SUBSCRIPTION active internal (non customer) license consumers are accounted for as they consume resources if they can login
internal static async Task<long> ActiveInternalUserCountAsync()
{
using (AyContext ct = ServiceProviderProvider.DBContext)
@@ -51,6 +51,7 @@ namespace AyaNova.Biz
}
//This is where SUBSCRIPTION active CUSTOMER CONTACT license consumers are accounted for
//NOTE: AllowLogin is checked here in addition to Active because we only care about potential LOGIN users here as they consume rental / subscription server resources
internal static async Task<long> ActiveCustomerContactUserCountAsync()
{
using (AyContext ct = ServiceProviderProvider.DBContext)
@@ -759,6 +760,7 @@ namespace AyaNova.Biz
//Check the SUBSCRIPTION license allows this
//INTERNAL USERS
//ACTIVE internal users consume a license in subscription mode
if (!proposedObj.IsOutsideCustomerContactTypeUser && proposedObj.Active)
{
//Yes, it might be affected depending on things
@@ -768,7 +770,7 @@ namespace AyaNova.Biz
if (isNew)
{
//This operation is about to consume one more license, check that we are not at the limit already
await AddErrorIfExcessUsersAnyBuildType(CurrentActiveInternalUserCount, LicensedInternalUserCount);
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveInternalUserCount, LicensedInternalUserCount);
}
else
{
@@ -777,13 +779,14 @@ namespace AyaNova.Biz
{
//going from non inside to inside and/or to active
//Yes, this is about to consume one more license, check that we are not at the limit already
await AddErrorIfExcessUsersAnyBuildType(CurrentActiveInternalUserCount, LicensedInternalUserCount);
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveInternalUserCount, LicensedInternalUserCount);
}
}
}
//CUSTOMERS
if (proposedObj.IsOutsideCustomerContactTypeUser && proposedObj.Active)
//ACTIVE AND ALLOWLOGIN customer users consume a customer login license in subscription mode
if (proposedObj.IsOutsideCustomerContactTypeUser && proposedObj.Active && proposedObj.AllowLogin)
{
//Yes, it might be affected depending on things
long CurrentActiveCustomerContactUserCount = await UserBiz.ActiveCustomerContactUserCountAsync();
@@ -792,16 +795,16 @@ namespace AyaNova.Biz
if (isNew)
{
//This operation is about to consume one more license, check that we are not at the limit already
await AddErrorIfExcessUsersAnyBuildType(CurrentActiveCustomerContactUserCount, LicensedCustomerContactCount);
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveCustomerContactUserCount, LicensedCustomerContactCount);
}
else
{
//did anything that might affect licensing change?
if (!currentObj.IsOutsideCustomerContactTypeUser || (!currentObj.Active))//currently not a customer contact user or if it is it's not active
if (!currentObj.IsOutsideCustomerContactTypeUser || (!currentObj.Active)|| (!currentObj.AllowLogin))//currently not a customer contact user or if it is it's not active or wasn't set to allow login
{
//going from non customer contact to customer contact and or active (may not happen but better safe than sorry down the road some day)
//going from non customer contact to customer contact and or active and or login (may not happen but better safe than sorry down the road some day)
//Yes, this is about to consume one more license, check that we are not at the limit already
await AddErrorIfExcessUsersAnyBuildType(CurrentActiveCustomerContactUserCount, LicensedCustomerContactCount);
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveCustomerContactUserCount, LicensedCustomerContactCount);
}
}
}
@@ -817,7 +820,7 @@ namespace AyaNova.Biz
if (isNew)
{
//This operation is about to consume one more license, check that we are not at the limit already
await AddErrorIfExcessUsersAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
}
else
{
@@ -826,7 +829,7 @@ namespace AyaNova.Biz
{
//going from non tech to tech and active
//Yes, this is about to consume one more license, check that we are not at the limit already
await AddErrorIfExcessUsersAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
}
}
}
@@ -957,7 +960,7 @@ namespace AyaNova.Biz
return;
}
private async Task AddErrorIfExcessUsersAnyBuildType(long CurrentActiveCount, long LicensedUserCount)
private async Task AddErrorIfAtLicenseLimitAnyBuildType(long CurrentActiveCount, long LicensedUserCount)
{
if (CurrentActiveCount >= LicensedUserCount)
{