From 7d3d9cfeee00c1c31b9be1ff3d716f8075de1c7f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 22 Jan 2020 15:49:04 +0000 Subject: [PATCH] --- .../Controllers/DataListTemplateController.cs | 25 +++++++++++++++---- server/AyaNova/DataList/DataListFactory.cs | 1 + server/AyaNova/biz/DataListTemplateBiz.cs | 25 ++++++++++--------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/server/AyaNova/Controllers/DataListTemplateController.cs b/server/AyaNova/Controllers/DataListTemplateController.cs index 6e988ce7..3b0a16c6 100644 --- a/server/AyaNova/Controllers/DataListTemplateController.cs +++ b/server/AyaNova/Controllers/DataListTemplateController.cs @@ -57,6 +57,11 @@ namespace AyaNova.Api.Controllers if (serverState.IsClosed) return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); + //Attempt to get the data list by key to see if key is valid and for the default template and valid field names + var DataList = DataListFactory.GetAyaDataList(DataListKey); + if (DataList == null) + return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); + //Instantiate the business object handler DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext); @@ -66,7 +71,7 @@ namespace AyaNova.Api.Controllers if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); - var o = await biz.GetAsync(DataListKey); + var o = await biz.GetAsync(DataListKey, true, DataList); if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); @@ -111,10 +116,15 @@ namespace AyaNova.Api.Controllers if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); + //Attempt to get the data list by key to see if key is valid and for the default template and valid field names + var DataList = DataListFactory.GetAyaDataList(DataListKey); + if (DataList == null) + return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); + //Instantiate the business object handler DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext); - var o = await biz.GetNoLogAsync(DataListKey); + var o = await biz.GetAsync(DataListKey, false, DataList); if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); @@ -123,7 +133,7 @@ namespace AyaNova.Api.Controllers try { - if (!biz.Put(o, inObj)) + if (!biz.Put(o, inObj, DataList)) return BadRequest(new ApiErrorResponse(biz.Errors)); } catch (DbUpdateConcurrencyException) @@ -132,7 +142,7 @@ namespace AyaNova.Api.Controllers // return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); // else //these always exist so can only be concurrency conflict - return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); + return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); } return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true)); } @@ -157,10 +167,15 @@ namespace AyaNova.Api.Controllers if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); + //Attempt to get the data list by key to see if key is valid + var DataList = DataListFactory.GetAyaDataList(DataListKey); + if (DataList == null) + return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); + //Instantiate the business object handler DataListTemplateBiz biz = DataListTemplateBiz.GetBiz(ct, HttpContext); - var o = await biz.GetNoLogAsync(DataListKey); + var o = await biz.GetAsync(DataListKey, false, DataList); if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); diff --git a/server/AyaNova/DataList/DataListFactory.cs b/server/AyaNova/DataList/DataListFactory.cs index b01f4f14..f926765f 100644 --- a/server/AyaNova/DataList/DataListFactory.cs +++ b/server/AyaNova/DataList/DataListFactory.cs @@ -10,6 +10,7 @@ namespace AyaNova.DataList //Instantiate list object specified //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 + //returns null if doesn't exist internal static IAyaDataList GetAyaDataList(string ListKey) { System.Reflection.Assembly ass = System.Reflection.Assembly.GetEntryAssembly(); diff --git a/server/AyaNova/biz/DataListTemplateBiz.cs b/server/AyaNova/biz/DataListTemplateBiz.cs index 10623857..56264bf6 100644 --- a/server/AyaNova/biz/DataListTemplateBiz.cs +++ b/server/AyaNova/biz/DataListTemplateBiz.cs @@ -109,26 +109,27 @@ namespace AyaNova.Biz /// GET //Get one - internal async Task GetAsync(string DataListKey, bool log=true) + internal async Task GetAsync(string DataListKey, bool log, IAyaDataList dataList) { - //This is simple so nothing more here, but often will be copying to a different output object or some other ops - var ret = await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId && (m.Public == true || m.UserId == UserId)); - if (ret != null) + //DataListKey always exists, if not in db then in default form + var ret = await ct.DataListTemplate.SingleOrDefaultAsync(m => m.DataListKey == DataListKey); + + if (log) { //Log - EventLogProcessor.LogEventToDatabase(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct); + EventLogProcessor.LogEventToDatabase(new Event(UserId, ret.Id, BizType, AyaEvent.Retrieved), ct); } return ret; } - //////////////////////////////////////////////////////////////////////////////////////////////// - /// GET - internal async Task GetNoLogAsync(long fetchId) - { - //This is simple so nothing more here, but often will be copying to a different output object or some other ops - return await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId); - } + // //////////////////////////////////////////////////////////////////////////////////////////////// + // /// GET + // internal async Task GetNoLogAsync(long fetchId) + // { + // //This is simple so nothing more here, but often will be copying to a different output object or some other ops + // return await ct.DataListTemplate.SingleOrDefaultAsync(m => m.Id == fetchId); + // } // //get picklist (NOT PAGED) // internal async Task> GetPickListAsync(string listKey)