public void Deconstruct( out FileMarker fileMarker, out GlobalFolder globalFolder, out IDaoFactory daoFactory, out SettingsManager settingsManager) { fileMarker = FileMarker; globalFolder = GlobalFolder; daoFactory = DaoFactory; settingsManager = SettingsManager; }
public FileMarkAsReadOperationScope( FileMarker fileMarker, GlobalFolder globalFolder, IDaoFactory daoFactory, SettingsManager settingsManager) { FileMarker = fileMarker; GlobalFolder = globalFolder; DaoFactory = daoFactory; SettingsManager = settingsManager; }
public FileSecurity( IDaoFactory daoFactory, UserManager userManager, TenantManager tenantManager, AuthContext authContext, AuthManager authManager, GlobalFolder globalFolder, FileSecurityCommon fileSecurityCommon) { this.daoFactory = daoFactory; UserManager = userManager; TenantManager = tenantManager; AuthContext = authContext; AuthManager = authManager; GlobalFolder = globalFolder; FileSecurityCommon = fileSecurityCommon; }
public FileMarker( TenantManager tenantManager, UserManager userManager, IDaoFactory daoFactory, GlobalFolder globalFolder, FileSecurity fileSecurity, CoreBaseSettings coreBaseSettings, AuthContext authContext, IServiceProvider serviceProvider) { TenantManager = tenantManager; UserManager = userManager; DaoFactory = daoFactory; GlobalFolder = globalFolder; FileSecurity = fileSecurity; CoreBaseSettings = coreBaseSettings; AuthContext = authContext; ServiceProvider = serviceProvider; cache = AscCache.Memory; }
public FileMarker( TenantManager tenantManager, UserManager userManager, IDaoFactory daoFactory, GlobalFolder globalFolder, FileSecurity fileSecurity, CoreBaseSettings coreBaseSettings, AuthContext authContext, IServiceProvider serviceProvider, WorkerQueueOptionsManager <AsyncTaskData> workerQueueOptionsManager, FileMarkerHelper fileMarkerHelper) { TenantManager = tenantManager; UserManager = userManager; DaoFactory = daoFactory; GlobalFolder = globalFolder; FileSecurity = fileSecurity; CoreBaseSettings = coreBaseSettings; AuthContext = authContext; ServiceProvider = serviceProvider; FileMarkerHelper = fileMarkerHelper; cache = AscCache.Memory; tasks = workerQueueOptionsManager.Value; }
public List <FileEntry <T> > GetPrivacyForMe <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.GetSecurityDao <T>(); var subjects = new List <Guid> { AuthContext.CurrentAccount.ID }; var records = securityDao.GetShares(subjects); var fileIds = new Dictionary <object, FileShare>(); var folderIds = new Dictionary <object, FileShare>(); var recordGroup = records.GroupBy(r => new { r.EntryId, r.EntryType }, (key, group) => new { firstRecord = group.OrderBy(r => r, new SubjectComparer(subjects)) .ThenByDescending(r => r.Share, new FileShareRecord.ShareComparer()) .First() }); foreach (var r in recordGroup.Where(r => r.firstRecord.Share != FileShare.Restrict)) { if (r.firstRecord.EntryType == FileEntryType.Folder) { if (!folderIds.ContainsKey(r.firstRecord.EntryId)) { folderIds.Add(r.firstRecord.EntryId, r.firstRecord.Share); } } else { if (!fileIds.ContainsKey(r.firstRecord.EntryId)) { fileIds.Add(r.firstRecord.EntryId, r.firstRecord.Share); } } } var entries = new List <FileEntry <T> >(); if (filterType != FilterType.FoldersOnly) { var files = fileDao.GetFilesFiltered(fileIds.Keys.Select(r => (T)r).ToArray(), filterType, subjectGroup, subjectID, searchText, searchInContent); files.ForEach(x => { if (fileIds.ContainsKey(x.ID)) { x.Access = fileIds[x.ID]; x.FolderIdDisplay = GlobalFolder.GetFolderPrivacy <T>(daoFactory); } }); entries.AddRange(files); } if (filterType == FilterType.None || filterType == FilterType.FoldersOnly) { var folders = folderDao.GetFolders(folderIds.Keys.Select(r => (T)r).ToArray(), filterType, subjectGroup, subjectID, searchText, withSubfolders, false); if (withSubfolders) { folders = FilterRead(folders).ToList(); } folders.ForEach(x => { if (folderIds.ContainsKey(x.ID)) { x.Access = folderIds[x.ID]; x.FolderIdDisplay = GlobalFolder.GetFolderPrivacy <T>(daoFactory); } }); entries.AddRange(folders.Cast <FileEntry <T> >()); } if (filterType != FilterType.FoldersOnly && withSubfolders) { var filesInSharedFolders = fileDao.GetFiles(folderIds.Keys.Select(r => (T)r).ToArray(), filterType, subjectGroup, subjectID, searchText, searchInContent); filesInSharedFolders = FilterRead(filesInSharedFolders).ToList(); entries.AddRange(filesInSharedFolders); entries = entries.Distinct().ToList(); } entries = entries.Where(f => f.RootFolderType == FolderType.Privacy && // show users files f.RootFolderCreator != AuthContext.CurrentAccount.ID // don't show my files ).ToList(); return(entries); }
public List <FileEntry> GetSharesForMe(FilterType filterType, bool subjectGroup, Guid subjectID, string searchText = "", bool searchInContent = false, bool withSubfolders = false) { var folderDao = daoFactory.FolderDao; var fileDao = daoFactory.FileDao; var securityDao = daoFactory.SecurityDao; var subjects = GetUserSubjects(AuthContext.CurrentAccount.ID); var records = securityDao.GetShares(subjects); var fileIds = new Dictionary <object, FileShare>(); var folderIds = new Dictionary <object, FileShare>(); var recordGroup = records.GroupBy(r => new { r.EntryId, r.EntryType }, (key, group) => new { firstRecord = group.OrderBy(r => r, new SubjectComparer(subjects)) .ThenByDescending(r => r.Share, new FileShareRecord.ShareComparer()) .First() }); foreach (var r in recordGroup.Where(r => r.firstRecord.Share != FileShare.Restrict)) { if (r.firstRecord.EntryType == FileEntryType.Folder) { if (!folderIds.ContainsKey(r.firstRecord.EntryId)) { folderIds.Add(r.firstRecord.EntryId, r.firstRecord.Share); } } else { if (!fileIds.ContainsKey(r.firstRecord.EntryId)) { fileIds.Add(r.firstRecord.EntryId, r.firstRecord.Share); } } } var entries = new List <FileEntry>(); if (filterType != FilterType.FoldersOnly) { var files = fileDao.GetFilesForShare(fileIds.Keys.ToArray(), filterType, subjectGroup, subjectID, searchText, searchInContent); files.ForEach(x => { if (fileIds.ContainsKey(x.ID)) { x.Access = fileIds[x.ID]; x.FolderIdDisplay = GlobalFolder.GetFolderShare(folderDao); } }); entries.AddRange(files); } if (filterType == FilterType.None || filterType == FilterType.FoldersOnly) { var folders = folderDao.GetFolders(folderIds.Keys.ToArray(), filterType, subjectGroup, subjectID, searchText, withSubfolders, false); if (withSubfolders) { folders = FilterRead(folders).ToList(); } folders.ForEach(x => { if (folderIds.ContainsKey(x.ID)) { x.Access = folderIds[x.ID]; x.FolderIdDisplay = GlobalFolder.GetFolderShare(folderDao); } }); entries.AddRange(folders.Cast <FileEntry>()); } if (filterType != FilterType.FoldersOnly && withSubfolders) { var filesInSharedFolders = fileDao.GetFiles(folderIds.Keys.ToArray(), filterType, subjectGroup, subjectID, searchText, searchInContent); filesInSharedFolders = FilterRead(filesInSharedFolders).ToList(); entries.AddRange(filesInSharedFolders); entries = entries.Distinct().ToList(); } entries = entries.Where(f => f.RootFolderType == FolderType.USER && // show users files f.RootFolderCreator != AuthContext.CurrentAccount.ID // don't show my files ).ToList(); if (UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)) { entries = entries.Where(r => !r.ProviderEntry).ToList(); } var failedEntries = entries.Where(x => !string.IsNullOrEmpty(x.Error)); var failedRecords = new List <FileShareRecord>(); foreach (var failedEntry in failedEntries) { var entryType = failedEntry.FileEntryType; var failedRecord = records.First(x => x.EntryId.Equals(failedEntry.ID) && x.EntryType == entryType); failedRecord.Share = FileShare.None; failedRecords.Add(failedRecord); } if (failedRecords.Any()) { securityDao.DeleteShareRecords(failedRecords); } return(entries.Where(x => string.IsNullOrEmpty(x.Error)).ToList()); }
internal void ExecMarkFileAsNew <T>(AsyncTaskData <T> obj) { TenantManager.SetCurrentTenant(Convert.ToInt32(obj.TenantID)); var folderDao = DaoFactory.GetFolderDao <T>(); T parentFolderId; if (obj.FileEntry.FileEntryType == FileEntryType.File) { parentFolderId = ((File <T>)obj.FileEntry).FolderID; } else { parentFolderId = ((Folder <T>)obj.FileEntry).ID; } var parentFolders = folderDao.GetParentFolders(parentFolderId); parentFolders.Reverse(); var userIDs = obj.UserIDs; var userEntriesData = new Dictionary <Guid, List <FileEntry <T> > >(); if (obj.FileEntry.RootFolderType == FolderType.BUNCH) { if (!userIDs.Any()) { return; } parentFolders.Add(folderDao.GetFolder(GlobalFolder.GetFolderProjects <T>(DaoFactory))); var entries = new List <FileEntry <T> > { obj.FileEntry }; entries = entries.Concat(parentFolders).ToList(); userIDs.ForEach(userID => { if (userEntriesData.ContainsKey(userID)) { userEntriesData[userID].AddRange(entries); } else { userEntriesData.Add(userID, entries); } RemoveFromCahce(GlobalFolder.GetFolderProjects(DaoFactory), userID); }); } else { var filesSecurity = FileSecurity; if (!userIDs.Any()) { userIDs = filesSecurity.WhoCanRead(obj.FileEntry).Where(x => x != obj.CurrentAccountId).ToList(); } if (obj.FileEntry.ProviderEntry) { userIDs = userIDs.Where(u => !UserManager.GetUsers(u).IsVisitor(UserManager)).ToList(); } parentFolders.ForEach(parentFolder => filesSecurity .WhoCanRead(parentFolder) .Where(userID => userIDs.Contains(userID) && userID != obj.CurrentAccountId) .ToList() .ForEach(userID => { if (userEntriesData.ContainsKey(userID)) { userEntriesData[userID].Add(parentFolder); } else { userEntriesData.Add(userID, new List <FileEntry <T> > { parentFolder }); } }) ); if (obj.FileEntry.RootFolderType == FolderType.USER) { var folderShare = folderDao.GetFolder(GlobalFolder.GetFolderShare <T>(DaoFactory)); foreach (var userID in userIDs) { var userFolderId = folderDao.GetFolderIDUser(false, userID); if (Equals(userFolderId, 0)) { continue; } Folder <T> rootFolder = null; if (obj.FileEntry.ProviderEntry) { rootFolder = obj.FileEntry.RootFolderCreator == userID ? folderDao.GetFolder(userFolderId) : folderShare; } else if (!Equals(obj.FileEntry.RootFolderId, userFolderId)) { rootFolder = folderShare; } else { RemoveFromCahce(userFolderId, userID); } if (rootFolder == null) { continue; } if (userEntriesData.ContainsKey(userID)) { userEntriesData[userID].Add(rootFolder); } else { userEntriesData.Add(userID, new List <FileEntry <T> > { rootFolder }); } RemoveFromCahce(rootFolder.ID, userID); } } else if (obj.FileEntry.RootFolderType == FolderType.COMMON) { userIDs.ForEach(userID => RemoveFromCahce(GlobalFolder.GetFolderCommon(this, DaoFactory), userID)); if (obj.FileEntry.ProviderEntry) { var commonFolder = folderDao.GetFolder(GlobalFolder.GetFolderCommon <T>(this, DaoFactory)); userIDs.ForEach(userID => { if (userEntriesData.ContainsKey(userID)) { userEntriesData[userID].Add(commonFolder); } else { userEntriesData.Add(userID, new List <FileEntry <T> > { commonFolder }); } RemoveFromCahce(GlobalFolder.GetFolderCommon(this, DaoFactory), userID); }); } } else if (obj.FileEntry.RootFolderType == FolderType.Privacy) { foreach (var userID in userIDs) { var privacyFolderId = folderDao.GetFolderIDPrivacy(false, userID); if (Equals(privacyFolderId, 0)) { continue; } var rootFolder = folderDao.GetFolder(privacyFolderId); if (rootFolder == null) { continue; } if (userEntriesData.ContainsKey(userID)) { userEntriesData[userID].Add(rootFolder); } else { userEntriesData.Add(userID, new List <FileEntry <T> > { rootFolder }); } RemoveFromCahce(rootFolder.ID, userID); } } userIDs.ForEach(userID => { if (userEntriesData.ContainsKey(userID)) { userEntriesData[userID].Add(obj.FileEntry); } else { userEntriesData.Add(userID, new List <FileEntry <T> > { obj.FileEntry }); } }); } var tagDao = DaoFactory.GetTagDao <T>(); var newTags = new List <Tag>(); var updateTags = new List <Tag>(); foreach (var userID in userEntriesData.Keys) { if (tagDao.GetNewTags(userID, obj.FileEntry).Any()) { continue; } var entries = userEntriesData[userID].Distinct().ToList(); var exist = tagDao.GetNewTags(userID, entries).ToList(); var update = exist.Where(t => t.EntryType == FileEntryType.Folder).ToList(); update.ForEach(t => t.Count++); updateTags.AddRange(update); entries.ForEach(entry => { if (entry != null && exist.All(tag => tag != null && !tag.EntryId.Equals(entry.ID))) { newTags.Add(Tag.New(userID, entry)); } }); } if (updateTags.Any()) { tagDao.UpdateNewTags(updateTags); } if (newTags.Any()) { tagDao.SaveTags(newTags); } }