From 80dc19567339804cbc4975caa777cb45c9e38c78 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 11 Mar 2020 23:50:22 +0000 Subject: [PATCH] --- ...-picklist-autocomplete-template-system.txt | 2 +- .../AyaNova/Controllers/PickListController.cs | 83 +++++++++--- server/AyaNova/biz/AyaType.cs | 2 +- server/AyaNova/biz/BizRoles.cs | 9 ++ server/AyaNova/biz/PickListBiz.cs | 118 ++++-------------- 5 files changed, 102 insertions(+), 112 deletions(-) diff --git a/devdocs/specs/core-picklist-autocomplete-template-system.txt b/devdocs/specs/core-picklist-autocomplete-template-system.txt index 03c5d707..70aae0e3 100644 --- a/devdocs/specs/core-picklist-autocomplete-template-system.txt +++ b/devdocs/specs/core-picklist-autocomplete-template-system.txt @@ -38,7 +38,7 @@ AUTOCOMPLETE - PUT PickList/Template (body AyaType, body viewJson) - Update a view to use a new default - updates cache when it updates db as well - - POST PickList/TemplateReset(AyaType) + - DELETE PickList/Template (AyaType) - for ui, resets the view back to it's default - GET PickList/Template (AyaType) - for ui picklistvieweditor to populate ui with current template (or default if not edited) diff --git a/server/AyaNova/Controllers/PickListController.cs b/server/AyaNova/Controllers/PickListController.cs index 321345ad..d97af030 100644 --- a/server/AyaNova/Controllers/PickListController.cs +++ b/server/AyaNova/Controllers/PickListController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Logging; using Microsoft.AspNetCore.Authorization; +using Microsoft.EntityFrameworkCore; using AyaNova.Models; using AyaNova.Api.ControllerHelpers; using AyaNova.Biz; @@ -55,7 +56,7 @@ namespace AyaNova.Api.Controllers return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); } - //Instantiate the business object handler + //Instantiate the business object handler PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext); // //NOTE: This is the first check and often the only check but in some cases with some objects this will also need to check biz object rules @@ -65,7 +66,7 @@ namespace AyaNova.Api.Controllers if (!ModelState.IsValid) return BadRequest(new ApiErrorResponse(ModelState)); - var o = await biz.GetPickListAsync(ayaType,query); + var o = await biz.GetPickListAsync(ayaType, query); if (o == null) return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); @@ -90,27 +91,81 @@ namespace AyaNova.Api.Controllers } + + /// - /// List of all fields for data list key specified - /// - /// List of PickListFieldDefinition - [HttpGet("ListFields")] - public ActionResult GetPickListFields([FromQuery] string PickListKey) + /// POST (replace) Pick List template + /// + /// + /// + /// + [HttpPost("Template/{ayatype}")] + public async Task ReplacePickListTemplate([FromRoute] AyaType ayaType, [FromBody] string template) { if (!serverState.IsOpen) - { return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - } - var PickList = PickListFactory.GetAyaPickList(PickListKey); - //was the name not found as a list? - if (PickList == null) + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + + //Instantiate the business object handler + PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext); + + // var o = await biz.GetAsync(ayaType, false); + // if (o == null) + // return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); + + if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType)) + return StatusCode(403, new ApiNotAuthorizedResponse()); + + try { - return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, "PickListKey", $"PickList \"{PickListKey}\" specified does not exist")); + if (!await biz.ReplaceAsync(ayaType, template)) + return BadRequest(new ApiErrorResponse(biz.Errors)); } + catch (DbUpdateConcurrencyException) + { - return Ok(ApiOkResponse.Response(PickList.FieldDefinitions, true)); + return StatusCode(409, new ApiErrorResponse(ApiErrorCode.CONCURRENCY_CONFLICT)); + } + return Ok(ApiOkResponse.Response(new { ConcurrencyToken = o.ConcurrencyToken }, true)); } + + /// + /// Delete customized template + /// (revert to default) + /// + /// + /// Ok + [HttpDelete("Template/{ayatype}")] + public async Task DeletePickListTemplate([FromRoute] AyaType ayatype) + { + if (!serverState.IsOpen) + return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); + + if (!ModelState.IsValid) + return BadRequest(new ApiErrorResponse(ModelState)); + + //Instantiate the business object handler + PickListBiz biz = PickListBiz.GetBiz(ct, HttpContext); + + + if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType)) + return StatusCode(403, new ApiNotAuthorizedResponse()); + + if (!await biz.DeleteAsync(o)) + return BadRequest(new ApiErrorResponse(biz.Errors)); + + return NoContent(); + } + + + + + + + + }//eoc }//ens \ No newline at end of file diff --git a/server/AyaNova/biz/AyaType.cs b/server/AyaNova/biz/AyaType.cs index 226d8e57..2fb1d716 100644 --- a/server/AyaNova/biz/AyaType.cs +++ b/server/AyaNova/biz/AyaType.cs @@ -27,7 +27,7 @@ namespace AyaNova.Biz ServerState = 4, License = 5, LogFile = 6, - DEPRECATED_REUSELATER_7 = 7, + PickListTemplate = 7, DEPRECATED_REUSELATER_8 = 8, JobOperations = 9, AyaNova7Import = 10, diff --git a/server/AyaNova/biz/BizRoles.cs b/server/AyaNova/biz/BizRoles.cs index 3def6788..1950c426 100644 --- a/server/AyaNova/biz/BizRoles.cs +++ b/server/AyaNova/biz/BizRoles.cs @@ -155,6 +155,15 @@ namespace AyaNova.Biz ReadFullRecord = AuthorizationRoles.All }); + //////////////////////////////////////////////////////////// + //PICKLISTTEMPLATE + // + roles.Add(AyaType.PickListTemplate, new BizRoleSet() + { + Change = AuthorizationRoles.BizAdminFull, + ReadFullRecord = AuthorizationRoles.All + }); + //////////////////////////////////////////////////////////////////// #endregion all roles init diff --git a/server/AyaNova/biz/PickListBiz.cs b/server/AyaNova/biz/PickListBiz.cs index 17003cf4..d5497e9b 100644 --- a/server/AyaNova/biz/PickListBiz.cs +++ b/server/AyaNova/biz/PickListBiz.cs @@ -22,7 +22,7 @@ namespace AyaNova.Biz UserId = currentUserId; UserTranslationId = userTranslationId; CurrentUserRoles = UserRoles; - BizType = AyaType.DataListView; + BizType = AyaType.PickListTemplate; } internal static PickListBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) @@ -34,81 +34,7 @@ namespace AyaNova.Biz } - - // //////////////////////////////////////////////////////////////////////////////////////////////// - // //EXISTS - // internal async Task ExistsAsync(long id) - // { - // return await ct.DataListView.AnyAsync(e => e.Id == id); - // } - - - - // //////////////////////////////////////////////////////////////////////////////////////////////// - // //CREATE - // internal async Task CreateAsync(DataListView inObj) - // { - // await ValidateAsync(inObj, true); - // if (HasErrors) - // return null; - // else - // { - // //do stuff with datafilter - // DataListView outObj = inObj; - // outObj.UserId = UserId; - - - // await ct.DataListView.AddAsync(outObj); - // await ct.SaveChangesAsync(); - - // //Handle child and associated items: - - // //EVENT LOG - // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); - - - - // return outObj; - - // } - // } - - - - - // //////////////////////////////////////////////////////////////////////////////////////////////// - // //DUPLICATE - // // - - // internal async Task DuplicateAsync(DataListView dbObj) - // { - - // DataListView outObj = new DataListView(); - // CopyObject.Copy(dbObj, outObj); - // //generate unique name - // string newUniqueName = string.Empty; - // bool NotUnique = true; - // long l = 1; - // do - // { - // newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObj.Name, l++, 255); - // NotUnique = await ct.DataListView.AnyAsync(m => m.Name == newUniqueName); - // } while (NotUnique); - // outObj.Name = newUniqueName; - // outObj.Id = 0; - // outObj.ConcurrencyToken = 0; - - - - // await ct.DataListView.AddAsync(outObj); - // await ct.SaveChangesAsync(); - - // //Handle child and associated items: - // await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); - - // return outObj; - - // } + //////////////////////////////////////////////////////////////////////////////////////////////// /// GET @@ -184,34 +110,34 @@ namespace AyaNova.Biz } - // //////////////////////////////////////////////////////////////////////////////////////////////// - // //DELETE - // // - // internal async Task DeleteAsync(DataListView dbObj) - // { - // //Determine if the object can be deleted, do the deletion tentatively - // //Probably also in here deal with tags and associated search text etc + //////////////////////////////////////////////////////////////////////////////////////////////// + //DELETE + // + internal async Task DeleteAsync(DataListView dbObj) + { + //Determine if the object can be deleted, do the deletion tentatively + //Probably also in here deal with tags and associated search text etc - // //FUTURE POSSIBLE NEED - // //ValidateCanDelete(dbObj); + //FUTURE POSSIBLE NEED + //ValidateCanDelete(dbObj); - // if (HasErrors) - // return false; - // ct.DataListView.Remove(dbObj); - // await ct.SaveChangesAsync(); + if (HasErrors) + return false; + ct.DataListView.Remove(dbObj); + await ct.SaveChangesAsync(); - // //Delete sibling objects + //Delete sibling objects - // //Event log process delete - // await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct); + //Event log process delete + await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct); - // //Delete search index - // //Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); + //Delete search index + //Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); - // return true; - // } + return true; + } //////////////////////////////////////////////////////////////////////////////////////////////// //VALIDATION