diff --git a/server/AyaNova/Controllers/PickListController.cs b/server/AyaNova/Controllers/PickListController.cs index 4a9ffa32..44481a34 100644 --- a/server/AyaNova/Controllers/PickListController.cs +++ b/server/AyaNova/Controllers/PickListController.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore; using AyaNova.Models; using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; -//using AyaNova.PickList; +using AyaNova.PickList; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -77,10 +77,30 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); - - var UserRoles = UserRolesFromContext.Roles(HttpContext.Items); + var PickList = PickListFactory.GetAyaPickList(ayaType); - var o = await biz.GetPickListAsync(ayaType, query, inactive, UserRoles); + //was the name not found as a pick list? + if (PickList == null) + { + //not a user error so no need to localize + AddError(ApiErrorCode.NOT_FOUND, "ayaType", $"PickList for type \"{ayaType}\" specified does not exist"); + return null; + + } + + //check rights + + if (!userRoles.HasAnyFlags(PickList.AllowedRoles)) + { + AddError(ApiErrorCode.NOT_AUTHORIZED, "ayaType"); + return null; + } + throw new System.UnauthorizedAccessException("User roles insufficient for this datalist"); + + + // var UserRoles = UserRolesFromContext.Roles(HttpContext.Items); + + var o = await biz.GetPickListAsync(PickList, query, inactive); /* this is how a bad validation is handled in a widget post //we need to validate the query and return an explanation if it's bad so user doesn't get confused and think theya re doing the right thing but not getting results anyway diff --git a/server/AyaNova/PickList/PickListFetcher.cs b/server/AyaNova/PickList/PickListFetcher.cs index 63aa4f28..b20a1e19 100644 --- a/server/AyaNova/PickList/PickListFetcher.cs +++ b/server/AyaNova/PickList/PickListFetcher.cs @@ -17,26 +17,16 @@ namespace AyaNova.PickList { - internal static async Task> GetResponseAsync(AyaType ayaType, string autoCompleteQuery, string tagSpecificQuery, bool includeInactive, AyContext ct, AuthorizationRoles userRoles) + internal static async Task> GetResponseAsync(IAyaPickList PickList, string autoCompleteQuery, string tagSpecificQuery, bool includeInactive, AyContext ct) { - var PickList = PickListFactory.GetAyaPickList(ayaType); - - //was the name not found as a list? - if (PickList == null) - { - throw new System.ArgumentOutOfRangeException($"PickList for type \"{ayaType}\" specified does not exist"); - } - - //check rights - - if (!userRoles.HasAnyFlags(PickList.AllowedRoles)) - throw new System.UnauthorizedAccessException("User roles insufficient for this datalist"); + + //Template string Template = null; //Attempt to fetch custom template - var t = await ct.PickListTemplate.FirstOrDefaultAsync(m => m.Id == ((long)ayaType)); + var t = await ct.PickListTemplate.FirstOrDefaultAsync(m => m.Id == ((long)PickList.DefaultListObjectType)); if (t == null) { Template = PickList.DefaultTemplate; diff --git a/server/AyaNova/biz/PickListBiz.cs b/server/AyaNova/biz/PickListBiz.cs index ad9b6263..c2b41c7b 100644 --- a/server/AyaNova/biz/PickListBiz.cs +++ b/server/AyaNova/biz/PickListBiz.cs @@ -7,7 +7,7 @@ using AyaNova.Util; using AyaNova.Api.ControllerHelpers; using AyaNova.Models; using AyaNova.PickList; - +using EnumsNET; namespace AyaNova.Biz { @@ -56,21 +56,10 @@ namespace AyaNova.Biz //get picklist - internal async Task> GetPickListAsync(AyaType ayaType, string query, bool inactive, AuthorizationRoles userRoles) + internal async Task> GetPickListAsync(IAyaPickList PickList, string query, bool inactive) { - var PickList = PickListFactory.GetAyaPickList(ayaType); - - //was the name not found as a pick list? - if (PickList == null) - { - //not a user error so no need to localize - AddError(ApiErrorCode.NOT_FOUND, "ayaType", $"PickList for type \"{ayaType}\" specified does not exist"); - return null; - - } - - + //Crack and validate the query part set a broken rule if not valid and return null //else do the query @@ -81,10 +70,12 @@ namespace AyaNova.Biz //Here need to handle scenario of badly formed query so user knows they did it wrong and doesn't just assume it's not there - //determine if this is a tag query - bool HasAutoCompleteQuery = !string.IsNullOrWhiteSpace(query); - if (HasAutoCompleteQuery) + //determine if this is a tag query and extract it + bool HasQuery = !string.IsNullOrWhiteSpace(query); + if (HasQuery) { + AutoCompleteQuery=query; + //is it a dual template and tag query? if (AutoCompleteQuery.Contains(" ")) { // split the query on space @@ -114,13 +105,17 @@ namespace AyaNova.Biz } else { - //just a regular query + //is it a tag only query? + if(AutoCompleteQuery.Contains("..")){ + TagSpecificQuery=AutoCompleteQuery.Replace("..",""); + AutoCompleteQuery=null; + } + } } +//Autocomplete and tagonly query terms now set for consumption by PickListFetcher, ready to fetch... - - - List items = await PickListFetcher.GetResponseAsync(ayaType, AutoCompleteQuery, TagSpecificQuery, inactive, ct, userRoles); + List items = await PickListFetcher.GetResponseAsync(PickList, AutoCompleteQuery, TagSpecificQuery, inactive, ct); return items; }