From 50b9f873d92041609c415e109f4503a94e2dd671 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 16 Jun 2020 22:17:25 +0000 Subject: [PATCH] --- .../AyaNova/Controllers/NotifyController.cs | 12 ++++----- server/AyaNova/util/DbUtil.cs | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/server/AyaNova/Controllers/NotifyController.cs b/server/AyaNova/Controllers/NotifyController.cs index f0fe394c..d9f7e29e 100644 --- a/server/AyaNova/Controllers/NotifyController.cs +++ b/server/AyaNova/Controllers/NotifyController.cs @@ -41,13 +41,13 @@ namespace AyaNova.Api.Controllers /// [AllowAnonymous] [HttpGet("hello")] - public ActionResult GetPreLoginPing() + public async Task GetPreLoginPing() { - //note: this route is called by the client to determine if it should display trial login ui - //offer a language selection up front and or see if the server is contactable - // if (serverState.IsClosed) - // return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); - return Ok(ApiOkResponse.Response(AyaNova.Core.License.ActiveKey.Status)); + bool showSampleLogins = false; + if (AyaNova.Core.License.ActiveKey.Status == AyaNova.Core.License.AyaNovaLicenseKey.LicenseStatus.ActiveTrial) + showSampleLogins = await AyaNova.Util.DbUtil.DBHasTrialUsersAsync(ct, log); + + return Ok(ApiOkResponse.Response(showSampleLogins)); } diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs index 9516ed1b..e9d97799 100644 --- a/server/AyaNova/util/DbUtil.cs +++ b/server/AyaNova/util/DbUtil.cs @@ -4,6 +4,7 @@ using AyaNova.Models; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; +using System.Linq; namespace AyaNova.Util { @@ -407,11 +408,34 @@ namespace AyaNova.Util if (await ct.Part.AnyAsync()) return false; if (await ct.Project.AnyAsync()) return false; if (await ct.PurchaseOrder.AnyAsync()) return false; - + return true; } + + /////////////////////////////////////////// + // Check if DB has evaluation user accounts + // CALLED BY by login ping from licent via notify controller + internal static async Task DBHasTrialUsersAsync(AyContext ct, ILogger _log) + { + _log.LogDebug("DB trial users presence check"); + //There are 22 trial users (more but for internal use) in a trial database + if (await ct.User.LongCountAsync() < 22) return false; + + //just check for a few for testing + if(await ct.User.AsNoTracking() + .Where(z => + z.Login == "BizAdminFull" || + z.Login == "DispatchFull" || + z.Login == "InventoryFull" || + z.Login == "Accounting" || + z.Login == "TechFull" + ).LongCountAsync() < 5) return false; + + return true; + } + /////////////////////////////////////////// // Ensure the db is not modified //