diff --git a/devdocs/todo.txt b/devdocs/todo.txt
index 4becdc93..25f476f3 100644
--- a/devdocs/todo.txt
+++ b/devdocs/todo.txt
@@ -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
###*** 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
- 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
diff --git a/server/AyaNova/Controllers/UserController.cs b/server/AyaNova/Controllers/UserController.cs
index b25194bc..5f9ada8d 100644
--- a/server/AyaNova/Controllers/UserController.cs
+++ b/server/AyaNova/Controllers/UserController.cs
@@ -327,7 +327,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
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))
{
return StatusCode(403, new ApiNotAuthorizedResponse());
diff --git a/server/AyaNova/Controllers/WidgetController.cs b/server/AyaNova/Controllers/WidgetController.cs
index 50710e43..80619579 100644
--- a/server/AyaNova/Controllers/WidgetController.cs
+++ b/server/AyaNova/Controllers/WidgetController.cs
@@ -51,7 +51,7 @@ namespace AyaNova.Api.Controllers
/// Get full widget object
///
/// Required roles:
- /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting
+ /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
///
///
/// A single widget
@@ -86,7 +86,7 @@ namespace AyaNova.Api.Controllers
/// Get filter and sort options
///
/// Required roles:
- /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting
+ /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
///
///
/// Filter options
@@ -113,7 +113,7 @@ namespace AyaNova.Api.Controllers
/// Get paged list of widgets
///
/// Required roles:
- /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting
+ /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited
///
/// Paged collection of widgets with paging data
[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:
/// BizAdminFull, InventoryFull
- /// TechFull (owned only)
///
///
///
@@ -214,7 +213,7 @@ namespace AyaNova.Api.Controllers
///
/// Required roles:
/// BizAdminFull, InventoryFull
- /// TechFull (owned only)
+ ///
///
///
///
@@ -262,7 +261,7 @@ namespace AyaNova.Api.Controllers
/// Post widget
///
/// Required roles:
- /// BizAdminFull, InventoryFull, TechFull
+ /// BizAdminFull, InventoryFull
///
///
///
@@ -275,7 +274,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler
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))
return StatusCode(403, new ApiNotAuthorizedResponse());
@@ -291,6 +290,43 @@ namespace AyaNova.Api.Controllers
}
+ ///
+ /// Duplicate widget
+ ///
+ /// Required roles:
+ /// BizAdminFull, InventoryFull
+ ///
+ /// Create a duplicate of this item id
+ ///
+ [HttpPost("duplicate/{id}")]
+ public async Task 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));
+
+ }
+
///
@@ -298,7 +334,7 @@ namespace AyaNova.Api.Controllers
///
/// Required roles:
/// BizAdminFull, InventoryFull
- /// TechFull (owned only)
+ ///
///
///
///
diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs
index 639f398b..22657e51 100644
--- a/server/AyaNova/biz/WidgetBiz.cs
+++ b/server/AyaNova/biz/WidgetBiz.cs
@@ -85,7 +85,7 @@ namespace AyaNova.Biz
{
//do stuff with widget
Widget outObj = inObj;
-
+
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
@@ -113,7 +113,7 @@ namespace AyaNova.Biz
{
//do stuff with widget
Widget outObj = inObj;
-
+
//Test get serial id visible id number from generator
outObj.Serial = ServerBootConfig.WIDGET_SERIAL.GetNext();
outObj.Tags = TagUtil.NormalizeTags(outObj.Tags);
@@ -131,6 +131,29 @@ namespace AyaNova.Biz
}
+ ////////////////////////////////////////////////////////////////////////////////////////////////
+ //DUPLICATE
+ //
+
+ internal async Task 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
@@ -139,7 +162,7 @@ namespace AyaNova.Biz
//put
internal bool Put(Widget dbObj, Widget inObj)
{
-
+
//make a snapshot of the original for validation but update the original to preserve workflow
Widget SnapshotOfOriginalDBObj = new Widget();
CopyObject.Copy(dbObj, SnapshotOfOriginalDBObj);
@@ -351,7 +374,7 @@ namespace AyaNova.Biz
// // }
// }
-
+
//Name required
if (string.IsNullOrWhiteSpace(proposedObj.Name))
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");