This commit is contained in:
@@ -127,28 +127,28 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// Get available types allowed for Custom fields
|
// /// Get available types allowed for Custom fields
|
||||||
/// Used to build UI for customizing a form
|
// /// Used to build UI for customizing a form
|
||||||
///
|
// ///
|
||||||
/// Required roles:
|
// /// Required roles:
|
||||||
/// BizAdminFull only has rights to customize forms
|
// /// BizAdminFull only has rights to customize forms
|
||||||
///
|
// ///
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
/// <returns>A list of type string values valid for custom fields</returns>
|
// /// <returns>A list of type string values valid for custom fields</returns>
|
||||||
[HttpGet("AvailableCustomTypes")]
|
// [HttpGet("AvailableCustomTypes")]
|
||||||
public ActionResult GetAvailableCustomTypes()
|
// public ActionResult GetAvailableCustomTypes()
|
||||||
{
|
// {
|
||||||
if (serverState.IsClosed)
|
// if (serverState.IsClosed)
|
||||||
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
// return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
|
||||||
|
|
||||||
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.FormCustom))
|
// if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.FormCustom))
|
||||||
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));
|
||||||
return Ok(ApiOkResponse.Response(CustomFieldType.ValidCustomFieldTypes, true));
|
// return Ok(ApiOkResponse.Response(CustomFieldType.ValidCustomFieldTypes, true));
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -221,38 +221,38 @@ namespace AyaNova.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// Post FormCustom
|
// /// Post FormCustom
|
||||||
///
|
// ///
|
||||||
/// Required roles: BizAdminFull
|
// /// Required roles: BizAdminFull
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
/// <param name="inObj"></param>
|
// /// <param name="inObj"></param>
|
||||||
/// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
// /// <param name="apiVersion">Automatically filled from route path, no need to specify in body</param>
|
||||||
/// <returns></returns>
|
// /// <returns></returns>
|
||||||
[HttpPost]
|
// [HttpPost]
|
||||||
public async Task<IActionResult> PostFormCustom([FromBody] FormCustom inObj, ApiVersion apiVersion)
|
// public async Task<IActionResult> PostFormCustom([FromBody] FormCustom inObj, ApiVersion apiVersion)
|
||||||
{
|
// {
|
||||||
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));
|
||||||
|
|
||||||
//Instantiate the business object handler
|
// //Instantiate the business object handler
|
||||||
FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext);
|
// FormCustomBiz biz = FormCustomBiz.GetBiz(ct, HttpContext);
|
||||||
|
|
||||||
//check rights
|
// //check rights
|
||||||
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));
|
||||||
|
|
||||||
//Create and validate
|
// //Create and validate
|
||||||
FormCustom o = await biz.CreateAsync(inObj);
|
// FormCustom o = await biz.CreateAsync(inObj);
|
||||||
if (o == null)
|
// if (o == null)
|
||||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
// return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||||
else
|
// else
|
||||||
return CreatedAtAction(nameof(FormCustomController.GetFormCustom), new { formkey = o.FormKey, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
// return CreatedAtAction(nameof(FormCustomController.GetFormCustom), new { formkey = o.FormKey, version = apiVersion.ToString() }, new ApiCreatedResponse(o));
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
|
//************************************************
|
||||||
|
// This contains all the fields that are on customizable forms
|
||||||
|
//in addition it serves as a source for valid form keys in AvailableFormKeys
|
||||||
|
//
|
||||||
public static class FormAvailableFields
|
public static class FormAvailableFields
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
internal static FormCustomBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
|
internal static FormCustomBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new FormCustomBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
return new FormCustomBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +89,14 @@ namespace AyaNova.Biz
|
|||||||
//Get one
|
//Get one
|
||||||
internal async Task<FormCustom> GetAsync(string formKey)
|
internal async Task<FormCustom> GetAsync(string formKey)
|
||||||
{
|
{
|
||||||
|
TODO: this must create the formCustom record if it doesn't already exist
|
||||||
|
//Step 1: check if exists, if it does then just return it
|
||||||
|
|
||||||
|
//If it doesn't exist, vet the form key name is ok by checking with this list
|
||||||
|
//FormAvailableFields.AvailableFormKeys
|
||||||
|
// and if it is then create it, save to db and then return it
|
||||||
|
|
||||||
|
|
||||||
var ret = await ct.FormCustom.SingleOrDefaultAsync(m => m.FormKey == formKey);
|
var ret = await ct.FormCustom.SingleOrDefaultAsync(m => m.FormKey == formKey);
|
||||||
//Do not log this, it's going to be called a zillion times anyway
|
//Do not log this, it's going to be called a zillion times anyway
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user