This commit is contained in:
2020-03-06 21:50:53 +00:00
parent d17e88db12
commit 2adcc9f016
8 changed files with 24 additions and 20 deletions

View File

@@ -368,7 +368,7 @@ namespace AyaNova
var ct = context.RequestServices.GetService<AyContext>(); var ct = context.RequestServices.GetService<AyContext>();
//get the user record //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_ROLES"] = u.roles;
context.Request.HttpContext.Items["AY_USERNAME"] = u.name; context.Request.HttpContext.Items["AY_USERNAME"] = u.name;
context.Request.HttpContext.Items["AY_USER_ID"] = u.id; context.Request.HttpContext.Items["AY_USER_ID"] = u.id;

View File

@@ -28,9 +28,10 @@ namespace AyaNova.Biz
u.Password = Hasher.hash(u.Salt, "l3tm3in"); u.Password = Hasher.hash(u.Salt, "l3tm3in");
u.Roles = AuthorizationRoles.All;//AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull; 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.UserType = UserType.Administrator;
u.UserOptions = new UserOptions(); u.UserOptions = new UserOptions();
u.UserOptions.TranslationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;//Ensure primeTranslations is called first
await ct.User.AddAsync(u); await ct.User.AddAsync(u);
await ct.SaveChangesAsync(); await ct.SaveChangesAsync();

View File

@@ -334,7 +334,7 @@ namespace AyaNova.Biz
} }
//See if any users exist with this translation selected in which case it's not deleteable //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"); AddError(ApiErrorCode.VALIDATION_REFERENTIAL_INTEGRITY, "object", "Can't be deleted in use by one or more Users");
return; return;

View File

@@ -456,7 +456,7 @@ namespace AyaNova.Biz
Active = o.Active, Active = o.Active,
Name = o.Name, Name = o.Name,
Roles = o.Roles, Roles = o.Roles,
TranslationId = o.TranslationId, TranslationId = o.UserOptions.TranslationId,
UserType = o.UserType, UserType = o.UserType,
EmployeeNumber = o.EmployeeNumber, EmployeeNumber = o.EmployeeNumber,
Notes = o.Notes, Notes = o.Notes,
@@ -673,7 +673,7 @@ namespace AyaNova.Biz
i.Roles = AuthorizationRoles.NoRole; i.Roles = AuthorizationRoles.NoRole;
//temporary translation id to satisfy db settings //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); User o = await CreateAsync(i);
if (HasErrors) if (HasErrors)
@@ -754,7 +754,7 @@ namespace AyaNova.Biz
break; break;
} }
u.TranslationId = await TranslationBiz.TranslationNameToIdStaticAsync(NewTranslationName, ct); u.UserOptions.TranslationId = await TranslationBiz.TranslationNameToIdStaticAsync(NewTranslationName, ct);
ct.SaveChanges(); ct.SaveChanges();
#endregion set translation #endregion set translation

View File

@@ -22,8 +22,8 @@ namespace AyaNova.Models
public string Salt { get; set; } public string Salt { get; set; }
[Required] [Required]
public AuthorizationRoles Roles { get; set; } public AuthorizationRoles Roles { get; set; }
[Required] // [Required]
public long TranslationId { get; set; } // public long TranslationId { get; set; }
public string DlKey { get; set; } public string DlKey { get; set; }
public DateTime? DlKeyExpire { get; set; } public DateTime? DlKeyExpire { get; set; }

View File

@@ -8,16 +8,18 @@ namespace AyaNova.Models
public long Id { get; set; } public long Id { get; set; }
public uint ConcurrencyToken { get; set; } public uint ConcurrencyToken { get; set; }
[Required]
public long TranslationId { get; set; }
//------------- //-------------
[EmailAddress] [EmailAddress]
public string EmailAddress { get; set; } public string EmailAddress { get; set; }
/* /*
Hexadecimal notation: #RGB[A] Hexadecimal notation: #RGB[A]
R (red), G (green), B (blue), and A (alpha) are hexadecimal characters (09, AF). 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. R (red), G (green), B (blue), and A (alpha) are hexadecimal characters (09, AF). 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)] [MaxLength(12)]
public string UiColor { get; set; } public string UiColor { get; set; }
//browser forced overrides //browser forced overrides

View File

@@ -168,7 +168,7 @@ namespace AyaNova.Util
//Add user table //Add user table
await ExecQueryAsync("CREATE TABLE auser (id BIGSERIAL PRIMARY KEY, active bool not null, name varchar(255) not null unique, " + 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, " + "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)"); "headofficeid bigint, subvendorid bigint, customfields text, tags varchar(255) ARRAY)");
@@ -177,7 +177,7 @@ namespace AyaNova.Util
//Add user options table //Add user options table
await ExecQueryAsync("CREATE TABLE auseroptions (id BIGSERIAL PRIMARY KEY, " + 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 //Prime the db with the default MANAGER account

View File

@@ -582,7 +582,7 @@ namespace AyaNova.Util
else else
u.Password = u.Login; u.Password = u.Login;
u.Roles = roles; u.Roles = roles;
u.TranslationId = translationId;
u.UserType = userType; u.UserType = userType;
u.EmployeeNumber = "A-" + (454 + SeededUserCount).ToString() + "-Y"; u.EmployeeNumber = "A-" + (454 + SeededUserCount).ToString() + "-Y";
u.Notes = Fake.Lorem.Sentence();//Fake.Lorem.Paragraph(2); u.Notes = Fake.Lorem.Sentence();//Fake.Lorem.Paragraph(2);
@@ -590,10 +590,11 @@ namespace AyaNova.Util
u.Tags = RandomTags(Fake); u.Tags = RandomTags(Fake);
//Children and relations //Children and relations
u.UserOptions = new UserOptions(); 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.EmailAddress = p.Email.Replace("gmail.com", "helloayanova.com").Replace("hotmail.com", "helloayanova.com").Replace("yahoo.com", "helloayanova.com");
u.UserOptions.Hour12 = true; u.UserOptions.Hour12 = true;
u.UserOptions.CurrencyName = "USD"; 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); // WidgetBiz biz = WidgetBiz.GetBiz(ServiceProviderProvider.DBContext);
var f = new Bogus.Faker(); var f = new Bogus.Faker();
//RANDOM ROLES //RANDOM ROLES
Array values = Enum.GetValues(typeof(UserType)); Array values = Enum.GetValues(typeof(UserType));