Files: refactoring
This commit is contained in:
parent
c3dd78047a
commit
ece437cbc0
@ -78,8 +78,9 @@ namespace ASC.Api.Documents
|
||||
public class FilesController : ControllerBase
|
||||
{
|
||||
private readonly ApiContext ApiContext;
|
||||
private readonly FileStorageService FileStorageService;
|
||||
private readonly FileStorageService<string> FileStorageService;
|
||||
|
||||
public FileStorageService<int> FileStorageServiceInt { get; }
|
||||
public GlobalFolderHelper GlobalFolderHelper { get; }
|
||||
public FileWrapperHelper FileWrapperHelper { get; }
|
||||
public FilesSettingsHelper FilesSettingsHelper { get; }
|
||||
@ -118,7 +119,8 @@ namespace ASC.Api.Documents
|
||||
/// <param name="fileStorageService"></param>
|
||||
public FilesController(
|
||||
ApiContext context,
|
||||
FileStorageService fileStorageService,
|
||||
FileStorageService<string> fileStorageService,
|
||||
FileStorageService<int> fileStorageServiceInt,
|
||||
GlobalFolderHelper globalFolderHelper,
|
||||
FileWrapperHelper fileWrapperHelper,
|
||||
FilesSettingsHelper filesSettingsHelper,
|
||||
@ -153,6 +155,7 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
ApiContext = context;
|
||||
FileStorageService = fileStorageService;
|
||||
FileStorageServiceInt = fileStorageServiceInt;
|
||||
GlobalFolderHelper = globalFolderHelper;
|
||||
FileWrapperHelper = fileWrapperHelper;
|
||||
FilesSettingsHelper = filesSettingsHelper;
|
||||
@ -669,7 +672,7 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
using (var memStream = new MemoryStream(Encoding.UTF8.GetBytes(content)))
|
||||
{
|
||||
var file = FileUploader.Exec(folderId,
|
||||
var file = FileUploader.Exec(folderId.ToString(),
|
||||
title.EndsWith(extension, StringComparison.OrdinalIgnoreCase) ? title : (title + extension),
|
||||
memStream.Length, memStream);
|
||||
return FileWrapperHelper.Get(file);
|
||||
@ -834,7 +837,7 @@ namespace ASC.Api.Documents
|
||||
[Read("file/{fileId:int}")]
|
||||
public FileWrapper GetFileInfo(int fileId, int version = -1)
|
||||
{
|
||||
var file = FileStorageService.GetFile(fileId, version).NotFoundIfNull("File not found");
|
||||
var file = FileStorageServiceInt.GetFile(fileId, version).NotFoundIfNull("File not found");
|
||||
return FileWrapperHelper.Get(file);
|
||||
}
|
||||
|
||||
@ -905,7 +908,7 @@ namespace ASC.Api.Documents
|
||||
[Read("file/{fileId}/checkconversion")]
|
||||
public IEnumerable<ConversationResult> CheckConversion(string fileId, bool start)
|
||||
{
|
||||
return FileStorageService.CheckConversion<string>(new ItemList<ItemList<string>>
|
||||
return FileStorageService.CheckConversion(new ItemList<ItemList<string>>
|
||||
{
|
||||
new ItemList<string> { fileId, "0", start.ToString() }
|
||||
})
|
||||
@ -969,7 +972,7 @@ namespace ASC.Api.Documents
|
||||
|
||||
var ids = FileStorageService.MoveOrCopyFilesCheck(itemList, batchModel.DestFolderId).Keys.Select(id => "file_" + id);
|
||||
|
||||
var entries = FileStorageService.GetItems<string>(new ItemList<string>(ids), FilterType.FilesOnly, false, "", "");
|
||||
var entries = FileStorageService.GetItems(new ItemList<string>(ids), FilterType.FilesOnly, false, "", "");
|
||||
return entries.Select(x => FileWrapperHelper.Get((File<string>)x));
|
||||
}
|
||||
|
||||
@ -1031,7 +1034,7 @@ namespace ASC.Api.Documents
|
||||
itemList.AddRange((model.FolderIds ?? new List<string>()).Select(x => "folder_" + x));
|
||||
itemList.AddRange((model.FileIds ?? new List<string>()).Select(x => "file_" + x));
|
||||
|
||||
return FileStorageService.MarkAsRead<string>(itemList).Select(FileOperationWraperHelper.Get<string>);
|
||||
return FileStorageService.MarkAsRead(itemList).Select(FileOperationWraperHelper.Get<string>);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1109,7 +1112,7 @@ namespace ASC.Api.Documents
|
||||
itemList.AddRange((batch.FolderIds ?? new List<string>()).Select(x => "folder_" + x));
|
||||
itemList.AddRange((batch.FileIds ?? new List<string>()).Select(x => "file_" + x));
|
||||
|
||||
return FileStorageService.DeleteItems<string>("delete", itemList, false, batch.DeleteAfter, batch.Immediately).Select(FileOperationWraperHelper.Get<string>);
|
||||
return FileStorageService.DeleteItems("delete", itemList, false, batch.DeleteAfter, batch.Immediately).Select(FileOperationWraperHelper.Get<string>);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1121,7 +1124,7 @@ namespace ASC.Api.Documents
|
||||
[Update("fileops/emptytrash")]
|
||||
public IEnumerable<FileOperationWraper> EmptyTrash()
|
||||
{
|
||||
return FileStorageService.EmptyTrash<int>().Select(FileOperationWraperHelper.Get<string>);
|
||||
return FileStorageService.EmptyTrash().Select(FileOperationWraperHelper.Get<string>);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1163,7 +1166,7 @@ namespace ASC.Api.Documents
|
||||
[Read("file/{fileId}/share")]
|
||||
public IEnumerable<FileShareWrapper> GetFileSecurityInfo(string fileId)
|
||||
{
|
||||
var fileShares = FileStorageService.GetSharedInfo<string>(new ItemList<string> { string.Format("file_{0}", fileId) });
|
||||
var fileShares = FileStorageService.GetSharedInfo(new ItemList<string> { string.Format("file_{0}", fileId) });
|
||||
return fileShares.Select(FileShareWrapperHelper.Get);
|
||||
}
|
||||
|
||||
@ -1177,7 +1180,7 @@ namespace ASC.Api.Documents
|
||||
[Read("folder/{folderId}/share")]
|
||||
public IEnumerable<FileShareWrapper> GetFolderSecurityInfo(string folderId)
|
||||
{
|
||||
var fileShares = FileStorageService.GetSharedInfo<string>(new ItemList<string> { string.Format("folder_{0}", folderId) });
|
||||
var fileShares = FileStorageService.GetSharedInfo(new ItemList<string> { string.Format("folder_{0}", folderId) });
|
||||
return fileShares.Select(FileShareWrapperHelper.Get);
|
||||
}
|
||||
|
||||
@ -1206,7 +1209,7 @@ namespace ASC.Api.Documents
|
||||
Aces = list,
|
||||
Message = sharingMessage
|
||||
};
|
||||
FileStorageService.SetAceObject<string>(aceCollection, notify);
|
||||
FileStorageService.SetAceObject(aceCollection, notify);
|
||||
}
|
||||
return GetFileSecurityInfo(fileId);
|
||||
}
|
||||
@ -1236,7 +1239,7 @@ namespace ASC.Api.Documents
|
||||
Aces = list,
|
||||
Message = sharingMessage
|
||||
};
|
||||
FileStorageService.SetAceObject<string>(aceCollection, notify);
|
||||
FileStorageService.SetAceObject(aceCollection, notify);
|
||||
}
|
||||
|
||||
return GetFolderSecurityInfo(folderId);
|
||||
@ -1258,7 +1261,7 @@ namespace ASC.Api.Documents
|
||||
itemList.AddRange((model.FolderIds ?? new List<string>()).Select(x => "folder_" + x));
|
||||
itemList.AddRange((model.FileIds ?? new List<string>()).Select(x => "file_" + x));
|
||||
|
||||
FileStorageService.RemoveAce<string>(itemList);
|
||||
FileStorageService.RemoveAce(itemList);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1279,7 +1282,7 @@ namespace ASC.Api.Documents
|
||||
var file = GetFileInfo(fileId);
|
||||
|
||||
var objectId = "file_" + file.Id;
|
||||
var sharedInfo = FileStorageService.GetSharedInfo<string>(new ItemList<string> { objectId }).Find(r => r.SubjectId == FileConstant.ShareLinkId);
|
||||
var sharedInfo = FileStorageService.GetSharedInfo(new ItemList<string> { objectId }).Find(r => r.SubjectId == FileConstant.ShareLinkId);
|
||||
if (sharedInfo == null || sharedInfo.Share != share)
|
||||
{
|
||||
var list = new ItemList<AceWrapper>
|
||||
@ -1296,8 +1299,8 @@ namespace ASC.Api.Documents
|
||||
Entries = new ItemList<string> { objectId },
|
||||
Aces = list
|
||||
};
|
||||
FileStorageService.SetAceObject<string>(aceCollection, false);
|
||||
sharedInfo = FileStorageService.GetSharedInfo<string>(new ItemList<string> { objectId }).Find(r => r.SubjectId == FileConstant.ShareLinkId);
|
||||
FileStorageService.SetAceObject(aceCollection, false);
|
||||
sharedInfo = FileStorageService.GetSharedInfo(new ItemList<string> { objectId }).Find(r => r.SubjectId == FileConstant.ShareLinkId);
|
||||
}
|
||||
|
||||
return sharedInfo.Link;
|
||||
@ -1394,7 +1397,7 @@ namespace ASC.Api.Documents
|
||||
ProviderKey = providerKey,
|
||||
};
|
||||
|
||||
var folder = FileStorageService.SaveThirdParty<string>(thirdPartyParams);
|
||||
var folder = FileStorageService.SaveThirdParty(thirdPartyParams);
|
||||
|
||||
return FolderWrapperHelper.Get(folder);
|
||||
}
|
||||
@ -1418,7 +1421,7 @@ namespace ASC.Api.Documents
|
||||
/// <short>Get third party folder</short>
|
||||
/// <returns>Connected providers folder</returns>
|
||||
[Read("thirdparty/common")]
|
||||
public IEnumerable<Folder> GetCommonThirdPartyFolders()
|
||||
public IEnumerable<Folder<string>> GetCommonThirdPartyFolders()
|
||||
{
|
||||
var parent = FileStorageService.GetFolder(GlobalFolderHelper.FolderCommon.ToString());
|
||||
return EntryManager.GetThirpartyFolders(parent);
|
||||
@ -1437,7 +1440,7 @@ namespace ASC.Api.Documents
|
||||
[Delete("thirdparty/{providerId:int}")]
|
||||
public object DeleteThirdParty(int providerId)
|
||||
{
|
||||
return FileStorageService.DeleteThirdParty<string>(providerId.ToString(CultureInfo.InvariantCulture));
|
||||
return FileStorageService.DeleteThirdParty(providerId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
}
|
||||
|
||||
@ -1573,7 +1576,7 @@ namespace ASC.Api.Documents
|
||||
}
|
||||
|
||||
var startIndex = Convert.ToInt32(ApiContext.StartIndex);
|
||||
var items = FileStorageService.GetFolderItems(
|
||||
var items = FileStorageServiceInt.GetFolderItems(
|
||||
folderId,
|
||||
startIndex,
|
||||
Convert.ToInt32(ApiContext.Count) - 1, //NOTE: in ApiContext +1
|
||||
|
@ -30,18 +30,13 @@ namespace ASC.Files.Core
|
||||
{
|
||||
public interface IDaoFactory
|
||||
{
|
||||
IFolderDao FolderDao { get; }
|
||||
|
||||
IFolderDao<T> GetFolderDao<T>();
|
||||
|
||||
IFileDao FileDao { get; }
|
||||
|
||||
IFileDao<T> GetFileDao<T>();
|
||||
|
||||
ITagDao TagDao { get; }
|
||||
ITagDao<T> GetTagDao<T>();
|
||||
|
||||
ISecurityDao SecurityDao { get; }
|
||||
ISecurityDao<T> GetSecurityDao<T>();
|
||||
|
||||
IProviderDao ProviderDao { get; }
|
||||
}
|
||||
|
@ -299,273 +299,4 @@ namespace ASC.Files.Core
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface encapsulates access toFolderId files
|
||||
/// </summary>
|
||||
public interface IFileDao
|
||||
{
|
||||
/// <summary>
|
||||
/// Clear the application cache for the specific file
|
||||
/// </summary>
|
||||
void InvalidateCache(object fileId);
|
||||
|
||||
/// <summary>
|
||||
/// Receive file
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <returns></returns>
|
||||
File GetFile(object fileId);
|
||||
|
||||
/// <summary>
|
||||
/// Receive file
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="fileVersion">file version</param>
|
||||
/// <returns></returns>
|
||||
File GetFile(object fileId, int fileVersion);
|
||||
|
||||
/// <summary>
|
||||
/// Receive file
|
||||
/// </summary>
|
||||
/// <param name="parentId">folder id</param>
|
||||
/// <param name="title">file name</param>
|
||||
/// <returns>
|
||||
/// file
|
||||
/// </returns>
|
||||
File GetFile(object parentId, string title);
|
||||
|
||||
/// <summary>
|
||||
/// Receive last file without forcesave
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="fileVersion"></param>
|
||||
/// <returns></returns>
|
||||
File GetFileStable(object fileId, int fileVersion = -1);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all versions of the file
|
||||
/// </summary>
|
||||
/// <param name="fileId"></param>
|
||||
/// <returns></returns>
|
||||
List<File> GetFileHistory(object fileId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file (s) by ID (s)
|
||||
/// </summary>
|
||||
/// <param name="fileIds">id file</param>
|
||||
/// <returns></returns>
|
||||
List<File> GetFiles(object[] fileIds);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file (s) by ID (s) for share
|
||||
/// </summary>
|
||||
/// <param name="fileIds">id file</param>
|
||||
/// <param name="filterType"></param>
|
||||
/// <param name="subjectGroup"></param>
|
||||
/// <param name="subjectID"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="searchInContent"></param>
|
||||
/// <returns></returns>
|
||||
List<File> GetFilesForShare(object[] fileIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
List<object> GetFiles(object parentId);
|
||||
|
||||
/// <summary>
|
||||
/// Get files in folder
|
||||
/// </summary>
|
||||
/// <param name="parentId">folder id</param>
|
||||
/// <param name="orderBy"></param>
|
||||
/// <param name="filterType">filterType type</param>
|
||||
/// <param name="subjectGroup"></param>
|
||||
/// <param name="subjectID"></param>
|
||||
/// <param name="searchText"> </param>
|
||||
/// <param name="searchInContent"></param>
|
||||
/// <param name="withSubfolders"> </param>
|
||||
/// <returns>list of files</returns>
|
||||
/// <remarks>
|
||||
/// Return only the latest versions of files of a folder
|
||||
/// </remarks>
|
||||
List<File> GetFiles(object parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent, bool withSubfolders = false);
|
||||
|
||||
/// <summary>
|
||||
/// Get stream of file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns>Stream</returns>
|
||||
Stream GetFileStream(File file);
|
||||
|
||||
/// <summary>
|
||||
/// Get stream of file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <returns>Stream</returns>
|
||||
Stream GetFileStream(File file, long offset);
|
||||
|
||||
/// <summary>
|
||||
/// Get presigned uri
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="expires"></param>
|
||||
/// <returns>Stream uri</returns>
|
||||
Uri GetPreSignedUri(File file, TimeSpan expires);
|
||||
|
||||
/// <summary>
|
||||
/// Check is supported PreSignedUri
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns>Stream uri</returns>
|
||||
bool IsSupportedPreSignedUri(File file);
|
||||
|
||||
/// <summary>
|
||||
/// Saves / updates the version of the file
|
||||
/// and save stream of file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="fileStream"> </param>
|
||||
/// <returns></returns>
|
||||
/// <remarks>
|
||||
/// Updates the file if:
|
||||
/// - The file comes with the given id
|
||||
/// - The file with that name in the folder / container exists
|
||||
///
|
||||
/// Save in all other cases
|
||||
/// </remarks>
|
||||
File SaveFile(File file, Stream fileStream);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="fileStream"></param>
|
||||
/// <returns></returns>
|
||||
File ReplaceFileVersion(File file, Stream fileStream);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a file including all previous versions
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
void DeleteFile(object fileId);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not file
|
||||
/// </summary>
|
||||
/// <param name="title">file name</param>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <returns>Returns true if the file exists, otherwise false</returns>
|
||||
bool IsExist(string title, object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// Moves a file or set of files in a folder
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="toFolderId">The ID of the destination folder</param>
|
||||
object MoveFile(object fileId, object toFolderId);
|
||||
|
||||
/// <summary>
|
||||
/// Copy the files in a folder
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="toFolderId">The ID of the destination folder</param>
|
||||
File CopyFile(object fileId, object toFolderId);
|
||||
|
||||
/// <summary>
|
||||
/// Rename file
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <param name="newTitle">new name</param>
|
||||
object FileRename(File file, string newTitle);
|
||||
|
||||
/// <summary>
|
||||
/// Update comment file
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="fileVersion">file version</param>
|
||||
/// <param name="comment">new comment</param>
|
||||
string UpdateComment(object fileId, int fileVersion, string comment);
|
||||
|
||||
/// <summary>
|
||||
/// Complete file version
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="fileVersion">file version</param>
|
||||
void CompleteVersion(object fileId, int fileVersion);
|
||||
|
||||
/// <summary>
|
||||
/// Continue file version
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <param name="fileVersion">file version</param>
|
||||
void ContinueVersion(object fileId, int fileVersion);
|
||||
|
||||
/// <summary>
|
||||
/// Check the need to use the trash before removing
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
bool UseTrashForRemove(File file);
|
||||
|
||||
#region chunking
|
||||
|
||||
ChunkedUploadSession<object> CreateUploadSession(File file, long contentLength);
|
||||
|
||||
void UploadChunk(ChunkedUploadSession<object> uploadSession, Stream chunkStream, long chunkLength);
|
||||
|
||||
void AbortUploadSession(ChunkedUploadSession<object> uploadSession);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Only in TMFileDao
|
||||
|
||||
/// <summary>
|
||||
/// Set created by
|
||||
/// </summary>
|
||||
/// <param name="fileIds"></param>
|
||||
/// <param name="newOwnerId"></param>
|
||||
void ReassignFiles(object[] fileIds, Guid newOwnerId);
|
||||
|
||||
/// <summary>
|
||||
/// Search files in SharedWithMe & Projects
|
||||
/// </summary>
|
||||
/// <param name="parentIds"></param>
|
||||
/// <param name="filterType"></param>
|
||||
/// <param name="subjectGroup"></param>
|
||||
/// <param name="subjectID"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="searchInContent"></param>
|
||||
/// <returns></returns>
|
||||
List<File> GetFiles(object[] parentIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent);
|
||||
|
||||
/// <summary>
|
||||
/// Search the list of files containing text
|
||||
/// Only in TMFileDao
|
||||
/// </summary>
|
||||
/// <param name="text">search text</param>
|
||||
/// <param name="bunch"></param>
|
||||
/// <returns>list of files</returns>
|
||||
IEnumerable<File> Search(string text, bool bunch = false);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether file exists on storage
|
||||
/// </summary>
|
||||
/// <param name="file">file</param>
|
||||
/// <returns></returns>
|
||||
bool IsExistOnStorage(File file);
|
||||
|
||||
void SaveEditHistory(File file, string changes, Stream differenceStream);
|
||||
|
||||
List<EditHistory> GetEditHistory(DocumentServiceHelper documentServiceHelper, object fileId, int fileVersion = 0);
|
||||
|
||||
Stream GetDifferenceStream(File file);
|
||||
|
||||
bool ContainChanges(object fileId, int fileVersion);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -282,257 +282,4 @@ namespace ASC.Files.Core
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface IFolderDao
|
||||
{
|
||||
/// <summary>
|
||||
/// Get folder by id.
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <returns>folder</returns>
|
||||
Folder GetFolder(object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the folder with the given name and id of the root
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
Folder GetFolder(string title, object parentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root folder
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <returns>root folder</returns>
|
||||
Folder GetRootFolder(object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the root folder
|
||||
/// </summary>
|
||||
/// <param name="fileId">file id</param>
|
||||
/// <returns>root folder</returns>
|
||||
Folder GetRootFolderByFile(object fileId);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of folders in current folder.
|
||||
/// </summary>
|
||||
/// <param name="parentId"></param>
|
||||
List<Folder> GetFolders(object parentId);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of folders.
|
||||
/// </summary>
|
||||
/// <param name="parentId"></param>
|
||||
/// <param name="orderBy"></param>
|
||||
/// <param name="filterType"></param>
|
||||
/// <param name="subjectGroup"></param>
|
||||
/// <param name="subjectID"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="withSubfolders"></param>
|
||||
/// <returns></returns>
|
||||
List<Folder> GetFolders(object parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the folder (s) by ID (s)
|
||||
/// </summary>
|
||||
/// <param name="folderIds"></param>
|
||||
/// <param name="filterType"></param>
|
||||
/// <param name="subjectGroup"></param>
|
||||
/// <param name="subjectID"></param>
|
||||
/// <param name="searchText"></param>
|
||||
/// <param name="searchSubfolders"></param>
|
||||
/// <param name="checkShare"></param>
|
||||
/// <returns></returns>
|
||||
List<Folder> GetFolders(object[] folderIds, FilterType filterType = FilterType.None, bool subjectGroup = false, Guid? subjectID = null, string searchText = "", bool searchSubfolders = false, bool checkShare = true);
|
||||
|
||||
/// <summary>
|
||||
/// Get folder, contains folder with id
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <returns></returns>
|
||||
List<Folder> GetParentFolders(object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// save or update folder
|
||||
/// </summary>
|
||||
/// <param name="folder"></param>
|
||||
/// <returns></returns>
|
||||
object SaveFolder(Folder folder);
|
||||
|
||||
/// <summary>
|
||||
/// delete folder
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
void DeleteFolder(object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// move folder
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <param name="toFolderId">destination folder id</param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
object MoveFolder(object folderId, object toFolderId, CancellationToken? cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// copy folder
|
||||
/// </summary>
|
||||
/// <param name="folderId"></param>
|
||||
/// <param name="toFolderId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
Folder CopyFolder(object folderId, object toFolderId, CancellationToken? cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Validate the transfer operation directory to another directory.
|
||||
/// </summary>
|
||||
/// <param name="folderIds"></param>
|
||||
/// <param name="to"></param>
|
||||
/// <returns>
|
||||
/// Returns pair of file ID, file name, in which the same name.
|
||||
/// </returns>
|
||||
IDictionary<object, string> CanMoveOrCopy(object[] folderIds, object to);
|
||||
|
||||
/// <summary>
|
||||
/// Rename folder
|
||||
/// </summary>
|
||||
/// <param name="folder"></param>
|
||||
/// <param name="newTitle">new name</param>
|
||||
object RenameFolder(Folder folder, string newTitle);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of files and folders to the container in your
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <returns></returns>
|
||||
int GetItemsCount(object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// Check folder on emptiness
|
||||
/// </summary>
|
||||
/// <param name="folderId">folder id</param>
|
||||
/// <returns></returns>
|
||||
bool IsEmpty(object folderId);
|
||||
|
||||
/// <summary>
|
||||
/// Check the need to use the trash before removing
|
||||
/// </summary>
|
||||
/// <param name="folder"></param>
|
||||
/// <returns></returns>
|
||||
bool UseTrashForRemove(Folder folder);
|
||||
|
||||
/// <summary>
|
||||
/// Check the need to use recursion for operations
|
||||
/// </summary>
|
||||
/// <param name="folderId"> </param>
|
||||
/// <param name="toRootFolderId"> </param>
|
||||
/// <returns></returns>
|
||||
bool UseRecursiveOperation(object folderId, object toRootFolderId);
|
||||
|
||||
/// <summary>
|
||||
/// Check the possibility to calculate the number of subitems
|
||||
/// </summary>
|
||||
/// <param name="entryId"> </param>
|
||||
/// <returns></returns>
|
||||
bool CanCalculateSubitems(object entryId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns maximum size of file which can be uploaded to specific folder
|
||||
/// </summary>
|
||||
/// <param name="folderId">Id of the folder</param>
|
||||
/// <param name="chunkedUpload">Determines whenever supposed upload will be chunked (true) or not (false)</param>
|
||||
/// <returns>Maximum size of file which can be uploaded to folder</returns>
|
||||
long GetMaxUploadSize(object folderId, bool chunkedUpload = false);
|
||||
|
||||
#region Only for TMFolderDao
|
||||
|
||||
/// <summary>
|
||||
/// Set created by
|
||||
/// </summary>
|
||||
/// <param name="folderIds"></param>
|
||||
/// <param name="newOwnerId"></param>
|
||||
void ReassignFolders(object[] folderIds, Guid newOwnerId);
|
||||
|
||||
/// <summary>
|
||||
/// Search the list of folders containing text in title
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="bunch"></param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<Folder> Search(string text, bool bunch = false);
|
||||
|
||||
/// <summary>
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="module"></param>
|
||||
/// <param name="bunch"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="createIfNotExists"></param>
|
||||
/// <returns></returns>
|
||||
object GetFolderID(string module, string bunch, string data, bool createIfNotExists);
|
||||
|
||||
IEnumerable<object> GetFolderIDs(string module, string bunch, IEnumerable<string> data, bool createIfNotExists);
|
||||
|
||||
/// <summary>
|
||||
/// Returns id folder "Shared Documents"
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
object GetFolderIDCommon(bool createIfNotExists);
|
||||
|
||||
/// <summary>
|
||||
/// Returns id folder "My Documents"
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="createIfNotExists"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
object GetFolderIDUser(bool createIfNotExists, Guid? userId = null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns id folder "Shared with me"
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="createIfNotExists"></param>
|
||||
/// <returns></returns>
|
||||
object GetFolderIDShare(bool createIfNotExists);
|
||||
|
||||
/// <summary>
|
||||
/// Returns id folder "Trash"
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="createIfNotExists"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
object GetFolderIDTrash(bool createIfNotExists, Guid? userId = null);
|
||||
|
||||
/// <summary>
|
||||
/// Returns id folder "Projects"
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="createIfNotExists"></param>
|
||||
/// <returns></returns>
|
||||
object GetFolderIDProjects(bool createIfNotExists);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Return id of related object
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="folderID"></param>
|
||||
/// <returns></returns>
|
||||
string GetBunchObjectID(object folderID);
|
||||
|
||||
/// <summary>
|
||||
/// Return ids of related objects
|
||||
/// Only in TMFolderDao
|
||||
/// </summary>
|
||||
/// <param name="folderIDs"></param>
|
||||
/// <returns></returns>
|
||||
Dictionary<string, string> GetBunchObjectIDs(List<object> folderIDs);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -29,16 +29,17 @@ using System.Collections.Generic;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
public interface ITagDao<T> : ITagDao
|
||||
public interface ITagDao<T>
|
||||
{
|
||||
IEnumerable<Tag> GetNewTags(Guid subject, Folder<T> parentFolder, bool deepSearch);
|
||||
|
||||
IEnumerable<Tag> GetTags(T entryID, FileEntryType entryType, TagType tagType);
|
||||
}
|
||||
|
||||
public interface ITagDao
|
||||
{
|
||||
IEnumerable<Tag> GetTags(TagType tagType, IEnumerable<FileEntry> fileEntries);
|
||||
IEnumerable<Tag> GetTags(TagType tagType, IEnumerable<FileEntry<T>> fileEntries);
|
||||
|
||||
IEnumerable<Tag> GetNewTags(Guid subject, IEnumerable<FileEntry<T>> fileEntries);
|
||||
|
||||
IEnumerable<Tag> GetNewTags(Guid subject, FileEntry<T> fileEntry);
|
||||
|
||||
IEnumerable<Tag> GetTags(Guid owner, TagType tagType);
|
||||
|
||||
@ -46,12 +47,6 @@ namespace ASC.Files.Core
|
||||
|
||||
IEnumerable<Tag> GetTags(string[] names, TagType tagType);
|
||||
|
||||
IEnumerable<Tag> GetNewTags(Guid subject, Folder parentFolder, bool deepSearch);
|
||||
|
||||
IEnumerable<Tag> GetNewTags(Guid subject, IEnumerable<FileEntry> fileEntries);
|
||||
|
||||
IEnumerable<Tag> GetNewTags(Guid subject, FileEntry fileEntry);
|
||||
|
||||
IEnumerable<Tag> SaveTags(IEnumerable<Tag> tag);
|
||||
|
||||
IEnumerable<Tag> SaveTags(Tag tag);
|
||||
@ -63,7 +58,5 @@ namespace ASC.Files.Core
|
||||
void RemoveTags(IEnumerable<Tag> tag);
|
||||
|
||||
void RemoveTags(Tag tag);
|
||||
|
||||
IEnumerable<Tag> GetTags(object entryID, FileEntryType entryType, TagType tagType);
|
||||
}
|
||||
}
|
@ -36,19 +36,11 @@ namespace ASC.Files.Core.Data
|
||||
public class DaoFactory : IDaoFactory
|
||||
{
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
public IFileDao FileDao { get; }
|
||||
public IFolderDao FolderDao { get; }
|
||||
public ITagDao TagDao { get; }
|
||||
public ISecurityDao SecurityDao { get; }
|
||||
public IProviderDao ProviderDao { get; }
|
||||
|
||||
public DaoFactory(IServiceProvider serviceProvider, IFileDao fileDao, IFolderDao folderDao, ITagDao tagDao, ISecurityDao securityDao)
|
||||
public DaoFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
FileDao = fileDao;
|
||||
FolderDao = folderDao;
|
||||
TagDao = tagDao;
|
||||
SecurityDao = securityDao;
|
||||
}
|
||||
|
||||
public IFileDao<T> GetFileDao<T>()
|
||||
@ -64,6 +56,11 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
return ServiceProvider.GetService<ITagDao<T>>();
|
||||
}
|
||||
|
||||
public ISecurityDao<T> GetSecurityDao<T>()
|
||||
{
|
||||
return ServiceProvider.GetService<ISecurityDao<T>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DaoFactoryExtention
|
||||
|
@ -51,14 +51,14 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Files.Core.Data
|
||||
{
|
||||
public class FileDao : AbstractDao, IFileDao, IFileDao<int>
|
||||
public class FileDao : AbstractDao, IFileDao<int>
|
||||
{
|
||||
private static readonly object syncRoot = new object();
|
||||
public FactoryIndexer<FilesWrapper> FactoryIndexer { get; }
|
||||
public GlobalStore GlobalStore { get; }
|
||||
public GlobalSpace GlobalSpace { get; }
|
||||
public GlobalFolder GlobalFolder { get; }
|
||||
public IFolderDao FolderDao { get; }
|
||||
public IFolderDao<int> FolderDao { get; }
|
||||
public ChunkedUploadSessionHolder ChunkedUploadSessionHolder { get; }
|
||||
|
||||
public FileDao(
|
||||
@ -78,7 +78,7 @@ namespace ASC.Files.Core.Data
|
||||
GlobalStore globalStore,
|
||||
GlobalSpace globalSpace,
|
||||
GlobalFolder globalFolder,
|
||||
IFolderDao folderDao,
|
||||
IFolderDao<int> folderDao,
|
||||
ChunkedUploadSessionHolder chunkedUploadSessionHolder)
|
||||
: base(
|
||||
dbContextManager,
|
||||
@ -102,42 +102,22 @@ namespace ASC.Files.Core.Data
|
||||
ChunkedUploadSessionHolder = chunkedUploadSessionHolder;
|
||||
}
|
||||
|
||||
public void InvalidateCache(object fileId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void InvalidateCache(int fileId)
|
||||
{
|
||||
}
|
||||
|
||||
public File GetFile(object fileId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> GetFile(int fileId)
|
||||
{
|
||||
var query = GetFileQuery(r => r.Id == fileId && r.CurrentVersion);
|
||||
return FromQueryWithShared(query).SingleOrDefault();
|
||||
}
|
||||
|
||||
public File GetFile(object fileId, int fileVersion)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> GetFile(int fileId, int fileVersion)
|
||||
{
|
||||
var query = GetFileQuery(r => r.Id == fileId && r.Version == fileVersion);
|
||||
return FromQueryWithShared(query).SingleOrDefault();
|
||||
}
|
||||
|
||||
public File GetFile(object parentId, string title)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> GetFile(int parentId, string title)
|
||||
{
|
||||
if (string.IsNullOrEmpty(title)) throw new ArgumentNullException(title);
|
||||
@ -148,11 +128,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query).FirstOrDefault();
|
||||
}
|
||||
|
||||
public File GetFileStable(object fileId, int fileVersion = -1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> GetFileStable(int fileId, int fileVersion = -1)
|
||||
{
|
||||
var query = GetFileQuery(r => r.Id == fileId && r.Forcesave == ForcesaveType.None);
|
||||
@ -167,11 +142,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query).SingleOrDefault();
|
||||
}
|
||||
|
||||
public List<File> GetFileHistory(object fileId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<File<int>> GetFileHistory(int fileId)
|
||||
{
|
||||
var query = GetFileQuery(r => r.Id == fileId).OrderByDescending(r => r.Version);
|
||||
@ -179,11 +149,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query);
|
||||
}
|
||||
|
||||
public List<File> GetFiles(object[] fileIds)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<File<int>> GetFiles(int[] fileIds)
|
||||
{
|
||||
if (fileIds == null || fileIds.Length == 0) return new List<File<int>>();
|
||||
@ -193,11 +158,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query);
|
||||
}
|
||||
|
||||
public List<File> GetFilesForShare(object[] fileIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<File<int>> GetFilesForShare(int[] fileIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent)
|
||||
{
|
||||
if (fileIds == null || fileIds.Length == 0 || filterType == FilterType.FoldersOnly) return new List<File<int>>();
|
||||
@ -253,11 +213,6 @@ namespace ASC.Files.Core.Data
|
||||
}
|
||||
|
||||
|
||||
public List<object> GetFiles(object parentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<int> GetFiles(int parentId)
|
||||
{
|
||||
var query = GetFileQuery(r => r.FolderId == parentId && r.CurrentVersion).Select(r => r.Id);
|
||||
@ -268,11 +223,6 @@ namespace ASC.Files.Core.Data
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<File> GetFiles(object parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent, bool withSubfolders = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<File<int>> GetFiles(int parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent, bool withSubfolders = false)
|
||||
{
|
||||
if (filterType == FilterType.FoldersOnly) return new List<File<int>>();
|
||||
@ -362,21 +312,11 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(q);
|
||||
}
|
||||
|
||||
public Stream GetFileStream(File file, long offset)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Stream GetFileStream(File<int> file, long offset)
|
||||
{
|
||||
return GlobalStore.GetStore().GetReadStream(string.Empty, GetUniqFilePath(file), (int)offset);
|
||||
}
|
||||
|
||||
public Uri GetPreSignedUri(File file, TimeSpan expires)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Uri GetPreSignedUri(File<int> file, TimeSpan expires)
|
||||
{
|
||||
return GlobalStore.GetStore().GetPreSignedUri(string.Empty, GetUniqFilePath(file), expires,
|
||||
@ -386,31 +326,16 @@ namespace ASC.Files.Core.Data
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsSupportedPreSignedUri(File file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsSupportedPreSignedUri(File<int> file)
|
||||
{
|
||||
return GlobalStore.GetStore().IsSupportedPreSignedUri;
|
||||
}
|
||||
|
||||
public Stream GetFileStream(File file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Stream GetFileStream(File<int> file)
|
||||
{
|
||||
return GetFileStream(file, 0);
|
||||
}
|
||||
|
||||
public File SaveFile(File file, Stream fileStream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> SaveFile(File<int> file, Stream fileStream)
|
||||
{
|
||||
if (file == null)
|
||||
@ -547,11 +472,6 @@ namespace ASC.Files.Core.Data
|
||||
return GetFile(file.ID);
|
||||
}
|
||||
|
||||
public File ReplaceFileVersion(File file, Stream fileStream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> ReplaceFileVersion(File<int> file, Stream fileStream)
|
||||
{
|
||||
if (file == null) throw new ArgumentNullException("file");
|
||||
@ -691,11 +611,6 @@ namespace ASC.Files.Core.Data
|
||||
GlobalStore.GetStore().Save(string.Empty, GetUniqFilePath(file), stream, file.Title);
|
||||
}
|
||||
|
||||
public void DeleteFile(object fileId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void DeleteFile(int fileId)
|
||||
{
|
||||
DeleteFile(fileId, true);
|
||||
@ -752,11 +667,6 @@ namespace ASC.Files.Core.Data
|
||||
.Any();
|
||||
}
|
||||
|
||||
public object MoveFile(object fileId, object toFolderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int MoveFile(int fileId, int toFolderId)
|
||||
{
|
||||
if (fileId == default) return default;
|
||||
@ -777,7 +687,7 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
f.FolderId = toFolderId;
|
||||
|
||||
if (GlobalFolder.GetFolderTrash(FolderDao).Equals(toFolderId))
|
||||
if (GlobalFolder.GetFolderTrash<int>(FolderDao).Equals(toFolderId))
|
||||
{
|
||||
f.ModifiedBy = AuthContext.CurrentAccount.ID;
|
||||
f.ModifiedOn = DateTime.UtcNow;
|
||||
@ -809,11 +719,6 @@ namespace ASC.Files.Core.Data
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public File CopyFile(object fileId, object toFolderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public File<int> CopyFile(int fileId, int toFolderId)
|
||||
{
|
||||
var file = GetFile(fileId);
|
||||
@ -838,11 +743,6 @@ namespace ASC.Files.Core.Data
|
||||
return null;
|
||||
}
|
||||
|
||||
public object FileRename(File file, string newTitle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int FileRename(File<int> file, string newTitle)
|
||||
{
|
||||
newTitle = Global.ReplaceInvalidCharsAndTruncate(newTitle);
|
||||
@ -860,11 +760,6 @@ namespace ASC.Files.Core.Data
|
||||
return file.ID;
|
||||
}
|
||||
|
||||
public string UpdateComment(object fileId, int fileVersion, string comment)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string UpdateComment(int fileId, int fileVersion, string comment)
|
||||
{
|
||||
comment ??= string.Empty;
|
||||
@ -882,11 +777,6 @@ namespace ASC.Files.Core.Data
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void CompleteVersion(object fileId, int fileVersion)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void CompleteVersion(int fileId, int fileVersion)
|
||||
{
|
||||
var toUpdate = Query(FilesDbContext.Files)
|
||||
@ -901,11 +791,6 @@ namespace ASC.Files.Core.Data
|
||||
FilesDbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public void ContinueVersion(object fileId, int fileVersion)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ContinueVersion(int fileId, int fileVersion)
|
||||
{
|
||||
using var tx = FilesDbContext.Database.BeginTransaction();
|
||||
@ -931,11 +816,6 @@ namespace ASC.Files.Core.Data
|
||||
tx.Commit();
|
||||
}
|
||||
|
||||
public bool UseTrashForRemove(File file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool UseTrashForRemove(File<int> file)
|
||||
{
|
||||
return file.RootFolderType != FolderType.TRASH;
|
||||
@ -963,7 +843,7 @@ namespace ASC.Files.Core.Data
|
||||
|
||||
public string GetUniqFileVersionPath(int fileId, int version)
|
||||
{
|
||||
return fileId != null
|
||||
return fileId != 0
|
||||
? string.Format("{0}/v{1}", GetUniqFileDirectory(fileId), version)
|
||||
: null;
|
||||
}
|
||||
@ -975,21 +855,11 @@ namespace ASC.Files.Core.Data
|
||||
|
||||
#region chunking
|
||||
|
||||
public ChunkedUploadSession<object> CreateUploadSession(File file, long contentLength)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ChunkedUploadSession<int> CreateUploadSession(File<int> file, long contentLength)
|
||||
{
|
||||
return ChunkedUploadSessionHolder.CreateUploadSession(file, contentLength);
|
||||
}
|
||||
|
||||
public void UploadChunk(ChunkedUploadSession<object> uploadSession, Stream stream, long chunkLength)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UploadChunk(ChunkedUploadSession<int> uploadSession, Stream stream, long chunkLength)
|
||||
{
|
||||
if (!uploadSession.UseChunks)
|
||||
@ -1024,11 +894,6 @@ namespace ASC.Files.Core.Data
|
||||
return file;
|
||||
}
|
||||
|
||||
public void AbortUploadSession(ChunkedUploadSession<object> uploadSession)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void AbortUploadSession(ChunkedUploadSession<int> uploadSession)
|
||||
{
|
||||
ChunkedUploadSessionHolder.AbortUploadSession(uploadSession);
|
||||
@ -1060,11 +925,6 @@ namespace ASC.Files.Core.Data
|
||||
|
||||
#region Only in TMFileDao
|
||||
|
||||
public void ReassignFiles(object[] fileIds, Guid newOwnerId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReassignFiles(int[] fileIds, Guid newOwnerId)
|
||||
{
|
||||
var toUpdate = Query(FilesDbContext.Files)
|
||||
@ -1079,11 +939,6 @@ namespace ASC.Files.Core.Data
|
||||
FilesDbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public List<File> GetFiles(object[] parentIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<File<int>> GetFiles(int[] parentIds, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool searchInContent)
|
||||
{
|
||||
if (parentIds == null || parentIds.Length == 0 || filterType == FilterType.FoldersOnly) return new List<File<int>>();
|
||||
@ -1141,12 +996,7 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(q);
|
||||
}
|
||||
|
||||
public IEnumerable<File> Search(string searchText, bool bunch)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerable<File<int>> IFileDao<int>.Search(string searchText, bool bunch)
|
||||
public IEnumerable<File<int>> Search(string searchText, bool bunch)
|
||||
{
|
||||
if (FactoryIndexer.TrySelectIds(s => s.MatchAll(searchText), out var ids))
|
||||
{
|
||||
@ -1176,11 +1026,6 @@ namespace ASC.Files.Core.Data
|
||||
GlobalStore.GetStore().DeleteDirectory(GetUniqFileDirectory(fileId));
|
||||
}
|
||||
|
||||
public bool IsExistOnStorage(File file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsExistOnStorage(File<int> file)
|
||||
{
|
||||
return GlobalStore.GetStore().IsFile(GetUniqFilePath(file));
|
||||
@ -1188,11 +1033,6 @@ namespace ASC.Files.Core.Data
|
||||
|
||||
private const string DiffTitle = "diff.zip";
|
||||
|
||||
public void SaveEditHistory(File file, string changes, Stream differenceStream)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SaveEditHistory(File<int> file, string changes, Stream differenceStream)
|
||||
{
|
||||
if (file == null) throw new ArgumentNullException("file");
|
||||
@ -1215,11 +1055,6 @@ namespace ASC.Files.Core.Data
|
||||
GlobalStore.GetStore().Save(string.Empty, GetUniqFilePath(file, DiffTitle), differenceStream, DiffTitle);
|
||||
}
|
||||
|
||||
public List<EditHistory> GetEditHistory(DocumentServiceHelper documentServiceHelper, object fileId, int fileVersion = 0)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<EditHistory> GetEditHistory(DocumentServiceHelper documentServiceHelper, int fileId, int fileVersion = 0)
|
||||
{
|
||||
var query = Query(FilesDbContext.Files)
|
||||
@ -1254,21 +1089,11 @@ namespace ASC.Files.Core.Data
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Stream GetDifferenceStream(File file)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Stream GetDifferenceStream(File<int> file)
|
||||
{
|
||||
return GlobalStore.GetStore().GetReadStream(string.Empty, GetUniqFilePath(file, DiffTitle));
|
||||
}
|
||||
|
||||
public bool ContainChanges(object fileId, int fileVersion)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool ContainChanges(int fileId, int fileVersion)
|
||||
{
|
||||
return Query(FilesDbContext.Files)
|
||||
@ -1432,9 +1257,7 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
public static DIHelper AddFileDaoService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<IFileDao, FileDao>();
|
||||
services.TryAddScoped<IFileDao<int>, FileDao>();
|
||||
services.TryAddTransient<File>();
|
||||
services.TryAddTransient<File<int>>();
|
||||
|
||||
return services
|
||||
|
@ -50,7 +50,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Files.Core.Data
|
||||
{
|
||||
public class FolderDao : AbstractDao, IFolderDao, IFolderDao<int>
|
||||
public class FolderDao : AbstractDao, IFolderDao<int>
|
||||
{
|
||||
private const string my = "my";
|
||||
private const string common = "common";
|
||||
@ -97,22 +97,12 @@ namespace ASC.Files.Core.Data
|
||||
Logger = options.Get("ASC.Files");
|
||||
}
|
||||
|
||||
public Folder GetFolder(object folderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Folder<int> GetFolder(int folderId)
|
||||
{
|
||||
var query = GetFolderQuery(r => r.Id == folderId);
|
||||
return FromQueryWithShared(query).SingleOrDefault();
|
||||
}
|
||||
|
||||
public Folder GetFolder(string title, object parentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Folder<int> GetFolder(string title, int parentId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(title)) throw new ArgumentNullException(title);
|
||||
@ -123,10 +113,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Folder GetRootFolder(object folderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Folder<int> GetRootFolder(int folderId)
|
||||
{
|
||||
var id = FilesDbContext.Tree
|
||||
@ -140,10 +126,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query).SingleOrDefault();
|
||||
}
|
||||
|
||||
public Folder GetRootFolderByFile(object fileId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Folder<int> GetRootFolderByFile(int fileId)
|
||||
{
|
||||
var subq = Query(FilesDbContext.Files)
|
||||
@ -161,20 +143,11 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(query).SingleOrDefault();
|
||||
}
|
||||
|
||||
public List<Folder> GetFolders(object parentId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public List<Folder<int>> GetFolders(int parentId)
|
||||
{
|
||||
return GetFolders(parentId, default, default, false, default, string.Empty);
|
||||
}
|
||||
|
||||
public List<Folder> GetFolders(object parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<Folder<int>> GetFolders(int parentId, OrderBy orderBy, FilterType filterType, bool subjectGroup, Guid subjectID, string searchText, bool withSubfolders = false)
|
||||
{
|
||||
if (filterType == FilterType.FilesOnly || filterType == FilterType.ByExtension
|
||||
@ -242,11 +215,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(q);
|
||||
}
|
||||
|
||||
public List<Folder> GetFolders(object[] folderIds, FilterType filterType = FilterType.None, bool subjectGroup = false, Guid? subjectID = null, string searchText = "", bool searchSubfolders = false, bool checkShare = true)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<Folder<int>> GetFolders(int[] folderIds, FilterType filterType = FilterType.None, bool subjectGroup = false, Guid? subjectID = null, string searchText = "", bool searchSubfolders = false, bool checkShare = true)
|
||||
{
|
||||
if (filterType == FilterType.FilesOnly || filterType == FilterType.ByExtension
|
||||
@ -298,11 +266,6 @@ namespace ASC.Files.Core.Data
|
||||
return checkShare ? FromQueryWithShared(q) : FromQuery(q);
|
||||
}
|
||||
|
||||
public List<Folder> GetParentFolders(object folderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<Folder<int>> GetParentFolders(int folderId)
|
||||
{
|
||||
var q = GetFolderQuery()
|
||||
@ -314,11 +277,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(q);
|
||||
}
|
||||
|
||||
public object SaveFolder(Folder folder)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int SaveFolder(Folder<int> folder)
|
||||
{
|
||||
if (folder == null) throw new ArgumentNullException("folder");
|
||||
@ -414,10 +372,6 @@ namespace ASC.Files.Core.Data
|
||||
.Any();
|
||||
}
|
||||
|
||||
public void DeleteFolder(object folderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public void DeleteFolder(int id)
|
||||
{
|
||||
if (id == default) throw new ArgumentNullException("folderId");
|
||||
@ -474,10 +428,6 @@ namespace ASC.Files.Core.Data
|
||||
FactoryIndexer.DeleteAsync(new FoldersWrapper { Id = (int)id });
|
||||
}
|
||||
|
||||
public object MoveFolder(object folderId, object toFolderId, CancellationToken? cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public int MoveFolder(int folderId, int toFolderId, CancellationToken? cancellationToken)
|
||||
{
|
||||
using (var tx = FilesDbContext.Database.BeginTransaction())
|
||||
@ -542,10 +492,6 @@ namespace ASC.Files.Core.Data
|
||||
return folderId;
|
||||
}
|
||||
|
||||
public Folder CopyFolder(object folderId, object toFolderId, CancellationToken? cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public Folder<int> CopyFolder(int folderId, int toFolderId, CancellationToken? cancellationToken)
|
||||
{
|
||||
var folder = GetFolder(folderId);
|
||||
@ -569,10 +515,6 @@ namespace ASC.Files.Core.Data
|
||||
return copy;
|
||||
}
|
||||
|
||||
public IDictionary<object, string> CanMoveOrCopy(object[] folderIds, object to)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public IDictionary<int, string> CanMoveOrCopy(int[] folderIds, int to)
|
||||
{
|
||||
var result = new Dictionary<int, string>();
|
||||
@ -624,11 +566,6 @@ namespace ASC.Files.Core.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public object RenameFolder(Folder folder, string newTitle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int RenameFolder(Folder<int> folder, string newTitle)
|
||||
{
|
||||
var toUpdate = Query(FilesDbContext.Folders)
|
||||
@ -644,10 +581,6 @@ namespace ASC.Files.Core.Data
|
||||
return folder.ID;
|
||||
}
|
||||
|
||||
public int GetItemsCount(object folderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int GetItemsCount(int folderId)
|
||||
{
|
||||
@ -675,51 +608,26 @@ namespace ASC.Files.Core.Data
|
||||
return count;
|
||||
}
|
||||
|
||||
public bool IsEmpty(object folderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsEmpty(int folderId)
|
||||
{
|
||||
return GetItemsCount(folderId) == 0;
|
||||
}
|
||||
|
||||
public bool UseTrashForRemove(Folder folder)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool UseTrashForRemove(Folder<int> folder)
|
||||
{
|
||||
return folder.RootFolderType != FolderType.TRASH && folder.FolderType != FolderType.BUNCH;
|
||||
}
|
||||
|
||||
public bool UseRecursiveOperation(object folderId, object toRootFolderId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool UseRecursiveOperation(int folderId, int toRootFolderId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanCalculateSubitems(object entryId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool CanCalculateSubitems(int entryId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public long GetMaxUploadSize(object folderId, bool chunkedUpload)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public long GetMaxUploadSize(int folderId, bool chunkedUpload)
|
||||
{
|
||||
var tmp = long.MaxValue;
|
||||
@ -747,11 +655,6 @@ namespace ASC.Files.Core.Data
|
||||
|
||||
#region Only for TMFolderDao
|
||||
|
||||
public void ReassignFolders(object[] folderIds, Guid newOwnerId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReassignFolders(int[] folderIds, Guid newOwnerId)
|
||||
{
|
||||
var toUpdate = Query(FilesDbContext.Folders)
|
||||
@ -765,12 +668,8 @@ namespace ASC.Files.Core.Data
|
||||
FilesDbContext.SaveChanges();
|
||||
}
|
||||
|
||||
public IEnumerable<Folder> Search(string text, bool bunch)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerable<Folder<int>> IFolderDao<int>.Search(string text, bool bunch)
|
||||
public IEnumerable<Folder<int>> Search(string text, bool bunch)
|
||||
{
|
||||
return Search(text).Where(f => bunch
|
||||
? f.RootFolderType == FolderType.BUNCH
|
||||
@ -791,12 +690,7 @@ namespace ASC.Files.Core.Data
|
||||
return FromQueryWithShared(q);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<object> GetFolderIDs(string module, string bunch, IEnumerable<string> data, bool createIfNotExists)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
IEnumerable<int> IFolderDao<int>.GetFolderIDs(string module, string bunch, IEnumerable<string> data, bool createIfNotExists)
|
||||
public IEnumerable<int> GetFolderIDs(string module, string bunch, IEnumerable<string> data, bool createIfNotExists)
|
||||
{
|
||||
if (string.IsNullOrEmpty(module)) throw new ArgumentNullException("module");
|
||||
if (string.IsNullOrEmpty(bunch)) throw new ArgumentNullException("bunch");
|
||||
@ -863,12 +757,7 @@ namespace ASC.Files.Core.Data
|
||||
return folderIds;
|
||||
}
|
||||
|
||||
public virtual object GetFolderID(string module, string bunch, string data, bool createIfNotExists)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int IFolderDao<int>.GetFolderID(string module, string bunch, string data, bool createIfNotExists)
|
||||
public int GetFolderID(string module, string bunch, string data, bool createIfNotExists)
|
||||
{
|
||||
if (string.IsNullOrEmpty(module)) throw new ArgumentNullException("module");
|
||||
if (string.IsNullOrEmpty(bunch)) throw new ArgumentNullException("bunch");
|
||||
@ -934,53 +823,27 @@ namespace ASC.Files.Core.Data
|
||||
return newFolderId;
|
||||
}
|
||||
|
||||
|
||||
public object GetFolderIDProjects(bool createIfNotExists)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int IFolderDao<int>.GetFolderIDProjects(bool createIfNotExists)
|
||||
{
|
||||
return (this as IFolderDao<int>).GetFolderID(FileConstant.ModuleId, projects, null, createIfNotExists);
|
||||
}
|
||||
|
||||
public object GetFolderIDTrash(bool createIfNotExists, Guid? userId = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int IFolderDao<int>.GetFolderIDTrash(bool createIfNotExists, Guid? userId = null)
|
||||
public int GetFolderIDTrash(bool createIfNotExists, Guid? userId = null)
|
||||
{
|
||||
return (this as IFolderDao<int>).GetFolderID(FileConstant.ModuleId, trash, (userId ?? AuthContext.CurrentAccount.ID).ToString(), createIfNotExists);
|
||||
}
|
||||
|
||||
public object GetFolderIDCommon(bool createIfNotExists)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int IFolderDao<int>.GetFolderIDCommon(bool createIfNotExists)
|
||||
public int GetFolderIDCommon(bool createIfNotExists)
|
||||
{
|
||||
return (this as IFolderDao<int>).GetFolderID(FileConstant.ModuleId, common, null, createIfNotExists);
|
||||
}
|
||||
|
||||
public object GetFolderIDUser(bool createIfNotExists, Guid? userId = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int IFolderDao<int>.GetFolderIDUser(bool createIfNotExists, Guid? userId = null)
|
||||
public int GetFolderIDUser(bool createIfNotExists, Guid? userId = null)
|
||||
{
|
||||
return (this as IFolderDao<int>).GetFolderID(FileConstant.ModuleId, my, (userId ?? AuthContext.CurrentAccount.ID).ToString(), createIfNotExists);
|
||||
}
|
||||
|
||||
public object GetFolderIDShare(bool createIfNotExists)
|
||||
{
|
||||
return GetFolderID(FileConstant.ModuleId, share, null, createIfNotExists);
|
||||
}
|
||||
|
||||
int IFolderDao<int>.GetFolderIDShare(bool createIfNotExists)
|
||||
public int GetFolderIDShare(bool createIfNotExists)
|
||||
{
|
||||
return (this as IFolderDao<int>).GetFolderID(FileConstant.ModuleId, share, null, createIfNotExists);
|
||||
}
|
||||
@ -1096,10 +959,6 @@ namespace ASC.Files.Core.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public string GetBunchObjectID(object folderID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public string GetBunchObjectID(int folderID)
|
||||
{
|
||||
return Query(FilesDbContext.BunchObjects)
|
||||
@ -1108,11 +967,6 @@ namespace ASC.Files.Core.Data
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetBunchObjectIDs(List<object> folderIDs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Dictionary<string, string> GetBunchObjectIDs(List<int> folderIDs)
|
||||
{
|
||||
return Query(FilesDbContext.BunchObjects)
|
||||
@ -1185,9 +1039,7 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
public static DIHelper AddFolderDaoService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<IFolderDao, FolderDao>();
|
||||
services.TryAddScoped<IFolderDao<int>, FolderDao>();
|
||||
services.TryAddTransient<Folder>();
|
||||
services.TryAddTransient<Folder<int>>();
|
||||
|
||||
return services
|
||||
|
@ -42,7 +42,7 @@ using ASC.Web.Studio.Utility;
|
||||
|
||||
namespace ASC.Files.Core.Data
|
||||
{
|
||||
internal class SecurityDao : AbstractDao, ISecurityDao
|
||||
internal class SecurityDao : AbstractDao, ISecurityDao<int>
|
||||
{
|
||||
public SecurityDao(UserManager userManager,
|
||||
DbContextManager<FilesDbContext> dbContextManager,
|
||||
@ -180,7 +180,7 @@ namespace ASC.Files.Core.Data
|
||||
return FromQuery(q);
|
||||
}
|
||||
|
||||
public IEnumerable<FileShareRecord> GetPureShareRecords(IEnumerable<FileEntry> entries)
|
||||
public IEnumerable<FileShareRecord> GetPureShareRecords(IEnumerable<FileEntry<int>> entries)
|
||||
{
|
||||
if (entries == null) return new List<FileShareRecord>();
|
||||
|
||||
@ -195,7 +195,7 @@ namespace ASC.Files.Core.Data
|
||||
return GetPureShareRecordsDb(files, folders);
|
||||
}
|
||||
|
||||
public IEnumerable<FileShareRecord> GetPureShareRecords(FileEntry entry)
|
||||
public IEnumerable<FileShareRecord> GetPureShareRecords(FileEntry<int> entry)
|
||||
{
|
||||
if (entry == null) return new List<FileShareRecord>();
|
||||
|
||||
@ -228,7 +228,7 @@ namespace ASC.Files.Core.Data
|
||||
/// </summary>
|
||||
/// <param name="entries"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<FileShareRecord> GetShares(IEnumerable<FileEntry> entries)
|
||||
public IEnumerable<FileShareRecord> GetShares(IEnumerable<FileEntry<int>> entries)
|
||||
{
|
||||
if (entries == null) return new List<FileShareRecord>();
|
||||
|
||||
@ -248,7 +248,7 @@ namespace ASC.Files.Core.Data
|
||||
/// </summary>
|
||||
/// <param name="entry"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<FileShareRecord> GetShares(FileEntry entry)
|
||||
public IEnumerable<FileShareRecord> GetShares(FileEntry<int> entry)
|
||||
{
|
||||
if (entry == null) return new List<FileShareRecord>();
|
||||
|
||||
@ -259,13 +259,13 @@ namespace ASC.Files.Core.Data
|
||||
return SaveFilesAndFoldersForShare(files, foldersInt);
|
||||
}
|
||||
|
||||
private void SelectFilesAndFoldersForShare(FileEntry entry, ICollection<string> files, ICollection<string> folders, ICollection<int> foldersInt)
|
||||
private void SelectFilesAndFoldersForShare(FileEntry<int> entry, ICollection<string> files, ICollection<string> folders, ICollection<int> foldersInt)
|
||||
{
|
||||
object folderId;
|
||||
if (entry.FileEntryType == FileEntryType.File)
|
||||
{
|
||||
var fileId = MappingID(entry.ID);
|
||||
folderId = ((File)entry).FolderID;
|
||||
folderId = ((File<int>)entry).FolderID;
|
||||
if (!files.Contains(fileId.ToString())) files.Add(fileId.ToString());
|
||||
}
|
||||
else
|
||||
@ -369,7 +369,7 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
public static DIHelper AddSecurityDaoService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<ISecurityDao, SecurityDao>();
|
||||
services.TryAddScoped<ISecurityDao<int>, SecurityDao>();
|
||||
|
||||
return services
|
||||
.AddUserManagerService()
|
||||
|
@ -73,7 +73,7 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetTags(TagType tagType, IEnumerable<FileEntry> fileEntries)
|
||||
public IEnumerable<Tag> GetTags(TagType tagType, IEnumerable<FileEntry<int>> fileEntries)
|
||||
{
|
||||
var filesId = fileEntries.Where(e => e.FileEntryType == FileEntryType.File).Select(e => MappingID(e.ID).ToString()).ToList();
|
||||
var foldersId = fileEntries.Where(e => e.FileEntryType == FileEntryType.Folder).Select(e => MappingID(e.ID).ToString()).ToList();
|
||||
@ -88,11 +88,6 @@ namespace ASC.Files.Core.Data
|
||||
return FromQuery(q);
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetTags(object entryID, FileEntryType entryType, TagType tagType)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetTags(int entryID, FileEntryType entryType, TagType tagType)
|
||||
{
|
||||
var q = Query(FilesDbContext.Tag)
|
||||
@ -381,12 +376,12 @@ namespace ASC.Files.Core.Data
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetNewTags(Guid subject, FileEntry fileEntry)
|
||||
public IEnumerable<Tag> GetNewTags(Guid subject, FileEntry<int> fileEntry)
|
||||
{
|
||||
return GetNewTags(subject, new List<FileEntry>(1) { fileEntry });
|
||||
return GetNewTags(subject, new List<FileEntry<int>>(1) { fileEntry });
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetNewTags(Guid subject, IEnumerable<FileEntry> fileEntries)
|
||||
public IEnumerable<Tag> GetNewTags(Guid subject, IEnumerable<FileEntry<int>> fileEntries)
|
||||
{
|
||||
List<Tag> result;
|
||||
|
||||
@ -419,198 +414,9 @@ namespace ASC.Files.Core.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetNewTags(Guid subject, Folder parentFolder, bool deepSearch)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<Tag> GetNewTags(Guid subject, Folder<int> parentFolder, bool deepSearch)
|
||||
{
|
||||
if (parentFolder == null || parentFolder.ID == 0)
|
||||
throw new ArgumentException("folderId");
|
||||
|
||||
var result = new List<Tag>();
|
||||
|
||||
var monitorFolderIds = new object[] { parentFolder.ID }.AsEnumerable();
|
||||
|
||||
var getBaseSqlQuery = new Func<IQueryable<TagLinkData>>(() =>
|
||||
{
|
||||
var fnResult = Query(FilesDbContext.Tag)
|
||||
.Join(FilesDbContext.TagLink, r => r.Id, l => l.TagId, (tag, link) => new TagLinkData { Tag = tag, Link = link })
|
||||
.Where(r => r.Link.TenantId == r.Tag.TenantId)
|
||||
.Where(r => r.Tag.Flag == TagType.New)
|
||||
.Distinct();
|
||||
|
||||
if (subject != Guid.Empty)
|
||||
{
|
||||
fnResult = fnResult.Where(r => r.Tag.Owner == subject);
|
||||
}
|
||||
|
||||
return fnResult;
|
||||
});
|
||||
|
||||
var tempTags = Enumerable.Empty<Tag>();
|
||||
|
||||
if (parentFolder.FolderType == FolderType.SHARE)
|
||||
{
|
||||
var shareQuery =
|
||||
new Func<IQueryable<TagLinkData>>(() => getBaseSqlQuery().Where(
|
||||
r => FilesDbContext.Security
|
||||
.Where(a => a.TenantId == r.Link.TenantId)
|
||||
.Where(a => a.EntryId == r.Link.EntryId)
|
||||
.Where(a => a.EntryType == r.Link.EntryType)
|
||||
.Any()));
|
||||
|
||||
var tmpShareFileTags =
|
||||
shareQuery()
|
||||
.Join(FilesDbContext.Files, r => r.Link.EntryId, f => f.Id.ToString(), (tagLink, file) => new { tagLink, file })
|
||||
.Where(r => r.file.TenantId == r.tagLink.Link.TenantId)
|
||||
.Where(r => r.file.CreateBy != subject)
|
||||
.Where(r => r.tagLink.Link.EntryType == FileEntryType.File)
|
||||
.Select(r => new
|
||||
{
|
||||
r.tagLink,
|
||||
root = FilesDbContext.Folders
|
||||
.Join(FilesDbContext.Tree, a => a.Id, b => b.ParentId, (folder, tree) => new { folder, tree })
|
||||
.Where(x => x.folder.TenantId == r.file.TenantId)
|
||||
.Where(x => x.tree.FolderId == r.file.FolderId)
|
||||
.OrderByDescending(r => r.tree.Level)
|
||||
.Select(r => r.folder)
|
||||
.FirstOrDefault()
|
||||
})
|
||||
.Where(r => r.root.FolderType == FolderType.USER)
|
||||
.Select(r => r.tagLink);
|
||||
|
||||
tempTags = tempTags.Concat(FromQuery(tmpShareFileTags));
|
||||
|
||||
|
||||
var tmpShareFolderTags =
|
||||
shareQuery()
|
||||
.Join(FilesDbContext.Folders, r => r.Link.EntryId, f => f.Id.ToString(), (tagLink, folder) => new { tagLink, folder })
|
||||
.Where(r => r.folder.TenantId == r.tagLink.Link.TenantId)
|
||||
.Where(r => r.folder.CreateBy != subject)
|
||||
.Where(r => r.tagLink.Link.EntryType == FileEntryType.Folder)
|
||||
.Select(r => new
|
||||
{
|
||||
r.tagLink,
|
||||
root = FilesDbContext.Folders
|
||||
.Join(FilesDbContext.Tree, a => a.Id, b => b.ParentId, (folder, tree) => new { folder, tree })
|
||||
.Where(x => x.folder.TenantId == r.folder.TenantId)
|
||||
.Where(x => x.tree.FolderId == r.folder.ParentId)
|
||||
.OrderByDescending(r => r.tree.Level)
|
||||
.Select(r => r.folder)
|
||||
.FirstOrDefault()
|
||||
})
|
||||
.Where(r => r.root.FolderType == FolderType.USER)
|
||||
.Select(r => r.tagLink);
|
||||
|
||||
tempTags = tempTags.Concat(FromQuery(tmpShareFolderTags));
|
||||
|
||||
var tmpShareSboxTags =
|
||||
shareQuery()
|
||||
.Join(FilesDbContext.ThirdpartyIdMapping, r => r.Link.EntryId, r => r.HashId, (tagLink, mapping) => new { tagLink, mapping })
|
||||
.Where(r => r.mapping.TenantId == r.tagLink.Link.TenantId)
|
||||
.Join(FilesDbContext.ThirdpartyAccount, r => r.mapping.TenantId, r => r.TenantId, (tagLinkMapping, account) => new { tagLinkMapping.tagLink, tagLinkMapping.mapping, account })
|
||||
.Where(r => r.account.UserId != subject)
|
||||
.Where(r => r.account.FolderType == FolderType.USER)
|
||||
.Where(r =>
|
||||
r.mapping.Id.StartsWith("sbox-" + r.account.Id) ||
|
||||
r.mapping.Id.StartsWith("box-" + r.account.Id) ||
|
||||
r.mapping.Id.StartsWith("dropbox-" + r.account.Id) ||
|
||||
r.mapping.Id.StartsWith("spoint-" + r.account.Id) ||
|
||||
r.mapping.Id.StartsWith("drive-" + r.account.Id) ||
|
||||
r.mapping.Id.StartsWith("onedrive-" + r.account.Id)
|
||||
)
|
||||
.Select(r => r.tagLink);
|
||||
|
||||
tempTags = tempTags.Concat(FromQuery(tmpShareSboxTags));
|
||||
}
|
||||
else if (parentFolder.FolderType == FolderType.Projects)
|
||||
{
|
||||
var q = getBaseSqlQuery()
|
||||
.Join(FilesDbContext.BunchObjects, r => r.Link.TenantId, r => r.TenantId, (tagLink, bunch) => new { tagLink, bunch })
|
||||
.Where(r => r.bunch.LeftNode == r.tagLink.Link.EntryId)
|
||||
.Where(r => r.tagLink.Link.EntryType == FileEntryType.Folder)
|
||||
.Where(r => r.bunch.RightNode.StartsWith("projects/project/"))
|
||||
.Select(r => r.tagLink);
|
||||
tempTags = tempTags.Concat(FromQuery(q));
|
||||
}
|
||||
|
||||
if (tempTags.Any())
|
||||
{
|
||||
if (!deepSearch) return tempTags;
|
||||
|
||||
monitorFolderIds = monitorFolderIds.Concat(tempTags.Where(x => x.EntryType == FileEntryType.Folder).Select(x => x.EntryId));
|
||||
result.AddRange(tempTags);
|
||||
}
|
||||
|
||||
var monitorFolderIdsInt = monitorFolderIds.Select(r => Convert.ToInt32(r)).ToList();
|
||||
var subFoldersSqlQuery =
|
||||
FilesDbContext.Tree
|
||||
.Where(r => monitorFolderIdsInt.Any(a => r.ParentId == a));
|
||||
|
||||
if (!deepSearch)
|
||||
{
|
||||
subFoldersSqlQuery = subFoldersSqlQuery.Where(r => r.Level == 1);
|
||||
}
|
||||
|
||||
monitorFolderIds = monitorFolderIds.Concat(subFoldersSqlQuery.Select(r => r.FolderId).ToList().ConvertAll(r => (object)r));
|
||||
|
||||
var monitorFolderIdsStrings = monitorFolderIds.Select(r => r.ToString()).ToList();
|
||||
|
||||
var newTagsForFolders = getBaseSqlQuery()
|
||||
.Where(r => monitorFolderIdsStrings.Any(a => r.Link.EntryId == a))
|
||||
.Where(r => r.Link.EntryType == FileEntryType.Folder);
|
||||
|
||||
result.AddRange(FromQuery(newTagsForFolders));
|
||||
|
||||
var where = (deepSearch ? monitorFolderIds.ToArray() : new object[] { parentFolder.ID })
|
||||
.Select(r => r.ToString())
|
||||
.ToList();
|
||||
|
||||
var newTagsForFiles =
|
||||
getBaseSqlQuery()
|
||||
.Join(FilesDbContext.Files, r => r.Link.EntryId, r => r.Id.ToString(), (tagLink, file) => new { tagLink, file })
|
||||
.Where(r => r.file.TenantId == r.tagLink.Link.TenantId)
|
||||
.Where(r => where.Any(a => r.file.FolderId.ToString() == a))
|
||||
.Where(r => r.tagLink.Link.EntryType == FileEntryType.File)
|
||||
.Select(r => r.tagLink);
|
||||
|
||||
result.AddRange(FromQuery(newTagsForFiles));
|
||||
|
||||
if (parentFolder.FolderType == FolderType.USER || parentFolder.FolderType == FolderType.COMMON)
|
||||
{
|
||||
var folderType = parentFolder.FolderType;
|
||||
|
||||
var querySelect = FilesDbContext.ThirdpartyAccount
|
||||
.Where(r => r.TenantId == TenantID)
|
||||
.Where(r => r.FolderType == folderType);
|
||||
|
||||
if (folderType == FolderType.USER)
|
||||
{
|
||||
querySelect = querySelect.Where(r => r.UserId == subject);
|
||||
}
|
||||
|
||||
var folderIds = querySelect.Select(r => r.Id).ToList();
|
||||
var thirdpartyFolderIds = folderIds.ConvertAll(r => "sbox-" + r)
|
||||
.Concat(folderIds.ConvertAll(r => $"box-{r}"))
|
||||
.Concat(folderIds.ConvertAll(r => $"dropbox-{r}"))
|
||||
.Concat(folderIds.ConvertAll(r => $"spoint-{r}"))
|
||||
.Concat(folderIds.ConvertAll(r => $"drive-{r}"))
|
||||
.Concat(folderIds.ConvertAll(r => $"onedrive-{r}"));
|
||||
|
||||
var newTagsForSBox = getBaseSqlQuery()
|
||||
.Join(FilesDbContext.ThirdpartyIdMapping, r => r.Link.EntryId, r => r.HashId, (tagLink, mapping) => new { tagLink, mapping })
|
||||
.Where(r => r.mapping.TenantId == r.tagLink.Link.TenantId)
|
||||
.Where(r => thirdpartyFolderIds.Any(a => r.mapping.Id == a))
|
||||
.Where(r => r.tagLink.Tag.Owner == subject)
|
||||
.Where(r => r.tagLink.Link.EntryType == FileEntryType.Folder)
|
||||
.Select(r => r.tagLink);
|
||||
|
||||
result.AddRange(FromQuery(newTagsForSBox));
|
||||
}
|
||||
|
||||
return result;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected List<Tag> FromQuery(IQueryable<TagLinkData> dbFilesTags)
|
||||
@ -644,7 +450,6 @@ namespace ASC.Files.Core.Data
|
||||
{
|
||||
public static DIHelper AddTagDaoService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<ITagDao, TagDao>();
|
||||
services.TryAddScoped<ITagDao<int>, TagDao>();
|
||||
return services
|
||||
.AddUserManagerService()
|
||||
|
@ -54,41 +54,10 @@ namespace ASC.Files.Core
|
||||
[EnumMember] IsEditingAlone = 0x10
|
||||
}
|
||||
|
||||
public class File<T> : File
|
||||
{
|
||||
[DataMember(Name = "id")]
|
||||
public new T ID { get; set; }
|
||||
|
||||
public new T FolderID { get; set; }
|
||||
|
||||
private T _folderIdDisplay;
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
public new T FolderIdDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_folderIdDisplay != null) return _folderIdDisplay;
|
||||
|
||||
return FolderID;
|
||||
}
|
||||
set { _folderIdDisplay = value; }
|
||||
}
|
||||
|
||||
public new string UniqID
|
||||
{
|
||||
get { return string.Format("{0}_{1}", GetType().Name.ToLower(), ID); }
|
||||
}
|
||||
|
||||
public File(Global global, FilesLinkUtility filesLinkUtility, FileUtility fileUtility, FileConverter fileConverter) : base(global, filesLinkUtility, fileUtility, fileConverter)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract(Name = "file", Namespace = "")]
|
||||
[DebuggerDisplay("{Title} ({ID} v{Version})")]
|
||||
public class File : FileEntry
|
||||
public class File<T> : FileEntry<T>
|
||||
{
|
||||
private FileStatus _status;
|
||||
|
||||
@ -106,7 +75,7 @@ namespace ASC.Files.Core
|
||||
FileConverter = fileConverter;
|
||||
}
|
||||
|
||||
public object FolderID { get; set; }
|
||||
public T FolderID { get; set; }
|
||||
|
||||
[DataMember(Name = "version")]
|
||||
public int Version { get; set; }
|
||||
@ -250,10 +219,10 @@ namespace ASC.Files.Core
|
||||
public FileUtility FileUtility { get; }
|
||||
public FileConverter FileConverter { get; }
|
||||
|
||||
private object _folderIdDisplay;
|
||||
private T _folderIdDisplay;
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
public override object FolderIdDisplay
|
||||
public override T FolderIdDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -264,7 +233,7 @@ namespace ASC.Files.Core
|
||||
set { _folderIdDisplay = value; }
|
||||
}
|
||||
|
||||
public static string Serialize(File file)
|
||||
public static string Serialize(File<T> file)
|
||||
{
|
||||
using (var ms = new FileEntrySerializer().ToXml(file))
|
||||
{
|
||||
|
@ -33,10 +33,8 @@ using ASC.Web.Files.Classes;
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Name = "entry", Namespace = "")]
|
||||
[KnownType(typeof(Folder))]
|
||||
[KnownType(typeof(File))]
|
||||
[Serializable]
|
||||
public abstract class FileEntry : ICloneable
|
||||
public abstract class FileEntry<T> : ICloneable
|
||||
{
|
||||
public FileEntry(Global global)
|
||||
{
|
||||
@ -44,7 +42,7 @@ namespace ASC.Files.Core
|
||||
}
|
||||
|
||||
[DataMember(Name = "id")]
|
||||
public object ID { get; set; }
|
||||
public T ID { get; set; }
|
||||
|
||||
[DataMember(Name = "title", IsRequired = true)]
|
||||
public virtual string Title { get; set; }
|
||||
@ -99,7 +97,7 @@ namespace ASC.Files.Core
|
||||
public string ProviderKey { get; set; }
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
public abstract object FolderIdDisplay
|
||||
public abstract T FolderIdDisplay
|
||||
{
|
||||
get;
|
||||
set;
|
||||
@ -118,7 +116,7 @@ namespace ASC.Files.Core
|
||||
|
||||
public Guid RootFolderCreator { get; set; }
|
||||
|
||||
public object RootFolderId { get; set; }
|
||||
public T RootFolderId { get; set; }
|
||||
|
||||
public abstract bool IsNew { get; set; }
|
||||
|
||||
@ -136,8 +134,12 @@ namespace ASC.Files.Core
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var f = obj as FileEntry;
|
||||
return f != null && Equals(f.ID, ID);
|
||||
return obj is FileEntry<T> f && Equals(f.ID, ID);
|
||||
}
|
||||
|
||||
public bool Equals(FileEntry<T> obj)
|
||||
{
|
||||
return Equals(obj.ID, ID);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
@ -50,44 +50,13 @@ namespace ASC.Files.Core
|
||||
[EnumMember] Projects = 8
|
||||
}
|
||||
|
||||
public class Folder<T> : Folder
|
||||
{
|
||||
[DataMember(Name = "id")]
|
||||
public new T ID { get; set; }
|
||||
|
||||
public new T ParentFolderID { get; set; }
|
||||
|
||||
private T _folderIdDisplay;
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
public new T FolderIdDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_folderIdDisplay != null) return _folderIdDisplay;
|
||||
|
||||
return ParentFolderID;
|
||||
}
|
||||
set { _folderIdDisplay = value; }
|
||||
}
|
||||
|
||||
public new string UniqID
|
||||
{
|
||||
get { return string.Format("{0}_{1}", GetType().Name.ToLower(), ID); }
|
||||
}
|
||||
|
||||
public Folder(Global global) : base(global)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "folder", Namespace = "")]
|
||||
[DebuggerDisplay("{Title} ({ID})")]
|
||||
public class Folder : FileEntry
|
||||
public class Folder<T> : FileEntry<T>
|
||||
{
|
||||
public FolderType FolderType { get; set; }
|
||||
|
||||
public object ParentFolderID { get; set; }
|
||||
public T ParentFolderID { get; set; }
|
||||
|
||||
[DataMember(Name = "total_files")]
|
||||
public int TotalFiles { get; set; }
|
||||
@ -110,10 +79,10 @@ namespace ASC.Files.Core
|
||||
set { NewForMe = Convert.ToInt32(value); }
|
||||
}
|
||||
|
||||
private object _folderIdDisplay;
|
||||
private T _folderIdDisplay;
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
public override object FolderIdDisplay
|
||||
public override T FolderIdDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -78,12 +78,12 @@ namespace ASC.Files.Core
|
||||
}
|
||||
|
||||
|
||||
public static Tag New(Guid owner, FileEntry entry)
|
||||
public static Tag New<T>(Guid owner, FileEntry<T> entry)
|
||||
{
|
||||
return New(owner, entry, 1);
|
||||
}
|
||||
|
||||
public static Tag New(Guid owner, FileEntry entry, int count)
|
||||
public static Tag New<T>(Guid owner, FileEntry<T> entry, int count)
|
||||
{
|
||||
return new Tag("new", TagType.New, owner, entry, count);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,9 +38,7 @@ using ASC.Files.Core.Data;
|
||||
using ASC.Files.Resources;
|
||||
using ASC.Web.Core.Files;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace ASC.Web.Files.Core.Search
|
||||
{
|
||||
@ -93,12 +91,12 @@ namespace ASC.Web.Files.Core.Search
|
||||
DaoFactory = daoFactory;
|
||||
}
|
||||
|
||||
public static FilesWrapper GetFilesWrapper(IServiceProvider serviceProvider, File d, List<int> parentFolders = null)
|
||||
public static FilesWrapper GetFilesWrapper<T>(IServiceProvider serviceProvider, File<T> d, List<int> parentFolders = null)
|
||||
{
|
||||
var wrapper = serviceProvider.GetService<FilesWrapper>();
|
||||
var tenantManager = serviceProvider.GetService<TenantManager>();
|
||||
|
||||
wrapper.Id = (int)d.ID;
|
||||
wrapper.Id = Convert.ToInt32(d.ID);
|
||||
wrapper.Title = d.Title;
|
||||
wrapper.Version = d.Version;
|
||||
wrapper.Encrypted = d.Encrypted;
|
||||
@ -120,8 +118,8 @@ namespace ASC.Web.Files.Core.Search
|
||||
if (Encrypted) return null;
|
||||
if (!FileUtility.CanIndex(Title)) return null;
|
||||
|
||||
var fileDao = DaoFactory.FileDao;
|
||||
var file = ServiceProvider.GetService<File>();
|
||||
var fileDao = DaoFactory.GetFileDao<int>();
|
||||
var file = ServiceProvider.GetService<File<int>>();
|
||||
file.ID = Id;
|
||||
file.Title = Title;
|
||||
file.Version = Version;
|
||||
|
@ -45,13 +45,13 @@ namespace ASC.Web.Files.Core.Search
|
||||
|
||||
protected override string Table { get { return "files_folder"; } }
|
||||
|
||||
public static FoldersWrapper GetFolderWrapper(IServiceProvider serviceProvider, Folder d)
|
||||
public static FoldersWrapper GetFolderWrapper<T>(IServiceProvider serviceProvider, Folder<T> d)
|
||||
{
|
||||
var tenantManager = serviceProvider.GetService<TenantManager>();
|
||||
|
||||
return new FoldersWrapper
|
||||
{
|
||||
Id = (int)d.ID,
|
||||
Id = Convert.ToInt32(d.ID),
|
||||
Title = d.Title,
|
||||
TenantId = tenantManager.GetCurrentTenant().TenantId
|
||||
};
|
||||
|
@ -101,87 +101,87 @@ namespace ASC.Files.Core.Security
|
||||
FileSecurityCommon = fileSecurityCommon;
|
||||
}
|
||||
|
||||
public List<Tuple<FileEntry, bool>> CanRead<T>(IEnumerable<FileEntry> entry, Guid userId)
|
||||
public List<Tuple<FileEntry<T>, bool>> CanRead<T>(IEnumerable<FileEntry<T>> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Read);
|
||||
return Can(entry, userId, FilesSecurityActions.Read);
|
||||
}
|
||||
|
||||
public bool CanRead<T>(FileEntry entry, Guid userId)
|
||||
public bool CanRead<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Read);
|
||||
return Can(entry, userId, FilesSecurityActions.Read);
|
||||
}
|
||||
|
||||
public bool CanComment<T>(FileEntry entry, Guid userId)
|
||||
public bool CanComment<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Comment);
|
||||
return Can(entry, userId, FilesSecurityActions.Comment);
|
||||
}
|
||||
|
||||
public bool CanFillForms<T>(FileEntry entry, Guid userId)
|
||||
public bool CanFillForms<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.FillForms);
|
||||
return Can(entry, userId, FilesSecurityActions.FillForms);
|
||||
}
|
||||
|
||||
public bool CanReview<T>(FileEntry entry, Guid userId)
|
||||
public bool CanReview<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Review);
|
||||
return Can(entry, userId, FilesSecurityActions.Review);
|
||||
}
|
||||
|
||||
public bool CanCreate<T>(FileEntry entry, Guid userId)
|
||||
public bool CanCreate<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Create);
|
||||
return Can(entry, userId, FilesSecurityActions.Create);
|
||||
}
|
||||
|
||||
public bool CanEdit<T>(FileEntry entry, Guid userId)
|
||||
public bool CanEdit<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Edit);
|
||||
return Can(entry, userId, FilesSecurityActions.Edit);
|
||||
}
|
||||
|
||||
public bool CanDelete<T>(FileEntry entry, Guid userId)
|
||||
public bool CanDelete<T>(FileEntry<T> entry, Guid userId)
|
||||
{
|
||||
return Can<T>(entry, userId, FilesSecurityActions.Delete);
|
||||
return Can(entry, userId, FilesSecurityActions.Delete);
|
||||
}
|
||||
|
||||
public bool CanRead<T>(FileEntry entry)
|
||||
public bool CanRead<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanRead<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanRead(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public bool CanComment<T>(FileEntry entry)
|
||||
public bool CanComment<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanComment<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanComment(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public bool CanFillForms<T>(FileEntry entry)
|
||||
public bool CanFillForms<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanFillForms<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanFillForms(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public bool CanReview<T>(FileEntry entry)
|
||||
public bool CanReview<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanReview<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanReview(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public bool CanCreate<T>(FileEntry entry)
|
||||
public bool CanCreate<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanCreate<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanCreate(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public bool CanEdit<T>(FileEntry entry)
|
||||
public bool CanEdit<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanEdit<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanEdit(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public bool CanDelete<T>(FileEntry entry)
|
||||
public bool CanDelete<T>(FileEntry<T> entry)
|
||||
{
|
||||
return CanDelete<T>(entry, AuthContext.CurrentAccount.ID);
|
||||
return CanDelete(entry, AuthContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public IEnumerable<Guid> WhoCanRead<T>(FileEntry entry)
|
||||
public IEnumerable<Guid> WhoCanRead<T>(FileEntry<T> entry)
|
||||
{
|
||||
return WhoCan<T>(entry, FilesSecurityActions.Read);
|
||||
return WhoCan(entry, FilesSecurityActions.Read);
|
||||
}
|
||||
|
||||
private IEnumerable<Guid> WhoCan<T>(FileEntry entry, FilesSecurityActions action)
|
||||
private IEnumerable<Guid> WhoCan<T>(FileEntry<T> entry, FilesSecurityActions action)
|
||||
{
|
||||
var shares = GetShares(entry);
|
||||
|
||||
@ -236,7 +236,7 @@ namespace ASC.Files.Core.Security
|
||||
case FolderType.BUNCH:
|
||||
if (action == FilesSecurityActions.Read)
|
||||
{
|
||||
var folderDao = daoFactory.FolderDao;
|
||||
var folderDao = daoFactory.GetFolderDao<T>();
|
||||
var root = folderDao.GetFolder(entry.RootFolderId);
|
||||
if (root != null)
|
||||
{
|
||||
@ -246,7 +246,7 @@ namespace ASC.Files.Core.Security
|
||||
|
||||
if (adapter != null)
|
||||
{
|
||||
return adapter.WhoCanRead<T>(entry);
|
||||
return adapter.WhoCanRead(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -276,58 +276,58 @@ namespace ASC.Files.Core.Security
|
||||
return new[] { x.Subject };
|
||||
})
|
||||
.Distinct()
|
||||
.Where(x => Can<T>(entry, x, action))
|
||||
.Where(x => Can(entry, x, action))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<File<T>> FilterRead<T>(IEnumerable<File<T>> entries)
|
||||
{
|
||||
return Filter<T>(entries.Cast<FileEntry>(), FilesSecurityActions.Read, AuthContext.CurrentAccount.ID).Cast<File<T>>();
|
||||
return Filter(entries.Cast<FileEntry<T>>(), FilesSecurityActions.Read, AuthContext.CurrentAccount.ID).Cast<File<T>>();
|
||||
}
|
||||
|
||||
public IEnumerable<Folder<T>> FilterRead<T>(IEnumerable<Folder<T>> entries)
|
||||
{
|
||||
return Filter<T>(entries.Cast<FileEntry>(), FilesSecurityActions.Read, AuthContext.CurrentAccount.ID).Cast<Folder<T>>();
|
||||
return Filter(entries.Cast<FileEntry<T>>(), FilesSecurityActions.Read, AuthContext.CurrentAccount.ID).Cast<Folder<T>>();
|
||||
}
|
||||
|
||||
public IEnumerable<File<T>> FilterEdit<T>(IEnumerable<File<T>> entries)
|
||||
{
|
||||
return Filter<T>(entries.Cast<FileEntry>(), FilesSecurityActions.Edit, AuthContext.CurrentAccount.ID).Cast<File<T>>();
|
||||
return Filter(entries.Cast<FileEntry<T>>(), FilesSecurityActions.Edit, AuthContext.CurrentAccount.ID).Cast<File<T>>();
|
||||
}
|
||||
|
||||
public IEnumerable<Folder<T>> FilterEdit<T>(IEnumerable<Folder<T>> entries)
|
||||
{
|
||||
return Filter<T>(entries.Cast<FileEntry>(), FilesSecurityActions.Edit, AuthContext.CurrentAccount.ID).Cast<Folder<T>>();
|
||||
return Filter(entries.Cast<FileEntry<T>>(), FilesSecurityActions.Edit, AuthContext.CurrentAccount.ID).Cast<Folder<T>>();
|
||||
}
|
||||
|
||||
private bool Can<T>(FileEntry entry, Guid userId, FilesSecurityActions action)
|
||||
private bool Can<T>(FileEntry<T> entry, Guid userId, FilesSecurityActions action)
|
||||
{
|
||||
return Filter<T>(new[] { entry }, action, userId).Any();
|
||||
return Filter(new[] { entry }, action, userId).Any();
|
||||
}
|
||||
|
||||
private List<Tuple<FileEntry, bool>> Can<T>(IEnumerable<FileEntry> entry, Guid userId, FilesSecurityActions action)
|
||||
private List<Tuple<FileEntry<T>, bool>> Can<T>(IEnumerable<FileEntry<T>> entry, Guid userId, FilesSecurityActions action)
|
||||
{
|
||||
var filtres = Filter<T>(entry, action, userId);
|
||||
return entry.Select(r => new Tuple<FileEntry, bool>(r, filtres.Any(a => a.ID.Equals(r.ID)))).ToList();
|
||||
var filtres = Filter(entry, action, userId);
|
||||
return entry.Select(r => new Tuple<FileEntry<T>, bool>(r, filtres.Any(a => a.ID.Equals(r.ID)))).ToList();
|
||||
}
|
||||
|
||||
private IEnumerable<FileEntry> Filter<T>(IEnumerable<FileEntry> entries, FilesSecurityActions action, Guid userId)
|
||||
private IEnumerable<FileEntry<T>> Filter<T>(IEnumerable<FileEntry<T>> entries, FilesSecurityActions action, Guid userId)
|
||||
{
|
||||
if (entries == null || !entries.Any()) return Enumerable.Empty<FileEntry>();
|
||||
if (entries == null || !entries.Any()) return Enumerable.Empty<FileEntry<T>>();
|
||||
|
||||
var user = UserManager.GetUsers(userId);
|
||||
var isOutsider = user.IsOutsider(UserManager);
|
||||
|
||||
if (isOutsider && action != FilesSecurityActions.Read) return Enumerable.Empty<FileEntry>();
|
||||
if (isOutsider && action != FilesSecurityActions.Read) return Enumerable.Empty<FileEntry<T>>();
|
||||
|
||||
entries = entries.Where(f => f != null).ToList();
|
||||
var result = new List<FileEntry>(entries.Count());
|
||||
var result = new List<FileEntry<T>>(entries.Count());
|
||||
|
||||
// save entries order
|
||||
var order = entries.Select((f, i) => new { Id = GetUniqID(f), Pos = i }).ToDictionary(e => e.Id, e => e.Pos);
|
||||
var order = entries.Select((f, i) => new { Id = f.UniqID, Pos = i }).ToDictionary(e => e.Id, e => e.Pos);
|
||||
|
||||
// common or my files
|
||||
Func<FileEntry, bool> filter =
|
||||
Func<FileEntry<T>, bool> filter =
|
||||
f => f.RootFolderType == FolderType.COMMON ||
|
||||
f.RootFolderType == FolderType.USER ||
|
||||
f.RootFolderType == FolderType.SHARE ||
|
||||
@ -353,13 +353,13 @@ namespace ASC.Files.Core.Security
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action != FilesSecurityActions.Read && e.FileEntryType == FileEntryType.Folder && ((Folder)e).FolderType == FolderType.Projects)
|
||||
if (action != FilesSecurityActions.Read && e.FileEntryType == FileEntryType.Folder && ((Folder<T>)e).FolderType == FolderType.Projects)
|
||||
{
|
||||
// Root Projects folder read-only
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action != FilesSecurityActions.Read && e.FileEntryType == FileEntryType.Folder && ((Folder)e).FolderType == FolderType.SHARE)
|
||||
if (action != FilesSecurityActions.Read && e.FileEntryType == FileEntryType.Folder && ((Folder<T>)e).FolderType == FolderType.SHARE)
|
||||
{
|
||||
// Root Share folder read-only
|
||||
continue;
|
||||
@ -378,7 +378,7 @@ namespace ASC.Files.Core.Security
|
||||
}
|
||||
|
||||
if (DefaultCommonShare == FileShare.Read && action == FilesSecurityActions.Read && e.FileEntryType == FileEntryType.Folder &&
|
||||
((Folder)e).FolderType == FolderType.COMMON)
|
||||
((Folder<T>)e).FolderType == FolderType.COMMON)
|
||||
{
|
||||
// all can read Common folder
|
||||
result.Add(e);
|
||||
@ -386,7 +386,7 @@ namespace ASC.Files.Core.Security
|
||||
}
|
||||
|
||||
if (action == FilesSecurityActions.Read && e.FileEntryType == FileEntryType.Folder &&
|
||||
((Folder)e).FolderType == FolderType.SHARE)
|
||||
((Folder<T>)e).FolderType == FolderType.SHARE)
|
||||
{
|
||||
// all can read Share folder
|
||||
result.Add(e);
|
||||
@ -416,7 +416,7 @@ namespace ASC.Files.Core.Security
|
||||
if (ace == null)
|
||||
{
|
||||
// share on parent folders
|
||||
ace = shares.Where(r => Equals(r.EntryId, ((File)e).FolderID) && r.EntryType == FileEntryType.Folder)
|
||||
ace = shares.Where(r => Equals(r.EntryId, ((File<T>)e).FolderID) && r.EntryType == FileEntryType.Folder)
|
||||
.OrderBy(r => r, new SubjectComparer(subjects))
|
||||
.ThenBy(r => r.Level)
|
||||
.ThenByDescending(r => r.Share, new FileShareRecord.ShareComparer())
|
||||
@ -440,7 +440,7 @@ namespace ASC.Files.Core.Security
|
||||
else if (action == FilesSecurityActions.Review && (e.Access == FileShare.Review || e.Access == FileShare.ReadWrite)) result.Add(e);
|
||||
else if (action == FilesSecurityActions.Edit && e.Access == FileShare.ReadWrite) result.Add(e);
|
||||
else if (action == FilesSecurityActions.Create && e.Access == FileShare.ReadWrite) result.Add(e);
|
||||
else if (e.Access != FileShare.Restrict && e.CreateBy == userId && (e.FileEntryType == FileEntryType.File || ((Folder)e).FolderType != FolderType.COMMON)) result.Add(e);
|
||||
else if (e.Access != FileShare.Restrict && e.CreateBy == userId && (e.FileEntryType == FileEntryType.File || ((Folder<T>)e).FolderType != FolderType.COMMON)) result.Add(e);
|
||||
|
||||
if (e.CreateBy == userId) e.Access = FileShare.None; //HACK: for client
|
||||
}
|
||||
@ -450,7 +450,7 @@ namespace ASC.Files.Core.Security
|
||||
filter = f => f.RootFolderType == FolderType.BUNCH;
|
||||
if (entries.Any(filter))
|
||||
{
|
||||
var folderDao = daoFactory.FolderDao;
|
||||
var folderDao = daoFactory.GetFolderDao<T>();
|
||||
var filteredEntries = entries.Where(filter).ToList();
|
||||
var roots = filteredEntries
|
||||
.Select(r => r.RootFolderId)
|
||||
@ -466,51 +466,51 @@ namespace ASC.Files.Core.Security
|
||||
|
||||
if (adapter == null) continue;
|
||||
|
||||
if (adapter.CanRead<T>(e, userId) &&
|
||||
adapter.CanCreate<T>(e, userId) &&
|
||||
adapter.CanEdit<T>(e, userId) &&
|
||||
adapter.CanDelete<T>(e, userId))
|
||||
if (adapter.CanRead(e, userId) &&
|
||||
adapter.CanCreate(e, userId) &&
|
||||
adapter.CanEdit(e, userId) &&
|
||||
adapter.CanDelete(e, userId))
|
||||
{
|
||||
e.Access = FileShare.None;
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.Comment && adapter.CanComment<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.Comment && adapter.CanComment(e, userId))
|
||||
{
|
||||
e.Access = FileShare.Comment;
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.FillForms && adapter.CanFillForms<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.FillForms && adapter.CanFillForms(e, userId))
|
||||
{
|
||||
e.Access = FileShare.FillForms;
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.Review && adapter.CanReview<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.Review && adapter.CanReview(e, userId))
|
||||
{
|
||||
e.Access = FileShare.Review;
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.Create && adapter.CanCreate<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.Create && adapter.CanCreate(e, userId))
|
||||
{
|
||||
e.Access = FileShare.ReadWrite;
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.Delete && adapter.CanDelete<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.Delete && adapter.CanDelete(e, userId))
|
||||
{
|
||||
e.Access = FileShare.ReadWrite;
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.Read && adapter.CanRead<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.Read && adapter.CanRead(e, userId))
|
||||
{
|
||||
if (adapter.CanCreate<T>(e, userId) ||
|
||||
adapter.CanDelete<T>(e, userId) ||
|
||||
adapter.CanEdit<T>(e, userId))
|
||||
if (adapter.CanCreate(e, userId) ||
|
||||
adapter.CanDelete(e, userId) ||
|
||||
adapter.CanEdit(e, userId))
|
||||
e.Access = FileShare.ReadWrite;
|
||||
else
|
||||
e.Access = FileShare.Read;
|
||||
|
||||
result.Add(e);
|
||||
}
|
||||
else if (action == FilesSecurityActions.Edit && adapter.CanEdit<T>(e, userId))
|
||||
else if (action == FilesSecurityActions.Edit && adapter.CanEdit(e, userId))
|
||||
{
|
||||
e.Access = FileShare.ReadWrite;
|
||||
|
||||
@ -523,7 +523,7 @@ namespace ASC.Files.Core.Security
|
||||
filter = f => f.RootFolderType == FolderType.TRASH;
|
||||
if ((action == FilesSecurityActions.Read || action == FilesSecurityActions.Delete) && entries.Any(filter))
|
||||
{
|
||||
var folderDao = daoFactory.FolderDao;
|
||||
var folderDao = daoFactory.GetFolderDao<T>();
|
||||
var mytrashId = folderDao.GetFolderIDTrash(false, userId);
|
||||
if (!Equals(mytrashId, 0))
|
||||
{
|
||||
@ -539,19 +539,13 @@ namespace ASC.Files.Core.Security
|
||||
}
|
||||
|
||||
// restore entries order
|
||||
result.Sort((x, y) => order[GetUniqID(x)].CompareTo(order[GetUniqID(y)]));
|
||||
result.Sort((x, y) => order[x.UniqID].CompareTo(order[y.UniqID]));
|
||||
return result;
|
||||
|
||||
//TODO
|
||||
string GetUniqID(FileEntry f)
|
||||
{
|
||||
return (f as File<T>)?.UniqID ?? (f as Folder<T>)?.UniqID;
|
||||
};
|
||||
}
|
||||
|
||||
public void Share(object entryId, FileEntryType entryType, Guid @for, FileShare share)
|
||||
public void Share<T>(T entryId, FileEntryType entryType, Guid @for, FileShare share)
|
||||
{
|
||||
var securityDao = daoFactory.SecurityDao;
|
||||
var securityDao = daoFactory.GetSecurityDao<T>();
|
||||
var r = new FileShareRecord
|
||||
{
|
||||
Tenant = TenantManager.GetCurrentTenant().TenantId,
|
||||
@ -564,21 +558,21 @@ namespace ASC.Files.Core.Security
|
||||
securityDao.SetShare(r);
|
||||
}
|
||||
|
||||
public IEnumerable<FileShareRecord> GetShares(IEnumerable<FileEntry> entries)
|
||||
public IEnumerable<FileShareRecord> GetShares<T>(IEnumerable<FileEntry<T>> entries)
|
||||
{
|
||||
return daoFactory.SecurityDao.GetShares(entries);
|
||||
return daoFactory.GetSecurityDao<T>().GetShares(entries);
|
||||
}
|
||||
|
||||
public IEnumerable<FileShareRecord> GetShares(FileEntry entry)
|
||||
public IEnumerable<FileShareRecord> GetShares<T>(FileEntry<T> entry)
|
||||
{
|
||||
return daoFactory.SecurityDao.GetShares(entry);
|
||||
return daoFactory.GetSecurityDao<T>().GetShares(entry);
|
||||
}
|
||||
|
||||
public List<FileEntry> GetSharesForMe<T>(FilterType filterType, bool subjectGroup, Guid subjectID, string searchText = "", bool searchInContent = false, bool withSubfolders = false)
|
||||
public List<FileEntry<T>> GetSharesForMe<T>(FilterType filterType, bool subjectGroup, Guid subjectID, string searchText = "", bool searchInContent = false, bool withSubfolders = false)
|
||||
{
|
||||
var folderDao = daoFactory.GetFolderDao<T>();
|
||||
var fileDao = daoFactory.GetFileDao<T>();
|
||||
var securityDao = daoFactory.SecurityDao;
|
||||
var securityDao = daoFactory.GetSecurityDao<T>();
|
||||
var subjects = GetUserSubjects(AuthContext.CurrentAccount.ID);
|
||||
|
||||
var records = securityDao.GetShares(subjects);
|
||||
@ -607,7 +601,7 @@ namespace ASC.Files.Core.Security
|
||||
}
|
||||
}
|
||||
|
||||
var entries = new List<FileEntry>();
|
||||
var entries = new List<FileEntry<T>>();
|
||||
|
||||
if (filterType != FilterType.FoldersOnly)
|
||||
{
|
||||
@ -642,7 +636,7 @@ namespace ASC.Files.Core.Security
|
||||
}
|
||||
});
|
||||
|
||||
entries.AddRange(folders.Cast<FileEntry>());
|
||||
entries.AddRange(folders.Cast<FileEntry<T>>());
|
||||
}
|
||||
|
||||
if (filterType != FilterType.FoldersOnly && withSubfolders)
|
||||
@ -685,9 +679,9 @@ namespace ASC.Files.Core.Security
|
||||
return entries.Where(x => string.IsNullOrEmpty(x.Error)).ToList();
|
||||
}
|
||||
|
||||
public void RemoveSubject(Guid subject)
|
||||
public void RemoveSubject<T>(Guid subject)
|
||||
{
|
||||
daoFactory.SecurityDao.RemoveSubject(subject);
|
||||
daoFactory.GetSecurityDao<T>().RemoveSubject(subject);
|
||||
}
|
||||
|
||||
public List<Guid> GetUserSubjects(Guid userId)
|
||||
|
@ -31,20 +31,20 @@ namespace ASC.Files.Core.Security
|
||||
{
|
||||
public interface IFileSecurity
|
||||
{
|
||||
bool CanRead<T>(FileEntry entry, Guid userId);
|
||||
bool CanRead<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
bool CanComment<T>(FileEntry entry, Guid userId);
|
||||
bool CanComment<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
bool CanReview<T>(FileEntry entry, Guid userId);
|
||||
bool CanReview<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
bool CanFillForms<T>(FileEntry entry, Guid userId);
|
||||
bool CanFillForms<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
bool CanCreate<T>(FileEntry entry, Guid userId);
|
||||
bool CanCreate<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
bool CanEdit<T>(FileEntry entry, Guid userId);
|
||||
bool CanEdit<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
bool CanDelete<T>(FileEntry entry, Guid userId);
|
||||
bool CanDelete<T>(FileEntry<T> entry, Guid userId);
|
||||
|
||||
IEnumerable<Guid> WhoCanRead<T>(FileEntry entry);
|
||||
IEnumerable<Guid> WhoCanRead<T>(FileEntry<T> entry);
|
||||
}
|
||||
}
|
@ -29,21 +29,21 @@ using System.Collections.Generic;
|
||||
|
||||
namespace ASC.Files.Core.Security
|
||||
{
|
||||
public interface ISecurityDao
|
||||
public interface ISecurityDao<T>
|
||||
{
|
||||
void SetShare(FileShareRecord r);
|
||||
|
||||
IEnumerable<FileShareRecord> GetShares(IEnumerable<Guid> subjects);
|
||||
|
||||
IEnumerable<FileShareRecord> GetShares(IEnumerable<FileEntry> entry);
|
||||
IEnumerable<FileShareRecord> GetShares(IEnumerable<FileEntry<T>> entry);
|
||||
|
||||
IEnumerable<FileShareRecord> GetShares(FileEntry entry);
|
||||
IEnumerable<FileShareRecord> GetShares(FileEntry<T> entry);
|
||||
|
||||
void RemoveSubject(Guid subject);
|
||||
|
||||
IEnumerable<FileShareRecord> GetPureShareRecords(IEnumerable<FileEntry> entries);
|
||||
IEnumerable<FileShareRecord> GetPureShareRecords(IEnumerable<FileEntry<T>> entries);
|
||||
|
||||
IEnumerable<FileShareRecord> GetPureShareRecords(FileEntry entry);
|
||||
IEnumerable<FileShareRecord> GetPureShareRecords(FileEntry<T> entry);
|
||||
|
||||
void DeleteShareRecords(IEnumerable<FileShareRecord> records);
|
||||
|
||||
|
@ -254,7 +254,7 @@ namespace ASC.Web.Files.Helpers
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
file = fileDao.GetFile(fileId);
|
||||
if (file == null) throw new Exception(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
if (!FileSecurity.CanRead<T>(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
if (!FileSecurity.CanRead(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
if (!SupportedFormats.Contains(FileUtility.GetFileExtension(file.Title))) throw new ArgumentException(FilesCommonResource.ErrorMassage_NotSupportedFormat);
|
||||
if (file.ContentLength > MaxFileSize) throw new Exception(FileSizeComment.GetFileSizeExceptionString(MaxFileSize));
|
||||
|
||||
@ -393,7 +393,7 @@ namespace ASC.Web.Files.Helpers
|
||||
if (folderId == null
|
||||
|| (folder = folderDao.GetFolder(folderId)) == null
|
||||
|| folder.RootFolderType == FolderType.TRASH
|
||||
|| !FileSecurity.CanCreate<T>(folder))
|
||||
|| !FileSecurity.CanCreate(folder))
|
||||
{
|
||||
if (GlobalFolderHelper.FolderMy != 0)
|
||||
{
|
||||
@ -420,7 +420,7 @@ namespace ASC.Web.Files.Helpers
|
||||
|
||||
FilesMessageService.Send(file, MessageInitiator.ThirdPartyProvider, MessageAction.DocumentSignComplete, "DocuSign", file.Title);
|
||||
|
||||
FileMarker.MarkAsNew<T>(file);
|
||||
FileMarker.MarkAsNew(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace ASC.Web.Files.Helpers
|
||||
SendHeadersMessage(headers, action, null);
|
||||
}
|
||||
|
||||
public void Send(FileEntry entry, Dictionary<string, string> headers, MessageAction action, params string[] description)
|
||||
public void Send<T>(FileEntry<T> entry, Dictionary<string, string> headers, MessageAction action, params string[] description)
|
||||
{
|
||||
// do not log actions in users folder
|
||||
if (entry == null || entry.RootFolderType == FolderType.USER) return;
|
||||
@ -77,7 +77,7 @@ namespace ASC.Web.Files.Helpers
|
||||
SendHeadersMessage(headers, action, MessageTarget.Create(entry.ID), description);
|
||||
}
|
||||
|
||||
public void Send(FileEntry entry1, FileEntry entry2, Dictionary<string, string> headers, MessageAction action, params string[] description)
|
||||
public void Send<T>(FileEntry<T> entry1, FileEntry<T> entry2, Dictionary<string, string> headers, MessageAction action, params string[] description)
|
||||
{
|
||||
// do not log actions in users folder
|
||||
if (entry1 == null || entry2 == null || entry1.RootFolderType == FolderType.USER || entry2.RootFolderType == FolderType.USER) return;
|
||||
@ -97,7 +97,7 @@ namespace ASC.Web.Files.Helpers
|
||||
}
|
||||
|
||||
|
||||
public void Send(FileEntry entry, MessageAction action, params string[] description)
|
||||
public void Send<T>(FileEntry<T> entry, MessageAction action, params string[] description)
|
||||
{
|
||||
// do not log actions in users folder
|
||||
if (entry == null || entry.RootFolderType == FolderType.USER) return;
|
||||
@ -112,7 +112,7 @@ namespace ASC.Web.Files.Helpers
|
||||
}
|
||||
|
||||
|
||||
public void Send(FileEntry entry, MessageInitiator initiator, MessageAction action, params string[] description)
|
||||
public void Send<T>(FileEntry<T> entry, MessageInitiator initiator, MessageAction action, params string[] description)
|
||||
{
|
||||
if (entry == null || entry.RootFolderType == FolderType.USER) return;
|
||||
|
||||
|
@ -381,7 +381,11 @@ namespace ASC.Web.Files.Classes
|
||||
internal static readonly IDictionary<string, object> TrashFolderCache =
|
||||
new ConcurrentDictionary<string, object>(); /*Use SYNCHRONIZED for cross thread blocks*/
|
||||
|
||||
public object GetFolderTrash(IFolderDao folderDao)
|
||||
public T GetFolderTrash<T>(IDaoFactory daoFactory)
|
||||
{
|
||||
return (T)Convert.ChangeType(GetFolderTrash(daoFactory), typeof(T));
|
||||
}
|
||||
public object GetFolderTrash(IDaoFactory daoFactory)
|
||||
{
|
||||
if (IsOutsider) return null;
|
||||
|
||||
@ -389,7 +393,7 @@ namespace ASC.Web.Files.Classes
|
||||
|
||||
if (!TrashFolderCache.TryGetValue(cacheKey, out var trashFolderId))
|
||||
{
|
||||
trashFolderId = AuthContext.IsAuthenticated ? folderDao.GetFolderIDTrash(true) : 0;
|
||||
trashFolderId = AuthContext.IsAuthenticated ? daoFactory.GetFolderDao<int>().GetFolderIDTrash(true) : 0;
|
||||
TrashFolderCache[cacheKey] = trashFolderId;
|
||||
}
|
||||
return trashFolderId;
|
||||
@ -473,7 +477,7 @@ namespace ASC.Web.Files.Classes
|
||||
{
|
||||
file = fileDao.SaveFile(file, stream);
|
||||
|
||||
fileMarker.MarkAsNew<T>(file);
|
||||
fileMarker.MarkAsNew(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -524,7 +528,7 @@ namespace ASC.Web.Files.Classes
|
||||
{
|
||||
get
|
||||
{
|
||||
return GlobalFolder.GetFolderTrash(DaoFactory.FolderDao);
|
||||
return GlobalFolder.GetFolderTrash(DaoFactory);
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -41,8 +41,6 @@ using ASC.Web.Core.Files;
|
||||
using ASC.Web.Core.Utility.Skins;
|
||||
using ASC.Web.Studio.Utility;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
|
||||
namespace ASC.Web.Files.Classes
|
||||
{
|
||||
public class PathProvider
|
||||
@ -108,11 +106,11 @@ namespace ASC.Web.Files.Classes
|
||||
return BaseCommonLinkUtility.ToAbsolute("~/Products/Files/Controls/" + fileName);
|
||||
}
|
||||
|
||||
public string GetFolderUrl(Folder folder, int projectID = 0)
|
||||
public string GetFolderUrl<T>(Folder<T> folder, int projectID = 0)
|
||||
{
|
||||
if (folder == null) throw new ArgumentNullException("folder", FilesCommonResource.ErrorMassage_FolderNotFound);
|
||||
|
||||
var folderDao = DaoFactory.FolderDao;
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
|
||||
switch (folder.RootFolderType)
|
||||
{
|
||||
@ -133,14 +131,14 @@ namespace ASC.Web.Files.Classes
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFolderUrl(object folderId)
|
||||
public string GetFolderUrl<T>(T folderId)
|
||||
{
|
||||
var folder = DaoFactory.FolderDao.GetFolder(folderId);
|
||||
var folder = DaoFactory.GetFolderDao<T>().GetFolder(folderId);
|
||||
|
||||
return GetFolderUrl(folder);
|
||||
}
|
||||
|
||||
public string GetFileStreamUrl(File file, string doc = null, bool lastVersion = false)
|
||||
public string GetFileStreamUrl<T>(File<T> file, string doc = null, bool lastVersion = false)
|
||||
{
|
||||
if (file == null) throw new ArgumentNullException("file", FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
|
||||
@ -164,7 +162,7 @@ namespace ASC.Web.Files.Classes
|
||||
return uriBuilder.Uri + "?" + query;
|
||||
}
|
||||
|
||||
public string GetFileChangesUrl(File file, string doc = null)
|
||||
public string GetFileChangesUrl<T>(File<T> file, string doc = null)
|
||||
{
|
||||
if (file == null) throw new ArgumentNullException("file", FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
|
||||
|
@ -50,8 +50,6 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
|
||||
namespace ASC.Web.Files.HttpHandlers
|
||||
{
|
||||
public class ChunkedUploaderHandler //: AbstractHttpAsyncHandler
|
||||
@ -206,7 +204,7 @@ namespace ASC.Web.Files.HttpHandlers
|
||||
context.Response.ContentType = "application/json";
|
||||
}
|
||||
|
||||
private static object ToResponseObject(File file)
|
||||
private static object ToResponseObject<T>(File<T> file)
|
||||
{
|
||||
return new
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
|
||||
using FileShare = ASC.Files.Core.Security.FileShare;
|
||||
using MimeMapping = ASC.Common.Web.MimeMapping;
|
||||
using SecurityContext = ASC.Core.SecurityContext;
|
||||
@ -303,7 +303,7 @@ namespace ASC.Web.Files
|
||||
return;
|
||||
}
|
||||
|
||||
if (!readLink && !FileSecurity.CanRead<T>(file))
|
||||
if (!readLink && !FileSecurity.CanRead(file))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return;
|
||||
@ -656,7 +656,7 @@ namespace ASC.Web.Files
|
||||
return;
|
||||
}
|
||||
|
||||
if (linkRight == FileShare.Restrict && SecurityContext.IsAuthenticated && !FileSecurity.CanRead<T>(file))
|
||||
if (linkRight == FileShare.Restrict && SecurityContext.IsAuthenticated && !FileSecurity.CanRead(file))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return;
|
||||
@ -902,7 +902,7 @@ namespace ASC.Web.Files
|
||||
return;
|
||||
}
|
||||
|
||||
if (linkRight == FileShare.Restrict && SecurityContext.IsAuthenticated && !FileSecurity.CanRead<T>(file))
|
||||
if (linkRight == FileShare.Restrict && SecurityContext.IsAuthenticated && !FileSecurity.CanRead(file))
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||
return;
|
||||
@ -944,7 +944,7 @@ namespace ASC.Web.Files
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetEtag(File file)
|
||||
private static string GetEtag<T>(File<T> file)
|
||||
{
|
||||
return file.ID + ":" + file.Version + ":" + file.Title.GetHashCode() + ":" + file.ContentLength;
|
||||
}
|
||||
@ -971,9 +971,9 @@ namespace ASC.Web.Files
|
||||
folder = folderDao.GetFolder(folderId);
|
||||
|
||||
if (folder == null) throw new HttpException((int)HttpStatusCode.NotFound, FilesCommonResource.ErrorMassage_FolderNotFound);
|
||||
if (!FileSecurity.CanCreate<T>(folder)) throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
if (!FileSecurity.CanCreate(folder)) throw new HttpException((int)HttpStatusCode.Forbidden, FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
|
||||
File file;
|
||||
File<T> file;
|
||||
var fileUri = context.Request.Query[FilesLinkUtility.FileUri];
|
||||
var fileTitle = context.Request.Query[FilesLinkUtility.FileTitle];
|
||||
try
|
||||
@ -1014,7 +1014,7 @@ namespace ASC.Web.Files
|
||||
: (FilesLinkUtility.GetFileWebEditorUrl(file.ID) + "#message/" + HttpUtility.UrlEncode(string.Format(FilesCommonResource.MessageFileCreated, folder.Title))));
|
||||
}
|
||||
|
||||
private File CreateFileFromTemplate<T>(Folder<T> folder, string fileTitle, string docType)
|
||||
private File<T> CreateFileFromTemplate<T>(Folder<T> folder, string fileTitle, string docType)
|
||||
{
|
||||
var storeTemplate = GlobalStore.GetStoreTemplate();
|
||||
|
||||
@ -1056,7 +1056,7 @@ namespace ASC.Web.Files
|
||||
return fileDao.SaveFile(file, stream);
|
||||
}
|
||||
|
||||
private File CreateFileFromUri<T>(Folder<T> folder, string fileUri, string fileTitle)
|
||||
private File<T> CreateFileFromUri<T>(Folder<T> folder, string fileUri, string fileTitle)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileTitle))
|
||||
fileTitle = Path.GetFileName(HttpUtility.UrlDecode(fileUri));
|
||||
|
@ -102,7 +102,7 @@ namespace ASC.Web.Files.Configuration
|
||||
{
|
||||
var security = FileSecurity;
|
||||
var fileDao = DaoFactory.GetFileDao<int>();
|
||||
return fileDao.Search(text).Where(security.CanRead<int>);
|
||||
return fileDao.Search(text).Where(security.CanRead);
|
||||
}
|
||||
|
||||
public IEnumerable<Folder<int>> SearchFolders(string text)
|
||||
@ -110,7 +110,7 @@ namespace ASC.Web.Files.Configuration
|
||||
var security = FileSecurity;
|
||||
IEnumerable<Folder<int>> result;
|
||||
var folderDao = DaoFactory.GetFolderDao<int>();
|
||||
result = folderDao.Search(text).Where(security.CanRead<int>);
|
||||
result = folderDao.Search(text).Where(security.CanRead);
|
||||
|
||||
if (ThirdpartyConfiguration.SupportInclusion
|
||||
&& (Global.IsAdministrator || FilesSettingsHelper.EnableThirdParty))
|
||||
@ -168,7 +168,7 @@ namespace ASC.Web.Files.Configuration
|
||||
return result.Concat(resultFolder).ToArray();
|
||||
}
|
||||
|
||||
private static string FolderPathBuilder(IEnumerable<Folder> folders)
|
||||
private static string FolderPathBuilder<T>(IEnumerable<Folder<T>> folders)
|
||||
{
|
||||
var titles = folders.Select(f => f.Title).ToList();
|
||||
const string separator = " \\ ";
|
||||
|
@ -113,7 +113,7 @@ namespace ASC.Api.Documents
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="entry"></param>
|
||||
protected FileEntryWrapper(FileEntry entry, EmployeeWraperHelper employeeWraperHelper, ApiDateTimeHelper apiDateTimeHelper)
|
||||
protected FileEntryWrapper(FileEntry<T> entry, EmployeeWraperHelper employeeWraperHelper, ApiDateTimeHelper apiDateTimeHelper)
|
||||
{
|
||||
Id = entry.ID;
|
||||
Title = entry.Title;
|
||||
@ -152,7 +152,7 @@ namespace ASC.Api.Documents
|
||||
EmployeeWraperHelper = employeeWraperHelper;
|
||||
}
|
||||
|
||||
protected internal T Get<T>(FileEntry entry) where T : FileEntryWrapper, new()
|
||||
protected internal T Get<T>(FileEntry<T> entry) where T : FileEntryWrapper, new()
|
||||
{
|
||||
return new T
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ namespace ASC.Api.Documents
|
||||
result.RootFolderType = FolderType.SHARE;
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
var parentFolder = folderDao.GetFolder(file.FolderID);
|
||||
if (!FileSecurity.CanRead<T>(parentFolder))
|
||||
if (!FileSecurity.CanRead(parentFolder))
|
||||
{
|
||||
result.FolderId = GlobalFolderHelper.FolderShare;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ namespace ASC.Api.Documents
|
||||
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
var parentFolder = folderDao.GetFolder(folder.ParentFolderID);
|
||||
if (!FileSecurity.CanRead<T>(parentFolder))
|
||||
if (!FileSecurity.CanRead(parentFolder))
|
||||
result.ParentId = GlobalFolderHelper.FolderShare;
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
{
|
||||
if (Type == EditorType.Embedded
|
||||
|| Type == EditorType.External
|
||||
|| !FileSharing.CanSetAccess<T>(File)) return null;
|
||||
|| !FileSharing.CanSetAccess(File)) return null;
|
||||
|
||||
try
|
||||
{
|
||||
@ -717,9 +717,9 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
var fileSecurity = FileSecurity;
|
||||
if (_configuration.Document.Info.File.RootFolderType == FolderType.USER
|
||||
&& !Equals(_configuration.Document.Info.File.RootFolderId, GlobalFolderHelper.FolderMy)
|
||||
&& !fileSecurity.CanRead<T>(parent))
|
||||
&& !fileSecurity.CanRead(parent))
|
||||
{
|
||||
if (fileSecurity.CanRead<T>(_configuration.Document.Info.File))
|
||||
if (fileSecurity.CanRead(_configuration.Document.Info.File))
|
||||
{
|
||||
return new GobackConfig
|
||||
{
|
||||
|
@ -45,7 +45,6 @@ using ASC.Web.Studio.Core;
|
||||
|
||||
using JWT;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
using FileShare = ASC.Files.Core.Security.FileShare;
|
||||
|
||||
namespace ASC.Web.Files.Services.DocumentService
|
||||
@ -145,17 +144,17 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
var fileSecurity = FileSecurity;
|
||||
rightToEdit = rightToEdit
|
||||
&& (linkRight == FileShare.ReadWrite
|
||||
|| fileSecurity.CanEdit<T>(file));
|
||||
|| fileSecurity.CanEdit(file));
|
||||
if (editPossible && !rightToEdit)
|
||||
{
|
||||
editPossible = false;
|
||||
}
|
||||
|
||||
rightToRename = rightToRename && rightToEdit && fileSecurity.CanEdit<T>(file);
|
||||
rightToRename = rightToRename && rightToEdit && fileSecurity.CanEdit(file);
|
||||
|
||||
rightToReview = rightToReview
|
||||
&& (linkRight == FileShare.Review || linkRight == FileShare.ReadWrite
|
||||
|| fileSecurity.CanReview<T>(file));
|
||||
|| fileSecurity.CanReview(file));
|
||||
if (reviewPossible && !rightToReview)
|
||||
{
|
||||
reviewPossible = false;
|
||||
@ -163,7 +162,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
rightToFillForms = rightToFillForms
|
||||
&& (linkRight == FileShare.FillForms || linkRight == FileShare.Review || linkRight == FileShare.ReadWrite
|
||||
|| fileSecurity.CanFillForms<T>(file));
|
||||
|| fileSecurity.CanFillForms(file));
|
||||
if (fillFormsPossible && !rightToFillForms)
|
||||
{
|
||||
fillFormsPossible = false;
|
||||
@ -171,7 +170,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
rightToComment = rightToComment
|
||||
&& (linkRight == FileShare.Comment || linkRight == FileShare.Review || linkRight == FileShare.ReadWrite
|
||||
|| fileSecurity.CanComment<T>(file));
|
||||
|| fileSecurity.CanComment(file));
|
||||
if (commentPossible && !rightToComment)
|
||||
{
|
||||
commentPossible = false;
|
||||
@ -179,7 +178,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
if (linkRight == FileShare.Restrict
|
||||
&& !(editPossible || reviewPossible || fillFormsPossible || commentPossible)
|
||||
&& !fileSecurity.CanRead<T>(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
&& !fileSecurity.CanRead(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
|
||||
if (file.RootFolderType == FolderType.TRASH) throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
|
||||
@ -299,12 +298,12 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
|
||||
|
||||
public string GetDocKey(File file)
|
||||
public string GetDocKey<T>(File<T> file)
|
||||
{
|
||||
return GetDocKey(file.ID, file.Version, file.ProviderEntry ? file.ModifiedOn : file.CreateOn);
|
||||
}
|
||||
|
||||
public string GetDocKey(object fileId, int fileVersion, DateTime modified)
|
||||
public string GetDocKey<T>(T fileId, int fileVersion, DateTime modified)
|
||||
{
|
||||
var str = string.Format("teamlab_{0}_{1}_{2}_{3}",
|
||||
fileId,
|
||||
@ -325,10 +324,10 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
{
|
||||
var fileSecurity = FileSecurity;
|
||||
var sharedLink =
|
||||
fileSecurity.CanEdit<T>(file, FileConstant.ShareLinkId)
|
||||
|| fileSecurity.CanReview<T>(file, FileConstant.ShareLinkId)
|
||||
|| fileSecurity.CanFillForms<T>(file, FileConstant.ShareLinkId)
|
||||
|| fileSecurity.CanComment<T>(file, FileConstant.ShareLinkId);
|
||||
fileSecurity.CanEdit(file, FileConstant.ShareLinkId)
|
||||
|| fileSecurity.CanReview(file, FileConstant.ShareLinkId)
|
||||
|| fileSecurity.CanFillForms(file, FileConstant.ShareLinkId)
|
||||
|| fileSecurity.CanComment(file, FileConstant.ShareLinkId);
|
||||
|
||||
var usersDrop = FileTracker.GetEditingBy(file.ID)
|
||||
.Where(uid =>
|
||||
@ -337,7 +336,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
{
|
||||
return !sharedLink;
|
||||
}
|
||||
return !fileSecurity.CanEdit<T>(file, uid) && !fileSecurity.CanReview<T>(file, uid) && !fileSecurity.CanFillForms<T>(file, uid) && !fileSecurity.CanComment<T>(file, uid);
|
||||
return !fileSecurity.CanEdit(file, uid) && !fileSecurity.CanReview(file, uid) && !fileSecurity.CanFillForms(file, uid) && !fileSecurity.CanComment(file, uid);
|
||||
})
|
||||
.Select(u => u.ToString()).ToArray();
|
||||
|
||||
|
@ -62,7 +62,6 @@ using Microsoft.Extensions.Options;
|
||||
using static ASC.Web.Files.Services.DocumentService.DocumentServiceTracker;
|
||||
|
||||
using CommandMethod = ASC.Web.Core.Files.DocumentService.CommandMethod;
|
||||
using File = ASC.Files.Core.File;
|
||||
|
||||
namespace ASC.Web.Files.Services.DocumentService
|
||||
{
|
||||
@ -293,7 +292,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
var app = ThirdPartySelector.GetAppByFileId(fileId.ToString());
|
||||
if (app == null)
|
||||
{
|
||||
File fileStable;
|
||||
File<T> fileStable;
|
||||
fileStable = DaoFactory.GetFileDao<T>().GetFileStable(fileId);
|
||||
|
||||
docKey = DocumentServiceHelper.GetDocKey(fileStable);
|
||||
@ -364,7 +363,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
var app = ThirdPartySelector.GetAppByFileId(fileId.ToString());
|
||||
if (app == null)
|
||||
{
|
||||
File fileStable;
|
||||
File<T> fileStable;
|
||||
fileStable = DaoFactory.GetFileDao<T>().GetFileStable(fileId);
|
||||
|
||||
var docKey = DocumentServiceHelper.GetDocKey(fileStable);
|
||||
@ -396,7 +395,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
File file = null;
|
||||
File<T> file = null;
|
||||
var saveMessage = "Not saved";
|
||||
|
||||
if (string.IsNullOrEmpty(fileData.Url))
|
||||
@ -407,7 +406,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
file = EntryManager.CompleteVersionFile(fileId, 0, false, false);
|
||||
|
||||
DaoFactory.FileDao.UpdateComment(file.ID, file.Version, string.Join("; ", comments));
|
||||
DaoFactory.GetFileDao<T>().UpdateComment(file.ID, file.Version, string.Join("; ", comments));
|
||||
|
||||
file = null;
|
||||
Logger.ErrorFormat("DocService save error. Empty url. File id: '{0}'. UserId: {1}. DocKey '{2}'", fileId, userId, fileData.Key);
|
||||
@ -633,7 +632,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveHistory(File file, string changes, string differenceUrl)
|
||||
private void SaveHistory<T>(File<T> file, string changes, string differenceUrl)
|
||||
{
|
||||
if (file == null) return;
|
||||
if (file.ProviderEntry) return;
|
||||
@ -641,7 +640,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
try
|
||||
{
|
||||
var fileDao = DaoFactory.FileDao;
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
var req = (HttpWebRequest)WebRequest.Create(differenceUrl);
|
||||
|
||||
// hack. http://ubuntuforums.org/showthread.php?t=1841740
|
||||
|
@ -52,7 +52,7 @@ namespace ASC.Web.Files.Services.NotifyService
|
||||
ServiceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void SendDocuSignComplete(File file, string sourceTitle)
|
||||
public void SendDocuSignComplete<T>(File<T> file, string sourceTitle)
|
||||
{
|
||||
using var scope = ServiceProvider.CreateScope();
|
||||
var notifySource = scope.ServiceProvider.GetService<NotifySource>();
|
||||
@ -112,7 +112,7 @@ namespace ASC.Web.Files.Services.NotifyService
|
||||
);
|
||||
}
|
||||
|
||||
public void SendShareNotice(FileEntry fileEntry, Dictionary<Guid, FileShare> recipients, string message)
|
||||
public void SendShareNotice<T>(FileEntry<T> fileEntry, Dictionary<Guid, FileShare> recipients, string message)
|
||||
{
|
||||
if (fileEntry == null || recipients.Count == 0) return;
|
||||
|
||||
@ -127,12 +127,12 @@ namespace ASC.Web.Files.Services.NotifyService
|
||||
var baseCommonLinkUtility = scope.ServiceProvider.GetService<BaseCommonLinkUtility>();
|
||||
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(notifySource, scope);
|
||||
|
||||
var folderDao = daoFactory.FolderDao;
|
||||
if (fileEntry.FileEntryType == FileEntryType.File && folderDao.GetFolder(((File)fileEntry).FolderID) == null) return;
|
||||
var folderDao = daoFactory.GetFolderDao<T>();
|
||||
if (fileEntry.FileEntryType == FileEntryType.File && folderDao.GetFolder(((File<T>)fileEntry).FolderID) == null) return;
|
||||
|
||||
var url = fileEntry.FileEntryType == FileEntryType.File
|
||||
? filesLinkUtility.GetFileWebPreviewUrl(fileUtility, fileEntry.Title, fileEntry.ID)
|
||||
: pathProvider.GetFolderUrl(((Folder)fileEntry));
|
||||
: pathProvider.GetFolderUrl(((Folder<T>)fileEntry));
|
||||
|
||||
var recipientsProvider = notifySource.GetRecipientsProvider();
|
||||
|
||||
@ -160,7 +160,7 @@ namespace ASC.Web.Files.Services.NotifyService
|
||||
}
|
||||
}
|
||||
|
||||
public void SendEditorMentions(FileEntry file, string documentUrl, List<Guid> recipientIds, string message)
|
||||
public void SendEditorMentions<T>(FileEntry<T> file, string documentUrl, List<Guid> recipientIds, string message)
|
||||
{
|
||||
if (file == null || recipientIds.Count == 0) return;
|
||||
|
||||
|
@ -43,8 +43,8 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
|
||||
static FileEntrySerializer()
|
||||
{
|
||||
serializers[typeof(File)] = new DataContractSerializer(typeof(File));
|
||||
serializers[typeof(ItemList<FileEntry>)] = new DataContractSerializer(typeof(ItemList<FileEntry>));
|
||||
serializers[typeof(File<>)] = new DataContractSerializer(typeof(File<>));
|
||||
//serializers[typeof(ItemList<FileEntry<>>)] = new DataContractSerializer(typeof(ItemList<FileEntry<>>));
|
||||
serializers[typeof(DataWrapper<>)] = new DataContractSerializer(typeof(DataWrapper<>));
|
||||
|
||||
//if (WorkContext.IsMono && !string.IsNullOrEmpty(WorkContext.MonoVersion))
|
||||
@ -60,7 +60,7 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
//}
|
||||
}
|
||||
|
||||
public System.IO.MemoryStream ToXml(object o)
|
||||
public System.IO.MemoryStream ToXml<T>(object o)
|
||||
{
|
||||
var result = new System.IO.MemoryStream();
|
||||
if (o == null)
|
||||
@ -85,7 +85,7 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
//remove incorrect ns
|
||||
foreach (XmlNode entry in xml.SelectNodes("//entry"))
|
||||
{
|
||||
var nsattr = entry.Attributes.Cast<XmlAttribute>().FirstOrDefault(a => a.Value == typeof(FileEntry).Name);
|
||||
var nsattr = entry.Attributes.Cast<XmlAttribute>().FirstOrDefault(a => a.Value == typeof(FileEntry<T>).Name);
|
||||
if (nsattr != null)
|
||||
{
|
||||
foreach (XmlAttribute a in entry.Attributes)
|
||||
@ -128,7 +128,7 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
typeName = XmlDictionaryString.Empty;
|
||||
typeNamespace = XmlDictionaryString.Empty;
|
||||
|
||||
if (declaredType == typeof(FileEntry))
|
||||
if (declaredType == typeof(FileEntry<>))
|
||||
{
|
||||
typeName = new XmlDictionaryString(XmlDictionary.Empty, type.Name.ToLower(), 0);
|
||||
typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, declaredType.Name, 0);
|
||||
|
@ -81,7 +81,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
_trashId = FolderDao.GetFolderIDTrash(true);
|
||||
|
||||
Folder root = null;
|
||||
Folder<T> root = null;
|
||||
if (0 < Folders.Count)
|
||||
{
|
||||
root = FolderDao.GetRootFolder(Folders[0]);
|
||||
@ -118,7 +118,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder;
|
||||
}
|
||||
else if (!_ignoreException && !FilesSecurity.CanDelete<T>(folder))
|
||||
else if (!_ignoreException && !FilesSecurity.CanDelete(folder))
|
||||
{
|
||||
canCalculate = FolderDao.CanCalculateSubitems(folderId) ? default : folderId;
|
||||
|
||||
@ -229,14 +229,14 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
}
|
||||
}
|
||||
|
||||
private bool WithError(IServiceScope scope, IEnumerable<File> files, bool folder, out string error)
|
||||
private bool WithError(IServiceScope scope, IEnumerable<File<T>> files, bool folder, out string error)
|
||||
{
|
||||
var entryManager = scope.ServiceProvider.GetService<EntryManager>();
|
||||
|
||||
error = null;
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (!FilesSecurity.CanDelete<T>(file))
|
||||
if (!FilesSecurity.CanDelete(file))
|
||||
{
|
||||
error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile;
|
||||
return true;
|
||||
|
@ -147,7 +147,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
}
|
||||
if (0 < Folders.Count)
|
||||
{
|
||||
FilesSecurity.FilterRead(FolderDao.GetFolders(Files.ToArray())).ToList().Cast<FileEntry>().ToList()
|
||||
FilesSecurity.FilterRead(FolderDao.GetFolders(Files.ToArray())).ToList().Cast<FileEntry<T>>().ToList()
|
||||
.ForEach(folder => fileMarker.RemoveMarkAsNew(folder));
|
||||
|
||||
var filesInFolder = GetFilesInFolders(scope, Folders, string.Empty);
|
||||
@ -168,7 +168,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var folder = FolderDao.GetFolder(folderId);
|
||||
if (folder == null || !FilesSecurity.CanRead<T>(folder)) continue;
|
||||
if (folder == null || !FilesSecurity.CanRead(folder)) continue;
|
||||
var folderPath = path + folder.Title + "/";
|
||||
|
||||
var files = FileDao.GetFiles(folder.ID, null, FilterType.None, false, Guid.Empty, string.Empty, true);
|
||||
|
@ -67,7 +67,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
protected override void Do(IServiceScope scope)
|
||||
{
|
||||
var fileMarker = scope.ServiceProvider.GetService<FileMarker>();
|
||||
var entries = new List<FileEntry>();
|
||||
var entries = new List<FileEntry<T>>();
|
||||
if (Folders.Any())
|
||||
{
|
||||
entries.AddRange(FolderDao.GetFolders(Folders.ToArray()));
|
||||
|
@ -63,7 +63,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
private readonly T _toFolderId;
|
||||
private readonly bool _copy;
|
||||
private readonly FileConflictResolveType _resolveType;
|
||||
private readonly List<FileEntry> _needToMark = new List<FileEntry>();
|
||||
private readonly List<FileEntry<T>> _needToMark = new List<FileEntry<T>>();
|
||||
|
||||
private readonly Dictionary<string, string> _headers;
|
||||
|
||||
@ -91,7 +91,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
//TODO: check on each iteration?
|
||||
var toFolder = FolderDao.GetFolder(_toFolderId);
|
||||
if (toFolder == null) return;
|
||||
if (!FilesSecurity.CanCreate<T>(toFolder)) throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
if (!FilesSecurity.CanCreate(toFolder)) throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
|
||||
if (FolderDao.GetParentFolders(toFolder.ID).Any(parent => Folders.Contains(parent.ID)))
|
||||
{
|
||||
@ -101,7 +101,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
|
||||
if (_copy)
|
||||
{
|
||||
Folder rootFrom = null;
|
||||
Folder<T> rootFrom = null;
|
||||
if (0 < Folders.Count) rootFrom = FolderDao.GetRootFolder(Folders[0]);
|
||||
if (0 < Files.Count) rootFrom = FolderDao.GetRootFolderByFile(Files[0]);
|
||||
if (rootFrom != null && rootFrom.FolderType == FolderType.TRASH) throw new InvalidOperationException("Can not copy from Trash.");
|
||||
@ -132,7 +132,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_FolderNotFound;
|
||||
}
|
||||
else if (!FilesSecurity.CanRead<T>(folder))
|
||||
else if (!FilesSecurity.CanRead(folder))
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder;
|
||||
}
|
||||
@ -174,7 +174,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
|
||||
if (!copy)
|
||||
{
|
||||
if (!FilesSecurity.CanDelete<T>(folder))
|
||||
if (!FilesSecurity.CanDelete(folder))
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
|
||||
}
|
||||
@ -207,7 +207,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
Status += string.Format("folder_{0}{1}", newFolderId, FileOperation.SPLIT_CHAR);
|
||||
}
|
||||
}
|
||||
else if (!FilesSecurity.CanDelete<T>(folder))
|
||||
else if (!FilesSecurity.CanDelete(folder))
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
|
||||
}
|
||||
@ -236,7 +236,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!FilesSecurity.CanDelete<T>(folder))
|
||||
if (!FilesSecurity.CanDelete(folder))
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException_MoveFolder;
|
||||
}
|
||||
@ -293,7 +293,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_FileNotFound;
|
||||
}
|
||||
else if (!FilesSecurity.CanRead<T>(file))
|
||||
else if (!FilesSecurity.CanRead(file))
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile;
|
||||
}
|
||||
@ -369,7 +369,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
if (_resolveType == FileConflictResolveType.Overwrite)
|
||||
{
|
||||
if (!FilesSecurity.CanEdit<T>(conflict))
|
||||
if (!FilesSecurity.CanEdit(conflict))
|
||||
{
|
||||
Error = FilesCommonResource.ErrorMassage_SecurityException;
|
||||
}
|
||||
@ -454,13 +454,13 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
}
|
||||
}
|
||||
|
||||
private bool WithError(IServiceScope scope, IEnumerable<File> files, out string error)
|
||||
private bool WithError(IServiceScope scope, IEnumerable<File<T>> files, out string error)
|
||||
{
|
||||
var entryManager = scope.ServiceProvider.GetService<EntryManager>();
|
||||
error = null;
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (!FilesSecurity.CanDelete<T>(file))
|
||||
if (!FilesSecurity.CanDelete(file))
|
||||
{
|
||||
error = FilesCommonResource.ErrorMassage_SecurityException_MoveFile;
|
||||
return true;
|
||||
|
@ -104,7 +104,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
|
||||
protected IFileDao<TId> FileDao { get; private set; }
|
||||
|
||||
protected ITagDao TagDao { get; private set; }
|
||||
protected ITagDao<TId> TagDao { get; private set; }
|
||||
|
||||
protected IProviderDao ProviderDao { get; private set; }
|
||||
|
||||
@ -154,7 +154,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
|
||||
FolderDao = daoFactory.GetFolderDao<TId>();
|
||||
FileDao = daoFactory.GetFileDao<TId>();
|
||||
TagDao = daoFactory.TagDao;
|
||||
TagDao = daoFactory.GetTagDao<TId>();
|
||||
ProviderDao = daoFactory.ProviderDao;
|
||||
FilesSecurity = fileSecurity;
|
||||
|
||||
|
@ -32,30 +32,29 @@ using ASC.Files.Core;
|
||||
using ASC.Web.Files.Helpers;
|
||||
using ASC.Web.Files.Services.WCFService.FileOperations;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
using FileShare = ASC.Files.Core.Security.FileShare;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService
|
||||
{
|
||||
public interface IFileStorageService
|
||||
public interface IFileStorageService<T>
|
||||
{
|
||||
#region Folder Manager
|
||||
|
||||
Folder GetFolder(string folderId);
|
||||
Folder<T> GetFolder(T folderId);
|
||||
|
||||
ItemList<Folder> GetFolders(string parentId);
|
||||
ItemList<Folder<T>> GetFolders(T parentId);
|
||||
|
||||
ItemList<object> GetPath(string folderId);
|
||||
ItemList<object> GetPath(T folderId);
|
||||
|
||||
Folder CreateNewFolder(string parentId, string title);
|
||||
Folder<T> CreateNewFolder(T parentId, string title);
|
||||
|
||||
Folder FolderRename(string folderId, string title);
|
||||
Folder<T> FolderRename(T folderId, string title);
|
||||
|
||||
DataWrapper<T> GetFolderItems<T>(string parentId, int from, int count, FilterType filter, bool subjectGroup, string subjectID, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy);
|
||||
DataWrapper<T> GetFolderItems(T parentId, int from, int count, FilterType filter, bool subjectGroup, string subjectID, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy);
|
||||
|
||||
object GetFolderItemsXml(string parentId, int from, int count, FilterType filter, bool subjectGroup, string subjectID, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy);
|
||||
object GetFolderItemsXml(T parentId, int from, int count, FilterType filter, bool subjectGroup, string subjectID, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy);
|
||||
|
||||
ItemList<FileEntry> GetItems(ItemList<string> items, FilterType filter, bool subjectGroup, string subjectID, string searchText);
|
||||
ItemList<FileEntry<T>> GetItems(ItemList<string> items, FilterType filter, bool subjectGroup, string subjectID, string searchText);
|
||||
|
||||
ItemDictionary<string, string> MoveOrCopyFilesCheck(ItemList<string> items, string destFolderId);
|
||||
|
||||
@ -73,21 +72,21 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
|
||||
File GetFile(string fileId, int version);
|
||||
|
||||
File<T> CreateNewFile<T>(FileModel<T> fileWrapper);
|
||||
File<T> CreateNewFile(FileModel<T> fileWrapper);
|
||||
|
||||
File FileRename(string fileId, string title);
|
||||
|
||||
KeyValuePair<File, ItemList<File>> UpdateToVersion(string fileId, int version);
|
||||
KeyValuePair<File<T>, ItemList<File<T>>> UpdateToVersion(T fileId, int version);
|
||||
|
||||
KeyValuePair<File, ItemList<File>> CompleteVersion(string fileId, int version, bool continueVersion);
|
||||
KeyValuePair<File<T>, ItemList<File<T>>> CompleteVersion(T fileId, int version, bool continueVersion);
|
||||
|
||||
string UpdateComment(string fileId, int version, string comment);
|
||||
string UpdateComment(T fileId, int version, string comment);
|
||||
|
||||
ItemList<File> GetFileHistory(string fileId);
|
||||
ItemList<File<T>> GetFileHistory(T fileId);
|
||||
|
||||
ItemList<File> GetSiblingsFile(string fileId, string folderId, FilterType filter, bool subjectGroup, string subjectID, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy);
|
||||
ItemList<File<T>> GetSiblingsFile(T fileId, T folderId, FilterType filter, bool subjectGroup, string subjectID, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy);
|
||||
|
||||
KeyValuePair<bool, string> TrackEditFile(string fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish);
|
||||
KeyValuePair<bool, string> TrackEditFile(T fileId, Guid tabId, string docKeyForTrack, string doc, bool isFinish);
|
||||
|
||||
ItemDictionary<string, string> CheckEditing(ItemList<string> filesId);
|
||||
|
||||
@ -113,7 +112,7 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
|
||||
#region Utils
|
||||
|
||||
ItemList<FileEntry> ChangeOwner(ItemList<string> items, Guid userId);
|
||||
ItemList<FileEntry<T>> ChangeOwner(ItemList<string> items, Guid userId);
|
||||
|
||||
ItemList<FileOperationResult> BulkDownload(Dictionary<string, string> items);
|
||||
|
||||
@ -167,9 +166,9 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
|
||||
ItemList<ThirdPartyParams> GetThirdParty();
|
||||
|
||||
ItemList<Folder> GetThirdPartyFolder(int folderType);
|
||||
ItemList<Folder<T>> GetThirdPartyFolder(int folderType);
|
||||
|
||||
Folder SaveThirdParty(ThirdPartyParams thirdPartyParams);
|
||||
Folder<T> SaveThirdParty(ThirdPartyParams thirdPartyParams);
|
||||
|
||||
object DeleteThirdParty(string providerId);
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
public class DataWrapper<T>
|
||||
{
|
||||
[DataMember(IsRequired = false, Name = "entries", EmitDefaultValue = false)]
|
||||
public ItemList<FileEntry> Entries { get; set; }
|
||||
public ItemList<FileEntry<T>> Entries { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false, Name = "total")]
|
||||
public int Total { get; set; }
|
||||
|
@ -55,7 +55,6 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
using FileShare = ASC.Files.Core.Security.FileShare;
|
||||
|
||||
namespace ASC.Web.Files.Utils
|
||||
@ -71,7 +70,7 @@ namespace ASC.Web.Files.Utils
|
||||
DaoFactory = daoFactory;
|
||||
}
|
||||
|
||||
public bool FileLockedForMe(object fileId, Guid userId = default)
|
||||
public bool FileLockedForMe<T>(T fileId, Guid userId = default)
|
||||
{
|
||||
var app = ThirdPartySelector.GetAppByFileId(fileId.ToString());
|
||||
if (app != null)
|
||||
@ -80,12 +79,12 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
|
||||
userId = userId == default ? AuthContext.CurrentAccount.ID : userId;
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var lockedBy = FileLockedBy(fileId, tagDao);
|
||||
return lockedBy != Guid.Empty && lockedBy != userId;
|
||||
}
|
||||
|
||||
public Guid FileLockedBy(object fileId, ITagDao tagDao)
|
||||
public Guid FileLockedBy<T>(T fileId, ITagDao<T> tagDao)
|
||||
{
|
||||
var tagLock = tagDao.GetTags(fileId, FileEntryType.File, TagType.Locked).FirstOrDefault();
|
||||
return tagLock != null ? tagLock.Owner : Guid.Empty;
|
||||
@ -243,14 +242,14 @@ namespace ASC.Web.Files.Utils
|
||||
cache = AscCache.Memory;
|
||||
}
|
||||
|
||||
public IEnumerable<FileEntry> GetEntries<T>(Folder<T> parent, int from, int count, FilterType filter, bool subjectGroup, Guid subjectId, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy, out int total)
|
||||
public IEnumerable<FileEntry<T>> GetEntries<T>(Folder<T> parent, int from, int count, FilterType filter, bool subjectGroup, Guid subjectId, string searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy, out int total)
|
||||
{
|
||||
total = 0;
|
||||
|
||||
if (parent == null) throw new ArgumentNullException("parent", FilesCommonResource.ErrorMassage_FolderNotFound);
|
||||
|
||||
var fileSecurity = FileSecurity;
|
||||
var entries = Enumerable.Empty<FileEntry>();
|
||||
var entries = Enumerable.Empty<FileEntry<T>>();
|
||||
|
||||
searchInContent = searchInContent && filter != FilterType.ByExtension && !Equals(parent.ID, GlobalFolderHelper.FolderTrash);
|
||||
|
||||
@ -343,29 +342,29 @@ namespace ASC.Web.Files.Utils
|
||||
folders = fileSecurity.FilterRead(folders).ToList();
|
||||
}
|
||||
|
||||
entries = entries.Concat(folders);
|
||||
entries = entries.Concat(folders.Cast<FileEntry<T>>());
|
||||
}
|
||||
|
||||
if (filter != FilterType.FoldersOnly && withSubfolders)
|
||||
{
|
||||
var files = DaoFactory.GetFileDao<int>().GetFiles(rootKeys, filter, subjectGroup, subjectId, searchText, searchInContent).ToList();
|
||||
files = fileSecurity.FilterRead(files).ToList();
|
||||
entries = entries.Concat(files);
|
||||
entries = entries.Concat(files.Cast<FileEntry<T>>());
|
||||
}
|
||||
}
|
||||
|
||||
parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalFiles : 1));
|
||||
parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalSubFolders + 1 : 0));
|
||||
parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder<T>)f).TotalFiles : 1));
|
||||
parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder<T>)f).TotalSubFolders + 1 : 0));
|
||||
}
|
||||
else if (parent.FolderType == FolderType.SHARE)
|
||||
{
|
||||
//share
|
||||
var shared = (IEnumerable<FileEntry>)fileSecurity.GetSharesForMe<T>(filter, subjectGroup, subjectId, searchText, searchInContent, withSubfolders);
|
||||
var shared = (IEnumerable<FileEntry<T>>)fileSecurity.GetSharesForMe<T>(filter, subjectGroup, subjectId, searchText, searchInContent, withSubfolders);
|
||||
|
||||
entries = entries.Concat(shared);
|
||||
|
||||
parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalFiles : 1));
|
||||
parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalSubFolders + 1 : 0));
|
||||
parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder<T>)f).TotalFiles : 1));
|
||||
parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder<T>)f).TotalSubFolders + 1 : 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -410,7 +409,7 @@ namespace ASC.Web.Files.Utils
|
||||
if (0 < count) entries = entries.Take(count);
|
||||
}
|
||||
|
||||
SetFileStatus(entries.Where(r => r != null && r.ID != null && r.FileEntryType == FileEntryType.File).Select(r => r as File).ToList());
|
||||
SetFileStatus(entries.Where(r => r != null && r.ID != null && r.FileEntryType == FileEntryType.File).Select(r => r as File<T>).ToList());
|
||||
|
||||
return entries;
|
||||
}
|
||||
@ -433,12 +432,12 @@ namespace ASC.Web.Files.Utils
|
||||
var providers = providerDao.GetProvidersInfo(parent.RootFolderType, searchText);
|
||||
folderList = providers
|
||||
.Select(providerInfo => GetFakeThirdpartyFolder<T>(providerInfo, parent.ID))
|
||||
.Where(r => fileSecurity.CanRead<T>(r)).ToList();
|
||||
.Where(r => fileSecurity.CanRead(r)).ToList();
|
||||
|
||||
if (folderList.Any())
|
||||
{
|
||||
var securityDao = DaoFactory.SecurityDao;
|
||||
securityDao.GetPureShareRecords(folderList.Cast<FileEntry>().ToArray())
|
||||
var securityDao = DaoFactory.GetSecurityDao<T>();
|
||||
securityDao.GetPureShareRecords(folderList.Cast<FileEntry<T>>().ToArray())
|
||||
//.Where(x => x.Owner == SecurityContext.CurrentAccount.ID)
|
||||
.Select(x => x.EntryId).Distinct().ToList()
|
||||
.ForEach(id =>
|
||||
@ -451,7 +450,7 @@ namespace ASC.Web.Files.Utils
|
||||
return folderList;
|
||||
}
|
||||
|
||||
public IEnumerable<FileEntry> FilterEntries(IEnumerable<FileEntry> entries, FilterType filter, bool subjectGroup, Guid subjectId, string searchText, bool searchInContent)
|
||||
public IEnumerable<FileEntry<T>> FilterEntries<T>(IEnumerable<FileEntry<T>> entries, FilterType filter, bool subjectGroup, Guid subjectId, string searchText, bool searchInContent)
|
||||
{
|
||||
if (entries == null || !entries.Any()) return entries;
|
||||
|
||||
@ -465,7 +464,7 @@ namespace ASC.Web.Files.Utils
|
||||
.ToList();
|
||||
}
|
||||
|
||||
Func<FileEntry, bool> where = null;
|
||||
Func<FileEntry<T>, bool> where = null;
|
||||
|
||||
switch (filter)
|
||||
{
|
||||
@ -476,7 +475,7 @@ namespace ASC.Web.Files.Utils
|
||||
case FilterType.ArchiveOnly:
|
||||
case FilterType.FilesOnly:
|
||||
case FilterType.MediaOnly:
|
||||
where = f => f.FileEntryType == FileEntryType.File && (((File)f).FilterType == filter || filter == FilterType.FilesOnly);
|
||||
where = f => f.FileEntryType == FileEntryType.File && (((File<T>)f).FilterType == filter || filter == FilterType.FilesOnly);
|
||||
break;
|
||||
case FilterType.FoldersOnly:
|
||||
where = f => f.FileEntryType == FileEntryType.Folder;
|
||||
@ -499,11 +498,11 @@ namespace ASC.Web.Files.Utils
|
||||
return entries;
|
||||
}
|
||||
|
||||
public IEnumerable<FileEntry> SortEntries(IEnumerable<FileEntry> entries, OrderBy orderBy)
|
||||
public IEnumerable<FileEntry<T>> SortEntries<T>(IEnumerable<FileEntry<T>> entries, OrderBy orderBy)
|
||||
{
|
||||
if (entries == null || !entries.Any()) return entries;
|
||||
|
||||
Comparison<FileEntry> sorter;
|
||||
Comparison<FileEntry<T>> sorter;
|
||||
|
||||
if (orderBy == null)
|
||||
{
|
||||
@ -534,7 +533,7 @@ namespace ASC.Web.Files.Utils
|
||||
{
|
||||
var cmp = 0;
|
||||
if (x.FileEntryType == FileEntryType.File && y.FileEntryType == FileEntryType.File)
|
||||
cmp = c * ((File)x).ContentLength.CompareTo(((File)y).ContentLength);
|
||||
cmp = c * ((File<T>)x).ContentLength.CompareTo(((File<T>)y).ContentLength);
|
||||
return cmp == 0 ? x.Title.EnumerableComparer(y.Title) : cmp;
|
||||
};
|
||||
break;
|
||||
@ -623,16 +622,16 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
|
||||
|
||||
public void SetFileStatus(File file)
|
||||
public void SetFileStatus<T>(File<T> file)
|
||||
{
|
||||
if (file == null || file.ID == null) return;
|
||||
|
||||
SetFileStatus(new List<File>(1) { file });
|
||||
SetFileStatus(new List<File<T>>(1) { file });
|
||||
}
|
||||
|
||||
public void SetFileStatus(IEnumerable<File> files)
|
||||
public void SetFileStatus<T>(IEnumerable<File<T>> files)
|
||||
{
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var tagsNew = tagDao.GetNewTags(AuthContext.CurrentAccount.ID, files);
|
||||
|
||||
var tagsLocked = tagDao.GetTags(TagType.Locked, files.ToArray());
|
||||
@ -654,12 +653,12 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public bool FileLockedForMe(object fileId, Guid userId = default)
|
||||
public bool FileLockedForMe<T>(T fileId, Guid userId = default)
|
||||
{
|
||||
return LockerManager.FileLockedForMe(fileId, userId);
|
||||
}
|
||||
|
||||
public Guid FileLockedBy(object fileId, ITagDao tagDao)
|
||||
public Guid FileLockedBy<T>(T fileId, ITagDao<T> tagDao)
|
||||
{
|
||||
return LockerManager.FileLockedBy(fileId, tagDao);
|
||||
}
|
||||
@ -687,7 +686,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (file == null) throw new FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
var fileSecurity = FileSecurity;
|
||||
if (checkRight && !editLink && (!(fileSecurity.CanEdit<T>(file) || fileSecurity.CanReview<T>(file)) || UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (checkRight && !editLink && (!(fileSecurity.CanEdit(file) || fileSecurity.CanReview(file)) || UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (checkRight && FileLockedForMe(file.ID)) throw new Exception(FilesCommonResource.ErrorMassage_LockedFile);
|
||||
if (checkRight && FileTracker.IsEditing(file.ID)) throw new Exception(FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile);
|
||||
if (file.RootFolderType == FolderType.TRASH) throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
@ -800,7 +799,7 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
}
|
||||
|
||||
FileMarker.MarkAsNew<T>(file);
|
||||
FileMarker.MarkAsNew(file);
|
||||
FileMarker.RemoveMarkAsNew(file);
|
||||
return file;
|
||||
}
|
||||
@ -822,7 +821,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (file == null) throw new FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
var fileSecurity = FileSecurity;
|
||||
if (!editLink && (!fileSecurity.CanEdit<T>(file, userId) && !fileSecurity.CanReview<T>(file, userId) && !fileSecurity.CanFillForms<T>(file, userId) && !fileSecurity.CanComment<T>(file, userId) || UserManager.GetUsers(userId).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (!editLink && (!fileSecurity.CanEdit(file, userId) && !fileSecurity.CanReview(file, userId) && !fileSecurity.CanFillForms(file, userId) && !fileSecurity.CanComment(file, userId) || UserManager.GetUsers(userId).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (FileLockedForMe(file.ID, userId)) throw new Exception(FilesCommonResource.ErrorMassage_LockedFile);
|
||||
if (file.RootFolderType == FolderType.TRASH) throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
|
||||
@ -849,7 +848,7 @@ namespace ASC.Web.Files.Utils
|
||||
fromFile = fileDao.GetFile(fromFile.ID, Math.Min(fromFile.Version, version));
|
||||
|
||||
if (fromFile == null) throw new FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
if (checkRight && !editLink && (!FileSecurity.CanEdit<T>(fromFile) || UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (checkRight && !editLink && (!FileSecurity.CanEdit(fromFile) || UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (FileLockedForMe(fromFile.ID)) throw new Exception(FilesCommonResource.ErrorMassage_LockedFile);
|
||||
if (checkRight && FileTracker.IsEditing(fromFile.ID)) throw new Exception(FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile);
|
||||
if (fromFile.RootFolderType == FolderType.TRASH) throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
@ -890,7 +889,7 @@ namespace ASC.Web.Files.Utils
|
||||
newFile = fileDao.SaveFile(newFile, stream);
|
||||
}
|
||||
|
||||
FileMarker.MarkAsNew<T>(newFile);
|
||||
FileMarker.MarkAsNew(newFile);
|
||||
|
||||
SetFileStatus(newFile);
|
||||
|
||||
@ -914,7 +913,7 @@ namespace ASC.Web.Files.Utils
|
||||
? fileDao.GetFile(fileId, version)
|
||||
: fileDao.GetFile(fileId);
|
||||
if (fileVersion == null) throw new FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
if (checkRight && (!FileSecurity.CanEdit<T>(fileVersion) || UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (checkRight && (!FileSecurity.CanEdit(fileVersion) || UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager))) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
|
||||
if (FileLockedForMe(fileVersion.ID)) throw new Exception(FilesCommonResource.ErrorMassage_LockedFile);
|
||||
if (fileVersion.RootFolderType == FolderType.TRASH) throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
if (fileVersion.ProviderEntry) throw new Exception(FilesCommonResource.ErrorMassage_BadRequest);
|
||||
@ -953,8 +952,8 @@ namespace ASC.Web.Files.Utils
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
file = fileDao.GetFile(fileId);
|
||||
if (file == null) throw new FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
if (!FileSecurity.CanEdit<T>(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_RenameFile);
|
||||
if (!FileSecurity.CanDelete<T>(file) && UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_RenameFile);
|
||||
if (!FileSecurity.CanEdit(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_RenameFile);
|
||||
if (!FileSecurity.CanDelete(file) && UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_RenameFile);
|
||||
if (FileLockedForMe(file.ID)) throw new Exception(FilesCommonResource.ErrorMassage_LockedFile);
|
||||
if (file.ProviderEntry && FileTracker.IsEditing(file.ID)) throw new Exception(FilesCommonResource.ErrorMassage_UpdateEditingFile);
|
||||
if (file.RootFolderType == FolderType.TRASH) throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
|
@ -57,7 +57,6 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
using SecurityContext = ASC.Core.SecurityContext;
|
||||
|
||||
namespace ASC.Web.Files.Utils
|
||||
@ -65,7 +64,7 @@ namespace ASC.Web.Files.Utils
|
||||
public class FileConverter
|
||||
{
|
||||
private static readonly object locker = new object();
|
||||
private static readonly IDictionary<File, ConvertFileOperationResult> conversionQueue = new Dictionary<File, ConvertFileOperationResult>(new FileComparer());
|
||||
private static readonly IDictionary<File<T>, ConvertFileOperationResult> conversionQueue = new Dictionary<File<T>, ConvertFileOperationResult>(new FileComparer());
|
||||
private readonly ICache cache;
|
||||
|
||||
private static Timer timer;
|
||||
@ -165,7 +164,7 @@ namespace ASC.Web.Files.Utils
|
||||
get { return FileUtility.ExtsMustConvert.Any() && !string.IsNullOrEmpty(FilesLinkUtility.DocServiceConverterUrl); }
|
||||
}
|
||||
|
||||
public bool MustConvert(File file)
|
||||
public bool MustConvert<T>(File<T> file)
|
||||
{
|
||||
if (file == null) return false;
|
||||
|
||||
@ -173,7 +172,7 @@ namespace ASC.Web.Files.Utils
|
||||
return FileUtility.ExtsMustConvert.Contains(ext);
|
||||
}
|
||||
|
||||
public bool EnableConvert(File file, string toExtension)
|
||||
public bool EnableConvert<T>(File<T> file, string toExtension)
|
||||
{
|
||||
if (file == null || string.IsNullOrEmpty(toExtension))
|
||||
{
|
||||
@ -200,16 +199,16 @@ namespace ASC.Web.Files.Utils
|
||||
return FileUtility.ExtsConvertible.Keys.Contains(fileExtension) && FileUtility.ExtsConvertible[fileExtension].Contains(toExtension);
|
||||
}
|
||||
|
||||
public Stream Exec(File file)
|
||||
public Stream Exec<T>(File<T> file)
|
||||
{
|
||||
return Exec(file, FileUtility.GetInternalExtension(file.Title));
|
||||
}
|
||||
|
||||
public Stream Exec(File file, string toExtension)
|
||||
public Stream Exec<T>(File<T> file, string toExtension)
|
||||
{
|
||||
if (!EnableConvert(file, toExtension))
|
||||
{
|
||||
var fileDao = DaoFactory.FileDao;
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
return fileDao.GetFileStream(file);
|
||||
}
|
||||
|
||||
@ -234,7 +233,7 @@ namespace ASC.Web.Files.Utils
|
||||
{
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
var fileSecurity = FileSecurity;
|
||||
if (!fileSecurity.CanRead<T>(file))
|
||||
if (!fileSecurity.CanRead(file))
|
||||
{
|
||||
var readLink = FileShareLink.Check(doc, true, fileDao, out file);
|
||||
if (file == null)
|
||||
@ -299,7 +298,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (timer == null)
|
||||
{
|
||||
timer = new Timer(CheckConvertFilesStatus<T>, null, 0, Timeout.Infinite);
|
||||
timer = new Timer(CheckConvertFilesStatus, null, 0, Timeout.Infinite);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -308,7 +307,7 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsConverting(File file)
|
||||
public bool IsConverting<T>(File<T> file)
|
||||
{
|
||||
if (!MustConvert(file) || !string.IsNullOrEmpty(file.ConvertedType))
|
||||
{
|
||||
@ -327,7 +326,7 @@ namespace ASC.Web.Files.Utils
|
||||
var file = pair.Key;
|
||||
var key = GetKey(file);
|
||||
var operation = cache.Get<ConvertFileOperationResult>(key);
|
||||
if (operation != null && (pair.Value || fileSecurity.CanRead<T>(file)))
|
||||
if (operation != null && (pair.Value || fileSecurity.CanRead(file)))
|
||||
{
|
||||
result.Add(operation);
|
||||
lock (locker)
|
||||
@ -343,7 +342,7 @@ namespace ASC.Web.Files.Utils
|
||||
return result;
|
||||
}
|
||||
|
||||
private string FileJsonSerializer(File file, string folderTitle)
|
||||
private string FileJsonSerializer<T>(File<T> file, string folderTitle)
|
||||
{
|
||||
if (file == null) return string.Empty;
|
||||
|
||||
@ -360,7 +359,7 @@ namespace ASC.Web.Files.Utils
|
||||
file.Version,
|
||||
file.FolderID,
|
||||
folderTitle ?? "",
|
||||
File.Serialize(file).Replace('"', '\''));
|
||||
File<T>.Serialize(file).Replace('"', '\''));
|
||||
}
|
||||
|
||||
private void CheckConvertFilesStatus<T>(object _)
|
||||
@ -376,7 +375,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
try
|
||||
{
|
||||
List<File<T>> filesIsConverting = new List<File<T>>();
|
||||
var filesIsConverting = new List<File<T>>();
|
||||
lock (locker)
|
||||
{
|
||||
timer.Change(Timeout.Infinite, Timeout.Infinite);
|
||||
@ -398,11 +397,10 @@ namespace ASC.Web.Files.Utils
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO:
|
||||
//filesIsConverting = conversionQueue
|
||||
// .Where(x => string.IsNullOrEmpty(x.Value.Processed))
|
||||
// .Select(x => x.Key)
|
||||
// .ToList();
|
||||
filesIsConverting = conversionQueue
|
||||
.Where(x => string.IsNullOrEmpty(x.Value.Processed))
|
||||
.Select(x => x.Key)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
var fileSecurity = FileSecurity;
|
||||
@ -448,7 +446,7 @@ namespace ASC.Web.Files.Utils
|
||||
Thread.CurrentThread.CurrentCulture = culture;
|
||||
Thread.CurrentThread.CurrentUICulture = culture;
|
||||
|
||||
if (!fileSecurity.CanRead<T>(file) && file.RootFolderType != FolderType.BUNCH)
|
||||
if (!fileSecurity.CanRead(file) && file.RootFolderType != FolderType.BUNCH)
|
||||
{
|
||||
//No rights in CRM after upload before attach
|
||||
throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
@ -525,7 +523,7 @@ namespace ASC.Web.Files.Utils
|
||||
continue;
|
||||
}
|
||||
|
||||
File newFile = null;
|
||||
File<T> newFile = null;
|
||||
var operationResultError = string.Empty;
|
||||
|
||||
try
|
||||
@ -555,9 +553,9 @@ namespace ASC.Web.Files.Utils
|
||||
{
|
||||
if (newFile != null)
|
||||
{
|
||||
var folderDao = daoFactory.FolderDao;
|
||||
var folderDao = daoFactory.GetFolderDao<T>();
|
||||
var folder = folderDao.GetFolder(newFile.FolderID);
|
||||
var folderTitle = fileSecurity.CanRead<T>(folder) ? folder.Title : null;
|
||||
var folderTitle = fileSecurity.CanRead(folder) ? folder.Title : null;
|
||||
operationResult.Result = FileJsonSerializer(newFile, folderTitle);
|
||||
}
|
||||
|
||||
@ -605,7 +603,7 @@ namespace ASC.Web.Files.Utils
|
||||
File<T> newFile = null;
|
||||
var newFileTitle = FileUtility.ReplaceFileExtension(file.Title, FileUtility.GetInternalExtension(file.Title));
|
||||
|
||||
if (!FilesSettingsHelper.StoreOriginalFiles && fileSecurity.CanEdit<T>(file))
|
||||
if (!FilesSettingsHelper.StoreOriginalFiles && fileSecurity.CanEdit(file))
|
||||
{
|
||||
newFile = (File<T>)file.Clone();
|
||||
newFile.Version++;
|
||||
@ -616,7 +614,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
var parent = folderDao.GetFolder(file.FolderID);
|
||||
if (parent != null
|
||||
&& fileSecurity.CanCreate<T>(parent))
|
||||
&& fileSecurity.CanCreate(parent))
|
||||
{
|
||||
folderId = parent.ID;
|
||||
}
|
||||
@ -626,7 +624,7 @@ namespace ASC.Web.Files.Utils
|
||||
if (FilesSettingsHelper.UpdateIfExist && (parent != null && !folderId.Equals(parent.ID) || !file.ProviderEntry))
|
||||
{
|
||||
newFile = fileDao.GetFile(folderId, newFileTitle);
|
||||
if (newFile != null && fileSecurity.CanEdit<T>(newFile) && !EntryManager.FileLockedForMe(newFile.ID) && !FileTracker.IsEditing(newFile.ID))
|
||||
if (newFile != null && fileSecurity.CanEdit(newFile) && !EntryManager.FileLockedForMe(newFile.ID) && !FileTracker.IsEditing(newFile.ID))
|
||||
{
|
||||
newFile.Version++;
|
||||
}
|
||||
@ -685,7 +683,7 @@ namespace ASC.Web.Files.Utils
|
||||
FilesMessageService.Send(newFile, MessageInitiator.DocsService, MessageAction.FileConverted, newFile.Title);
|
||||
FileMarker.MarkAsNew<T>(newFile);
|
||||
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var tags = tagDao.GetTags(file.ID, FileEntryType.File, TagType.System).ToList();
|
||||
if (tags.Any())
|
||||
{
|
||||
@ -696,20 +694,20 @@ namespace ASC.Web.Files.Utils
|
||||
return newFile;
|
||||
}
|
||||
|
||||
private static string GetKey(File f)
|
||||
private static string GetKey<T>(File<T> f)
|
||||
{
|
||||
return string.Format("fileConvertation-{0}", f.ID);
|
||||
}
|
||||
|
||||
|
||||
private class FileComparer : IEqualityComparer<File>
|
||||
private class FileComparer<T> : IEqualityComparer<File<T>>
|
||||
{
|
||||
public bool Equals(File x, File y)
|
||||
public bool Equals(File<T> x, File<T> y)
|
||||
{
|
||||
return x != null && y != null && Equals(x.ID, y.ID) && x.Version == y.Version;
|
||||
}
|
||||
|
||||
public int GetHashCode(File obj)
|
||||
public int GetHashCode(File<T> obj)
|
||||
{
|
||||
return obj.ID.GetHashCode() + obj.Version.GetHashCode();
|
||||
}
|
||||
|
@ -44,10 +44,6 @@ using ASC.Web.Files.Classes;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using static ASC.Web.Files.Utils.FileMarker;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
|
||||
namespace ASC.Web.Files.Utils
|
||||
{
|
||||
public class FileMarkerHelper
|
||||
@ -61,13 +57,13 @@ namespace ASC.Web.Files.Utils
|
||||
Log = optionsMonitor.CurrentValue;
|
||||
}
|
||||
|
||||
internal void ExecMarkFileAsNew<T>(AsyncTaskData obj)
|
||||
internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var scope = ServiceProvider.CreateScope();
|
||||
var fileMarker = scope.ServiceProvider.GetService<FileMarker>();
|
||||
fileMarker.ExecMarkFileAsNew<T>(obj);
|
||||
fileMarker.ExecMarkFileAsNew(obj);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -80,7 +76,7 @@ namespace ASC.Web.Files.Utils
|
||||
public class FileMarker
|
||||
{
|
||||
private static readonly object locker = new object();
|
||||
private readonly WorkerQueue<AsyncTaskData> tasks;
|
||||
private readonly WorkerQueue<AsyncTaskData<T>> tasks;
|
||||
private readonly ICache cache;
|
||||
|
||||
private const string CacheKeyFormat = "MarkedAsNew/{0}/folder_{1}";
|
||||
@ -104,7 +100,7 @@ namespace ASC.Web.Files.Utils
|
||||
CoreBaseSettings coreBaseSettings,
|
||||
AuthContext authContext,
|
||||
IServiceProvider serviceProvider,
|
||||
WorkerQueueOptionsManager<AsyncTaskData> workerQueueOptionsManager,
|
||||
WorkerQueueOptionsManager<AsyncTaskData<T>> workerQueueOptionsManager,
|
||||
FileMarkerHelper fileMarkerHelper)
|
||||
{
|
||||
TenantManager = tenantManager;
|
||||
@ -120,7 +116,7 @@ namespace ASC.Web.Files.Utils
|
||||
tasks = workerQueueOptionsManager.Value;
|
||||
}
|
||||
|
||||
internal void ExecMarkFileAsNew<T>(AsyncTaskData obj)
|
||||
internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)
|
||||
{
|
||||
TenantManager.SetCurrentTenant(Convert.ToInt32(obj.TenantID));
|
||||
|
||||
@ -136,7 +132,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
var userIDs = obj.UserIDs;
|
||||
|
||||
var userEntriesData = new Dictionary<Guid, List<FileEntry>>();
|
||||
var userEntriesData = new Dictionary<Guid, List<FileEntry<T>>>();
|
||||
|
||||
if (obj.FileEntry.RootFolderType == FolderType.BUNCH)
|
||||
{
|
||||
@ -144,7 +140,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
parentFolders.Add(folderDao.GetFolder(GlobalFolder.GetFolderProjects<T>(DaoFactory)));
|
||||
|
||||
var entries = new List<FileEntry> { obj.FileEntry };
|
||||
var entries = new List<FileEntry<T>> { obj.FileEntry };
|
||||
entries = entries.Concat(parentFolders).ToList();
|
||||
|
||||
userIDs.ForEach(userID =>
|
||||
@ -163,7 +159,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (!userIDs.Any())
|
||||
{
|
||||
userIDs = filesSecurity.WhoCanRead<T>(obj.FileEntry).Where(x => x != obj.CurrentAccountId).ToList();
|
||||
userIDs = filesSecurity.WhoCanRead(obj.FileEntry).Where(x => x != obj.CurrentAccountId).ToList();
|
||||
}
|
||||
if (obj.FileEntry.ProviderEntry)
|
||||
{
|
||||
@ -172,7 +168,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
parentFolders.ForEach(parentFolder =>
|
||||
filesSecurity
|
||||
.WhoCanRead<T>(parentFolder)
|
||||
.WhoCanRead(parentFolder)
|
||||
.Where(userID => userIDs.Contains(userID) && userID != obj.CurrentAccountId)
|
||||
.ToList()
|
||||
.ForEach(userID =>
|
||||
@ -180,7 +176,7 @@ namespace ASC.Web.Files.Utils
|
||||
if (userEntriesData.ContainsKey(userID))
|
||||
userEntriesData[userID].Add(parentFolder);
|
||||
else
|
||||
userEntriesData.Add(userID, new List<FileEntry> { parentFolder });
|
||||
userEntriesData.Add(userID, new List<FileEntry<T>> { parentFolder });
|
||||
})
|
||||
);
|
||||
|
||||
@ -195,7 +191,7 @@ namespace ASC.Web.Files.Utils
|
||||
var userFolderId = folderDao.GetFolderIDUser(false, userID);
|
||||
if (Equals(userFolderId, 0)) continue;
|
||||
|
||||
Folder rootFolder = null;
|
||||
Folder<T> rootFolder = null;
|
||||
if (obj.FileEntry.ProviderEntry)
|
||||
{
|
||||
rootFolder = obj.FileEntry.RootFolderCreator == userID
|
||||
@ -216,7 +212,7 @@ namespace ASC.Web.Files.Utils
|
||||
if (userEntriesData.ContainsKey(userID))
|
||||
userEntriesData[userID].Add(rootFolder);
|
||||
else
|
||||
userEntriesData.Add(userID, new List<FileEntry> { rootFolder });
|
||||
userEntriesData.Add(userID, new List<FileEntry<T>> { rootFolder });
|
||||
|
||||
RemoveFromCahce(rootFolder.ID, userID);
|
||||
}
|
||||
@ -228,13 +224,13 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (obj.FileEntry.ProviderEntry)
|
||||
{
|
||||
var commonFolder = folderDao.GetFolder(GlobalFolder.GetFolderCommon<T>(this, DaoFactory));
|
||||
var commonFolder = folderDao.GetFolder(GlobalFolder.GetFolderCommon(this, DaoFactory));
|
||||
userIDs.ForEach(userID =>
|
||||
{
|
||||
if (userEntriesData.ContainsKey(userID))
|
||||
userEntriesData[userID].Add(commonFolder);
|
||||
else
|
||||
userEntriesData.Add(userID, new List<FileEntry> { commonFolder });
|
||||
userEntriesData.Add(userID, new List<FileEntry<T>> { commonFolder });
|
||||
|
||||
RemoveFromCahce(GlobalFolder.GetFolderCommon(this, DaoFactory), userID);
|
||||
});
|
||||
@ -246,11 +242,11 @@ namespace ASC.Web.Files.Utils
|
||||
if (userEntriesData.ContainsKey(userID))
|
||||
userEntriesData[userID].Add(obj.FileEntry);
|
||||
else
|
||||
userEntriesData.Add(userID, new List<FileEntry> { obj.FileEntry });
|
||||
userEntriesData.Add(userID, new List<FileEntry<T>> { obj.FileEntry });
|
||||
});
|
||||
}
|
||||
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var newTags = new List<Tag>();
|
||||
var updateTags = new List<Tag>();
|
||||
|
||||
@ -281,26 +277,26 @@ namespace ASC.Web.Files.Utils
|
||||
tagDao.SaveTags(newTags);
|
||||
}
|
||||
|
||||
public void MarkAsNew<T>(FileEntry fileEntry, List<Guid> userIDs = null)
|
||||
public void MarkAsNew<T>(FileEntry<T> fileEntry, List<Guid> userIDs = null)
|
||||
{
|
||||
if (CoreBaseSettings.Personal) return;
|
||||
|
||||
if (fileEntry == null) return;
|
||||
userIDs ??= new List<Guid>();
|
||||
|
||||
var taskData = ServiceProvider.GetService<AsyncTaskData>();
|
||||
taskData.FileEntry = (FileEntry)fileEntry.Clone();
|
||||
var taskData = ServiceProvider.GetService<AsyncTaskData<T>>();
|
||||
taskData.FileEntry = (FileEntry<T>)fileEntry.Clone();
|
||||
taskData.UserIDs = userIDs;
|
||||
|
||||
if (fileEntry.RootFolderType == FolderType.BUNCH && !userIDs.Any())
|
||||
{
|
||||
var folderDao = DaoFactory.FolderDao;
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
var path = folderDao.GetBunchObjectID(fileEntry.RootFolderId);
|
||||
|
||||
var projectID = path.Split('/').Last();
|
||||
if (string.IsNullOrEmpty(projectID)) return;
|
||||
|
||||
var projectTeam = FileSecurity.WhoCanRead<T>(fileEntry)
|
||||
var projectTeam = FileSecurity.WhoCanRead(fileEntry)
|
||||
.Where(x => x != AuthContext.CurrentAccount.ID).ToList();
|
||||
|
||||
if (!projectTeam.Any()) return;
|
||||
@ -313,11 +309,11 @@ namespace ASC.Web.Files.Utils
|
||||
tasks.Add(taskData);
|
||||
|
||||
if (!tasks.IsStarted)
|
||||
tasks.Start(FileMarkerHelper.ExecMarkFileAsNew<T>);
|
||||
tasks.Start(FileMarkerHelper.ExecMarkFileAsNew);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveMarkAsNew(FileEntry fileEntry, Guid userID = default)
|
||||
public void RemoveMarkAsNew<T>(FileEntry<T> fileEntry, Guid userID = default)
|
||||
{
|
||||
if (CoreBaseSettings.Personal) return;
|
||||
|
||||
@ -325,11 +321,11 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (fileEntry == null) return;
|
||||
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var folderDao = DaoFactory.FolderDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
if (!tagDao.GetNewTags(userID, fileEntry).Any()) return;
|
||||
|
||||
object folderID;
|
||||
T folderID;
|
||||
int valueNew;
|
||||
var userFolderId = folderDao.GetFolderIDUser(false, userID);
|
||||
|
||||
@ -337,7 +333,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (fileEntry.FileEntryType == FileEntryType.File)
|
||||
{
|
||||
folderID = ((File)fileEntry).FolderID;
|
||||
folderID = ((File<T>)fileEntry).FolderID;
|
||||
|
||||
removeTags.Add(Tag.New(userID, fileEntry));
|
||||
valueNew = 1;
|
||||
@ -346,14 +342,14 @@ namespace ASC.Web.Files.Utils
|
||||
{
|
||||
folderID = fileEntry.ID;
|
||||
|
||||
var listTags = tagDao.GetNewTags(userID, (Folder)fileEntry, true).ToList();
|
||||
var listTags = tagDao.GetNewTags(userID, (Folder<T>)fileEntry, true).ToList();
|
||||
valueNew = listTags.FirstOrDefault(tag => tag.EntryId.Equals(fileEntry.ID)).Count;
|
||||
|
||||
if (Equals(fileEntry.ID, userFolderId) || Equals(fileEntry.ID, GlobalFolder.GetFolderCommon(this, DaoFactory)) || Equals(fileEntry.ID, GlobalFolder.GetFolderShare(DaoFactory)))
|
||||
{
|
||||
var folderTags = listTags.Where(tag => tag.EntryType == FileEntryType.Folder);
|
||||
|
||||
var providerFolderTags = folderTags.Select(tag => new KeyValuePair<Tag, Folder>(tag, folderDao.GetFolder(tag.EntryId)))
|
||||
var providerFolderTags = folderTags.Select(tag => new KeyValuePair<Tag, Folder<T>>(tag, folderDao.GetFolder(tag.EntryId)))
|
||||
.Where(pair => pair.Value != null && pair.Value.ProviderEntry).ToList();
|
||||
|
||||
foreach (var providerFolderTag in providerFolderTags)
|
||||
@ -370,14 +366,14 @@ namespace ASC.Web.Files.Utils
|
||||
parentFolders.Reverse();
|
||||
|
||||
var rootFolder = parentFolders.LastOrDefault();
|
||||
object rootFolderId = null;
|
||||
object cacheFolderId = null;
|
||||
T rootFolderId = default;
|
||||
T cacheFolderId = default;
|
||||
if (rootFolder == null)
|
||||
{
|
||||
}
|
||||
else if (rootFolder.RootFolderType == FolderType.BUNCH)
|
||||
{
|
||||
cacheFolderId = rootFolderId = GlobalFolder.GetFolderProjects(DaoFactory);
|
||||
cacheFolderId = rootFolderId = GlobalFolder.GetFolderProjects<T>(DaoFactory);
|
||||
}
|
||||
else if (rootFolder.RootFolderType == FolderType.COMMON)
|
||||
{
|
||||
@ -392,13 +388,13 @@ namespace ASC.Web.Files.Utils
|
||||
cacheFolderId = rootFolderId = userFolderId;
|
||||
else if (!rootFolder.ProviderEntry && !Equals(rootFolder.RootFolderId, userFolderId)
|
||||
|| rootFolder.ProviderEntry && rootFolder.RootFolderCreator != userID)
|
||||
cacheFolderId = rootFolderId = GlobalFolder.GetFolderShare(DaoFactory);
|
||||
cacheFolderId = rootFolderId = GlobalFolder.GetFolderShare<T>(DaoFactory);
|
||||
else
|
||||
cacheFolderId = userFolderId;
|
||||
}
|
||||
else if (rootFolder.RootFolderType == FolderType.SHARE)
|
||||
{
|
||||
cacheFolderId = GlobalFolder.GetFolderShare(DaoFactory);
|
||||
cacheFolderId = GlobalFolder.GetFolderShare<T>(DaoFactory);
|
||||
}
|
||||
|
||||
if (rootFolderId != null)
|
||||
@ -436,11 +432,11 @@ namespace ASC.Web.Files.Utils
|
||||
tagDao.RemoveTags(removeTags);
|
||||
}
|
||||
|
||||
public void RemoveMarkAsNewForAll(FileEntry fileEntry)
|
||||
public void RemoveMarkAsNewForAll<T>(FileEntry<T> fileEntry)
|
||||
{
|
||||
List<Guid> userIDs;
|
||||
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var tags = tagDao.GetTags(fileEntry.ID, fileEntry.FileEntryType == FileEntryType.File ? FileEntryType.File : FileEntryType.Folder, TagType.New);
|
||||
userIDs = tags.Select(tag => tag.Owner).Distinct().ToList();
|
||||
|
||||
@ -454,8 +450,8 @@ namespace ASC.Web.Files.Utils
|
||||
{
|
||||
var rootIds = new List<T>
|
||||
{
|
||||
GlobalFolder.GetFolderMy<T>(this, DaoFactory),
|
||||
GlobalFolder.GetFolderCommon<T>(this, DaoFactory),
|
||||
GlobalFolder.GetFolderMy(this, DaoFactory),
|
||||
GlobalFolder.GetFolderCommon(this, DaoFactory),
|
||||
GlobalFolder.GetFolderShare<T>(DaoFactory),
|
||||
GlobalFolder.GetFolderProjects<T>(DaoFactory)
|
||||
};
|
||||
@ -495,20 +491,20 @@ namespace ASC.Web.Files.Utils
|
||||
return news;
|
||||
}
|
||||
|
||||
public List<FileEntry> MarkedItems<T>(Folder<T> folder)
|
||||
public List<FileEntry<T>> MarkedItems<T>(Folder<T> folder)
|
||||
{
|
||||
if (folder == null) throw new ArgumentNullException("folder", FilesCommonResource.ErrorMassage_FolderNotFound);
|
||||
if (!FileSecurity.CanRead<T>(folder)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ViewFolder);
|
||||
if (folder.RootFolderType == FolderType.TRASH && !Equals(folder.ID, GlobalFolder.GetFolderTrash(DaoFactory.FolderDao))) throw new SecurityException(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
if (!FileSecurity.CanRead(folder)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ViewFolder);
|
||||
if (folder.RootFolderType == FolderType.TRASH && !Equals(folder.ID, GlobalFolder.GetFolderTrash<T>(DaoFactory))) throw new SecurityException(FilesCommonResource.ErrorMassage_ViewTrashItem);
|
||||
|
||||
var entryTags = new Dictionary<FileEntry, Tag>();
|
||||
var entryTags = new Dictionary<FileEntry<T>, Tag>();
|
||||
|
||||
var tagDao = DaoFactory.TagDao;
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
var tags = (tagDao.GetNewTags(AuthContext.CurrentAccount.ID, folder, true) ?? new List<Tag>()).ToList();
|
||||
|
||||
if (!tags.Any()) return new List<FileEntry>();
|
||||
if (!tags.Any()) return new List<FileEntry<T>>();
|
||||
|
||||
if (Equals(folder.ID, GlobalFolder.GetFolderMy(this, DaoFactory)) || Equals(folder.ID, GlobalFolder.GetFolderCommon(this, DaoFactory)) || Equals(folder.ID, GlobalFolder.GetFolderShare(DaoFactory)))
|
||||
{
|
||||
@ -533,7 +529,7 @@ namespace ASC.Web.Files.Utils
|
||||
{
|
||||
var entry = tag.EntryType == FileEntryType.File
|
||||
? fileDao.GetFile((T)tag.EntryId)
|
||||
: (FileEntry)folderDao.GetFolder((T)tag.EntryId);
|
||||
: (FileEntry<T>)folderDao.GetFolder((T)tag.EntryId);
|
||||
if (entry != null)
|
||||
{
|
||||
entryTags.Add(entry, tag);
|
||||
@ -549,15 +545,15 @@ namespace ASC.Web.Files.Utils
|
||||
var entry = entryTag.Key;
|
||||
var parentId =
|
||||
entry.FileEntryType == FileEntryType.File
|
||||
? ((File)entry).FolderID
|
||||
: ((Folder)entry).ParentFolderID;
|
||||
? ((File<T>)entry).FolderID
|
||||
: ((Folder<T>)entry).ParentFolderID;
|
||||
|
||||
var parentEntry = entryTags.Keys.FirstOrDefault(entryCountTag => Equals(entryCountTag.ID, parentId));
|
||||
if (parentEntry != null)
|
||||
entryTags[parentEntry].Count -= entryTag.Value.Count;
|
||||
}
|
||||
|
||||
var result = new List<FileEntry>();
|
||||
var result = new List<FileEntry<T>>();
|
||||
|
||||
foreach (var entryTag in entryTags)
|
||||
{
|
||||
@ -575,7 +571,7 @@ namespace ASC.Web.Files.Utils
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<FileEntry> SetTagsNew<T>(Folder<T> parent, IEnumerable<FileEntry> entries)
|
||||
public IEnumerable<FileEntry<T>> SetTagsNew<T>(Folder<T> parent, IEnumerable<FileEntry<T>> entries)
|
||||
{
|
||||
var tagDao = DaoFactory.GetTagDao<T>();
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
@ -641,7 +637,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (parentTreeTag == null)
|
||||
{
|
||||
if (fileSecurity.CanRead<T>(folderFromList))
|
||||
if (fileSecurity.CanRead(folderFromList))
|
||||
{
|
||||
tagDao.SaveTags(Tag.New(AuthContext.CurrentAccount.ID, folderFromList, -diff));
|
||||
}
|
||||
@ -672,7 +668,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (entry.FileEntryType == FileEntryType.Folder)
|
||||
{
|
||||
((Folder)entry).NewForMe = curTag != null ? curTag.Count : 0;
|
||||
((Folder<T>)entry).NewForMe = curTag != null ? curTag.Count : 0;
|
||||
}
|
||||
else if (curTag != null)
|
||||
{
|
||||
@ -708,38 +704,47 @@ namespace ASC.Web.Files.Utils
|
||||
var key = string.Format(CacheKeyFormat, userId, folderId);
|
||||
cache.Remove(key);
|
||||
}
|
||||
|
||||
|
||||
public class AsyncTaskData
|
||||
{
|
||||
public AsyncTaskData(TenantManager tenantManager, AuthContext authContext)
|
||||
{
|
||||
TenantID = tenantManager.GetCurrentTenant().TenantId;
|
||||
CurrentAccountId = authContext.CurrentAccount.ID;
|
||||
}
|
||||
|
||||
public int TenantID { get; private set; }
|
||||
|
||||
public FileEntry FileEntry { get; set; }
|
||||
|
||||
public List<Guid> UserIDs { get; set; }
|
||||
|
||||
public Guid CurrentAccountId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class AsyncTaskData<T>
|
||||
{
|
||||
public AsyncTaskData(TenantManager tenantManager, AuthContext authContext)
|
||||
{
|
||||
TenantID = tenantManager.GetCurrentTenant().TenantId;
|
||||
CurrentAccountId = authContext.CurrentAccount.ID;
|
||||
}
|
||||
|
||||
public int TenantID { get; private set; }
|
||||
|
||||
public FileEntry<T> FileEntry { get; set; }
|
||||
|
||||
public List<Guid> UserIDs { get; set; }
|
||||
|
||||
public Guid CurrentAccountId { get; set; }
|
||||
}
|
||||
|
||||
public static class FileMarkerExtention
|
||||
{
|
||||
public static DIHelper AddFileMarkerService(this DIHelper services)
|
||||
{
|
||||
|
||||
return services
|
||||
.AddFileMarkerService<string>()
|
||||
.AddFileMarkerService<int>()
|
||||
;
|
||||
}
|
||||
|
||||
public static DIHelper AddFileMarkerService<T>(this DIHelper services)
|
||||
{
|
||||
_ = services
|
||||
.TryAddTransient<AsyncTaskData>()
|
||||
.TryAddTransient<AsyncTaskData<T>>()
|
||||
.TryAddScoped<FileMarker>()
|
||||
.TryAddSingleton<FileMarkerHelper>()
|
||||
.TryAddSingleton<WorkerQueueOptionsManager<AsyncTaskData>>()
|
||||
.TryAddSingleton<WorkerQueue<AsyncTaskData>>()
|
||||
.AddSingleton<IConfigureOptions<WorkerQueue<AsyncTaskData>>, ConfigureWorkerQueue<AsyncTaskData>>();
|
||||
.TryAddSingleton<WorkerQueueOptionsManager<AsyncTaskData<T>>>()
|
||||
.TryAddSingleton<WorkerQueue<AsyncTaskData<T>>>()
|
||||
.AddSingleton<IConfigureOptions<WorkerQueue<AsyncTaskData<T>>>, ConfigureWorkerQueue<AsyncTaskData<T>>>();
|
||||
|
||||
_ = services.Configure<WorkerQueue<AsyncTaskData>>(r =>
|
||||
_ = services.Configure<WorkerQueue<AsyncTaskData<T>>>(r =>
|
||||
{
|
||||
r.workerCount = 1;
|
||||
r.waitInterval = (int)TimeSpan.FromSeconds(60).TotalMilliseconds;
|
||||
|
@ -106,11 +106,11 @@ namespace ASC.Web.Files.Utils
|
||||
if (file == null) return FileShare.Restrict;
|
||||
|
||||
var filesSecurity = FileSecurity;
|
||||
if (filesSecurity.CanEdit<T>(file, FileConstant.ShareLinkId)) return FileShare.ReadWrite;
|
||||
if (filesSecurity.CanReview<T>(file, FileConstant.ShareLinkId)) return FileShare.Review;
|
||||
if (filesSecurity.CanFillForms<T>(file, FileConstant.ShareLinkId)) return FileShare.FillForms;
|
||||
if (filesSecurity.CanComment<T>(file, FileConstant.ShareLinkId)) return FileShare.Comment;
|
||||
if (filesSecurity.CanRead<T>(file, FileConstant.ShareLinkId)) return FileShare.Read;
|
||||
if (filesSecurity.CanEdit(file, FileConstant.ShareLinkId)) return FileShare.ReadWrite;
|
||||
if (filesSecurity.CanReview(file, FileConstant.ShareLinkId)) return FileShare.Review;
|
||||
if (filesSecurity.CanFillForms(file, FileConstant.ShareLinkId)) return FileShare.FillForms;
|
||||
if (filesSecurity.CanComment(file, FileConstant.ShareLinkId)) return FileShare.Comment;
|
||||
if (filesSecurity.CanRead(file, FileConstant.ShareLinkId)) return FileShare.Read;
|
||||
return FileShare.Restrict;
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ASC.Web.Files.Utils
|
||||
{
|
||||
public class FileSharingAceHelper
|
||||
public class FileSharingAceHelper<T>
|
||||
{
|
||||
public FileSecurity FileSecurity { get; }
|
||||
public CoreBaseSettings CoreBaseSettings { get; }
|
||||
@ -85,10 +85,10 @@ namespace ASC.Web.Files.Utils
|
||||
FileSharingHelper = fileSharingHelper;
|
||||
}
|
||||
|
||||
public bool SetAceObject<T>(List<AceWrapper> aceWrappers, FileEntry entry, bool notify, string message)
|
||||
public bool SetAceObject(List<AceWrapper> aceWrappers, FileEntry<T> entry, bool notify, string message)
|
||||
{
|
||||
if (entry == null) throw new ArgumentNullException(FilesCommonResource.ErrorMassage_BadRequest);
|
||||
if (!FileSharingHelper.CanSetAccess<T>(entry)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException);
|
||||
if (!FileSharingHelper.CanSetAccess(entry)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException);
|
||||
|
||||
var fileSecurity = FileSecurity;
|
||||
|
||||
@ -166,10 +166,10 @@ namespace ASC.Web.Files.Utils
|
||||
if (recipients.Any())
|
||||
{
|
||||
if (entryType == FileEntryType.File
|
||||
|| ((Folder)entry).TotalSubFolders + ((Folder)entry).TotalFiles > 0
|
||||
|| ((Folder<T>)entry).TotalSubFolders + ((Folder<T>)entry).TotalFiles > 0
|
||||
|| entry.ProviderEntry)
|
||||
{
|
||||
FileMarker.MarkAsNew<T>(entry, recipients.Keys.ToList());
|
||||
FileMarker.MarkAsNew(entry, recipients.Keys.ToList());
|
||||
}
|
||||
|
||||
if (entry.RootFolderType == FolderType.USER
|
||||
@ -184,7 +184,7 @@ namespace ASC.Web.Files.Utils
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void RemoveAce<T>(List<FileEntry> entries)
|
||||
public void RemoveAce(List<FileEntry<T>> entries)
|
||||
{
|
||||
var fileSecurity = FileSecurity;
|
||||
|
||||
@ -229,13 +229,13 @@ namespace ASC.Web.Files.Utils
|
||||
public AuthContext AuthContext { get; }
|
||||
public UserManager UserManager { get; }
|
||||
|
||||
public bool CanSetAccess<T>(FileEntry entry)
|
||||
public bool CanSetAccess<T>(FileEntry<T> entry)
|
||||
{
|
||||
return
|
||||
entry != null
|
||||
&& (entry.RootFolderType == FolderType.COMMON && Global.IsAdministrator
|
||||
|| entry.RootFolderType == FolderType.USER
|
||||
&& (Equals(entry.RootFolderId, GlobalFolderHelper.GetFolderMy<T>()) || FileSecurity.CanEdit<T>(entry))
|
||||
&& (Equals(entry.RootFolderId, GlobalFolderHelper.GetFolderMy<T>()) || FileSecurity.CanEdit(entry))
|
||||
&& !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager));
|
||||
}
|
||||
}
|
||||
@ -274,15 +274,15 @@ namespace ASC.Web.Files.Utils
|
||||
Logger = optionsMonitor.CurrentValue;
|
||||
}
|
||||
|
||||
public bool CanSetAccess<T>(FileEntry entry)
|
||||
public bool CanSetAccess<T>(FileEntry<T> entry)
|
||||
{
|
||||
return FileSharingHelper.CanSetAccess<T>(entry);
|
||||
return FileSharingHelper.CanSetAccess(entry);
|
||||
}
|
||||
|
||||
public List<AceWrapper> GetSharedInfo<T>(FileEntry entry)
|
||||
public List<AceWrapper> GetSharedInfo<T>(FileEntry<T> entry)
|
||||
{
|
||||
if (entry == null) throw new ArgumentNullException(FilesCommonResource.ErrorMassage_BadRequest);
|
||||
if (!CanSetAccess<T>(entry))
|
||||
if (!CanSetAccess(entry))
|
||||
{
|
||||
Logger.ErrorFormat("User {0} can't get shared info for {1} {2}", AuthContext.CurrentAccount.ID, (entry.FileEntryType == FileEntryType.File ? "file" : "folder"), entry.ID);
|
||||
throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException);
|
||||
@ -325,7 +325,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (g.ID == Constants.LostGroupInfo.ID)
|
||||
{
|
||||
fileSecurity.RemoveSubject(r.Subject);
|
||||
fileSecurity.RemoveSubject<T>(r.Subject);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -347,7 +347,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (entry.FileEntryType == FileEntryType.File && result.All(w => w.SubjectId != FileConstant.ShareLinkId)
|
||||
&& entry.FileEntryType == FileEntryType.File
|
||||
&& !((File)entry).Encrypted)
|
||||
&& !((File<T>)entry).Encrypted)
|
||||
{
|
||||
var w = new AceWrapper
|
||||
{
|
||||
@ -421,8 +421,8 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
var result = new List<AceWrapper>();
|
||||
|
||||
var folderDao = DaoFactory.FolderDao;
|
||||
var fileDao = DaoFactory.FileDao;
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
|
||||
foreach (var objectId in objectIds)
|
||||
{
|
||||
@ -432,16 +432,16 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
|
||||
var entryType = objectId.StartsWith("file_") ? FileEntryType.File : FileEntryType.Folder;
|
||||
var entryId = objectId.Substring((entryType == FileEntryType.File ? "file_" : "folder_").Length);
|
||||
var entryId = (T)Convert.ChangeType(objectId.Substring((entryType == FileEntryType.File ? "file_" : "folder_").Length), typeof(T));
|
||||
|
||||
var entry = entryType == FileEntryType.File
|
||||
? (FileEntry)fileDao.GetFile(entryId)
|
||||
: (FileEntry)folderDao.GetFolder(entryId);
|
||||
? fileDao.GetFile(entryId)
|
||||
: (FileEntry<T>)folderDao.GetFolder(entryId);
|
||||
|
||||
IEnumerable<AceWrapper> acesForObject;
|
||||
try
|
||||
{
|
||||
acesForObject = GetSharedInfo<T>(entry);
|
||||
acesForObject = GetSharedInfo(entry);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -570,7 +570,8 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
public static DIHelper AddFileSharingAceHelperService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<FileSharingAceHelper>();
|
||||
services.TryAddScoped<FileSharingAceHelper<string>>();
|
||||
services.TryAddScoped<FileSharingAceHelper<int>>();
|
||||
|
||||
return services
|
||||
.AddFileSecurityService()
|
||||
|
@ -48,8 +48,6 @@ using ASC.Web.Studio.Utility;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
using File = ASC.Files.Core.File;
|
||||
|
||||
namespace ASC.Web.Files.Utils
|
||||
{
|
||||
public class FileUploader
|
||||
@ -128,7 +126,7 @@ namespace ASC.Web.Files.Utils
|
||||
var dao = DaoFactory.GetFileDao<T>();
|
||||
file = dao.SaveFile(file, data);
|
||||
|
||||
FileMarker.MarkAsNew<T>(file);
|
||||
FileMarker.MarkAsNew(file);
|
||||
|
||||
if (FileConverter.EnableAsUploaded && FileConverter.MustConvert(file))
|
||||
FileConverter.ExecAsync(file, deleteConvertStatus);
|
||||
@ -184,7 +182,7 @@ namespace ASC.Web.Files.Utils
|
||||
private bool CanEdit<T>(File<T> file)
|
||||
{
|
||||
return file != null
|
||||
&& FileSecurity.CanEdit<T>(file)
|
||||
&& FileSecurity.CanEdit(file)
|
||||
&& !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)
|
||||
&& !EntryManager.FileLockedForMe(file.ID)
|
||||
&& !FileTracker.IsEditing(file.ID)
|
||||
@ -200,7 +198,7 @@ namespace ASC.Web.Files.Utils
|
||||
if (folder == null)
|
||||
throw new DirectoryNotFoundException(FilesCommonResource.ErrorMassage_FolderNotFound);
|
||||
|
||||
if (!FileSecurity.CanCreate<T>(folder))
|
||||
if (!FileSecurity.CanCreate(folder))
|
||||
throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
|
||||
if (relativePath != null && relativePath.Any())
|
||||
@ -235,7 +233,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
#region chunked upload
|
||||
|
||||
public File VerifyChunkedUpload(string folderId, string fileName, long fileSize, bool updateIfExists, string relativePath = null)
|
||||
public File<T> VerifyChunkedUpload<T>(T folderId, string fileName, long fileSize, bool updateIfExists, string relativePath = null)
|
||||
{
|
||||
var maxUploadSize = GetMaxFileSize(folderId, true);
|
||||
|
||||
@ -300,7 +298,7 @@ namespace ASC.Web.Files.Utils
|
||||
|
||||
if (uploadSession.BytesUploaded == uploadSession.BytesTotal)
|
||||
{
|
||||
FileMarker.MarkAsNew<T>(uploadSession.File);
|
||||
FileMarker.MarkAsNew(uploadSession.File);
|
||||
ChunkedUploadSessionHolder.RemoveSession(uploadSession);
|
||||
}
|
||||
else
|
||||
@ -323,9 +321,9 @@ namespace ASC.Web.Files.Utils
|
||||
ChunkedUploadSessionHolder.RemoveSession(uploadSession);
|
||||
}
|
||||
|
||||
private long GetMaxFileSize(object folderId, bool chunkedUpload = false)
|
||||
private long GetMaxFileSize<T>(T folderId, bool chunkedUpload = false)
|
||||
{
|
||||
var folderDao = DaoFactory.FolderDao;
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
return folderDao.GetMaxUploadSize(folderId, chunkedUpload);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user