This commit is contained in:
@@ -30,8 +30,7 @@ IMMEDIATE ITEMS:
|
||||
|
||||
|
||||
- Search and search text indexing
|
||||
- NEXT UP: See the integration tests for the next things to be done
|
||||
- Add tests for searching and routes, test all variants of search including rights related stuff
|
||||
|
||||
- Update all the seeder code to add search indexing so can properly test huge search datasets
|
||||
- Need to find a way to add random text to Notes fields that varies but has some overlap ideally
|
||||
- bugbug: why is the single letter a being indexed? Missing shortness filter, A not in stopwords for english??
|
||||
|
||||
@@ -73,8 +73,8 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
var o = await biz.GetAsync(id);
|
||||
|
||||
if (o == null)
|
||||
@@ -83,7 +83,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.User, AyaEvent.Retrieved), ct);
|
||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Retrieved), ct);
|
||||
ct.SaveChanges();
|
||||
return Ok(new ApiOkResponse(o));
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
ApiPagedResponse<System.Object> pr = await biz.GetManyAsync(Url, nameof(ListUsers), pagingOptions);
|
||||
return Ok(new ApiOkWithPagingResponse<System.Object>(pr));
|
||||
@@ -154,8 +154,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
ApiPagedResponse<NameIdItem> pr = await biz.GetPickListAsync(Url, nameof(UserPickList), pagingOptions, q);
|
||||
return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
|
||||
}
|
||||
@@ -197,7 +196,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
if (!biz.Put(o, inObj))
|
||||
{
|
||||
@@ -207,7 +206,7 @@ namespace AyaNova.Api.Controllers
|
||||
try
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.User, AyaEvent.Modified), ct);
|
||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Modified), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
|
||||
}
|
||||
@@ -258,8 +257,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
var o = await ct.User.SingleOrDefaultAsync(m => m.Id == id);
|
||||
|
||||
@@ -282,7 +280,7 @@ namespace AyaNova.Api.Controllers
|
||||
try
|
||||
{
|
||||
//Log
|
||||
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.User, AyaEvent.Modified), ct);
|
||||
EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, AyaType.User, AyaEvent.Modified), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
|
||||
}
|
||||
@@ -334,7 +332,7 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
|
||||
//Create and validate
|
||||
User o = await biz.CreateAsync(inObj);
|
||||
@@ -350,8 +348,6 @@ namespace AyaNova.Api.Controllers
|
||||
//EVENT LOG
|
||||
//Note that event log is processed in the biz object unlike the widget for no apparent reason
|
||||
|
||||
//SEARCH INDEXING
|
||||
Search.ProcessNewObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.User, o.Name, o.EmployeeNumber, o.Notes, o.Name);
|
||||
|
||||
//return success and link
|
||||
//NOTE: this is a USER object so we don't want to return some key fields for security reasons
|
||||
@@ -397,14 +393,14 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
|
||||
//Instantiate the business object handler
|
||||
UserBiz biz = new UserBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
UserBiz biz = UserBiz.GetBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserLocaleIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items));
|
||||
if (!biz.Delete(dbObj))
|
||||
{
|
||||
return BadRequest(new ApiErrorResponse(biz.Errors));
|
||||
}
|
||||
|
||||
//Log
|
||||
EventLogProcessor.DeleteObject(biz.userId, AyaType.User, dbObj.Id, dbObj.Name, ct);
|
||||
EventLogProcessor.DeleteObject(biz.UserId, AyaType.User, dbObj.Id, dbObj.Name, ct);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Delete children / attached objects
|
||||
|
||||
@@ -19,19 +19,27 @@ namespace AyaNova.Biz
|
||||
internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object
|
||||
{
|
||||
private readonly AyContext ct;
|
||||
public readonly long userId;
|
||||
public readonly long UserId;
|
||||
public readonly long UserLocaleId;
|
||||
private readonly AuthorizationRoles userRoles;
|
||||
public bool V7ValidationImportMode { get; set; }
|
||||
|
||||
internal UserBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles)
|
||||
internal UserBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles)
|
||||
{
|
||||
ct = dbcontext;
|
||||
userId = currentUserId;
|
||||
UserId = currentUserId;
|
||||
UserLocaleId = userLocaleId;
|
||||
userRoles = UserRoles;
|
||||
V7ValidationImportMode = false;//default
|
||||
}
|
||||
|
||||
|
||||
internal static UserBiz GetBiz(AyContext ct, HttpContextExtensions , AuthorizationRoles UserRoles)
|
||||
{
|
||||
//long currentUserId, long userLocaleId
|
||||
return new UserBiz(ct, currentUserId, userLocaleId, UserRoles);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE
|
||||
internal async Task<User> CreateAsync(User inObj)
|
||||
@@ -47,8 +55,8 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//do stuff with User
|
||||
User outObj = inObj;
|
||||
outObj.OwnerId = userId;
|
||||
outObj.UserOptions = new UserOptions(userId);
|
||||
outObj.OwnerId = UserId;
|
||||
outObj.UserOptions = new UserOptions(UserId);
|
||||
|
||||
await ct.User.AddAsync(outObj);
|
||||
//save to get Id
|
||||
@@ -56,18 +64,19 @@ namespace AyaNova.Biz
|
||||
|
||||
//Handle child and associated items
|
||||
|
||||
//SearchHelper(break down text fields, save to db)
|
||||
//TagHelper(collection of tags??)
|
||||
//Associated user options object
|
||||
UserOptions options = new UserOptions(UserId);
|
||||
options.User = outObj;
|
||||
ct.UserOptions.Add(options);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Log event
|
||||
EventLogProcessor.AddEntry(new Event(userId, outObj.Id, AyaType.User, AyaEvent.Created), ct);
|
||||
|
||||
// UserOptions options = new UserOptions(outObj.Id, userId);
|
||||
// ct.UserOptions.Add(options);
|
||||
|
||||
//Save the final changes
|
||||
EventLogProcessor.AddEntry(new Event(UserId, outObj.Id, AyaType.User, AyaEvent.Created), ct);
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//SEARCH INDEXING
|
||||
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, AyaType.User, outObj.Name, outObj.EmployeeNumber, outObj.Notes, outObj.Name);
|
||||
|
||||
return outObj;
|
||||
|
||||
}
|
||||
|
||||
@@ -283,6 +283,62 @@ namespace AyaNova.Util
|
||||
}
|
||||
|
||||
|
||||
public static void GenSeedUserViaBiz(int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
|
||||
{
|
||||
AyContext ct = ServiceProviderProvider.DBContext;
|
||||
|
||||
for (int x = 0; x < count; x++)
|
||||
{
|
||||
User u = new User();
|
||||
u.Active = active;
|
||||
u.OwnerId = 1;
|
||||
var p = new Bogus.Person();
|
||||
u.Name = p.FullName;
|
||||
u.Salt = Hasher.GenerateSalt();
|
||||
if (login != null)
|
||||
{
|
||||
u.Login = login;
|
||||
u.Name += " - " + login;
|
||||
}
|
||||
else
|
||||
u.Login = p.FirstName;
|
||||
if (password != null)
|
||||
u.Password = Hasher.hash(u.Salt, password);
|
||||
else
|
||||
u.Password = Hasher.hash(u.Salt, u.Login);
|
||||
u.Roles = roles;
|
||||
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;
|
||||
u.UserType = userType;
|
||||
//TODO: After have USER and HEADOFFICE and VENDOR, if usertype is subcontractor or client or headoffice it needs to set a corresponding user's parent org record id to go with it
|
||||
|
||||
//Children and relations
|
||||
u.UserOptions = new UserOptions(1);
|
||||
u.UserOptions.EmailAddress = p.Email.Replace("gmail.com","helloayanova.com").Replace("hotmail.com","helloayanova.com").Replace("yahoo.com","helloayanova.com");
|
||||
|
||||
ct.User.Add(u);
|
||||
}
|
||||
//save to get id values
|
||||
ct.SaveChanges();
|
||||
|
||||
//Now that we have the ID values bulk add the event log entries
|
||||
//To save a db call iterate the local collection in the context, but...
|
||||
//can't modify the context in the foreach, even if it's another collection entirely, so need to save the id's in a temporary list
|
||||
List<long> ItemsAdded = new List<long>();
|
||||
foreach (User o in ct.User.Local)
|
||||
{
|
||||
ItemsAdded.Add(o.Id);
|
||||
}
|
||||
|
||||
//Now we have all the id's can actually add them to the context
|
||||
foreach (long l in ItemsAdded)
|
||||
{
|
||||
EventLogProcessor.AddEntry(new Event(1, l, AyaType.User, AyaEvent.Created), ct);
|
||||
}
|
||||
|
||||
//Now save the Event Log entries
|
||||
ct.SaveChanges();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
//Seed widget for testing
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user