licensing system change, all internal active, no more scheduleable resources / tech licensing
This commit is contained in:
@@ -26,18 +26,18 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
//This is where active tech license consumers are accounted for
|
||||
internal static async Task<long> ActiveTechUserCountAsync()
|
||||
{
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
var ret = await ct.User.AsNoTracking().Where(z => z.Active == true && (
|
||||
z.UserType == UserType.Service ||
|
||||
z.UserType == UserType.ServiceContractor)).LongCountAsync();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
// internal static async Task<long> ActiveTechUserCountAsync()
|
||||
// {
|
||||
// using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
// {
|
||||
// var ret = await ct.User.AsNoTracking().Where(z => z.Active == true && (
|
||||
// z.UserType == UserType.Service ||
|
||||
// z.UserType == UserType.ServiceContractor)).LongCountAsync();
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
|
||||
//This is where SUBSCRIPTION active internal (non customer) license consumers are accounted for as they consume resources if they can login
|
||||
//This is where SUBSCRIPTION AND PERPETUAL active internal (non customer) license consumers are accounted for
|
||||
internal static async Task<long> ActiveInternalUserCountAsync()
|
||||
{
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
@@ -75,46 +75,46 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
//Called by license processor when use downgrades to lesser amount of techs
|
||||
internal static async Task DeActivateExcessiveTechs(long KeepThisManyActiveTechs, ILogger _log)
|
||||
{
|
||||
var TotalActiveTechs = await ActiveTechUserCountAsync();
|
||||
int CountOfTechsToSetInactive = (int)(TotalActiveTechs - KeepThisManyActiveTechs);
|
||||
if (CountOfTechsToSetInactive < 1) return;
|
||||
_log.LogInformation($"New license is a downgrade with fewer scheduleable resources, deactivating {CountOfTechsToSetInactive} scheduleable users automatically so the license can be installed");
|
||||
//bugbug: exactly wrong, deactivating the most recently logged in over some who never logged in, could be that null login is causing it?
|
||||
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
{
|
||||
// //Called by license processor when use downgrades to lesser amount of techs
|
||||
// internal static async Task DeActivateExcessiveTechs(long KeepThisManyActiveTechs, ILogger _log)
|
||||
// {
|
||||
// var TotalActiveTechs = await ActiveTechUserCountAsync();
|
||||
// int CountOfTechsToSetInactive = (int)(TotalActiveTechs - KeepThisManyActiveTechs);
|
||||
// if (CountOfTechsToSetInactive < 1) return;
|
||||
// _log.LogInformation($"New license is a downgrade with fewer scheduleable resources, deactivating {CountOfTechsToSetInactive} scheduleable users automatically so the license can be installed");
|
||||
// //bugbug: exactly wrong, deactivating the most recently logged in over some who never logged in, could be that null login is causing it?
|
||||
// using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||
// {
|
||||
|
||||
//Algorithm: For deactivation favor subcontractors first over servicetechs, favor ones that have no login records and finally favor by oldest last login
|
||||
//theory is to catch the least likely to be currently active techs
|
||||
// //Algorithm: For deactivation favor subcontractors first over servicetechs, favor ones that have no login records and finally favor by oldest last login
|
||||
// //theory is to catch the least likely to be currently active techs
|
||||
|
||||
var NoLoginTechList = await ct.User.Where(z => z.Active == true && z.LastLogin == null && (
|
||||
z.UserType == UserType.Service ||
|
||||
z.UserType == UserType.ServiceContractor)).OrderByDescending(z => z.UserType).Take(CountOfTechsToSetInactive).ToListAsync();
|
||||
// var NoLoginTechList = await ct.User.Where(z => z.Active == true && z.LastLogin == null && (
|
||||
// z.UserType == UserType.Service ||
|
||||
// z.UserType == UserType.ServiceContractor)).OrderByDescending(z => z.UserType).Take(CountOfTechsToSetInactive).ToListAsync();
|
||||
|
||||
CountOfTechsToSetInactive -= NoLoginTechList.Count();
|
||||
foreach (User u in NoLoginTechList)
|
||||
{
|
||||
u.Active = false;
|
||||
var msg = $"User {u.Name} with no prior login automatically set to inactive to free up downgraded license";
|
||||
await NotifyEventHelper.AddOpsProblemEvent(msg);
|
||||
_log.LogInformation(msg);
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
// CountOfTechsToSetInactive -= NoLoginTechList.Count();
|
||||
// foreach (User u in NoLoginTechList)
|
||||
// {
|
||||
// u.Active = false;
|
||||
// var msg = $"User {u.Name} with no prior login automatically set to inactive to free up downgraded license";
|
||||
// await NotifyEventHelper.AddOpsProblemEvent(msg);
|
||||
// _log.LogInformation(msg);
|
||||
// }
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
|
||||
var HasLoginTechList = await ct.User.Where(z => z.Active == true && z.LastLogin != null && (
|
||||
z.UserType == UserType.Service ||
|
||||
z.UserType == UserType.ServiceContractor)).OrderByDescending(z => z.UserType).ThenBy(z => z.LastLogin).Take(CountOfTechsToSetInactive).ToListAsync();
|
||||
foreach (User u in HasLoginTechList)
|
||||
{
|
||||
u.Active = false;
|
||||
_log.LogInformation($"User {u.Name} who last logged in {u.LastLogin} automatically set to inactive to free up license");
|
||||
}
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
// var HasLoginTechList = await ct.User.Where(z => z.Active == true && z.LastLogin != null && (
|
||||
// z.UserType == UserType.Service ||
|
||||
// z.UserType == UserType.ServiceContractor)).OrderByDescending(z => z.UserType).ThenBy(z => z.LastLogin).Take(CountOfTechsToSetInactive).ToListAsync();
|
||||
// foreach (User u in HasLoginTechList)
|
||||
// {
|
||||
// u.Active = false;
|
||||
// _log.LogInformation($"User {u.Name} who last logged in {u.LastLogin} automatically set to inactive to free up license");
|
||||
// }
|
||||
// await ct.SaveChangesAsync();
|
||||
// }
|
||||
// }
|
||||
|
||||
internal static void ResetSuperUserPassword()
|
||||
{
|
||||
@@ -810,26 +810,51 @@ namespace AyaNova.Biz
|
||||
}
|
||||
#else
|
||||
//Check the PERPETUAL license allows this
|
||||
//TECHS ONLY
|
||||
if (proposedObj.IsTech && proposedObj.Active)
|
||||
// //TECHS ONLY
|
||||
// if (proposedObj.IsTech && proposedObj.Active)
|
||||
// {
|
||||
// //Yes, it might be affected depending on things
|
||||
// long CurrentActiveTechCount = await UserBiz.ActiveTechUserCountAsync();
|
||||
// long LicensedTechCount = AyaNova.Core.License.ActiveKey.ActiveTechsCount;
|
||||
|
||||
// if (isNew)
|
||||
// {
|
||||
// //This operation is about to consume one more license, check that we are not at the limit already
|
||||
// await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //did anything that might affect licensing change?
|
||||
// if (!currentObj.IsTech || (!currentObj.Active))//currently not a tech or if it is it's not active
|
||||
// {
|
||||
// //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 AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//INTERNAL USERS
|
||||
//ACTIVE internal users consume a license
|
||||
if (!proposedObj.IsOutsideCustomerContactTypeUser && proposedObj.Active)
|
||||
{
|
||||
//Yes, it might be affected depending on things
|
||||
long CurrentActiveTechCount = await UserBiz.ActiveTechUserCountAsync();
|
||||
long LicensedTechCount = AyaNova.Core.License.ActiveKey.ActiveTechsCount;
|
||||
long CurrentActiveInternalUserCount = await UserBiz.ActiveInternalUserCountAsync();
|
||||
long LicensedInternalUserCount = AyaNova.Core.License.ActiveKey.ActiveInternalUsersCount;
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
//This operation is about to consume one more license, check that we are not at the limit already
|
||||
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
|
||||
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveInternalUserCount, LicensedInternalUserCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
//did anything that might affect licensing change?
|
||||
if (!currentObj.IsTech || (!currentObj.Active))//currently not a tech or if it is it's not active
|
||||
if (currentObj.IsOutsideCustomerContactTypeUser || (!currentObj.Active))//currently not a inside user or if it is it's not active
|
||||
{
|
||||
//going from non tech to tech and active
|
||||
//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 AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveTechCount, LicensedTechCount);
|
||||
await AddErrorIfAtLicenseLimitAnyBuildType(CurrentActiveInternalUserCount, LicensedInternalUserCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user