This commit is contained in:
@@ -57,12 +57,19 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
//check rights at some point here
|
|
||||||
|
|
||||||
long UserId = UserIdFromContext.Id(HttpContext.Items);
|
long UserId = UserIdFromContext.Id(HttpContext.Items);
|
||||||
ApiPagedResponse pr = await DataListFetcher.GetResponse(listOptions.DataListKey, ct, Url, nameof(List), listOptions, MOCK_WIDGET_DISPLAY_TEMPLATE_JSON, UserId);
|
var UserRoles = UserRolesFromContext.Roles(HttpContext.Items);
|
||||||
|
try
|
||||||
return Ok(new ApiOkWithPagingResponse(pr));
|
{
|
||||||
|
ApiPagedResponse pr = await DataListFetcher.GetResponse(listOptions.DataListKey, ct, Url, nameof(List), listOptions, UserId, UserRoles);
|
||||||
|
return Ok(new ApiOkWithPagingResponse(pr));
|
||||||
|
}
|
||||||
|
catch (System.NotSupportedException)
|
||||||
|
{
|
||||||
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,60 +7,16 @@ namespace AyaNova.DataList
|
|||||||
{
|
{
|
||||||
internal static class DataListFactory
|
internal static class DataListFactory
|
||||||
{
|
{
|
||||||
// internal static IAyaDataList GetAyaDataList(string ListKey)
|
|
||||||
// {
|
|
||||||
// switch (ListKey)
|
|
||||||
// {
|
|
||||||
// case nameof(TestWidgetUserEmailDataList):
|
|
||||||
// return new TestWidgetUserEmailDataList();
|
|
||||||
// case nameof(WidgetDataList):
|
|
||||||
// return new WidgetDataList();
|
|
||||||
// default:
|
|
||||||
// throw new System.ArgumentOutOfRangeException($"DataListFactory: Unknown list \"{ListKey}\"");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private static List<string> DataListList = null;
|
|
||||||
|
|
||||||
// //To be called at startup
|
|
||||||
// private static void PopulateDataListCache()
|
|
||||||
// {
|
|
||||||
// System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
|
||||||
// DataListList = new List<string>();
|
|
||||||
// foreach (System.Reflection.TypeInfo ti in ass.DefinedTypes)
|
|
||||||
// {
|
|
||||||
// if (!ti.IsAbstract && ti.ImplementedInterfaces.Contains(typeof(IAyaDataList)))
|
|
||||||
// {
|
|
||||||
// DataListList.Add(ti.Name);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//Instantiate list object specified
|
//Instantiate list object specified
|
||||||
//this is safe as it's only called from our own code internally
|
//this is safe as it's only attempting to load assemblies in the AyaNova.DataList namespace so can't attempt to instantiate some random object or nefarious object
|
||||||
internal static IAyaDataList GetAyaDataList(string ListKey)
|
internal static IAyaDataList GetAyaDataList(string ListKey)
|
||||||
{
|
{
|
||||||
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
||||||
return ass.CreateInstance($"AyaNova.DataList.{ListKey}") as IAyaDataList;
|
return ass.CreateInstance($"AyaNova.DataList.{ListKey}") as IAyaDataList;
|
||||||
|
|
||||||
// if (DataListList == null)
|
|
||||||
// {
|
|
||||||
// throw new System.NullReferenceException($"DataListFactory::GetAyaDataList({ListKey}) -> The data list cache is empty!");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly();
|
|
||||||
|
|
||||||
// foreach (System.Reflection.TypeInfo ti in ass.DefinedTypes)
|
|
||||||
// {
|
|
||||||
// // if (!ti.IsAbstract && ti.ImplementedInterfaces.Contains(typeof(IAyaDataList)))
|
|
||||||
// if (ti.Name == ListKey)
|
|
||||||
// {
|
|
||||||
// return ass.CreateInstance(ti.FullName) as IAyaDataList;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// throw new System.ArgumentOutOfRangeException($"DEV ERROR in DataListFactory.cs: ListKey {ListKey} specified doesn't exist");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//List all the datalist types available
|
||||||
internal static List<string> GetListOfAllDataListKeyNames()
|
internal static List<string> GetListOfAllDataListKeyNames()
|
||||||
{
|
{
|
||||||
//https://stackoverflow.com/a/42574373/8939
|
//https://stackoverflow.com/a/42574373/8939
|
||||||
|
|||||||
@@ -7,18 +7,29 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using EnumsNET;
|
||||||
|
|
||||||
namespace AyaNova.DataList
|
namespace AyaNova.DataList
|
||||||
{
|
{
|
||||||
internal static class DataListFetcher
|
internal static class DataListFetcher
|
||||||
{
|
{
|
||||||
internal static async Task<ApiPagedResponse> GetResponse(string DataListKey, AyContext ct, IUrlHelper Url,
|
internal static async Task<ApiPagedResponse> GetResponse(string DataListKey, AyContext ct, IUrlHelper Url,
|
||||||
string routeName, ListOptions listOptions, long UserId)
|
string routeName, ListOptions listOptions, long UserId, AuthorizationRoles UserRoles)
|
||||||
{
|
{
|
||||||
|
|
||||||
// var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY);
|
// var AyaObjectFields = AyaObjectFieldDefinitions.AyaObjectFields(AyaObjectFieldDefinitions.TEST_WIDGET_USER_EMAIL_ADDRESS_LIST_KEY);
|
||||||
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
var DataList = DataListFactory.GetAyaDataList(DataListKey);
|
||||||
|
//was the name not found as a list?
|
||||||
|
if (DataList == null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentOutOfRangeException($"DataList \"{DataListKey}\" specified does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
//check rights
|
||||||
|
if (!UserRoles.HasAnyFlags(DataList.AllowedRoles))
|
||||||
|
{
|
||||||
|
throw new System.NotSupportedException("User roles insufficient for this datalist");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: FETCH DATALISTTEMPLATE HERE OR USE DEFAULT IF FAULTY OR NOT FOUND
|
//TODO: FETCH DATALISTTEMPLATE HERE OR USE DEFAULT IF FAULTY OR NOT FOUND
|
||||||
var JSONDataListTemplate = DataList.DefaultDataListDisplayTemplate;
|
var JSONDataListTemplate = DataList.DefaultDataListDisplayTemplate;
|
||||||
|
|||||||
Reference in New Issue
Block a user