ayType aytype all now AyaType or ayaType

This commit is contained in:
2020-05-15 21:08:37 +00:00
parent 7806e0df26
commit 8f3118d309
11 changed files with 77 additions and 42 deletions

View File

@@ -45,7 +45,7 @@ etc
EVENT LOG DB SCHEMA EVENT LOG DB SCHEMA
------------------------------------ ------------------------------------
AYTYPE (object type int), AYaTYPE (object type int),
AYID (object id), AYID (object id),
AYEVENT (event of interest type int defined in central master enum of all events), AYEVENT (event of interest type int defined in central master enum of all events),
TIMESTAMP (unix epoch), TIMESTAMP (unix epoch),

View File

@@ -37,7 +37,30 @@ namespace AyaNova.Api.ControllerHelpers
return false; return false;
} }
/// <summary>
/// any access at all?
/// </summary>
/// <param name="HttpContextItems"></param>
/// <param name="objectType"></param>
/// <returns></returns>
internal static bool HasAnyRole(IDictionary<object, object> HttpContextItems, AyaType objectType)
{
AuthorizationRoles currentUserRoles = UserRolesFromContext.Roles(HttpContextItems);
return HasAnyRole(currentUserRoles, objectType);
}
/// <summary>
/// User has any access at all to this object?
/// </summary>
/// <param name="currentUserRoles"></param>
/// <param name="objectType"></param>
/// <returns></returns>
internal static bool HasAnyRole(AuthorizationRoles currentUserRoles, AyaType objectType)
{
var RoleSet = BizRoles.GetRoleSet(objectType);
var AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change | RoleSet.Select;
return currentUserRoles.HasAnyFlags(AllowedRoles);
}
/// <summary> /// <summary>
/// READ FULL RECORD (not just name and id) /// READ FULL RECORD (not just name and id)
@@ -97,7 +120,7 @@ namespace AyaNova.Api.ControllerHelpers
var RoleSet = BizRoles.GetRoleSet(objectType); var RoleSet = BizRoles.GetRoleSet(objectType);
var AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change; var AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change;
return currentUserRoles.HasAnyFlags(AllowedRoles); return currentUserRoles.HasAnyFlags(AllowedRoles);
// if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Change)) // if (currentUserRoles.HasAnyFlags(BizRoles.GetRoleSet(objectType).Change))
// return true; // return true;

View File

@@ -56,7 +56,7 @@ namespace AyaNova.Api.Controllers
if (serverState.IsClosed) if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
if (!Authorized.HasReadFullRole(HttpContext.Items, opt.AyType)) if (!Authorized.HasReadFullRole(HttpContext.Items, opt.AyaType))
{ {
return StatusCode(403, new ApiNotAuthorizedResponse()); return StatusCode(403, new ApiNotAuthorizedResponse());
} }
@@ -125,7 +125,7 @@ namespace AyaNova.Api.Controllers
} }
public sealed class V7Event public sealed class V7Event
{ {
public AyaType AyType { get; set; } public AyaType AyaType { get; set; }
public long AyId { get; set; } public long AyId { get; set; }
public long Creator { get; set; } public long Creator { get; set; }
public long Modifier { get; set; } public long Modifier { get; set; }
@@ -140,7 +140,7 @@ namespace AyaNova.Api.Controllers
public sealed class EventLogOptions public sealed class EventLogOptions
{ {
[FromQuery] [FromQuery]
public AyaType AyType { get; set; } public AyaType AyaType { get; set; }
[FromQuery] [FromQuery]
public long AyId { get; set; } public long AyId { get; set; }
[FromQuery] [FromQuery]

View File

@@ -114,6 +114,7 @@ namespace AyaNova.Api.Controllers
if (serverState.IsClosed) if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
//since this is for opening an entire object it's appropriate to check if they have read full role first
if (!Authorized.HasReadFullRole(HttpContext.Items, ayaType)) if (!Authorized.HasReadFullRole(HttpContext.Items, ayaType))
return StatusCode(403, new ApiNotAuthorizedResponse()); return StatusCode(403, new ApiNotAuthorizedResponse());
@@ -140,11 +141,8 @@ namespace AyaNova.Api.Controllers
} }
// var res = await Search.GetInfoAsync(ct, UserTranslationIdFromContext.Id(HttpContext.Items),
// UserRolesFromContext.Roles(HttpContext.Items), UserIdFromContext.Id(HttpContext.Items), phrase, max, ayaType, id);
return Ok(ApiOkResponse.Response(res, true)); }
}
//------------ //------------

View File

