This commit is contained in:
2021-02-04 14:43:30 +00:00
parent 4d852e2320
commit 9f0c111d3d
4 changed files with 54 additions and 172 deletions

View File

@@ -80,7 +80,7 @@ namespace AyaNova.Api.Controllers
if (tableRequest.FilterId != 0)
{
DataListSavedFilterBiz filterbiz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
SavedFilter = await filterbiz.GetAsync(tableRequest.FilterId, false);
SavedFilter = await filterbiz.GetAsync(tableRequest.FilterId);
}
var DataList = DataListFactory.GetAyaDataList(tableRequest.DataListKey);
if (DataList == null)

View File

@@ -59,8 +59,8 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
@@ -113,12 +113,12 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
var o = await biz.GetAsync(inObj.Id, false);
var o = await biz.GetAsync(inObj.Id);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
try
{
@@ -151,9 +151,9 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
//check roles
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// //check roles
// if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
@@ -174,40 +174,6 @@ namespace AyaNova.Api.Controllers
}
/// <summary>
/// Duplicate DataListSavedFilter
/// </summary>
/// <param name="id">Create a duplicate of this items id</param>
/// <param name="apiVersion">From route path</param>
/// <returns></returns>
[HttpPost("duplicate/{id}")]
public async Task<IActionResult> Duplicate([FromRoute] long id, ApiVersion apiVersion)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
//Instantiate the business object handler
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
//If a user has change roles
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
var oSrc = await biz.GetAsync(id, false);
if (oSrc == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Create and validate
DataListSavedFilter o = await biz.DuplicateAsync(oSrc);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction(nameof(DataListSavedFilterController.GetDataListSavedFilter), new { id = o.Id, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
}
/// <summary>
/// Delete DataListSavedFilter
@@ -226,12 +192,12 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
var o = await biz.GetAsync(id, false);
var o = await biz.GetAsync(id);
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
if (!await biz.DeleteAsync(o))
return BadRequest(new ApiErrorResponse(biz.Errors));
@@ -239,32 +205,32 @@ namespace AyaNova.Api.Controllers
return NoContent();
}
/// <summary>
/// Get default Columns and Sort for DataList
/// </summary>
/// <param name="dataListKey">Key of an existing DataList</param>
/// <returns>Columns and Sort</returns>
[HttpGet("default/{dataListKey}")]
public ActionResult GetDefaultDataListSavedFilter([FromRoute] string dataListKey)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
// /// <summary>
// /// Get default Columns and Sort for DataList
// /// </summary>
// /// <param name="dataListKey">Key of an existing DataList</param>
// /// <returns>Columns and Sort</returns>
// [HttpGet("default/{dataListKey}")]
// public ActionResult GetDefaultDataListSavedFilter([FromRoute] string dataListKey)
// {
// if (!serverState.IsOpen)
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
//Instantiate the business object handler
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
// //Instantiate the business object handler
// DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
return StatusCode(403, new ApiNotAuthorizedResponse());
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
// return StatusCode(403, new ApiNotAuthorizedResponse());
if (!ModelState.IsValid)
return BadRequest(new ApiErrorResponse(ModelState));
// if (!ModelState.IsValid)
// return BadRequest(new ApiErrorResponse(ModelState));
var o = AyaNova.DataList.DataListFactory.GetAyaDataList(dataListKey); ;
if (o == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
// var o = AyaNova.DataList.DataListFactory.GetAyaDataList(dataListKey); ;
// if (o == null)
// return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
return Ok(ApiOkResponse.Response(new { Columns = o.DefaultColumns, SortBy = o.DefaultSortBy }));
}
// return Ok(ApiOkResponse.Response(new { Columns = o.DefaultColumns, SortBy = o.DefaultSortBy }));
// }
//------------

View File

@@ -77,53 +77,19 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE
//
internal async Task<DataListSavedFilter> DuplicateAsync(DataListSavedFilter dbObject)
{
DataListSavedFilter outObj = new DataListSavedFilter();
CopyObject.Copy(dbObject, outObj);
//generate unique name
string newUniqueName = string.Empty;
bool NotUnique = true;
long l = 1;
do
{
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255);
NotUnique = await ct.DataListSavedFilter.AnyAsync(z => z.Name == newUniqueName);
} while (NotUnique);
outObj.Name = newUniqueName;
outObj.Id = 0;
outObj.Concurrency = 0;
await ct.DataListSavedFilter.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 one
internal async Task<DataListSavedFilter> GetAsync(long fetchId, bool logTheGetEvent = true)
internal async Task<DataListSavedFilter> GetAsync(long fetchId)
{
//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.DataListSavedFilter.SingleOrDefaultAsync(z => z.Id == fetchId && (z.Public == true || z.UserId == UserId));
if (logTheGetEvent && ret != null)
{
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
}
var ret = await ct.DataListSavedFilter.AsNoTracking().SingleOrDefaultAsync(z => z.Id == fetchId && (z.Public == true || z.UserId == UserId));
// if (logTheGetEvent && ret != null)
// {
// //Log
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
// }
return ret;
}
@@ -204,27 +170,15 @@ namespace AyaNova.Biz
//
internal async Task<bool> DeleteAsync(DataListSavedFilter dbObject)
{
//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(dbObject);
ValidateCanDelete(dbObject);
if (HasErrors)
return false;
ct.DataListSavedFilter.Remove(dbObject);
await ct.SaveChangesAsync();
//Delete sibling objects
//Event log process delete
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct);
//Delete search index
//Search.ProcessDeletedObjectKeywords(dbObject.Id, BizType);
//was it a "reset" of default?
if (dbObject.DefaultFilter)
await EnsureDefaultAsync(dbObject.ListKey);
return true;
}
@@ -232,6 +186,15 @@ namespace AyaNova.Biz
//VALIDATION
//
private void ValidateCanDelete(DataListSavedFilter inObj)
{
if (inObj.UserId != UserId)
{
AddError(ApiErrorCode.NOT_AUTHORIZED, "generalerror", "Can't delete another users filter");
}
}
//Can save or update?
private void Validate(DataListSavedFilter inObj, bool isNew)
{
@@ -285,53 +248,6 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", "Filter is not valid JSON string, can't convert to List<DataListFilterOption>, error: " + ex.Message);
}
// //Filter json must parse
// //this is all automated normally so not going to do too much parsing here
// //just ensure it's basically there
// if (!string.IsNullOrWhiteSpace(inObj.ListView))
// {
// try
// {
// var v = JArray.Parse(inObj.ListView);
// for (int i = 0; i < v.Count; i++)
// {
// var filterItem = v[i];
// if (filterItem["fld"] == null)
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, object is missing required \"fld\" property ");
// else
// {
// var fld = filterItem["fld"].Value<string>();
// if (string.IsNullOrWhiteSpace(fld))
// AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, \"fld\" property is empty and required");
// //validate the field name if we can
// if (DataList != null)
// {
// var TheField = DataList.FieldDefinitions.SingleOrDefault(z => z.FieldKey.ToLowerInvariant() == fld.ToLowerInvariant());
// if (TheField == null)
// {
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", $"ListView array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
// }
// }
// }
// //NOTE: value of nothing, null or empty is a valid value so no checking for it here
// }
// }
// catch (Newtonsoft.Json.JsonReaderException ex)
// {
// AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", "ListView is not valid JSON string: " + ex.Message);
// }
// }
return;
}

View File

@@ -59,7 +59,7 @@ namespace AyaNova.Models
if (selectedRequest.FilterId != 0)
{
DataListSavedFilterBiz filterbiz = new DataListSavedFilterBiz(ct, userId, userTranslationId, userRoles);
SavedFilter = await filterbiz.GetAsync(selectedRequest.FilterId, false);
SavedFilter = await filterbiz.GetAsync(selectedRequest.FilterId);
}
var DataList = DataListFactory.GetAyaDataList(selectedRequest.DataListKey);
if (DataList == null)