From 0ba9b971efe68d44f68326d13abae46b31b31cce Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 29 Nov 2018 16:05:35 +0000 Subject: [PATCH] --- devdocs/todo.txt | 3 +- .../Controllers/DataFilterController.cs | 10 +- server/AyaNova/biz/DataFilterBiz.cs | 114 +++++------------- 3 files changed, 33 insertions(+), 94 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index be7a7440..1d952157 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -85,7 +85,8 @@ SERVER - This object will be replicated repeatedly so it always pays to clean it up more and more - WidgetBiz Put/Patch also share nearly the same process keywords code, so move to common method!! - + - Delete user should delete private datafilters + - Did I code how to handle implications of user delete anywhere yet?? - Stage 2 AFTER POSTED TEST ROUND COMPLETED diff --git a/server/AyaNova/Controllers/DataFilterController.cs b/server/AyaNova/Controllers/DataFilterController.cs index 74d6d30a..7d79dc7a 100644 --- a/server/AyaNova/Controllers/DataFilterController.cs +++ b/server/AyaNova/Controllers/DataFilterController.cs @@ -51,7 +51,7 @@ namespace AyaNova.Api.Controllers /// Get full DataFilter object /// /// Required roles: - /// BizAdminFull, InventoryFull, BizAdminLimited, InventoryLimited, TechFull, TechLimited, Accounting + /// Any (for public filter), owned only for private filter /// /// /// A single DataFilter @@ -85,7 +85,7 @@ namespace AyaNova.Api.Controllers /// Required roles: Any /// /// - /// Paged id/name collection of DataFilters with paging data + /// List of public or owned data filters for listKey provided [HttpGet("PickList", Name = nameof(DataFilterPickList))] public async Task DataFilterPickList([FromQuery] string ListKey) { @@ -108,8 +108,7 @@ namespace AyaNova.Api.Controllers /// Put (update) DataFilter /// /// Required roles: - /// BizAdminFull, InventoryFull - /// TechFull (owned only) + /// Any (public filter) or owned only (private filter) /// /// /// @@ -189,8 +188,7 @@ namespace AyaNova.Api.Controllers /// Delete DataFilter /// /// Required roles: - /// BizAdminFull, InventoryFull - /// TechFull (owned only) + /// Any if public otherwise creator only /// /// /// diff --git a/server/AyaNova/biz/DataFilterBiz.cs b/server/AyaNova/biz/DataFilterBiz.cs index 34eb7e57..7bd0c526 100644 --- a/server/AyaNova/biz/DataFilterBiz.cs +++ b/server/AyaNova/biz/DataFilterBiz.cs @@ -15,7 +15,7 @@ namespace AyaNova.Biz { - internal class DataFilterBiz : BizObject, IJobObject + internal class DataFilterBiz : BizObject { internal DataFilterBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) @@ -129,26 +129,6 @@ namespace AyaNova.Biz return ret; } - // //get many (paged) - // internal async Task> GetManyAsync(IUrlHelper Url, string routeName, PagingOptions pagingOptions) - // { - - // pagingOptions.Offset = pagingOptions.Offset ?? PagingOptions.DefaultOffset; - // pagingOptions.Limit = pagingOptions.Limit ?? PagingOptions.DefaultLimit; - - // var items = await ct.DataFilter - // .OrderBy(m => m.Id) - // .Skip(pagingOptions.Offset.Value) - // .Take(pagingOptions.Limit.Value) - // .ToArrayAsync(); - - // var totalRecordCount = await ct.DataFilter.CountAsync(); - // var pageLinks = new PaginationLinkBuilder(Url, routeName, null, pagingOptions, totalRecordCount).PagingLinksObject(); - - // ApiPagedResponse pr = new ApiPagedResponse(items, pageLinks); - // return pr; - // } - //get picklist (NOT PAGED) internal async Task> GetPickListAsync(string listKey) @@ -222,9 +202,6 @@ namespace AyaNova.Biz //Delete search index Search.ProcessDeletedObjectKeywords(dbObj.Id, BizType); - //TAGS - TagMapBiz.DeleteAllForObject(new AyaTypeId(BizType, dbObj.Id), ct); - ct.SaveChanges(); return true; } @@ -236,15 +213,6 @@ namespace AyaNova.Biz //Can save or update? private void Validate(DataFilter inObj, bool isNew) { - //run validation and biz rules - if (isNew) - { - //NEW datafilters must be active - if (inObj.Active == null || ((bool)inObj.Active) == false) - { - AddError(ValidationErrorType.InvalidValue, "Active", "New datafilter must be active"); - } - } //OwnerId required if (!isNew) @@ -253,6 +221,10 @@ namespace AyaNova.Biz AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); } + //Owner must be current user, there are no exceptions + if (inObj.OwnerId != UserId) + AddError(ValidationErrorType.InvalidValue, "OwnerId", "OwnerId must be current user Id"); + //Name required if (string.IsNullOrWhiteSpace(inObj.Name)) AddError(ValidationErrorType.RequiredPropertyEmpty, "Name"); @@ -271,25 +243,11 @@ namespace AyaNova.Biz } } - //Start date AND end date must both be null or both contain values - if (inObj.StartDate == null && inObj.EndDate != null) - AddError(ValidationErrorType.RequiredPropertyEmpty, "StartDate"); - - if (inObj.StartDate != null && inObj.EndDate == null) - AddError(ValidationErrorType.RequiredPropertyEmpty, "EndDate"); - - //Start date before end date - if (inObj.StartDate != null && inObj.EndDate != null) - if (inObj.StartDate > inObj.EndDate) - AddError(ValidationErrorType.StartDateMustComeBeforeEndDate, "StartDate"); - - //Enum is valid value - - if (!inObj.Roles.IsValid()) - { - AddError(ValidationErrorType.InvalidValue, "Roles"); - } + if (string.IsNullOrWhiteSpace(inObj.ListKey)) + AddError(ValidationErrorType.RequiredPropertyEmpty, "ListKey"); + if (inObj.ListKey.Length > 255) + AddError(ValidationErrorType.LengthExceeded, "ListKey", "255 max"); return; } @@ -298,48 +256,30 @@ namespace AyaNova.Biz //Can delete? private void ValidateCanDelete(DataFilter inObj) { - //whatever needs to be check to delete this object + //Leaving this off for now } - //////////////////////////////////////////////////////////////////////////////////////////////// - //JOB / OPERATIONS - // - public async Task HandleJobAsync(OpsJob job) - { - //Hand off the particular job to the corresponding processing code - //NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so - //basically any error condition during job processing should throw up an exception if it can't be handled - switch (job.JobType) - { - case JobType.TestDataFilterJob: - await ProcessTestJobAsync(job); - break; - default: - throw new System.ArgumentOutOfRangeException($"DataFilterBiz.HandleJob-> Invalid job type{job.JobType.ToString()}"); - } - } + // //////////////////////////////////////////////////////////////////////////////////////////////// + // //JOB / OPERATIONS + // // + // public async Task HandleJobAsync(OpsJob job) + // { + // //Hand off the particular job to the corresponding processing code + // //NOTE: If this code throws an exception the caller (JobsBiz::ProcessJobsAsync) will automatically set the job to failed and log the exeption so + // //basically any error condition during job processing should throw up an exception if it can't be handled + // switch (job.JobType) + // { + // case JobType.TestDataFilterJob: + // await ProcessTestJobAsync(job); + // break; + // default: + // throw new System.ArgumentOutOfRangeException($"DataFilterBiz.HandleJob-> Invalid job type{job.JobType.ToString()}"); + // } + // } - /// - /// /// Handle the test job - /// - /// - private async Task ProcessTestJobAsync(OpsJob job) - { - var sleepTime = 30 * 1000; - //Simulate a long running job here - JobsBiz.UpdateJobStatus(job.GId, JobStatus.Running, ct); - JobsBiz.LogJob(job.GId, $"DataFilterBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct); - //Uncomment this to test if the job prevents other routes from running - //result is NO it doesn't prevent other requests, so we are a-ok for now - await Task.Delay(sleepTime); - JobsBiz.LogJob(job.GId, "DataFilterBiz::ProcessTestJob done sleeping setting job to finished", ct); - JobsBiz.UpdateJobStatus(job.GId, JobStatus.Completed, ct); - - } - //Other job handlers here...