This commit is contained in:
2018-08-23 20:42:47 +00:00
parent 0c0818a539
commit a1e1eb9376
7 changed files with 69 additions and 59 deletions

View File

@@ -20,6 +20,10 @@ CODING WORK
Overall plan for now: anything standing in the way of making the initial client shell UI needs to be done first, everything else can wait Overall plan for now: anything standing in the way of making the initial client shell UI needs to be done first, everything else can wait
- Audit log - Audit log
- CRUD methods for widget
- replicate crud to other objects
- Route for retrieving as log format for reading (like reports: one for specific object id and type, one for user id as log of what they've been doing etc)
- Test with huge dataset
- Localized text - Localized text
- Search and search text indexing - Search and search text indexing
- Auto visible id number assigning code - Auto visible id number assigning code

View File

@@ -85,6 +85,9 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Retrieved), ct);
return Ok(new ApiOkResponse(o)); return Ok(new ApiOkResponse(o));
} }
@@ -191,14 +194,14 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
} }
var oFromDb = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id); var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
if (oFromDb == null) if (o == null)
{ {
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, oFromDb.OwnerId)) if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, o.OwnerId))
{ {
return StatusCode(401, new ApiNotAuthorizedResponse()); return StatusCode(401, new ApiNotAuthorizedResponse());
} }
@@ -206,7 +209,7 @@ namespace AyaNova.Api.Controllers
//Instantiate the business object handler //Instantiate the business object handler
WidgetBiz biz = new WidgetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); WidgetBiz biz = new WidgetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
if (!biz.Put(oFromDb, inObj)) if (!biz.Put(o, inObj))
{ {
return BadRequest(new ApiErrorResponse(biz.Errors)); return BadRequest(new ApiErrorResponse(biz.Errors));
} }
@@ -230,7 +233,10 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken })); //Log
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
} }
@@ -265,20 +271,20 @@ namespace AyaNova.Api.Controllers
WidgetBiz biz = new WidgetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); WidgetBiz biz = new WidgetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
var oFromDb = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id); var o = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id);
if (oFromDb == null) if (o == null)
{ {
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, oFromDb.OwnerId)) if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Widget, o.OwnerId))
{ {
return StatusCode(401, new ApiNotAuthorizedResponse()); return StatusCode(401, new ApiNotAuthorizedResponse());
} }
//patch and validate //patch and validate
if (!biz.Patch(oFromDb, objectPatch, concurrencyToken)) if (!biz.Patch(o, objectPatch, concurrencyToken))
{ {
return BadRequest(new ApiErrorResponse(biz.Errors)); return BadRequest(new ApiErrorResponse(biz.Errors));
} }
@@ -299,7 +305,11 @@ namespace AyaNova.Api.Controllers
} }
} }
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }));
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
return Ok(new ApiOkResponse(new { ConcurrencyToken = o.ConcurrencyToken }));
} }
@@ -346,8 +356,9 @@ namespace AyaNova.Api.Controllers
//save and success return //save and success return
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
//Only here process save event?? //Log
EventLogProcessor.AddEntry(); EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o)); return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
} }
} }
@@ -400,6 +411,9 @@ namespace AyaNova.Api.Controllers
//Delete children / attached objects //Delete children / attached objects
biz.DeleteChildren(dbObj); biz.DeleteChildren(dbObj);
//Log
EventLogProcessor.DeleteObject(biz.userId, AyaType.Widget, dbObj.Id, dbObj.Name, ct);
return NoContent(); return NoContent();
} }

View File

@@ -27,6 +27,23 @@ namespace AyaNova.Biz
} }
/// <summary>
/// Handle delete
/// remove all prior entries for object, add one deleted entry
/// </summary>
/// <param name="userId"></param>
/// <param name="ayType"></param>
/// <param name="ayId"></param>
/// <param name="textra"></param>
/// <param name="ct"></param>
internal static void DeleteObject(long userId, AyaType ayType, long ayId, string textra, AyContext ct)
{
ct.Database.ExecuteSqlCommand("delete from aevent where aytype = {0} and ayid={1}", new object[] { (int)ayType }, new object[] { ayId });
ct.Event.Add(new Event(userId, ayId, ayType, AyaEvent.Deleted, textra));
ct.SaveChanges();
}
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
}//eoc }//eoc

View File

@@ -17,7 +17,7 @@ namespace AyaNova.Biz
internal class WidgetBiz : BizObject, IJobObject internal class WidgetBiz : BizObject, IJobObject
{ {
private readonly AyContext ct; private readonly AyContext ct;
private readonly long userId; public readonly long userId;
private readonly AuthorizationRoles userRoles; private readonly AuthorizationRoles userRoles;
@@ -38,43 +38,13 @@ namespace AyaNova.Biz
return null; return null;
else else
{ {
using (var trans = ct.Database.BeginTransaction())
{
// try
// {
//do stuff with widget //do stuff with widget
Widget outObj = inObj; Widget outObj = inObj;
outObj.OwnerId = userId; outObj.OwnerId = userId;
//SearchHelper(break down text fields, save to db) //SearchHelper(break down text fields, save to db)
//TagHelper(collection of tags??) //TagHelper(collection of tags??)
await ct.Widget.AddAsync(outObj); await ct.Widget.AddAsync(outObj);
//Log creation
Event ev = new Event();
ev.AyEvent = AyaEvent.Created;
ev.AyId = outObj.Id;
ev.AyType = AyaType.Widget;
ev.OwnerId = outObj.OwnerId;
await ct.Event.AddAsync(ev);
// Commit transaction if all commands succeed, transaction will auto-rollback
// when disposed if either commands fails
trans.Commit();
return outObj; return outObj;
// }
// catch (Exception ex)
// {
// throw ex;
// }
}
} }
} }

View File

@@ -19,10 +19,12 @@ namespace AyaNova.Util
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
/////////// CHANGE THIS ON NEW SCHEMA UPDATE //////////////////// /////////// CHANGE THIS ON NEW SCHEMA UPDATE ////////////////////
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 9; private const int DESIRED_SCHEMA_LEVEL = 9;
internal const long EXPECTED_COLUMN_COUNT = 76; internal const long EXPECTED_COLUMN_COUNT = 76;
internal const long EXPECTED_INDEX_COUNT = 15; internal const long EXPECTED_INDEX_COUNT = 15;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////

View File

@@ -278,6 +278,7 @@ namespace AyaNova.Util
EraseTable("atag", conn); EraseTable("atag", conn);
EraseTable("afileattachment", conn); EraseTable("afileattachment", conn);
EraseTable("awidget", conn); EraseTable("awidget", conn);
EraseTable("aevent", conn);
conn.Close(); conn.Close();
} }

View File

@@ -273,8 +273,10 @@ namespace AyaNova.Util
//this is nonsense but just to test an enum //this is nonsense but just to test an enum
o.Roles = AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited; o.Roles = AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited;
ct.Widget.Add(o); ct.Widget.Add(o);
}
ct.SaveChanges(); ct.SaveChanges();
EventLogProcessor.AddEntry(new Event(o.OwnerId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
}
} }