diff --git a/API/Data/MigrateBookmarks.cs b/API/Data/MigrateBookmarks.cs index 43aa14bee..294acc57a 100644 --- a/API/Data/MigrateBookmarks.cs +++ b/API/Data/MigrateBookmarks.cs @@ -14,7 +14,8 @@ namespace API.Data; public static class MigrateBookmarks { /// - /// This will migrate existing bookmarks to bookmark folder based + /// This will migrate existing bookmarks to bookmark folder based. + /// If the bookmarks folder already exists, this will not run. /// /// Bookmark directory is configurable. This will always use the default bookmark directory. /// diff --git a/API/Data/MigrateChangePasswordRoles.cs b/API/Data/MigrateChangePasswordRoles.cs index 1a5681f5a..d9a07ab24 100644 --- a/API/Data/MigrateChangePasswordRoles.cs +++ b/API/Data/MigrateChangePasswordRoles.cs @@ -5,11 +5,23 @@ using Microsoft.AspNetCore.Identity; namespace API.Data; +/// +/// New role introduced in v0.5.1. Adds the role to all users. +/// public static class MigrateChangePasswordRoles { + /// + /// Will not run if any users have the ChangePassword role already + /// + /// + /// public static async Task Migrate(IUnitOfWork unitOfWork, UserManager userManager) { - foreach (var user in await unitOfWork.UserRepository.GetAllUsers()) + var usersWithRole = await userManager.GetUsersInRoleAsync(PolicyConstants.ChangePasswordRole); + if (usersWithRole.Count != 0) return; + + var allUsers = await unitOfWork.UserRepository.GetAllUsers(); + foreach (var user in allUsers) { await userManager.RemoveFromRoleAsync(user, "ChangePassword"); await userManager.AddToRoleAsync(user, PolicyConstants.ChangePasswordRole); diff --git a/API/Program.cs b/API/Program.cs index c6cb7ed69..3a0d9ab25 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -36,7 +36,7 @@ namespace API var directoryService = new DirectoryService(null, new FileSystem()); - MigrateConfigFiles.Migrate(isDocker, directoryService); + //MigrateConfigFiles.Migrate(isDocker, directoryService); // Before anything, check if JWT has been generated properly or if user still has default if (!Configuration.CheckIfJwtTokenSet() && diff --git a/API/Startup.cs b/API/Startup.cs index b66c58a18..2f9ad133b 100644 --- a/API/Startup.cs +++ b/API/Startup.cs @@ -144,7 +144,6 @@ namespace API { // Apply all migrations on startup var logger = serviceProvider.GetRequiredService>(); - var context = serviceProvider.GetRequiredService(); var userManager = serviceProvider.GetRequiredService>(); @@ -152,30 +151,7 @@ namespace API logger, cacheService); // Only run this if we are upgrading - var usersWithRole = await userManager.GetUsersInRoleAsync(PolicyConstants.ChangePasswordRole); - if (usersWithRole.Count == 0) - { - await MigrateChangePasswordRoles.Migrate(unitOfWork, userManager); - } - - var requiresCoverImageMigration = !Directory.Exists(directoryService.CoverImageDirectory); - try - { - // If this is a new install, tables wont exist yet - if (requiresCoverImageMigration) - { - MigrateCoverImages.ExtractToImages(context, directoryService, imageService); - } - } - catch (Exception) - { - requiresCoverImageMigration = false; - } - - if (requiresCoverImageMigration) - { - await MigrateCoverImages.UpdateDatabaseWithImages(context, directoryService); - } + await MigrateChangePasswordRoles.Migrate(unitOfWork, userManager); }).GetAwaiter() .GetResult(); }