This commit is contained in:
2018-08-24 17:05:33 +00:00
parent 871182ebdb
commit 33626df512
8 changed files with 70 additions and 29 deletions

View File

@@ -46,11 +46,18 @@ TEXTRA (text field to identify stuff that can't be retrieved from source object,
DELETION DELETION
-------- --------
The only way an entry is removed from the log is via deletion of the source object Initially, the only way an entry is removed from the log is via deletion of the source object
When a source object is deleted, the entire history for that object is removed from the log and a new entry is created showing the deletion and textual representation of the object When a source object is deleted, the entire history for that object is removed from the log and a new entry is created showing the deletion and textual representation of the object
- The record has the object type so no need to redundently store that, just the name: "1234" for workorder 1234 or "ABC Accounting" for the client name etc - The record has the object type so no need to redundently store that, just the name: "1234" for workorder 1234 or "ABC Accounting" for the client name etc
PURGING (FUTURE)
----------------
Items that might be most purgeable in any future purge scenario:
- Retrieved events
- File attachment download events
- fetch logfile
TODO: TODO:
1) Implement this log and routes to interact with it 1) Implement this log and routes to interact with it

View File

@@ -59,7 +59,7 @@ namespace AyaNova.Api.Controllers
//TODO: Centralize this code somewhere else, it's going to be needed for backup as well //TODO: Centralize this code somewhere else, it's going to be needed for backup as well
//consider the 1 hour thing, is this legit depending on client? //consider the 1 hour thing, is this legit depending on client?
@@ -224,18 +224,23 @@ namespace AyaNova.Api.Controllers
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, errorMessage)); return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_INVALID_VALUE, null, errorMessage));
} }
long UserId = UserIdFromContext.Id(HttpContext.Items);
//We have our files and a confirmed AyObject, ready to attach and save permanently //We have our files and a confirmed AyObject, ready to attach and save permanently
if (uploadFormData.UploadedFiles.Count > 0) if (uploadFormData.UploadedFiles.Count > 0)
{ {
foreach (UploadedFileInfo a in uploadFormData.UploadedFiles) foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
{ {
var v = FileUtil.storeFileAttachment(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, UserIdFromContext.Id(HttpContext.Items), attachToObject, ct); var v = FileUtil.storeFileAttachment(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, UserId, attachToObject, ct);
returnList.Add(new NameIdItem() returnList.Add(new NameIdItem()
{ {
Name = v.DisplayFileName, Name = v.DisplayFileName,
Id = v.Id Id = v.Id
}); });
//Log
EventLogProcessor.AddEntry(new Event(UserId, attachToObject.ObjectId, attachToObject.ObjectType, AyaEvent.AttachmentCreate, v.DisplayFileName), ct);
} }
} }
} }
@@ -289,6 +294,7 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
long UserId = UserIdFromContext.Id(HttpContext.Items);
if (!Authorized.IsAuthorizedToDelete(HttpContext.Items, dbObj.AttachToObjectType, dbObj.OwnerId)) if (!Authorized.IsAuthorizedToDelete(HttpContext.Items, dbObj.AttachToObjectType, dbObj.OwnerId))
{ {
@@ -299,6 +305,9 @@ namespace AyaNova.Api.Controllers
//this handles removing the file if there are no refs left and also the db record for the attachment //this handles removing the file if there are no refs left and also the db record for the attachment
FileUtil.deleteFileAttachment(dbObj, ct); FileUtil.deleteFileAttachment(dbObj, ct);
//Log
EventLogProcessor.AddEntry(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct);
return NoContent(); return NoContent();
} }
@@ -339,8 +348,8 @@ namespace AyaNova.Api.Controllers
} }
//Make sure the token provided is for the current user //Make sure the token provided is for the current user
long lAuthenticatedUserId = UserIdFromContext.Id(HttpContext.Items); long UserId = UserIdFromContext.Id(HttpContext.Items);
if (lAuthenticatedUserId != dlkeyUser.Id) if (UserId != dlkeyUser.Id)
{ {
return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_AUTHORIZED, "dlkey", "Download token not valid")); return BadRequest(new ApiErrorResponse(ApiErrorCode.NOT_AUTHORIZED, "dlkey", "Download token not valid"));
} }
@@ -375,6 +384,9 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, null, $"Physical file {dbObj.StoredFileName} not found despite attachment record, this file is missing")); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND, null, $"Physical file {dbObj.StoredFileName} not found despite attachment record, this file is missing"));
} }
//Log
EventLogProcessor.AddEntry(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDownload, dbObj.DisplayFileName), ct);
return PhysicalFile(filePath, mimetype, dbObj.DisplayFileName); return PhysicalFile(filePath, mimetype, dbObj.DisplayFileName);
} }

View File

@@ -126,6 +126,8 @@ namespace AyaNova.Api.Controllers
} }
var ret = AyaNova.Core.License.LicenseInfoAsJson; var ret = AyaNova.Core.License.LicenseInfoAsJson;
//Log
EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
return Ok(new ApiOkResponse(ret)); return Ok(new ApiOkResponse(ret));
} }
@@ -176,6 +178,9 @@ namespace AyaNova.Api.Controllers
//Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above) //Send the request to RockFish here (or at least start the job to do it in which case return Accepted instead of no content and update comment above)
var ret = Core.License.RequestTrial(requestData.EmailAddress, requestData.RegisteredTo, log); var ret = Core.License.RequestTrial(requestData.EmailAddress, requestData.RegisteredTo, log);
//Log
EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseTrialRequest), ct);
return Ok(new ApiOkResponse(ret)); return Ok(new ApiOkResponse(ret));
} }

