From 2adcc9f01653cca1a95099497e7af7f7be332631 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 6 Mar 2020 21:50:53 +0000 Subject: [PATCH] --- server/AyaNova/Startup.cs | 2 +- server/AyaNova/biz/PrimeData.cs | 3 ++- server/AyaNova/biz/TranslationBiz.cs | 2 +- server/AyaNova/biz/UserBiz.cs | 6 +++--- server/AyaNova/models/User.cs | 4 ++-- server/AyaNova/models/UserOptions.cs | 16 +++++++++------- server/AyaNova/util/AySchema.cs | 4 ++-- server/AyaNova/util/Seeder.cs | 7 ++++--- 8 files changed, 24 insertions(+), 20 deletions(-) diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 49627173..2d1a37d2 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -368,7 +368,7 @@ namespace AyaNova var ct = context.RequestServices.GetService(); //get the user record - var u = await ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, translationId = m.TranslationId }).FirstAsync(); + var u = await ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, translationId = m.UserOptions.TranslationId }).FirstAsync(); context.Request.HttpContext.Items["AY_ROLES"] = u.roles; context.Request.HttpContext.Items["AY_USERNAME"] = u.name; context.Request.HttpContext.Items["AY_USER_ID"] = u.id; diff --git a/server/AyaNova/biz/PrimeData.cs b/server/AyaNova/biz/PrimeData.cs index 2512c29c..0c4f58d7 100644 --- a/server/AyaNova/biz/PrimeData.cs +++ b/server/AyaNova/biz/PrimeData.cs @@ -28,9 +28,10 @@ namespace AyaNova.Biz u.Password = Hasher.hash(u.Salt, "l3tm3in"); u.Roles = AuthorizationRoles.All;//AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull; - u.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;//Ensure primeTranslations is called first + u.UserType = UserType.Administrator; u.UserOptions = new UserOptions(); + u.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;//Ensure primeTranslations is called first await ct.User.AddAsync(u); await ct.SaveChangesAsync(); diff --git a/server/AyaNova/biz/TranslationBiz.cs b/server/AyaNova/biz/TranslationBiz.cs index b850d2a4..81d599d1 100644 --- a/server/AyaNova/biz/TranslationBiz.cs +++ b/server/AyaNova/biz/TranslationBiz.cs @@ -334,7 +334,7 @@ namespace AyaNova.Biz } //See if any users exist with this translation selected in which case it's not deleteable - if (await ct.User.AnyAsync(e => e.TranslationId == inObj.Id)) + if (await ct.UserOptions.AnyAsync(e => e.TranslationId == inObj.Id)) { AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "object", "Can't be deleted in use by one or more Users"); return; diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 6c4d629d..2f6b6667 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -456,7 +456,7 @@ namespace AyaNova.Biz Active = o.Active, Name = o.Name, Roles = o.Roles, - TranslationId = o.TranslationId, + TranslationId = o.UserOptions.TranslationId, UserType = o.UserType, EmployeeNumber = o.EmployeeNumber, Notes = o.Notes, @@ -673,7 +673,7 @@ namespace AyaNova.Biz i.Roles = AuthorizationRoles.NoRole; //temporary translation id to satisfy db settings - i.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID; + i.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID; User o = await CreateAsync(i); if (HasErrors) @@ -754,7 +754,7 @@ namespace AyaNova.Biz break; } - u.TranslationId = await TranslationBiz.TranslationNameToIdStaticAsync(NewTranslationName, ct); + u.UserOptions.TranslationId = await TranslationBiz.TranslationNameToIdStaticAsync(NewTranslationName, ct); ct.SaveChanges(); #endregion set translation diff --git a/server/AyaNova/models/User.cs b/server/AyaNova/models/User.cs index af3d0c35..b25e54e5 100644 --- a/server/AyaNova/models/User.cs +++ b/server/AyaNova/models/User.cs @@ -22,8 +22,8 @@ namespace AyaNova.Models public string Salt { get; set; } [Required] public AuthorizationRoles Roles { get; set; } - [Required] - public long TranslationId { get; set; } + // [Required] + // public long TranslationId { get; set; } public string DlKey { get; set; } public DateTime? DlKeyExpire { get; set; } diff --git a/server/AyaNova/models/UserOptions.cs b/server/AyaNova/models/UserOptions.cs index 87353bf1..8b27d84d 100644 --- a/server/AyaNova/models/UserOptions.cs +++ b/server/AyaNova/models/UserOptions.cs @@ -8,16 +8,18 @@ namespace AyaNova.Models public long Id { get; set; } public uint ConcurrencyToken { get; set; } - + [Required] + public long TranslationId { get; set; } + //------------- [EmailAddress] public string EmailAddress { get; set; } - - /* - Hexadecimal notation: #RGB[A] - R (red), G (green), B (blue), and A (alpha) are hexadecimal characters (0–9, A–F). A is optional. The three-digit notation (#RGB) is a shorter version of the six-digit form (#RRGGBB). For example, #f09 is the same color as #ff0099. Likewise, the four-digit RGB notation (#RGBA) is a shorter version of the eight-digit form (#RRGGBBAA). For example, #0f38 is the same color as #00ff3388. - */ - [MaxLength(12)] + + /* + Hexadecimal notation: #RGB[A] + R (red), G (green), B (blue), and A (alpha) are hexadecimal characters (0–9, A–F). A is optional. The three-digit notation (#RGB) is a shorter version of the six-digit form (#RRGGBB). For example, #f09 is the same color as #ff0099. Likewise, the four-digit RGB notation (#RGBA) is a shorter version of the eight-digit form (#RRGGBBAA). For example, #0f38 is the same color as #00ff3388. + */ + [MaxLength(12)] public string UiColor { get; set; } //browser forced overrides diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index a322f120..ad032b44 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -168,7 +168,7 @@ namespace AyaNova.Util //Add user table await ExecQueryAsync("CREATE TABLE auser (id BIGSERIAL PRIMARY KEY, active bool not null, name varchar(255) not null unique, " + - "login text not null, password text not null, salt text not null, roles integer not null, translationid bigint not null REFERENCES atranslation (id), " + + "login text not null, password text not null, salt text not null, roles integer not null, " + "dlkey text, dlkeyexpire timestamp, usertype integer not null, employeenumber varchar(255), notes text, customerid bigint, " + "headofficeid bigint, subvendorid bigint, customfields text, tags varchar(255) ARRAY)"); @@ -177,7 +177,7 @@ namespace AyaNova.Util //Add user options table await ExecQueryAsync("CREATE TABLE auseroptions (id BIGSERIAL PRIMARY KEY, " + - "userid bigint not null, languageoverride text, timezoneoverride text, currencyname text, hour12 bool not null, emailaddress text, uicolor varchar(12) not null default '#000000')"); + "userid bigint not null, translationid bigint not null REFERENCES atranslation (id), languageoverride text, timezoneoverride text, currencyname text, hour12 bool not null, emailaddress text, uicolor varchar(12) not null default '#000000')"); //Prime the db with the default MANAGER account diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index 1dc72652..95d61733 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -582,7 +582,7 @@ namespace AyaNova.Util else u.Password = u.Login; u.Roles = roles; - u.TranslationId = translationId; + u.UserType = userType; u.EmployeeNumber = "A-" + (454 + SeededUserCount).ToString() + "-Y"; u.Notes = Fake.Lorem.Sentence();//Fake.Lorem.Paragraph(2); @@ -590,10 +590,11 @@ namespace AyaNova.Util u.Tags = RandomTags(Fake); //Children and relations u.UserOptions = new UserOptions(); + u.UserOptions.TranslationId = translationId; u.UserOptions.EmailAddress = p.Email.Replace("gmail.com", "helloayanova.com").Replace("hotmail.com", "helloayanova.com").Replace("yahoo.com", "helloayanova.com"); u.UserOptions.Hour12 = true; u.UserOptions.CurrencyName = "USD"; - u.UserOptions.UiColor= Fake.Internet.Color(); + u.UserOptions.UiColor = Fake.Internet.Color(); @@ -625,7 +626,7 @@ namespace AyaNova.Util // WidgetBiz biz = WidgetBiz.GetBiz(ServiceProviderProvider.DBContext); var f = new Bogus.Faker(); - + //RANDOM ROLES Array values = Enum.GetValues(typeof(UserType));