From 801615c981204769f127330d40a0bc5061821901 Mon Sep 17 00:00:00 2001 From: Pieter Kuyck Date: Sat, 13 Mar 2021 12:34:47 +0100 Subject: [PATCH] fix: user delete --- Oqtane.Server/Controllers/UserController.cs | 1 + Oqtane.Server/Repository/FolderRepository.cs | 10 +++++++++- .../Repository/Interfaces/IFolderRepository.cs | 3 ++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index 9819994b..46189e57 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -271,6 +271,7 @@ namespace Oqtane.Controllers if (result != null) { + _folders.DeleteUserFolder(id); _users.DeleteUser(id); _logger.Log(LogLevel.Information, this, LogFunction.Delete, "User Deleted {UserId}", id); } diff --git a/Oqtane.Server/Repository/FolderRepository.cs b/Oqtane.Server/Repository/FolderRepository.cs index dc7125bb..a7acd0b3 100644 --- a/Oqtane.Server/Repository/FolderRepository.cs +++ b/Oqtane.Server/Repository/FolderRepository.cs @@ -90,7 +90,15 @@ namespace Oqtane.Repository _db.Folder.Remove(folder); _db.SaveChanges(); } - + public void DeleteUserFolder(int userId) + { + string userFolderPath = Utilities.PathCombine("Users", userId.ToString(), System.IO.Path.DirectorySeparatorChar.ToString()); + List folderIdsToDelete = new List(_db.Folder.Where(a => a.Path == userFolderPath).Select(a => a.FolderId)); + foreach (int folderId in folderIdsToDelete) + { + DeleteFolder(folderId); + } + } public string GetFolderPath(int folderId) { Folder folder = _db.Folder.Find(folderId); diff --git a/Oqtane.Server/Repository/Interfaces/IFolderRepository.cs b/Oqtane.Server/Repository/Interfaces/IFolderRepository.cs index 5ce7467f..977d6a28 100644 --- a/Oqtane.Server/Repository/Interfaces/IFolderRepository.cs +++ b/Oqtane.Server/Repository/Interfaces/IFolderRepository.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Oqtane.Models; namespace Oqtane.Repository @@ -12,6 +12,7 @@ namespace Oqtane.Repository Folder GetFolder(int folderId, bool tracking); Folder GetFolder(int siteId, string path); void DeleteFolder(int folderId); + void DeleteUserFolder(int userId); string GetFolderPath(int folderId); string GetFolderPath(Folder folder); }