View File

@@ -161,6 +161,10 @@ namespace AyaNova.Api.Controllers
{ {
//save and success return //save and success return
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Locale, AyaEvent.Created), ct);
return CreatedAtAction("GetLocale", new { id = o.Id }, new ApiCreatedResponse(o)); return CreatedAtAction("GetLocale", new { id = o.Id }, new ApiCreatedResponse(o));
} }
} }
@@ -236,6 +240,9 @@ namespace AyaNova.Api.Controllers
} }
} }
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, oDbParent.Id, AyaType.Locale, AyaEvent.Modified), ct);
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken })); return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }));
} }
@@ -269,7 +276,7 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Locale, oFromDb.OwnerId)) if (!Authorized.IsAuthorizedToModify(HttpContext.Items, AyaType.Locale, oFromDb.OwnerId))
{ {
return StatusCode(401, new ApiNotAuthorizedResponse()); return StatusCode(401, new ApiNotAuthorizedResponse());
@@ -302,6 +309,9 @@ namespace AyaNova.Api.Controllers
} }
} }
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, oFromDb.Id, AyaType.Locale, AyaEvent.Modified), ct);
return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken })); return Ok(new ApiOkResponse(new { ConcurrencyToken = oFromDb.ConcurrencyToken }));
} }
@@ -355,6 +365,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.Locale, dbObj.Id, dbObj.Name, ct);
return NoContent(); return NoContent();
} }

View File

@@ -80,19 +80,9 @@ namespace AyaNova.Api.Controllers
return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND));
} }
// //read it and stream it back in a json object
//Log
EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.LogFile, AyaEvent.Retrieved,logname), ct);
// Newtonsoft.Json.Linq.JObject o = Newtonsoft.Json.Linq.JObject.FromObject(new
// {
// log = new
// {
// name = logname,
// log = System.IO.File.ReadAllText(logFilePath)
// }
// });
// return Ok(new ApiOkResponse(o));
return Content(System.IO.File.ReadAllText(logFilePath)); return Content(System.IO.File.ReadAllText(logFilePath));

View File

@@ -66,6 +66,10 @@ namespace AyaNova.Api.Controllers
} }
string sResult = await GetTheMetrics("plain"); string sResult = await GetTheMetrics("plain");
//Log
EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
return Content(sResult); return Content(sResult);
} }
@@ -91,14 +95,12 @@ namespace AyaNova.Api.Controllers
return StatusCode(401, new ApiNotAuthorizedResponse()); return StatusCode(401, new ApiNotAuthorizedResponse());
} }
string sResult = await GetTheMetrics("json"); string sResult = await GetTheMetrics("json");
//return Ok(new ApiOkResponse(new { metrics = sResult }));
// /THIS IS NOT RETURNING VALID PARSEABLE JSON, FIX IT
//IDEAS:
//try parsing the result first then return it
//
JObject json = JObject.Parse(sResult); JObject json = JObject.Parse(sResult);
//Log
EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
return Ok(new ApiOkResponse(json)); return Ok(new ApiOkResponse(json));
} }

View File

@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using AyaNova.Api.ControllerHelpers; using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz; using AyaNova.Biz;
using AyaNova.Models;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
@@ -19,6 +20,7 @@ namespace AyaNova.Api.Controllers
[Produces("application/json")] [Produces("application/json")]
public class ServerStateController : Controller public class ServerStateController : Controller
{ {
private readonly AyContext ct;
private readonly ILogger<ServerStateController> log; private readonly ILogger<ServerStateController> log;
private readonly ApiServerState serverState; private readonly ApiServerState serverState;
@@ -27,8 +29,10 @@ namespace AyaNova.Api.Controllers
/// </summary> /// </summary>
/// <param name="logger"></param> /// <param name="logger"></param>
/// <param name="apiServerState"></param> /// <param name="apiServerState"></param>
public ServerStateController(ILogger<ServerStateController> logger, ApiServerState apiServerState) /// <param name="dbcontext"></param>
public ServerStateController(ILogger<ServerStateController> logger, ApiServerState apiServerState, AyContext dbcontext)
{ {
ct = dbcontext;
log = logger; log = logger;
serverState = apiServerState; serverState = apiServerState;
} }
@@ -90,6 +94,9 @@ namespace AyaNova.Api.Controllers
serverState.SetState(desiredState, state.Reason); serverState.SetState(desiredState, state.Reason);
//Log
EventLogProcessor.AddEntry(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.ServerState, AyaEvent.ServerStateChange, $"{state.ServerState}-{state.Reason}"), ct);
return NoContent(); return NoContent();
} }

View File

@@ -12,10 +12,15 @@ namespace AyaNova.Biz
Deleted = 0, Deleted = 0,
Created = 1, Created = 1,
Retrieved = 2, Retrieved = 2,
Modified = 3 Modified = 3,
//specific events //specific events
AttachmentCreate=4,
AttachmentDelete=5,
AttachmentDownload=6,
LicenseFetch=7,
LicenseTrialRequest=8,
ServerStateChange=9
} }