Files: DI

This commit is contained in:
pavelbannov 2020-02-14 13:45:46 +03:00
parent 785cc4c5a3
commit c082019270
14 changed files with 208 additions and 86 deletions

View File

@ -104,7 +104,7 @@ namespace ASC.ElasticSearch
{
public static IServiceCollection AddClientService(this IServiceCollection services)
{
services.TryAddSingleton<Client>();
services.TryAddScoped<Client>();
return services
.AddCoreConfigurationService();
}

View File

@ -571,7 +571,7 @@ namespace ASC.ElasticSearch
{
public static IServiceCollection AddFactoryIndexerService(this IServiceCollection services)
{
services.TryAddSingleton<FactoryIndexer>();
services.TryAddScoped<FactoryIndexer>();
return services
.AddClientService()
.AddCoreBaseSettingsService();
@ -579,7 +579,7 @@ namespace ASC.ElasticSearch
public static IServiceCollection AddFactoryIndexerHelperService(this IServiceCollection services)
{
services.TryAddSingleton<FactoryIndexerHelper>();
services.TryAddScoped<FactoryIndexerHelper>();
return services
.AddFactoryIndexerService();
}

View File

@ -228,7 +228,7 @@ namespace ASC.Web.Files.Classes
{
public static IServiceCollection AddFilesSettingsHelperService(this IServiceCollection services)
{
services.TryAddScoped<SettingsManager>();
services.TryAddScoped<FilesSettingsHelper>();
return services
.AddSettingsManagerService()
.AddCoreBaseSettingsService();

View File

@ -45,6 +45,7 @@ using ASC.Web.Studio.UserControls.Statistics;
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace ASC.Files.Core.Data
@ -954,6 +955,7 @@ namespace ASC.Files.Core.Data
{
public static IServiceCollection AddFolderDaoService(this IServiceCollection services)
{
services.TryAddScoped<IFolderDao, FolderDao>();
return services
.AddFactoryIndexerService<FoldersWrapper>()
.AddTenantManagerService()

View File

@ -40,6 +40,7 @@ using ASC.Web.Studio.UserControls.Statistics;
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace ASC.Files.Core.Data
{
@ -366,6 +367,8 @@ namespace ASC.Files.Core.Data
{
public static IServiceCollection AddSecurityDaoService(this IServiceCollection services)
{
services.TryAddScoped<ISecurityDao, SecurityDao>();
return services
.AddUserManagerService()
.AddFilesDbContextService()

View File

@ -39,6 +39,7 @@ using ASC.Web.Studio.UserControls.Statistics;
using ASC.Web.Studio.Utility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace ASC.Files.Core.Data
{
@ -604,6 +605,7 @@ namespace ASC.Files.Core.Data
{
public static IServiceCollection AddTagDaoService(this IServiceCollection services)
{
services.TryAddScoped<ITagDao, TagDao>();
return services
.AddUserManagerService()
.AddFilesDbContextService()

View File

@ -30,12 +30,14 @@ using System.Linq;
using ASC.Core;
using ASC.Core.Users;
using ASC.Files.Core.Data;
using ASC.Web.Core;
using ASC.Web.Files.Api;
using ASC.Web.Files.Classes;
using ASC.Web.Files.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace ASC.Files.Core.Security
{
@ -80,7 +82,7 @@ namespace ASC.Files.Core.Security
public TenantManager TenantManager { get; }
public AuthContext AuthContext { get; }
public AuthManager AuthManager { get; }
public GlobalFolderHelper GlobalFolderHelper { get; }
public GlobalFolder GlobalFolder { get; }
public FileSecurityCommon FileSecurityCommon { get; }
public FileSecurity(
@ -89,7 +91,7 @@ namespace ASC.Files.Core.Security
TenantManager tenantManager,
AuthContext authContext,
AuthManager authManager,
GlobalFolderHelper globalFolderHelper,
GlobalFolder globalFolder,
FileSecurityCommon fileSecurityCommon)
{
this.daoFactory = daoFactory;
@ -97,7 +99,7 @@ namespace ASC.Files.Core.Security
TenantManager = tenantManager;
AuthContext = authContext;
AuthManager = authManager;
GlobalFolderHelper = globalFolderHelper;
GlobalFolder = globalFolder;
FileSecurityCommon = fileSecurityCommon;
}
@ -617,7 +619,7 @@ namespace ASC.Files.Core.Security
if (fileIds.ContainsKey(x.ID))
{
x.Access = fileIds[x.ID];
x.FolderIdDisplay = GlobalFolderHelper.FolderShare;
x.FolderIdDisplay = GlobalFolder.GetFolderShare(folderDao);
}
});
@ -637,7 +639,7 @@ namespace ASC.Files.Core.Security
if (folderIds.ContainsKey(x.ID))
{
x.Access = folderIds[x.ID];
x.FolderIdDisplay = GlobalFolderHelper.FolderShare;
x.FolderIdDisplay = GlobalFolder.GetFolderShare(folderDao);
}
});
@ -750,6 +752,8 @@ namespace ASC.Files.Core.Security
{
public static IServiceCollection AddFileSecurityCommonService(this IServiceCollection services)
{
services.TryAddScoped<FileSecurityCommon>();
return services
.AddUserManagerService()
.AddWebItemSecurity();
@ -757,7 +761,17 @@ namespace ASC.Files.Core.Security
public static IServiceCollection AddFileSecurityService(this IServiceCollection services)
{
return services;
services.TryAddScoped<FileSecurity>();
services.TryAddScoped<IFileSecurity, FileSecurity>();
return services
.AddDaoFactoryService()
.AddUserManagerService()
.AddTenantManagerService()
.AddAuthContextService()
.AddAuthManager()
.AddGlobalFolderService()
.AddFileSecurityCommonService();
}
}
}

View File

@ -233,10 +233,10 @@ namespace ASC.Web.Files.Services.DocumentService
public EditorType Type = EditorType.Desktop;
private string _breadCrumbs;
public InfoConfig(EntryManager entryManager, FileSharing fileSharing, IFileStorageService fileStorageService)
public InfoConfig(BreadCrumbsManager breadCrumbsManager, FileSharingHelper fileSharingHelper, IFileStorageService fileStorageService)
{
EntryManager = entryManager;
FileSharing = fileSharing;
BreadCrumbsManager = breadCrumbsManager;
FileSharingHelper = fileSharingHelper;
FileStorageService = fileStorageService;
}
@ -267,7 +267,7 @@ namespace ASC.Web.Files.Services.DocumentService
{
const string crumbsSeporator = " \\ ";
var breadCrumbsList = EntryManager.GetBreadCrumbs(File.FolderID);
var breadCrumbsList = BreadCrumbsManager.GetBreadCrumbs(File.FolderID);
_breadCrumbs = string.Join(crumbsSeporator, breadCrumbsList.Select(folder => folder.Title).ToArray());
}
@ -297,7 +297,7 @@ namespace ASC.Web.Files.Services.DocumentService
{
if (Type == EditorType.Embedded
|| Type == EditorType.External
|| !FileSharing.CanSetAccess(File)) return null;
|| !FileSharingHelper.CanSetAccess(File)) return null;
try
{
@ -310,8 +310,8 @@ namespace ASC.Web.Files.Services.DocumentService
}
}
public EntryManager EntryManager { get; }
public FileSharing FileSharing { get; }
public BreadCrumbsManager BreadCrumbsManager { get; }
public FileSharingHelper FileSharingHelper { get; }
public IFileStorageService FileStorageService { get; }
}
@ -956,8 +956,8 @@ namespace ASC.Web.Files.Services.DocumentService
services.TryAddTransient<InfoConfig>();
return services
.AddEntryManagerService()
.AddFileSharingService();
.AddBreadCrumbsManagerService()
.AddFileSharingHelperService();
}
public static IServiceCollection AddEditorConfigurationService(this IServiceCollection services)

View File

@ -682,11 +682,8 @@ namespace ASC.Web.Files.Services.DocumentService
.AddDocumentServiceConnectorService()
.AddNotifyClientService()
.AddEncryptionAddressHelperService()
.AddSocketManagerService();
/*
MailMergeTaskRunner mailMergeTaskRunner
*/
.AddSocketManagerService()
.AddMailMergeTaskRunnerService();
}
}
}

View File

@ -2116,10 +2116,6 @@ namespace ASC.Web.Files.Services.WCFService
.AddSocketManagerService()
.AddFileOperationsManagerHelperService();
;
/*
FileOperationsManagerHelper fileOperationsManagerHelper,
*/
}
}
}

View File

@ -41,7 +41,7 @@ namespace ASC.Files
{
services.AddHttpContextAccessor();
services.AddControllers().AddControllersAsServices()
services.AddControllers()
.AddNewtonsoftJson()
.AddXmlSerializerFormatters();

View File

@ -92,6 +92,83 @@ namespace ASC.Web.Files.Utils
}
}
public class BreadCrumbsManager
{
public IDaoFactory DaoFactory { get; }
public FileSecurity FileSecurity { get; }
public GlobalFolderHelper GlobalFolderHelper { get; }
public AuthContext AuthContext { get; }
public BreadCrumbsManager(
IDaoFactory daoFactory,
FileSecurity fileSecurity,
GlobalFolderHelper globalFolderHelper,
AuthContext authContext)
{
DaoFactory = daoFactory;
FileSecurity = fileSecurity;
GlobalFolderHelper = globalFolderHelper;
AuthContext = authContext;
}
public List<Folder> GetBreadCrumbs(object folderId)
{
var folderDao = DaoFactory.FolderDao;
return GetBreadCrumbs(folderId, folderDao);
}
public List<Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao)
{
if (folderId == null) return new List<Folder>();
var breadCrumbs = FileSecurity.FilterRead(folderDao.GetParentFolders(folderId)).ToList();
var firstVisible = breadCrumbs.ElementAtOrDefault(0);
object rootId = null;
if (firstVisible == null)
{
rootId = GlobalFolderHelper.FolderShare;
}
else
{
switch (firstVisible.FolderType)
{
case FolderType.DEFAULT:
if (!firstVisible.ProviderEntry)
{
rootId = GlobalFolderHelper.FolderShare;
}
else
{
switch (firstVisible.RootFolderType)
{
case FolderType.USER:
rootId = AuthContext.CurrentAccount.ID == firstVisible.RootFolderCreator
? GlobalFolderHelper.FolderMy
: GlobalFolderHelper.FolderShare;
break;
case FolderType.COMMON:
rootId = GlobalFolderHelper.FolderCommon;
break;
}
}
break;
case FolderType.BUNCH:
rootId = GlobalFolderHelper.FolderProjects;
break;
}
}
if (rootId != null)
{
breadCrumbs.Insert(0, folderDao.GetFolder(rootId));
}
return breadCrumbs;
}
}
public class EntryManager
{
private const string UPDATE_LIST = "filesUpdateList";
@ -115,6 +192,7 @@ namespace ASC.Web.Files.Utils
public ThirdpartyConfiguration ThirdpartyConfiguration { get; }
public DocumentServiceConnector DocumentServiceConnector { get; }
public LockerManager LockerManager { get; }
public BreadCrumbsManager BreadCrumbsManager { get; }
public IServiceProvider ServiceProvider { get; }
public ILog Logger { get; }
@ -138,6 +216,7 @@ namespace ASC.Web.Files.Utils
ThirdpartyConfiguration thirdpartyConfiguration,
DocumentServiceConnector documentServiceConnector,
LockerManager lockerManager,
BreadCrumbsManager breadCrumbsManager,
IServiceProvider serviceProvider)
{
DaoFactory = daoFactory;
@ -158,6 +237,7 @@ namespace ASC.Web.Files.Utils
ThirdpartyConfiguration = thirdpartyConfiguration;
DocumentServiceConnector = documentServiceConnector;
LockerManager = lockerManager;
BreadCrumbsManager = breadCrumbsManager;
ServiceProvider = serviceProvider;
Logger = optionsMonitor.CurrentValue;
cache = AscCache.Memory;
@ -534,59 +614,12 @@ namespace ASC.Web.Files.Utils
public List<Folder> GetBreadCrumbs(object folderId)
{
var folderDao = DaoFactory.FolderDao;
return GetBreadCrumbs(folderId, folderDao);
return BreadCrumbsManager.GetBreadCrumbs(folderId);
}
public List<Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao)
{
if (folderId == null) return new List<Folder>();
var breadCrumbs = FileSecurity.FilterRead(folderDao.GetParentFolders(folderId)).ToList();
var firstVisible = breadCrumbs.ElementAtOrDefault(0);
object rootId = null;
if (firstVisible == null)
{
rootId = GlobalFolderHelper.FolderShare;
}
else
{
switch (firstVisible.FolderType)
{
case FolderType.DEFAULT:
if (!firstVisible.ProviderEntry)
{
rootId = GlobalFolderHelper.FolderShare;
}
else
{
switch (firstVisible.RootFolderType)
{
case FolderType.USER:
rootId = AuthContext.CurrentAccount.ID == firstVisible.RootFolderCreator
? GlobalFolderHelper.FolderMy
: GlobalFolderHelper.FolderShare;
break;
case FolderType.COMMON:
rootId = GlobalFolderHelper.FolderCommon;
break;
}
}
break;
case FolderType.BUNCH:
rootId = GlobalFolderHelper.FolderProjects;
break;
}
}
if (rootId != null)
{
breadCrumbs.Insert(0, folderDao.GetFolder(rootId));
}
return breadCrumbs;
return BreadCrumbsManager.GetBreadCrumbs(folderId, folderDao);
}
@ -1048,6 +1081,7 @@ namespace ASC.Web.Files.Utils
.AddFilesIntegrationService()
.AddThirdpartyConfigurationService()
.AddLockerManagerService()
.AddBreadCrumbsManagerService()
;
}
}
@ -1062,4 +1096,17 @@ namespace ASC.Web.Files.Utils
.AddDaoFactoryService();
}
}
public static class BreadCrumbsManagerExtension
{
public static IServiceCollection AddBreadCrumbsManagerService(this IServiceCollection services)
{
services.TryAddScoped<BreadCrumbsManager>();
return services
.AddDaoFactoryService()
.AddFileSecurityService()
.AddGlobalFolderHelperService()
.AddAuthContextService();
}
}
}