@@ -21,14 +21,14 @@ namespace AyaNova.Biz
//Returns existance status of object type and id specified in database //Returns existance status of object type and id specified in database
internal static async Task<bool> ExistsAsync(AyaType aytype, long id, AyContext ct = null) internal static async Task<bool> ExistsAsync(AyaType ayaType, long id, AyContext ct = null)
{ {
//new up a context?? //new up a context??
if (ct == null) if (ct == null)
{ {
ct = ServiceProviderProvider.DBContext; ct = ServiceProviderProvider.DBContext;
} }
switch (aytype) switch (ayaType)
{ {
//CoreBizObject add here //CoreBizObject add here
@@ -108,7 +108,7 @@ namespace AyaNova.Biz
return await ct.WorkOrderTemplateItem.AnyAsync(m => m.Id == id); return await ct.WorkOrderTemplateItem.AnyAsync(m => m.Id == id);
default: default:
throw new System.NotSupportedException($"AyaNova.Biz.BizObjectExistsInDatabase::ExistsAsync type {aytype.ToString()} is not supported"); throw new System.NotSupportedException($"AyaNova.Biz.BizObjectExistsInDatabase::ExistsAsync type {ayaType.ToString()} is not supported");
} }
} }

View File

@@ -20,9 +20,9 @@ namespace AyaNova.Biz
//Returns the biz object class that corresponds to the type presented //Returns the biz object class that corresponds to the type presented
//Used by SEARCH and objects with JOBS //Used by SEARCH and objects with JOBS
internal static BizObject GetBizObject(AyaType aytype, AyContext dbcontext, long userId = 1, AuthorizationRoles roles = AuthorizationRoles.All) internal static BizObject GetBizObject(AyaType ayaType, AyContext dbcontext, long userId = 1, AuthorizationRoles roles = AuthorizationRoles.All)
{ {
switch (aytype) switch (ayaType)
{ {
//CoreBizObject add here //CoreBizObject add here
case AyaType.ServerJob: case AyaType.ServerJob:
@@ -92,7 +92,7 @@ namespace AyaNova.Biz
return new WorkOrderTemplateBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles); return new WorkOrderTemplateBiz(dbcontext, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles);
default: default:
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectFactory::GetBizObject type {aytype.ToString()} is not supported"); throw new System.NotSupportedException($"AyaNova.BLL.BizObjectFactory::GetBizObject type {ayaType.ToString()} is not supported");
} }
} }

View File

