refactor user deletion

This commit is contained in:
Shaun Walker
2021-03-29 12:58:40 -04:00
parent 7223952eb2
commit d8bcc32239
7 changed files with 50 additions and 29 deletions

View File

@ -90,15 +90,7 @@ 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<int> folderIdsToDelete = new List<int>(_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);

View File

@ -12,7 +12,6 @@ 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);
}

View File

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Oqtane.Models;
@ -27,7 +27,7 @@ namespace Oqtane.Repository
return _db.UserRole.Where(item => item.UserId == userId)
.Include(item => item.Role) // eager load roles
.Include(item => item.User) // eager load users
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null);
.Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1);
}
public UserRole AddUserRole(UserRole userRole)