V13: Add Guids to Users (#13868)
* Add MSSQL migration * Make upgrade possible when user doesn't have a key yet * Migrate SQLite * Migrate the external login column * Fix logging in after migration * Handle fake GUID correctly * Make GetByKey async * Resolve external logins by key instead of id * Remove usage of naive UserIdToInt * Dont use ToGuid for property type defaults * Use constant GUID for user groups * Ensure that the same GUID is used to create the root user. * Add migration for two factor logins * Add default implementations * Fix unit test * Remove TODO * Fix integration tests * Add default implementation instead of throwing Co-authored-by: Bjarke Berg <mail@bergmania.dk> * Make SQLServer migration idempotent * Add comment about SQLite * Fix typo --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -251,8 +251,22 @@ internal class UserService : RepositoryService, IUserService
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
IQuery<IUser> query = Query<IUser>().Where(x => x.Email.Equals(email));
|
||||
return _userRepository.Get(query)?.FirstOrDefault();
|
||||
try
|
||||
{
|
||||
IQuery<IUser> query = Query<IUser>().Where(x => x.Email.Equals(email));
|
||||
return _userRepository.Get(query)?.FirstOrDefault();
|
||||
}
|
||||
catch(DbException)
|
||||
{
|
||||
// We also need to catch upgrade state here, because the framework will try to call this to validate the email.
|
||||
if (IsUpgrading)
|
||||
{
|
||||
return _userRepository.GetForUpgradeByEmail(email);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +299,7 @@ internal class UserService : RepositoryService, IUserService
|
||||
if (IsUpgrading)
|
||||
{
|
||||
// NOTE: this will not be cached
|
||||
return _userRepository.GetByUsername(username, false);
|
||||
return _userRepository.GetForUpgradeByUsername(username);
|
||||
}
|
||||
|
||||
throw;
|
||||
@@ -802,7 +816,7 @@ internal class UserService : RepositoryService, IUserService
|
||||
if (IsUpgrading)
|
||||
{
|
||||
// NOTE: this will not be cached
|
||||
return _userRepository.Get(id, false);
|
||||
return _userRepository.GetForUpgrade(id);
|
||||
}
|
||||
|
||||
throw;
|
||||
@@ -810,6 +824,15 @@ internal class UserService : RepositoryService, IUserService
|
||||
}
|
||||
}
|
||||
|
||||
public Task<IUser?> GetAsync(Guid key)
|
||||
{
|
||||
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
IQuery<IUser> query = Query<IUser>().Where(x => x.Key == key);
|
||||
return Task.FromResult(_userRepository.Get(query).FirstOrDefault());
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IUser> GetUsersById(params int[]? ids)
|
||||
{
|
||||
if (ids?.Length <= 0)
|
||||
|
||||
Reference in New Issue
Block a user