V13: Add default superuser key (#13955)
* Add default super user key to migrations * Minor tweaks * Obsolete superuser id --------- Co-authored-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Nikolaj <nikolajlauridsen@protonmail.ch>
This commit is contained in:
@@ -7,8 +7,15 @@ public static partial class Constants
|
||||
/// <summary>
|
||||
/// Gets the identifier of the 'super' user.
|
||||
/// </summary>
|
||||
[Obsolete("Use SuperUserKey instead. Scheduled for removal in V15.")]
|
||||
public const int SuperUserId = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique key of the 'super' user.
|
||||
/// </summary>
|
||||
public static readonly Guid SuperUserKey = new("1E70F841-C261-413B-ABB2-2D68CDB96094");
|
||||
|
||||
[Obsolete("Use SuperUserKey instead. Scheduled for removal in V15.")]
|
||||
public const string SuperUserIdAsString = "-1";
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1152,7 +1152,7 @@ internal class DatabaseDataCreator
|
||||
new UserDto
|
||||
{
|
||||
Id = Constants.Security.SuperUserId,
|
||||
Key = new Guid("1E70F841-C261-413B-ABB2-2D68CDB96094"),
|
||||
Key = Constants.Security.SuperUserKey,
|
||||
Disabled = false,
|
||||
NoConsole = false,
|
||||
UserName = "Administrator",
|
||||
|
||||
@@ -44,14 +44,21 @@ public class AddGuidsToUsers : UnscopedMigrationBase
|
||||
{
|
||||
var columns = SqlSyntax.GetColumnsInSchema(Context.Database).ToList();
|
||||
AddColumnIfNotExists<UserDto>(columns, NewColumnName);
|
||||
List<UserDto>? dtos = Database.Fetch<UserDto>();
|
||||
if (dtos is null)
|
||||
List<UserDto>? userDtos = Database.Fetch<UserDto>();
|
||||
if (userDtos is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MigrateExternalLogins(dtos);
|
||||
MigrateTwoFactorLogins(dtos);
|
||||
UserDto? superUser = userDtos.FirstOrDefault(x => x.Id == -1);
|
||||
if (superUser is not null)
|
||||
{
|
||||
superUser.Key = Constants.Security.SuperUserKey;
|
||||
Database.Update(superUser);
|
||||
}
|
||||
|
||||
MigrateExternalLogins(userDtos);
|
||||
MigrateTwoFactorLogins(userDtos);
|
||||
}
|
||||
|
||||
private void MigrateSqlite()
|
||||
@@ -78,7 +85,7 @@ public class AddGuidsToUsers : UnscopedMigrationBase
|
||||
List<UserDto> users = Database.Fetch<OldUserDto>().Select(x => new UserDto
|
||||
{
|
||||
Id = x.Id,
|
||||
Key = Guid.NewGuid(),
|
||||
Key = x.Id is -1 ? Constants.Security.SuperUserKey : Guid.NewGuid(),
|
||||
Disabled = x.Disabled,
|
||||
NoConsole = x.NoConsole,
|
||||
UserName = x.UserName,
|
||||
|
||||
Reference in New Issue
Block a user