@@ -14,9 +14,9 @@ namespace AyaNova.Biz
//Returns existance status of object type and id specified in database //Returns existance status of object type and id specified in database
internal static string Name(AyaType aytype, long id, System.Data.Common.DbCommand cmd) internal static string Name(AyaType ayaType, long id, System.Data.Common.DbCommand cmd)
{ {
if (aytype == AyaType.NoType || id == 0) if (ayaType == AyaType.NoType || id == 0)
{ {
return "-"; return "-";
} }
@@ -26,7 +26,7 @@ namespace AyaNova.Biz
string COLUMN = "name"; string COLUMN = "name";
//CoreBizObject add here BUT ONLY ADD IF AYATYPE NAME DIFFERS FROM TABLE NAME OR NO NAME FIELD AS PRIMARY NAME-LIKE COLUMN //CoreBizObject add here BUT ONLY ADD IF AYATYPE NAME DIFFERS FROM TABLE NAME OR NO NAME FIELD AS PRIMARY NAME-LIKE COLUMN
switch (aytype) switch (ayaType)
{ {
//Oddballs only, otherwise let default handle it //Oddballs only, otherwise let default handle it
@@ -58,7 +58,7 @@ namespace AyaNova.Biz
case AyaType.WorkOrderItemUnit: case AyaType.WorkOrderItemUnit:
return "-"; return "-";
default: default:
TABLE = "a" + aytype.ToString().ToLowerInvariant(); TABLE = "a" + ayaType.ToString().ToLowerInvariant();
break; break;
} }

View File

@@ -20,7 +20,7 @@ namespace AyaNova.Biz
/// <returns></returns> /// <returns></returns>
internal static async Task LogEventToDatabaseAsync(Event newEvent, AyContext ct) internal static async Task LogEventToDatabaseAsync(Event newEvent, AyContext ct)
{ {
//System.Diagnostics.Debug.WriteLine($"Event log event for {newEvent.AyId}:{newEvent.AyType} {newEvent.AyEvent} {newEvent.Created}"); //System.Diagnostics.Debug.WriteLine($"Event log event for {newEvent.AyId}:{newEvent.AyaType} {newEvent.AyEvent} {newEvent.Created}");
await ct.Event.AddAsync(newEvent); await ct.Event.AddAsync(newEvent);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
@@ -33,14 +33,14 @@ namespace AyaNova.Biz
/// remove all prior entries for object, add one deleted entry /// remove all prior entries for object, add one deleted entry
/// </summary> /// </summary>
/// <param name="userId"></param> /// <param name="userId"></param>
/// <param name="ayType"></param> /// <param name="ayaType"></param>
/// <param name="ayId"></param> /// <param name="ayId"></param>
/// <param name="textra"></param> /// <param name="textra"></param>
/// <param name="ct"></param> /// <param name="ct"></param>
internal static async Task DeleteObjectLogAsync(long userId, AyaType ayType, long ayId, string textra, AyContext ct) internal static async Task DeleteObjectLogAsync(long userId, AyaType ayaType, long ayId, string textra, AyContext ct)
{ {
await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aevent where aytype = {ayType} and ayid={ayId}"); await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aevent where ayatype = {ayaType} and ayid={ayId}");
await ct.Event.AddAsync(new Event(userId, ayId, ayType, AyaEvent.Deleted, textra)); await ct.Event.AddAsync(new Event(userId, ayId, ayaType, AyaEvent.Deleted, textra));
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();
} }
@@ -57,7 +57,7 @@ namespace AyaNova.Biz
//Set up the query //Set up the query
var q = ct.Event.Select(m => m).AsNoTracking(); var q = ct.Event.Select(m => m).AsNoTracking();
q = q.Where(m => m.AyId == opt.AyId && m.AyType == opt.AyType); q = q.Where(m => m.AyId == opt.AyId && m.AyaType == opt.AyaType);
q = q.OrderByDescending(m => m.Created); q = q.OrderByDescending(m => m.Created);
q = q.Skip(offset).Take(limit); q = q.Skip(offset).Take(limit);
@@ -77,7 +77,7 @@ namespace AyaNova.Biz
Name = BizObjectNameFetcherDirect.Name(AyaType.User, m.UserId, command) Name = BizObjectNameFetcherDirect.Name(AyaType.User, m.UserId, command)
}).ToArray(); }).ToArray();
ret.Name = BizObjectNameFetcherDirect.Name(opt.AyType, opt.AyId, command); ret.Name = BizObjectNameFetcherDirect.Name(opt.AyaType, opt.AyId, command);
return ret; return ret;
} }
} }
@@ -115,11 +115,11 @@ namespace AyaNova.Biz
{ {
Date = m.Created, Date = m.Created,
ObjectType = m.AyType, ObjectType = m.AyaType,
ObjectId = m.AyId, ObjectId = m.AyId,
Event = m.AyEvent, Event = m.AyEvent,
Textra = m.Textra, Textra = m.Textra,
Name = BizObjectNameFetcherDirect.Name(m.AyType, m.AyId, command) Name = BizObjectNameFetcherDirect.Name(m.AyaType, m.AyId, command)
}).ToArray(); }).ToArray();
ret.Name = BizObjectNameFetcherDirect.Name(AyaType.User, opt.UserId, command); ret.Name = BizObjectNameFetcherDirect.Name(AyaType.User, opt.UserId, command);
@@ -137,14 +137,14 @@ namespace AyaNova.Biz
internal static async Task V7_Modify_LogAsync(AyaNova.Api.Controllers.EventLogController.V7Event ev, AyContext ct) internal static async Task V7_Modify_LogAsync(AyaNova.Api.Controllers.EventLogController.V7Event ev, AyContext ct)
{ {
//delete the automatically created entry from the exported object //delete the automatically created entry from the exported object
await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aevent where aytype = {ev.AyType} and ayid={ev.AyId}"); await ct.Database.ExecuteSqlInterpolatedAsync($"delete from aevent where ayatype = {ev.AyaType} and ayid={ev.AyId}");
//Now create the entries to reflect the original data from v7 //Now create the entries to reflect the original data from v7
//CREATED //CREATED
await EventLogProcessor.LogEventToDatabaseAsync(new Event(ev.Creator, ev.AyId, ev.AyType, AyaEvent.Created, ev.Created, null), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(ev.Creator, ev.AyId, ev.AyaType, AyaEvent.Created, ev.Created, null), ct);
//MODIFIED //MODIFIED
await EventLogProcessor.LogEventToDatabaseAsync(new Event(ev.Modifier, ev.AyId, ev.AyType, AyaEvent.Modified, ev.Modified, null), ct); await EventLogProcessor.LogEventToDatabaseAsync(new Event(ev.Modifier, ev.AyId, ev.AyaType, AyaEvent.Modified, ev.Modified, null), ct);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();

View File

@@ -255,10 +255,24 @@ namespace AyaNova.Biz
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
// GET ANCESTOR // GET ANCESTOR
// //
internal static async Task<AyaTypeId> GetAncestor(AyaType ayType, long id, AyContext ct) internal static async Task<AyaTypeId> GetAncestor(AyaType ayaType, long id, AyContext ct)
{ {
//Note: there could be rules checking here in future, i.e. can only get own workorder or something switch (ayaType)
//if so, then need to implement AddError and in route handle Null return with Error check just like PUT route does now {
case AyaType.WorkOrderItem:
case AyaType.WorkOrderItemExpense:
case AyaType.WorkOrderItemLabor:
case AyaType.WorkOrderItemLoan:
case AyaType.WorkOrderItemPart:
case AyaType.WorkOrderItemPartRequest:
case AyaType.WorkOrderItemScheduledUser:
case AyaType.WorkOrderItemTask:
case AyaType.WorkOrderItemTravel:
default:
throw new System.NotSupportedException($"WorkOrderBiz::GetAncestor -> AyaType {ayaType.ToString()} is not supported");
}
//https://docs.microsoft.com/en-us/ef/core/querying/related-data //https://docs.microsoft.com/en-us/ef/core/querying/related-data
//docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections //docs say this will not query twice but will recognize the duplicate woitem bit which is required for multiple grandchild collections
@@ -285,7 +299,7 @@ namespace AyaNova.Biz
.SingleOrDefaultAsync(m => m.Id == id); .SingleOrDefaultAsync(m => m.Id == id);
} }
private async Task WorkOrderSearchIndexAsync(WorkOrder obj, bool isNew) private async Task WorkOrderSearchIndexAsync(WorkOrder obj, bool isNew)

View File

@@ -19,7 +19,7 @@ namespace AyaNova.Models
[Required] [Required]
public long AyId { get; set; } public long AyId { get; set; }
[Required] [Required]
public AyaType AyType { get; set; } public AyaType AyaType { get; set; }
[Required] [Required]
public AyaEvent AyEvent { get; set; } public AyaEvent AyEvent { get; set; }
@@ -32,12 +32,12 @@ namespace AyaNova.Models
Created = System.DateTime.UtcNow; Created = System.DateTime.UtcNow;
} }
public Event(long userId, long ayId, AyaType ayType, AyaEvent ayEvent, string textra = null) public Event(long userId, long ayId, AyaType ayaType, AyaEvent ayEvent, string textra = null)
{ {
Created = System.DateTime.UtcNow; Created = System.DateTime.UtcNow;
UserId = userId; UserId = userId;
AyId = ayId; AyId = ayId;
AyType = ayType; AyaType = ayaType;
AyEvent = ayEvent; AyEvent = ayEvent;
if (textra != null) if (textra != null)
{ {
@@ -47,12 +47,12 @@ namespace AyaNova.Models
} }
} }
public Event(long userId, long ayId, AyaType ayType, AyaEvent ayEvent, DateTime created, string textra = null) public Event(long userId, long ayId, AyaType ayaType, AyaEvent ayEvent, DateTime created, string textra = null)
{ {
Created = created; Created = created;
UserId = userId; UserId = userId;
AyId = ayId; AyId = ayId;
AyType = ayType; AyaType = ayaType;
AyEvent = ayEvent; AyEvent = ayEvent;
if (textra != null) if (textra != null)
{ {

View File

@@ -144,9 +144,9 @@ namespace AyaNova.Util
//create aevent biz event log table //create aevent biz event log table
await ExecQueryAsync("CREATE TABLE aevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created timestamp not null, userid bigint not null," + await ExecQueryAsync("CREATE TABLE aevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created timestamp not null, userid bigint not null," +
"ayid bigint not null, aytype integer not null, ayevent integer not null, textra varchar(255))"); "ayid bigint not null, ayatype integer not null, ayevent integer not null, textra varchar(255))");
//INDEX: Most selective first as there is more unique ID's than unique types //INDEX: Most selective first as there is more unique ID's than unique types
await ExecQueryAsync("CREATE INDEX aevent_typeid_idx ON aevent (ayid, aytype);"); await ExecQueryAsync("CREATE INDEX aevent_typeid_idx ON aevent (ayid, ayatype);");
await ExecQueryAsync("CREATE INDEX aevent_userid_idx ON aevent (userid);"); await ExecQueryAsync("CREATE INDEX aevent_userid_idx ON aevent (userid);");