This commit is contained in:
@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Biz;
|
using AyaNova.Biz;
|
||||||
//using AyaNova.PickList;
|
using AyaNova.PickList;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -77,10 +77,30 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
|
||||||
|
var PickList = PickListFactory.GetAyaPickList(ayaType);
|
||||||
|
|
||||||
var UserRoles = UserRolesFromContext.Roles(HttpContext.Items);
|
//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;
|
||||||
|
|
||||||
var o = await biz.GetPickListAsync(ayaType, query, inactive, UserRoles);
|
}
|
||||||
|
|
||||||
|
//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
|
/* 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
|
//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
|
||||||
|
|||||||
@@ -17,26 +17,16 @@ namespace AyaNova.PickList
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
internal static async Task<List<NameIdActiveItem>> GetResponseAsync(AyaType ayaType, string autoCompleteQuery, string tagSpecificQuery, bool includeInactive, AyContext ct, AuthorizationRoles userRoles)
|
internal static async Task<List<NameIdActiveItem>> 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
|
//Template
|
||||||
string Template = null;
|
string Template = null;
|
||||||
//Attempt to fetch custom template
|
//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)
|
if (t == null)
|
||||||
{
|
{
|
||||||
Template = PickList.DefaultTemplate;
|
Template = PickList.DefaultTemplate;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using AyaNova.Util;
|
|||||||
using AyaNova.Api.ControllerHelpers;
|
using AyaNova.Api.ControllerHelpers;
|
||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using AyaNova.PickList;
|
using AyaNova.PickList;
|
||||||
|
using EnumsNET;
|
||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
@@ -56,20 +56,9 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
//get picklist
|
//get picklist
|
||||||
internal async Task<List<NameIdActiveItem>> GetPickListAsync(AyaType ayaType, string query, bool inactive, AuthorizationRoles userRoles)
|
internal async Task<List<NameIdActiveItem>> 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
|
//Crack and validate the query part set a broken rule if not valid and return null
|
||||||
@@ -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
|
//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
|
//determine if this is a tag query and extract it
|
||||||
bool HasAutoCompleteQuery = !string.IsNullOrWhiteSpace(query);
|
bool HasQuery = !string.IsNullOrWhiteSpace(query);
|
||||||
if (HasAutoCompleteQuery)
|
if (HasQuery)
|
||||||
{
|
{
|
||||||
|
AutoCompleteQuery=query;
|
||||||
|
//is it a dual template and tag query?
|
||||||
if (AutoCompleteQuery.Contains(" "))
|
if (AutoCompleteQuery.Contains(" "))
|
||||||
{
|
{
|
||||||
// split the query on space
|
// split the query on space
|
||||||
@@ -114,13 +105,17 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
else
|
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<NameIdActiveItem> items = await PickListFetcher.GetResponseAsync(PickList, AutoCompleteQuery, TagSpecificQuery, inactive, ct);
|
||||||
|
|
||||||
List<NameIdActiveItem> items = await PickListFetcher.GetResponseAsync(ayaType, AutoCompleteQuery, TagSpecificQuery, inactive, ct, userRoles);
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user