Files: added origin for folders
This commit is contained in:
parent
fd228caf8a
commit
83c638b98a
@ -88,7 +88,7 @@ public interface IFolderDao<T>
|
||||
/// <param name="withSubfolders"></param>
|
||||
/// <param name="tagIds"></param>
|
||||
/// <returns></returns>
|
||||
IAsyncEnumerable<Folder<T>> GetFoldersAsync(T parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool exludeSubject = false);
|
||||
IAsyncEnumerable<Folder<T>> GetFoldersAsync(T parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool exludeSubject = false, bool withOrigin = false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the folder (s) by ID (s)
|
||||
|
@ -47,6 +47,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
private readonly ProviderFolderDao _providerFolderDao;
|
||||
private readonly CrossDao _crossDao;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly GlobalFolder _globalFolder;
|
||||
private static readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1);
|
||||
|
||||
public FolderDao(
|
||||
@ -67,7 +68,8 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
IDaoFactory daoFactory,
|
||||
ProviderFolderDao providerFolderDao,
|
||||
CrossDao crossDao,
|
||||
IMapper mapper)
|
||||
IMapper mapper,
|
||||
GlobalFolder globalFolder)
|
||||
: base(
|
||||
dbContextManager,
|
||||
userManager,
|
||||
@ -88,6 +90,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
_providerFolderDao = providerFolderDao;
|
||||
_crossDao = crossDao;
|
||||
_mapper = mapper;
|
||||
_globalFolder = globalFolder;
|
||||
}
|
||||
|
||||
public async Task<Folder<int>> GetFolderAsync(int folderId)
|
||||
@ -226,7 +229,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<Folder<int>> GetFoldersAsync(int parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public async IAsyncEnumerable<Folder<int>> GetFoldersAsync(int parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
@ -280,7 +283,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
}
|
||||
}
|
||||
|
||||
await foreach (var e in FromQueryWithShared(filesDbContext, q).AsAsyncEnumerable())
|
||||
await foreach (var e in (withOrigin ? FromQueryWithOrigin(filesDbContext, q) : FromQueryWithShared(filesDbContext, q)).AsAsyncEnumerable())
|
||||
{
|
||||
yield return _mapper.Map<DbFolderQuery, Folder<int>>(e);
|
||||
}
|
||||
@ -588,6 +591,16 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
.ToListAsync();
|
||||
|
||||
filesDbContext.Tag.RemoveRange(tagsToRemove);
|
||||
|
||||
var originToDelete = await Query(filesDbContext.Tag)
|
||||
.Where(t => t.Name == id.ToString() || subfoldersStrings.Contains(t.Name))
|
||||
.ToListAsync();
|
||||
|
||||
filesDbContext.Tag.RemoveRange(originToDelete);
|
||||
|
||||
await Query(filesDbContext.TagLink)
|
||||
.Where(l => originToDelete.Select(t => t.Id).Contains(l.TagId))
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
var securityToDelete = await Query(filesDbContext.Security)
|
||||
.Where(r => subfoldersStrings.Contains(r.EntryId))
|
||||
@ -630,6 +643,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
{
|
||||
using var filesDbContext = _dbContextFactory.CreateDbContext();
|
||||
var strategy = filesDbContext.Database.CreateExecutionStrategy();
|
||||
var trashIdTask = _globalFolder.GetFolderTrashAsync<int>(_daoFactory);
|
||||
|
||||
await strategy.ExecuteAsync(async () =>
|
||||
{
|
||||
@ -637,6 +651,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
using (var tx = await filesDbContext.Database.BeginTransactionAsync())
|
||||
{
|
||||
var folder = await GetFolderAsync(folderId);
|
||||
var oldParentId = folder.ParentId;
|
||||
|
||||
if (folder.FolderType != FolderType.DEFAULT && !DocSpaceHelper.IsRoom(folder.FolderType))
|
||||
{
|
||||
@ -696,6 +711,19 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
}
|
||||
}
|
||||
|
||||
var trashId = await trashIdTask;
|
||||
var tagDao = _daoFactory.GetTagDao<int>();
|
||||
|
||||
if (toFolderId == trashId)
|
||||
{
|
||||
var origin = Tag.Origin(folderId, FileEntryType.Folder, oldParentId, _authContext.CurrentAccount.ID);
|
||||
await tagDao.SaveTags(origin);
|
||||
}
|
||||
else if (oldParentId == trashId)
|
||||
{
|
||||
await tagDao.RemoveTagLinksAsync(folderId, FileEntryType.Folder, TagType.Origin);
|
||||
}
|
||||
|
||||
await filesDbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
await tx.CommitAsync().ConfigureAwait(false);
|
||||
|
||||
@ -1342,6 +1370,45 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
return e;
|
||||
}
|
||||
|
||||
protected IQueryable<DbFolderQuery> FromQueryWithOrigin(FilesDbContext filesDbContext, IQueryable<DbFolder> dbFolders)
|
||||
{
|
||||
var e = from r in dbFolders
|
||||
select new DbFolderQuery
|
||||
{
|
||||
Folder = r,
|
||||
Root = (from f in filesDbContext.Folders
|
||||
where f.Id ==
|
||||
(from t in filesDbContext.Tree
|
||||
where t.FolderId == r.ParentId
|
||||
orderby t.Level descending
|
||||
select t.ParentId
|
||||
).FirstOrDefault()
|
||||
where f.TenantId == r.TenantId
|
||||
select f
|
||||
).FirstOrDefault(),
|
||||
Origin = filesDbContext.Folders.AsNoTracking()
|
||||
.FirstOrDefault(f => f.TenantId == TenantID && f.Id.ToString() == filesDbContext.TagLink.AsNoTracking()
|
||||
.Where(l => l.TenantId == TenantID && Convert.ToInt32(l.EntryId) == r.Id && l.EntryType == FileEntryType.Folder)
|
||||
.Join(filesDbContext.Tag.AsNoTracking(), l => l.TagId, t => t.Id, (l, t) => new { t.Name, t.Type })
|
||||
.Where(t => t.Type == TagType.Origin)
|
||||
.Select(t => t.Name)
|
||||
.FirstOrDefault()),
|
||||
OriginRoom = filesDbContext.Folders.AsNoTracking()
|
||||
.FirstOrDefault(f => f.TenantId == TenantID && f.Id == filesDbContext.Tree.AsNoTracking()
|
||||
.Where(tree => tree.FolderId.ToString() == filesDbContext.TagLink.AsNoTracking()
|
||||
.Where(l => l.TenantId == TenantID && Convert.ToInt32(l.EntryId) == r.Id && l.EntryType == FileEntryType.Folder)
|
||||
.Join(filesDbContext.Tag.AsNoTracking(), l => l.TagId, t => t.Id, (l, t) => new { t.Name, t.Type })
|
||||
.Where(t => t.Type == TagType.Origin)
|
||||
.Select(t => t.Name)
|
||||
.FirstOrDefault())
|
||||
.OrderByDescending(tree => tree.Level).Skip(1)
|
||||
.Select(t => t.ParentId)
|
||||
.FirstOrDefault())
|
||||
};
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
protected IQueryable<DbFolderQuery> FromQuery(FilesDbContext filesDbContext, IQueryable<DbFolder> dbFiles)
|
||||
{
|
||||
var FilesDbContext = filesDbContext;
|
||||
@ -1688,7 +1755,7 @@ internal class FolderDao : AbstractDao, IFolderDao<int>
|
||||
}
|
||||
}
|
||||
|
||||
public class DbFolderQuery
|
||||
public class DbFolderQuery : OriginQuery
|
||||
{
|
||||
public DbFolder Folder { get; set; }
|
||||
public DbFolder Root { get; set; }
|
||||
|
@ -110,7 +110,7 @@ internal class BoxFolderDao : BoxDaoBase, IFolderDao<string>
|
||||
}
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ internal class DropboxFolderDao : DropboxDaoBase, IFolderDao<string>
|
||||
}
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ internal class GoogleDriveFolderDao : GoogleDriveDaoBase, IFolderDao<string>
|
||||
}
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ internal class OneDriveFolderDao : OneDriveDaoBase, IFolderDao<string>
|
||||
}
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
|
@ -181,7 +181,7 @@ internal class ProviderFolderDao : ProviderDaoBase, IFolderDao<string>
|
||||
return folders.Where(r => r != null);
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public async IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
var selector = GetSelector(parentId);
|
||||
var folderDao = selector.GetFolderDao(parentId);
|
||||
|
@ -116,7 +116,7 @@ internal class SharePointFolderDao : SharePointDaoBase, IFolderDao<string>
|
||||
}
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ internal class SharpBoxFolderDao : SharpBoxDaoBase, IFolderDao<string>
|
||||
return parentFolder.OfType<ICloudDirectoryEntry>().Select(ToFolder).ToAsyncEnumerable();
|
||||
}
|
||||
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false)
|
||||
public IAsyncEnumerable<Folder<string>> GetFoldersAsync(string parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false, bool excludeSubject = false, bool withOrigin = false)
|
||||
{
|
||||
if (CheckInvalidFilter(filterType))
|
||||
{
|
||||
|
@ -468,7 +468,7 @@ public class EntryManager
|
||||
withOrigin = true;
|
||||
}
|
||||
|
||||
var folders = _daoFactory.GetFolderDao<T>().GetFoldersAsync(parent.Id, orderBy, filterType, subjectGroup, subjectId, searchText, withSubfolders, excludeSubject);
|
||||
var folders = _daoFactory.GetFolderDao<T>().GetFoldersAsync(parent.Id, orderBy, filterType, subjectGroup, subjectId, searchText, withSubfolders, excludeSubject, withOrigin);
|
||||
var files = _daoFactory.GetFileDao<T>().GetFilesAsync(parent.Id, orderBy, filterType, subjectGroup, subjectId, searchText, searchInContent, withSubfolders, excludeSubject, withOrigin);
|
||||
|
||||
var task1 = _fileSecurity.FilterReadAsync(folders).ToListAsync();
|
||||
|
Loading…
Reference in New Issue
Block a user