This commit is contained in:
2019-06-10 20:12:49 +00:00
parent 728b5abab6
commit 1e18f5a11d
4 changed files with 76 additions and 13 deletions

View File

@@ -16,6 +16,10 @@ REALLY MAKING MORE PROGRESS WHEN CLIENT DEV DRIVES BACKEND DEV, STICK TO THAT!!
DO CLIENT STUFF NOW COME BACK TO THIS STUFF LATER DO CLIENT STUFF NOW COME BACK TO THIS STUFF LATER
###*** BEFORE NEXT UPDATE TO DEVOPS SERVER::::::: ###*** BEFORE NEXT UPDATE TO DEVOPS SERVER:::::::
TODO: Widget controller is doing a lot of database work in routes before calling biz, I'm concerned about separation of concerns here
- Controller shouldn't have to know about database or is this realistic with the design?
- Can I just move all DB related code out of widget or is this a nightmare at this point?
TODO: NEEDS A THINK, SOME CHANGES REQUIRE DB ERASURE BEFORE STARTUP TODO: NEEDS A THINK, SOME CHANGES REQUIRE DB ERASURE BEFORE STARTUP
- Make it fucking easier to test deploy and erase db and fetch key and all that shit - Make it fucking easier to test deploy and erase db and fetch key and all that shit
- I would like to deploy, bring it up and then from a simple command from the api explorer trigger all the above - I would like to deploy, bring it up and then from a simple command from the api explorer trigger all the above

View File

@@ -327,7 +327,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler //Instantiate the business object handler
UserBiz biz = UserBiz.GetBiz(ct, HttpContext); UserBiz biz = UserBiz.GetBiz(ct, HttpContext);
//If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner //If a user has change 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());

View File

@@ -51,7 +51,7 @@ namespace AyaNova.Api.Controllers
/// Get full widget object /// Get full widget object
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns>A single widget</returns> /// <returns>A single widget</returns>
@@ -86,7 +86,7 @@ namespace AyaNova.Api.Controllers
/// Get filter and sort options /// Get filter and sort options
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
/// ///
/// </summary> /// </summary>
/// <returns>Filter options</returns> /// <returns>Filter options</returns>
@@ -113,7 +113,7 @@ namespace AyaNova.Api.Controllers
/// Get paged list of widgets /// Get paged list of widgets
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
/// </summary> /// </summary>
/// <returns>Paged collection of widgets with paging data</returns> /// <returns>Paged collection of widgets with paging data</returns>
[HttpGet("ListWidgets", Name = nameof(ListWidgets))]//We MUST have a "Name" defined or we can't get the link for the pagination, non paged urls don't need a name [HttpGet("ListWidgets", Name = nameof(ListWidgets))]//We MUST have a "Name" defined or we can't get the link for the pagination, non paged urls don't need a name
@@ -167,7 +167,6 @@ namespace AyaNova.Api.Controllers
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull /// BizAdminFull, InventoryFull
/// TechFull (owned only)
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
@@ -214,7 +213,7 @@ namespace AyaNova.Api.Controllers
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull /// BizAdminFull, InventoryFull
/// TechFull (owned only) ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="concurrencyToken"></param> /// <param name="concurrencyToken"></param>
@@ -262,7 +261,7 @@ namespace AyaNova.Api.Controllers
/// Post widget /// Post widget
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull, TechFull /// BizAdminFull, InventoryFull
/// </summary> /// </summary>
/// <param name="inObj"></param> /// <param name="inObj"></param>
/// <returns></returns> /// <returns></returns>
@@ -275,7 +274,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler //Instantiate the business object handler
WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext); WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext);
//If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner //If a user has change 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());
@@ -291,6 +290,43 @@ namespace AyaNova.Api.Controllers
} }
/// <summary>
/// Duplicate widget
///
/// Required roles:
/// BizAdminFull, InventoryFull
/// </summary>
/// <param name="id">Create a duplicate of this item id</param>
/// <returns></returns>
[HttpPost("duplicate/{id}")]
public async Task<IActionResult> DuplicateWidget([FromRoute] long id)
{
if (!serverState.IsOpen)
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
//Instantiate the business object handler
WidgetBiz biz = WidgetBiz.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.GetNoLogAsync(id);
if (oSrc == null)
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
//Create and validate
Widget o = await biz.DuplicateAsync(oSrc);
if (o == null)
return BadRequest(new ApiErrorResponse(biz.Errors));
else
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
}
/// <summary> /// <summary>
@@ -298,7 +334,7 @@ namespace AyaNova.Api.Controllers
/// ///
/// Required roles: /// Required roles:
/// BizAdminFull, InventoryFull /// BizAdminFull, InventoryFull
/// TechFull (owned only) ///
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>

View File

@@ -131,6 +131,29 @@ namespace AyaNova.Biz
} }
////////////////////////////////////////////////////////////////////////////////////////////////
//DUPLICATE
//
internal async Task<Widget> DuplicateAsync(Widget dbObj)
{
Widget outObj = new Widget();
CopyObject.Copy(dbObj, outObj);
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
await ct.Widget.AddAsync(outObj);
await ct.SaveChangesAsync();
//Handle child and associated items:
EventLogProcessor.LogEventToDatabase(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
SearchIndex(outObj, true);
TagUtil.ProcessUpdateTagsInRepository(ct, outObj.Tags, null);
return outObj;
}
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//UPDATE //UPDATE