View File

@ -49,6 +49,39 @@ using Microsoft.Extensions.Options;
namespace ASC.Web.Files.Utils
{
public class FileSharingHelper
{
public FileSharingHelper(
Global global,
GlobalFolderHelper globalFolderHelper,
FileSecurity fileSecurity,
AuthContext authContext,
UserManager userManager)
{
Global = global;
GlobalFolderHelper = globalFolderHelper;
FileSecurity = fileSecurity;
AuthContext = authContext;
UserManager = userManager;
}
public Global Global { get; }
public GlobalFolderHelper GlobalFolderHelper { get; }
public FileSecurity FileSecurity { get; }
public AuthContext AuthContext { get; }
public UserManager UserManager { get; }
public bool CanSetAccess(FileEntry entry)
{
return
entry != null
&& (entry.RootFolderType == FolderType.COMMON && Global.IsAdministrator
|| entry.RootFolderType == FolderType.USER
&& (Equals(entry.RootFolderId, GlobalFolderHelper.FolderMy) || FileSecurity.CanEdit(entry))
&& !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager));
}
}
public class FileSharing
{
public Global Global { get; }
@ -64,6 +97,7 @@ namespace ASC.Web.Files.Utils
public CoreBaseSettings CoreBaseSettings { get; }
public NotifyClient NotifyClient { get; }
public IDaoFactory DaoFactory { get; }
public FileSharingHelper FileSharingHelper { get; }
public ILog Logger { get; }
public FileSharing(
@ -80,7 +114,8 @@ namespace ASC.Web.Files.Utils
DocumentServiceHelper documentServiceHelper,
CoreBaseSettings coreBaseSettings,
NotifyClient notifyClient,
IDaoFactory daoFactory)
IDaoFactory daoFactory,
FileSharingHelper fileSharingHelper)
{
Global = global;
GlobalFolderHelper = globalFolderHelper;
@ -95,17 +130,13 @@ namespace ASC.Web.Files.Utils
CoreBaseSettings = coreBaseSettings;
NotifyClient = notifyClient;
DaoFactory = daoFactory;
FileSharingHelper = fileSharingHelper;
Logger = optionsMonitor.CurrentValue;
}
public bool CanSetAccess(FileEntry entry)
{
return
entry != null
&& (entry.RootFolderType == FolderType.COMMON && Global.IsAdministrator
|| entry.RootFolderType == FolderType.USER
&& (Equals(entry.RootFolderId, GlobalFolderHelper.FolderMy) || FileSecurity.CanEdit(entry))
&& !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager));
return FileSharingHelper.CanSetAccess(entry);
}
public List<AceWrapper> GetSharedInfo(FileEntry entry)
@ -509,7 +540,22 @@ namespace ASC.Web.Files.Utils
.AddFileUtilityService()
.AddDocumentServiceHelperService()
.AddNotifyClientService()
.AddDaoFactoryService();
.AddDaoFactoryService()
.AddFileSharingHelperService();
}
}
public static class FileSharingHelperExtension
{
public static IServiceCollection AddFileSharingHelperService(this IServiceCollection services)
{
services.TryAddScoped<FileSharingHelper>();
return services
.AddGlobalService()
.AddGlobalFolderHelperService()
.AddFileSecurityService()
.AddAuthContextService()
.AddUserManagerService();
}
}
}

View File

@ -34,6 +34,9 @@ using ASC.Core;
using ASC.Core.Common;
using ASC.Web.Studio.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Newtonsoft.Json.Linq;
namespace ASC.Web.Files.Utils
@ -206,4 +209,16 @@ namespace ASC.Web.Files.Utils
return responseSend["response"].Value<string>();
}
}
public static class MailMergeTaskRunnerExtension
{
public static IServiceCollection AddMailMergeTaskRunnerService(this IServiceCollection services)
{
services.TryAddScoped<MailMergeTaskRunner>();
return services
.AddSetupInfo()
.AddSecurityContextService()
.AddBaseCommonLinkUtilityService();
}
}
}