This commit is contained in:
2020-03-11 23:50:22 +00:00
parent ca5b1c90cb
commit 80dc195673
5 changed files with 102 additions and 112 deletions

View File

@@ -38,7 +38,7 @@ AUTOCOMPLETE
- PUT PickList/Template (body AyaType, body viewJson) - PUT PickList/Template (body AyaType, body viewJson)
- Update a view to use a new default - Update a view to use a new default
- updates cache when it updates db as well - 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 - for ui, resets the view back to it's default
- GET PickList/Template (AyaType) - GET PickList/Template (AyaType)
- for ui picklistvieweditor to populate ui with current template (or default if not edited) - for ui picklistvieweditor to populate ui with current template (or default if not edited)

View File

@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using AyaNova.Models; using AyaNova.Models;
using AyaNova.Api.ControllerHelpers; using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz; using AyaNova.Biz;
@@ -55,7 +56,7 @@ namespace AyaNova.Api.Controllers
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); 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); 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 // //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) if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
var o = await biz.GetPickListAsync(ayaType,query); var o = await biz.GetPickListAsync(ayaType, query);
if (o == null) if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
@@ -90,27 +91,81 @@ namespace AyaNova.Api.Controllers
} }
/// <summary> /// <summary>
/// List of all fields for data list key specified /// POST (replace) Pick List template
/// </summary> /// </summary>
/// <returns>List of PickListFieldDefinition</returns> /// <param name="aytype"></param>
[HttpGet("ListFields")] /// <param name="template"></param>
public ActionResult GetPickListFields([FromQuery] string PickListKey) /// <returns></returns>
[HttpPost("Template/{ayatype}")]
public async Task<IActionResult> ReplacePickListTemplate([FromRoute] AyaType ayaType, [FromBody] string template)
{ {
if (!serverState.IsOpen) if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
}
var PickList = PickListFactory.GetAyaPickList(PickListKey); if (!ModelState.IsValid)
//was the name not found as a list? return BadRequest(new ApiErrorResponse(ModelState));
if (PickList == null)
//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));
} }
/// <summary>
/// Delete customized template
/// (revert to default)
/// </summary>
/// <param name="ayatype"></param>
/// <returns>Ok</returns>
[HttpDelete("Template/{ayatype}")]
public async Task<IActionResult> 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 }//eoc
}//ens }//ens

View File

@@ -27,7 +27,7 @@ namespace AyaNova.Biz
ServerState = 4, ServerState = 4,
License = 5, License = 5,
LogFile = 6, LogFile = 6,
DEPRECATED_REUSELATER_7 = 7, PickListTemplate = 7,
DEPRECATED_REUSELATER_8 = 8, DEPRECATED_REUSELATER_8 = 8,
JobOperations = 9, JobOperations = 9,
AyaNova7Import = 10, AyaNova7Import = 10,

View File

@@ -155,6 +155,15 @@ namespace AyaNova.Biz
ReadFullRecord = AuthorizationRoles.All ReadFullRecord = AuthorizationRoles.All
}); });
////////////////////////////////////////////////////////////
//PICKLISTTEMPLATE
//
roles.Add(AyaType.PickListTemplate, new BizRoleSet()
{
Change = AuthorizationRoles.BizAdminFull,
ReadFullRecord = AuthorizationRoles.All
});
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#endregion all roles init #endregion all roles init

View File

@@ -22,7 +22,7 @@ namespace AyaNova.Biz
UserId = currentUserId; UserId = currentUserId;
UserTranslationId = userTranslationId; UserTranslationId = userTranslationId;
CurrentUserRoles = UserRoles; CurrentUserRoles = UserRoles;
BizType = AyaType.DataListView; BizType = AyaType.PickListTemplate;
} }
internal static PickListBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) internal static PickListBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
@@ -34,81 +34,7 @@ namespace AyaNova.Biz
} }
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //EXISTS
// internal async Task<bool> ExistsAsync(long id)
// {
// return await ct.DataListView.AnyAsync(e => e.Id == id);
// }
// ////////////////////////////////////////////////////////////////////////////////////////////////
// //CREATE
// internal async Task<DataListView> 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<DataListView> 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 /// GET
@@ -184,34 +110,34 @@ namespace AyaNova.Biz
} }
// //////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// //DELETE //DELETE
// // //
// internal async Task<bool> DeleteAsync(DataListView dbObj) internal async Task<bool> DeleteAsync(DataListView dbObj)
// { {
// //Determine if the object can be deleted, do the deletion tentatively //Determine if the object can be deleted, do the deletion tentatively
// //Probably also in here deal with tags and associated search text etc //Probably also in here deal with tags and associated search text etc
// //FUTURE POSSIBLE NEED //FUTURE POSSIBLE NEED
// //ValidateCanDelete(dbObj); //ValidateCanDelete(dbObj);
// if (HasErrors) if (HasErrors)
// return false; return false;
// ct.DataListView.Remove(dbObj); ct.DataListView.Remove(dbObj);
// await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
// //Delete sibling objects //Delete sibling objects
// //Event log process delete //Event log process delete
// await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct); await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObj.Id, dbObj.Name, ct);
// //Delete search index //Delete search index
// //Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); //Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType);
// return true; return true;
// } }
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION //VALIDATION