This commit is contained in:
@@ -80,7 +80,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
if (tableRequest.FilterId != 0)
|
if (tableRequest.FilterId != 0)
|
||||||
{
|
{
|
||||||
DataListSavedFilterBiz filterbiz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
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);
|
var DataList = DataListFactory.GetAyaDataList(tableRequest.DataListKey);
|
||||||
if (DataList == null)
|
if (DataList == null)
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
@@ -113,12 +113,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetAsync(inObj.Id, false);
|
var o = await biz.GetAsync(inObj.Id);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasModifyRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -151,9 +151,9 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
//check roles
|
// //check roles
|
||||||
if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasCreateRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
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>
|
/// <summary>
|
||||||
/// Delete DataListSavedFilter
|
/// Delete DataListSavedFilter
|
||||||
@@ -226,12 +192,12 @@ namespace AyaNova.Api.Controllers
|
|||||||
//Instantiate the business object handler
|
//Instantiate the business object handler
|
||||||
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
var o = await biz.GetAsync(id, false);
|
var o = await biz.GetAsync(id);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
||||||
|
|
||||||
if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasDeleteRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
if (!await biz.DeleteAsync(o))
|
if (!await biz.DeleteAsync(o))
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
@@ -239,32 +205,32 @@ namespace AyaNova.Api.Controllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// Get default Columns and Sort for DataList
|
// /// Get default Columns and Sort for DataList
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
/// <param name="dataListKey">Key of an existing DataList</param>
|
// /// <param name="dataListKey">Key of an existing DataList</param>
|
||||||
/// <returns>Columns and Sort</returns>
|
// /// <returns>Columns and Sort</returns>
|
||||||
[HttpGet("default/{dataListKey}")]
|
// [HttpGet("default/{dataListKey}")]
|
||||||
public ActionResult GetDefaultDataListSavedFilter([FromRoute] string dataListKey)
|
// public ActionResult GetDefaultDataListSavedFilter([FromRoute] string dataListKey)
|
||||||
{
|
// {
|
||||||
if (!serverState.IsOpen)
|
// if (!serverState.IsOpen)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
// return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
|
||||||
//Instantiate the business object handler
|
// //Instantiate the business object handler
|
||||||
DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
// DataListSavedFilterBiz biz = DataListSavedFilterBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
// if (!Authorized.HasReadFullRole(HttpContext.Items, biz.BizType))
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
// return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
// if (!ModelState.IsValid)
|
||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
// return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
var o = AyaNova.DataList.DataListFactory.GetAyaDataList(dataListKey); ;
|
// var o = AyaNova.DataList.DataListFactory.GetAyaDataList(dataListKey); ;
|
||||||
if (o == null)
|
// if (o == null)
|
||||||
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
|
// 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 }));
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//------------
|
//------------
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
//Get one
|
//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
|
//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));
|
var ret = await ct.DataListSavedFilter.AsNoTracking().SingleOrDefaultAsync(z => z.Id == fetchId && (z.Public == true || z.UserId == UserId));
|
||||||
if (logTheGetEvent && ret != null)
|
// if (logTheGetEvent && ret != null)
|
||||||
{
|
// {
|
||||||
//Log
|
// //Log
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
// await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct);
|
||||||
}
|
// }
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,27 +170,15 @@ namespace AyaNova.Biz
|
|||||||
//
|
//
|
||||||
internal async Task<bool> DeleteAsync(DataListSavedFilter dbObject)
|
internal async Task<bool> DeleteAsync(DataListSavedFilter dbObject)
|
||||||
{
|
{
|
||||||
//Determine if the object can be deleted, do the deletion tentatively
|
ValidateCanDelete(dbObject);
|
||||||
//Probably also in here deal with tags and associated search text etc
|
|
||||||
|
|
||||||
//FUTURE POSSIBLE NEED
|
|
||||||
//ValidateCanDelete(dbObject);
|
|
||||||
|
|
||||||
if (HasErrors)
|
if (HasErrors)
|
||||||
return false;
|
return false;
|
||||||
ct.DataListSavedFilter.Remove(dbObject);
|
ct.DataListSavedFilter.Remove(dbObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
|
|
||||||
//Delete sibling objects
|
//was it a "reset" of default?
|
||||||
|
if (dbObject.DefaultFilter)
|
||||||
//Event log process delete
|
await EnsureDefaultAsync(dbObject.ListKey);
|
||||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct);
|
|
||||||
|
|
||||||
|
|
||||||
//Delete search index
|
|
||||||
//Search.ProcessDeletedObjectKeywords(dbObject.Id, BizType);
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +186,15 @@ namespace AyaNova.Biz
|
|||||||
//VALIDATION
|
//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?
|
//Can save or update?
|
||||||
private void Validate(DataListSavedFilter inObj, bool isNew)
|
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);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace AyaNova.Models
|
|||||||
if (selectedRequest.FilterId != 0)
|
if (selectedRequest.FilterId != 0)
|
||||||
{
|
{
|
||||||
DataListSavedFilterBiz filterbiz = new DataListSavedFilterBiz(ct, userId, userTranslationId, userRoles);
|
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);
|
var DataList = DataListFactory.GetAyaDataList(selectedRequest.DataListKey);
|
||||||
if (DataList == null)
|
if (DataList == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user