diff --git a/server/AyaNova/Controllers/LocaleController.cs b/server/AyaNova/Controllers/LocaleController.cs index 34f0f1da..f4f7720f 100644 --- a/server/AyaNova/Controllers/LocaleController.cs +++ b/server/AyaNova/Controllers/LocaleController.cs @@ -72,7 +72,8 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + // LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); var o = await biz.GetAsync(id); @@ -101,7 +102,8 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); var l = await biz.GetPickListAsync(); return Ok(new ApiOkResponse(l)); @@ -124,7 +126,8 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); + //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); var l = biz.LocaleKeyCoverage(); return Ok(new ApiOkResponse(l)); @@ -137,10 +140,10 @@ namespace AyaNova.Api.Controllers /// Required roles: Any /// /// - /// LocaleSubsetParam object defining the locale Id and a list of keys required + /// List of locale key strings /// A key value array of localized text values [HttpPost("SubSet")] - public async Task SubSet([FromBody] LocaleSubsetParam inObj) + public async Task SubSet([FromBody] List inObj) { if (serverState.IsClosed) { @@ -148,7 +151,10 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + + //Instantiate the business object handler + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); var l = await biz.GetSubset(inObj); return Ok(new ApiOkResponse(l)); @@ -172,7 +178,8 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + // LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); var o = await biz.DuplicateAsync(inObj); @@ -232,7 +239,8 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + // LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); try { @@ -297,7 +305,8 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); try { @@ -365,7 +374,8 @@ namespace AyaNova.Api.Controllers //Instantiate the business object handler - LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //LocaleBiz biz = new LocaleBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + LocaleBiz biz = LocaleBiz.GetBiz(ct, HttpContext); if (!biz.Delete(dbObj)) { return BadRequest(new ApiErrorResponse(biz.Errors)); @@ -395,19 +405,19 @@ namespace AyaNova.Api.Controllers //------------ - public class LocaleSubsetParam - { - [System.ComponentModel.DataAnnotations.Required] - public long LocaleId { get; set; } - [System.ComponentModel.DataAnnotations.Required] - public List Keys { get; set; } + // public class LocaleSubsetParam + // { + // [System.ComponentModel.DataAnnotations.Required] + // public long LocaleId { get; set; } + // [System.ComponentModel.DataAnnotations.Required] + // public List Keys { get; set; } - public LocaleSubsetParam() - { - Keys = new List(); - } + // public LocaleSubsetParam() + // { + // Keys = new List(); + // } - } + // } #if (DEBUG) public class LocaleCoverageInfo diff --git a/server/AyaNova/biz/BizObjectFactory.cs b/server/AyaNova/biz/BizObjectFactory.cs index 68647ffc..3c19ec23 100644 --- a/server/AyaNova/biz/BizObjectFactory.cs +++ b/server/AyaNova/biz/BizObjectFactory.cs @@ -38,7 +38,7 @@ namespace AyaNova.Biz case AyaType.TrialSeeder: return new TrialBiz(dbcontext, userId, roles); case AyaType.Locale: - return new LocaleBiz(dbcontext, userId, roles); + return new LocaleBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles); default: diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs index ddd19996..790e4207 100644 --- a/server/AyaNova/biz/LocaleBiz.cs +++ b/server/AyaNova/biz/LocaleBiz.cs @@ -20,15 +20,27 @@ namespace AyaNova.Biz { public bool SeedOrImportRelaxedRulesMode { get; set; } - internal LocaleBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) + internal LocaleBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles userRoles) { ct = dbcontext; UserId = currentUserId; + UserLocaleId = userLocaleId; CurrentUserRoles = userRoles; BizType = AyaType.Locale; SeedOrImportRelaxedRulesMode = false;//default } + internal static LocaleBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext) + { + return new LocaleBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items)); + } + + //Version for internal use + internal static LocaleBiz GetBizInternal(AyContext ct, long currentUserId, AuthorizationRoles roles) + { + return new LocaleBiz(ct, currentUserId, ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID, roles); + } + //////////////////////////////////////////////////////////////////////////////////////////////// @@ -141,26 +153,26 @@ namespace AyaNova.Biz #endif //Get the keys for a list of keys provided - internal async Task>> GetSubset(AyaNova.Api.Controllers.LocaleController.LocaleSubsetParam param) + internal async Task>> GetSubset(List param) { #if (DEBUG) - TrackRequestedKey(param.Keys); + TrackRequestedKey(param); #endif - var ret = await ct.LocaleItem.Where(x => x.LocaleId == param.LocaleId && param.Keys.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display); + var ret = await ct.LocaleItem.Where(x => x.LocaleId == UserLocaleId && param.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display); return ret.ToList(); } //Get the keys for a list of keys provided, static format for calling from other internal classes - internal static async Task>> GetSubsetStatic(AyaNova.Api.Controllers.LocaleController.LocaleSubsetParam param) + internal static async Task>> GetSubsetStatic(List param, long localeId) { #if (DEBUG) - TrackRequestedKey(param.Keys); + TrackRequestedKey(param); #endif AyContext ct = ServiceProviderProvider.DBContext; - if (!LocaleExistsStatic(param.LocaleId, ct)) - param.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID; - var ret = await ct.LocaleItem.Where(x => x.LocaleId == param.LocaleId && param.Keys.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display); + if (!LocaleExistsStatic(localeId, ct)) + localeId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID; + var ret = await ct.LocaleItem.Where(x => x.LocaleId == localeId && param.Contains(x.Key)).ToDictionaryAsync(x => x.Key, x => x.Display); return ret.ToList(); } diff --git a/server/AyaNova/biz/PrimeData.cs b/server/AyaNova/biz/PrimeData.cs index e0e5c8e9..1416cf95 100644 --- a/server/AyaNova/biz/PrimeData.cs +++ b/server/AyaNova/biz/PrimeData.cs @@ -9,7 +9,7 @@ using AyaNova.Models; namespace AyaNova.Biz { -//Prime the database with initial, minimum required data to boot and do things (manager account, locales) + //Prime the database with initial, minimum required data to boot and do things (manager account, locales) public static class PrimeData { // private readonly AyContext ct; @@ -29,19 +29,19 @@ namespace AyaNova.Biz //get a db and logger ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData"); User u = new User(); - u.Active=true; + u.Active = true; u.Name = "AyaNova Administrator"; u.Salt = Hasher.GenerateSalt(); u.Login = "manager"; u.Password = Hasher.hash(u.Salt, "l3tm3in"); u.Roles = AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull; u.OwnerId = 1; - u.LocaleId=ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first - u.UserType=UserType.Administrator; - u.UserOptions=new UserOptions(1); + u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first + u.UserType = UserType.Administrator; + u.UserOptions = new UserOptions(1); ct.User.Add(u); ct.SaveChanges(); - + } @@ -59,14 +59,15 @@ namespace AyaNova.Biz throw new System.Exception($"E1012: \"resource\" folder not found where expected: \"{ResourceFolderPath}\", installation damaged?"); } - + ImportLocale(ct, ResourceFolderPath, "en"); ImportLocale(ct, ResourceFolderPath, "es"); ImportLocale(ct, ResourceFolderPath, "fr"); ImportLocale(ct, ResourceFolderPath, "de"); //Ensure locales are present, not missing any keys and that there is a server default locale that exists - LocaleBiz lb = new LocaleBiz(ct, 1, AuthorizationRoles.OpsAdminFull); + //LocaleBiz lb = new LocaleBiz(ct, AuthorizationRoles.OpsAdminFull); + LocaleBiz lb = LocaleBiz.GetBizInternal(ct, 1, AuthorizationRoles.OpsAdminFull); lb.ValidateLocales(); } @@ -85,7 +86,7 @@ namespace AyaNova.Biz l.Name = localeCode; l.OwnerId = 1; l.Stock = true; - l.CjkIndex=false; + l.CjkIndex = false; foreach (JToken t in o.Children()) { diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index 17c5243f..b26b05ca 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -570,16 +570,16 @@ namespace AyaNova.Biz ct = ServiceProviderProvider.DBContext; //Get stopwords //Validate locale id, if not right then use default instead - var Param = new Api.Controllers.LocaleController.LocaleSubsetParam(); - Param.LocaleId = LocaleBiz.EnsuredLocaleIdStatic(localeId, ct); - Param.Keys.Add("StopWords1"); - Param.Keys.Add("StopWords2"); - Param.Keys.Add("StopWords3"); - Param.Keys.Add("StopWords4"); - Param.Keys.Add("StopWords5"); - Param.Keys.Add("StopWords6"); - Param.Keys.Add("StopWords7"); - var Stops = LocaleBiz.GetSubsetStatic(Param).Result; + var Param = new List(); + localeId = LocaleBiz.EnsuredLocaleIdStatic(localeId, ct); + Param.Add("StopWords1"); + Param.Add("StopWords2"); + Param.Add("StopWords3"); + Param.Add("StopWords4"); + Param.Add("StopWords5"); + Param.Add("StopWords6"); + Param.Add("StopWords7"); + var Stops = LocaleBiz.GetSubsetStatic(Param, localeId).Result; foreach (KeyValuePair kvp in Stops) {