From 945de40c164c5423bdb177f1d7f1a4f47f44a9ac Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 27 Nov 2020 16:14:14 +0000 Subject: [PATCH] --- .../ControllerHelpers/ImportModeFromContext.cs | 11 +++++++++++ server/AyaNova/Startup.cs | 5 +++++ server/AyaNova/biz/BizObject.cs | 4 +++- server/AyaNova/biz/BizObjectFactory.cs | 4 ++-- server/AyaNova/biz/CustomerBiz.cs | 7 ++++--- server/AyaNova/util/DbUtil.cs | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 server/AyaNova/ControllerHelpers/ImportModeFromContext.cs diff --git a/server/AyaNova/ControllerHelpers/ImportModeFromContext.cs b/server/AyaNova/ControllerHelpers/ImportModeFromContext.cs new file mode 100644 index 00000000..19ec0ccc --- /dev/null +++ b/server/AyaNova/ControllerHelpers/ImportModeFromContext.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +namespace AyaNova.Api.ControllerHelpers +{ + internal static class ImportModeFromContext + { + internal static bool ImportMode(IDictionary HttpContextItems) + { + return HttpContextItems["AY_IMPORT_MODE"] != null; + } + } +}//eons \ No newline at end of file diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 93df9d05..9a8df89b 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -463,6 +463,11 @@ namespace AyaNova context.Request.HttpContext.Items["AY_USER_ID"] = u.id; context.Request.HttpContext.Items["AY_TRANSLATION_ID"] = u.translationId; + //Is import mode header set? + + context.Request.HttpContext.Items["AY_IMPORT_MODE"]= context.Request.Headers.ContainsKey("X-AY-Import-Mode"); + + //CHECK JWT if ( !context.Request.Path.Value.EndsWith("/auth") && diff --git a/server/AyaNova/biz/BizObject.cs b/server/AyaNova/biz/BizObject.cs index d4d350d4..831e6ba5 100644 --- a/server/AyaNova/biz/BizObject.cs +++ b/server/AyaNova/biz/BizObject.cs @@ -13,7 +13,8 @@ namespace AyaNova.Biz public BizObject() { - + //default + ImportMode=false; } @@ -27,6 +28,7 @@ namespace AyaNova.Biz internal long UserId { get; set; } internal long UserTranslationId { get; set; } internal AuthorizationRoles CurrentUserRoles { get; set; } + internal bool ImportMode { get; set; }//mostly for v8 migrate notification disabling purposes but could be used for other things D.T.R. (down the road) #endregion diff --git a/server/AyaNova/biz/BizObjectFactory.cs b/server/AyaNova/biz/BizObjectFactory.cs index 01450694..0bb9ea67 100644 --- a/server/AyaNova/biz/BizObjectFactory.cs +++ b/server/AyaNova/biz/BizObjectFactory.cs @@ -12,7 +12,7 @@ namespace AyaNova.Biz //Returns the biz object class that corresponds to the type presented //Used by SEARCH and objects with JOBS - internal static BizObject GetBizObject(AyaType ayaType, AyContext ct, long userId = 1, AuthorizationRoles roles = AuthorizationRoles.All) + internal static BizObject GetBizObject(AyaType ayaType, AyContext ct, long userId = 1, AuthorizationRoles roles = AuthorizationRoles.All, bool InImportMode=false) { switch (ayaType) @@ -33,7 +33,7 @@ namespace AyaNova.Biz case AyaType.FileAttachment: return new AttachmentBiz(ct, userId, roles); case AyaType.Customer: - return new CustomerBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles); + return new CustomerBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles, InImportMode); case AyaType.CustomerNote: return new CustomerNoteBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles); case AyaType.User: diff --git a/server/AyaNova/biz/CustomerBiz.cs b/server/AyaNova/biz/CustomerBiz.cs index dec2071e..2d965175 100644 --- a/server/AyaNova/biz/CustomerBiz.cs +++ b/server/AyaNova/biz/CustomerBiz.cs @@ -13,21 +13,22 @@ namespace AyaNova.Biz { internal class CustomerBiz : BizObject, IJobObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject, IImportAbleObject { - internal CustomerBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles) + internal CustomerBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles, bool InImportMode) { ct = dbcontext; UserId = currentUserId; UserTranslationId = userTranslationId; CurrentUserRoles = UserRoles; BizType = AyaType.Customer; + ImportMode = InImportMode; } internal static CustomerBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null) { if (httpContext != null) - return new CustomerBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items)); + return new CustomerBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items), ImportModeFromContext.ImportMode(httpContext.Items)); else - return new CustomerBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull); + return new CustomerBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull, false); } //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs index f2b07e3f..55370f3d 100644 --- a/server/AyaNova/util/DbUtil.cs +++ b/server/AyaNova/util/DbUtil.cs @@ -251,7 +251,7 @@ namespace AyaNova.Util ///////////////////////////////////////////////////////// // Erase all user entered data from the db // This is called by seeder for trial seeding purposes - // + // and by v8 migrate v7 exporter internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log) {