Files: Global

This commit is contained in:
pavelbannov 2020-01-31 10:56:40 +03:00
parent 7d5a698be6
commit 2dba07ea11
3 changed files with 198 additions and 144 deletions

View File

@ -44,17 +44,20 @@ namespace ASC.Web.Files.Configuration
public CoreBaseSettings CoreBaseSettings { get; } public CoreBaseSettings CoreBaseSettings { get; }
public AuthContext AuthContext { get; } public AuthContext AuthContext { get; }
public UserManager UserManager { get; } public UserManager UserManager { get; }
public Global Global { get; }
public ProductEntryPoint( public ProductEntryPoint(
FilesSpaceUsageStatManager filesSpaceUsageStatManager, FilesSpaceUsageStatManager filesSpaceUsageStatManager,
CoreBaseSettings coreBaseSettings, CoreBaseSettings coreBaseSettings,
AuthContext authContext, AuthContext authContext,
UserManager userManager) UserManager userManager,
Global global)
{ {
FilesSpaceUsageStatManager = filesSpaceUsageStatManager; FilesSpaceUsageStatManager = filesSpaceUsageStatManager;
CoreBaseSettings = coreBaseSettings; CoreBaseSettings = coreBaseSettings;
AuthContext = authContext; AuthContext = authContext;
UserManager = userManager; UserManager = userManager;
Global = global;
} }
public static readonly Guid ID = WebItemManager.DocumentsProductID; public static readonly Guid ID = WebItemManager.DocumentsProductID;

View File

@ -29,23 +29,29 @@ using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using ASC.Common;
using ASC.Common.Caching; using ASC.Common.Caching;
using ASC.Common.Logging; using ASC.Common.Logging;
using ASC.Core; using ASC.Core;
using ASC.Core.Common.Settings;
using ASC.Core.Users; using ASC.Core.Users;
using ASC.Data.Storage; using ASC.Data.Storage;
using ASC.Files.Core; using ASC.Files.Core;
using ASC.Files.Core.Data; using ASC.Files.Core.Data;
using ASC.Files.Core.Security; using ASC.Files.Core.Security;
using ASC.Web.Core; using ASC.Web.Core;
using ASC.Web.Core.Users;
using ASC.Web.Core.WhiteLabel; using ASC.Web.Core.WhiteLabel;
using ASC.Web.Files.Core;
using ASC.Web.Files.Resources; using ASC.Web.Files.Resources;
using ASC.Web.Files.Services.WCFService; using ASC.Web.Files.Services.WCFService;
using ASC.Web.Files.Utils; using ASC.Web.Files.Utils;
using Autofac; using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Constants = ASC.Core.Configuration.Constants; using Constants = ASC.Core.Configuration.Constants;
using File = ASC.Files.Core.File; using File = ASC.Files.Core.File;
@ -53,38 +59,48 @@ namespace ASC.Web.Files.Classes
{ {
public class Global public class Global
{ {
private static readonly object Locker = new object(); public ICacheNotify<AscCacheItem> Notify { get; set; }
private static bool isInit; public CoreBaseSettings CoreBaseSettings { get; }
public static readonly ICacheNotify Notify = AscCache.Notify; public IConfiguration Configuration { get; }
public AuthContext AuthContext { get; }
public UserManager UserManager { get; }
public CoreSettings CoreSettings { get; }
public WebItemManager WebItemManager { get; }
public WebItemSecurity WebItemSecurity { get; }
public TenantManager TenantManager { get; }
public StorageFactory StorageFactory { get; }
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
public CustomNamingPeople CustomNamingPeople { get; }
public SettingsManager SettingsManager { get; }
static Global() public Global(
{ IContainer container,
Init(); CoreBaseSettings coreBaseSettings,
} IOptionsMonitor<ILog> options,
ICacheNotify<AscCacheItem> notify,
internal static void Init() IConfiguration configuration,
AuthContext authContext,
UserManager userManager,
CoreSettings coreSettings,
WebItemManager webItemManager,
WebItemSecurity webItemSecurity,
TenantManager tenantManager,
StorageFactory storageFactory,
DisplayUserSettingsHelper displayUserSettingsHelper,
CustomNamingPeople customNamingPeople,
SettingsManager settingsManager)
{ {
try try
{ {
if (isInit) return; Logger = options.CurrentValue;
Notify = notify;
lock (Locker) if (!container.TryResolve(out IDaoFactory factory))
{
if (isInit) return;
DIHelper.Register();
var container = DIHelper.Resolve();
IDaoFactory factory;
if (!container.TryResolve(out factory))
{ {
factory = new DaoFactory(); factory = new DaoFactory();
Logger.Fatal("Could not resolve IDaoFactory instance. Using default DaoFactory instead."); Logger.Fatal("Could not resolve IDaoFactory instance. Using default DaoFactory instead.");
} }
IFileStorageService storageService; if (!container.TryResolve(out IFileStorageService storageService))
if (!container.TryResolve(out storageService))
{ {
storageService = new FileStorageServiceController(); storageService = new FileStorageServiceController();
Logger.Fatal("Could not resolve IFileStorageService instance. Using default FileStorageServiceController instead."); Logger.Fatal("Could not resolve IFileStorageService instance. Using default FileStorageServiceController instead.");
@ -93,13 +109,10 @@ namespace ASC.Web.Files.Classes
DaoFactory = factory; DaoFactory = factory;
FileStorageService = storageService; FileStorageService = storageService;
SocketManager = new SocketManager(); SocketManager = new SocketManager();
if (CoreContext.Configuration.Standalone) if (coreBaseSettings.Standalone)
{ {
ClearCache(); ClearCache();
} }
isInit = true;
}
} }
catch (Exception error) catch (Exception error)
{ {
@ -107,13 +120,26 @@ namespace ASC.Web.Files.Classes
DaoFactory = new DaoFactory(); DaoFactory = new DaoFactory();
FileStorageService = new FileStorageServiceController(); FileStorageService = new FileStorageServiceController();
} }
CoreBaseSettings = coreBaseSettings;
Configuration = configuration;
AuthContext = authContext;
UserManager = userManager;
CoreSettings = coreSettings;
WebItemManager = webItemManager;
WebItemSecurity = webItemSecurity;
TenantManager = tenantManager;
StorageFactory = storageFactory;
DisplayUserSettingsHelper = displayUserSettingsHelper;
CustomNamingPeople = customNamingPeople;
SettingsManager = settingsManager;
} }
private static void ClearCache() private void ClearCache()
{ {
try try
{ {
Notify.Subscribe<AscCacheItem>((item, action) => Notify.Subscribe((item) =>
{ {
try try
{ {
@ -127,7 +153,7 @@ namespace ASC.Web.Files.Classes
{ {
Logger.Fatal("ClearCache action", e); Logger.Fatal("ClearCache action", e);
} }
}); }, CacheNotifyAction.Any);
} }
catch (Exception e) catch (Exception e)
{ {
@ -141,41 +167,40 @@ namespace ASC.Web.Files.Classes
public static readonly Regex InvalidTitleChars = new Regex("[\t*\\+:\"<>?|\\\\/\\p{Cs}]"); public static readonly Regex InvalidTitleChars = new Regex("[\t*\\+:\"<>?|\\\\/\\p{Cs}]");
public static bool EnableUploadFilter public bool EnableUploadFilter
{ {
get { return bool.TrueString.Equals(WebConfigurationManager.AppSettings["files.upload-filter"] ?? "false", StringComparison.InvariantCultureIgnoreCase); } get { return bool.TrueString.Equals(Configuration["files:upload-filter"] ?? "false", StringComparison.InvariantCultureIgnoreCase); }
} }
public static TimeSpan StreamUrlExpire public TimeSpan StreamUrlExpire
{ {
get get
{ {
int validateTimespan; int.TryParse(Configuration["files:stream-url-minute"], out var validateTimespan);
int.TryParse(WebConfigurationManager.AppSettings["files.stream-url-minute"], out validateTimespan);
if (validateTimespan <= 0) validateTimespan = 16; if (validateTimespan <= 0) validateTimespan = 16;
return TimeSpan.FromMinutes(validateTimespan); return TimeSpan.FromMinutes(validateTimespan);
} }
} }
public static bool IsAdministrator public bool IsAdministrator
{ {
get { return FileSecurity.IsAdministrator(SecurityContext.CurrentAccount.ID); } get { return FileSecurity.IsAdministrator(AuthContext.CurrentAccount.ID); }
} }
public static bool IsOutsider public bool IsOutsider
{ {
get { return CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsOutsider(); } get { return UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsOutsider(UserManager); }
} }
public static string GetDocDbKey() public string GetDocDbKey()
{ {
const string dbKey = "UniqueDocument"; const string dbKey = "UniqueDocument";
var resultKey = CoreContext.Configuration.GetSetting(dbKey); var resultKey = CoreSettings.GetSetting(dbKey);
if (!string.IsNullOrEmpty(resultKey)) return resultKey; if (!string.IsNullOrEmpty(resultKey)) return resultKey;
resultKey = Guid.NewGuid().ToString(); resultKey = Guid.NewGuid().ToString();
CoreContext.Configuration.SaveSetting(dbKey, resultKey); CoreSettings.SaveSetting(dbKey, resultKey);
return resultKey; return resultKey;
} }
@ -185,22 +210,22 @@ namespace ASC.Web.Files.Classes
private static readonly IDictionary<int, object> ProjectsRootFolderCache = private static readonly IDictionary<int, object> ProjectsRootFolderCache =
new ConcurrentDictionary<int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ new ConcurrentDictionary<int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/
public static object FolderProjects public object FolderProjects
{ {
get get
{ {
if (CoreContext.Configuration.Personal) return null; if (CoreBaseSettings.Personal) return null;
if (WebItemManager.Instance[WebItemManager.ProjectsProductID].IsDisabled()) return null; if (WebItemManager[WebItemManager.ProjectsProductID].IsDisabled(WebItemSecurity, AuthContext)) return null;
using (var folderDao = DaoFactory.GetFolderDao()) using (var folderDao = DaoFactory.GetFolderDao())
{ {
object result; object result;
if (!ProjectsRootFolderCache.TryGetValue(TenantProvider.CurrentTenantID, out result)) if (!ProjectsRootFolderCache.TryGetValue(TenantManager.GetCurrentTenant().TenantId, out result))
{ {
result = folderDao.GetFolderIDProjects(true); result = folderDao.GetFolderIDProjects(true);
ProjectsRootFolderCache[TenantProvider.CurrentTenantID] = result; ProjectsRootFolderCache[TenantManager.GetCurrentTenant().TenantId] = result;
} }
return result; return result;
@ -211,17 +236,16 @@ namespace ASC.Web.Files.Classes
private static readonly IDictionary<string, object> UserRootFolderCache = private static readonly IDictionary<string, object> UserRootFolderCache =
new ConcurrentDictionary<string, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ new ConcurrentDictionary<string, object>(); /*Use SYNCHRONIZED for cross thread blocks*/
public static object FolderMy public object FolderMy
{ {
get get
{ {
if (!SecurityContext.IsAuthenticated) return 0; if (!AuthContext.IsAuthenticated) return 0;
if (CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor()) return 0; if (UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)) return 0;
var cacheKey = string.Format("my/{0}/{1}", TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID); var cacheKey = string.Format("my/{0}/{1}", TenantManager.GetCurrentTenant().TenantId, AuthContext.CurrentAccount.ID);
object myFolderId; if (!UserRootFolderCache.TryGetValue(cacheKey, out var myFolderId))
if (!UserRootFolderCache.TryGetValue(cacheKey, out myFolderId))
{ {
myFolderId = GetFolderIdAndProccessFirstVisit(true); myFolderId = GetFolderIdAndProccessFirstVisit(true);
if (!Equals(myFolderId, 0)) if (!Equals(myFolderId, 0))
@ -231,7 +255,7 @@ namespace ASC.Web.Files.Classes
} }
protected internal set protected internal set
{ {
var cacheKey = string.Format("my/{0}/{1}", TenantProvider.CurrentTenantID, value); var cacheKey = string.Format("my/{0}/{1}", TenantManager.GetCurrentTenant().TenantId, value);
UserRootFolderCache.Remove(cacheKey); UserRootFolderCache.Remove(cacheKey);
} }
} }
@ -239,18 +263,17 @@ namespace ASC.Web.Files.Classes
private static readonly IDictionary<int, object> CommonFolderCache = private static readonly IDictionary<int, object> CommonFolderCache =
new ConcurrentDictionary<int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ new ConcurrentDictionary<int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/
public static object FolderCommon public object FolderCommon
{ {
get get
{ {
if (CoreContext.Configuration.Personal) return null; if (CoreBaseSettings.Personal) return null;
object commonFolderId; if (!CommonFolderCache.TryGetValue(TenantManager.GetCurrentTenant().TenantId, out var commonFolderId))
if (!CommonFolderCache.TryGetValue(TenantProvider.CurrentTenantID, out commonFolderId))
{ {
commonFolderId = GetFolderIdAndProccessFirstVisit(false); commonFolderId = GetFolderIdAndProccessFirstVisit(false);
if (!Equals(commonFolderId, 0)) if (!Equals(commonFolderId, 0))
CommonFolderCache[TenantProvider.CurrentTenantID] = commonFolderId; CommonFolderCache[TenantManager.GetCurrentTenant().TenantId] = commonFolderId;
} }
return commonFolderId; return commonFolderId;
} }
@ -259,15 +282,14 @@ namespace ASC.Web.Files.Classes
private static readonly IDictionary<int, object> ShareFolderCache = private static readonly IDictionary<int, object> ShareFolderCache =
new ConcurrentDictionary<int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ new ConcurrentDictionary<int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/
public static object FolderShare public object FolderShare
{ {
get get
{ {
if (CoreContext.Configuration.Personal) return null; if (CoreBaseSettings.Personal) return null;
if (IsOutsider) return null; if (IsOutsider) return null;
object sharedFolderId; if (!ShareFolderCache.TryGetValue(TenantManager.GetCurrentTenant().TenantId, out var sharedFolderId))
if (!ShareFolderCache.TryGetValue(TenantProvider.CurrentTenantID, out sharedFolderId))
{ {
using (var folderDao = DaoFactory.GetFolderDao()) using (var folderDao = DaoFactory.GetFolderDao())
{ {
@ -275,7 +297,7 @@ namespace ASC.Web.Files.Classes
} }
if (!sharedFolderId.Equals(0)) if (!sharedFolderId.Equals(0))
ShareFolderCache[TenantProvider.CurrentTenantID] = sharedFolderId; ShareFolderCache[TenantManager.GetCurrentTenant().TenantId] = sharedFolderId;
} }
return sharedFolderId; return sharedFolderId;
@ -285,26 +307,25 @@ namespace ASC.Web.Files.Classes
private static readonly IDictionary<string, object> TrashFolderCache = private static readonly IDictionary<string, object> TrashFolderCache =
new ConcurrentDictionary<string, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ new ConcurrentDictionary<string, object>(); /*Use SYNCHRONIZED for cross thread blocks*/
public static object FolderTrash public object FolderTrash
{ {
get get
{ {
if (IsOutsider) return null; if (IsOutsider) return null;
var cacheKey = string.Format("trash/{0}/{1}", TenantProvider.CurrentTenantID, SecurityContext.CurrentAccount.ID); var cacheKey = string.Format("trash/{0}/{1}", TenantManager.GetCurrentTenant().TenantId, AuthContext.CurrentAccount.ID);
object trashFolderId; if (!TrashFolderCache.TryGetValue(cacheKey, out var trashFolderId))
if (!TrashFolderCache.TryGetValue(cacheKey, out trashFolderId))
{ {
using (var folderDao = DaoFactory.GetFolderDao()) using (var folderDao = DaoFactory.GetFolderDao())
trashFolderId = SecurityContext.IsAuthenticated ? folderDao.GetFolderIDTrash(true) : 0; trashFolderId = AuthContext.IsAuthenticated ? folderDao.GetFolderIDTrash(true) : 0;
TrashFolderCache[cacheKey] = trashFolderId; TrashFolderCache[cacheKey] = trashFolderId;
} }
return trashFolderId; return trashFolderId;
} }
protected internal set protected internal set
{ {
var cacheKey = string.Format("trash/{0}/{1}", TenantProvider.CurrentTenantID, value); var cacheKey = string.Format("trash/{0}/{1}", TenantManager.GetCurrentTenant().TenantId, value);
TrashFolderCache.Remove(cacheKey); TrashFolderCache.Remove(cacheKey);
} }
} }
@ -313,28 +334,25 @@ namespace ASC.Web.Files.Classes
#endregion #endregion
public static ILog Logger public ILog Logger { get; set; }
{
get { return LogManager.GetLogger("ASC.Files"); }
}
public static IDaoFactory DaoFactory { get; private set; } public static IDaoFactory DaoFactory { get; private set; }
public static EncryptedDataDao DaoEncryptedData public EncryptedDataDao DaoEncryptedData
{ {
get { return new EncryptedDataDao(TenantProvider.CurrentTenantID, FileConstant.DatabaseId); } get { return new EncryptedDataDao(TenantManager.GetCurrentTenant().TenantId, FileConstant.DatabaseId); }
} }
public static IFileStorageService FileStorageService { get; private set; } public static IFileStorageService FileStorageService { get; private set; }
public static SocketManager SocketManager { get; private set; } public static SocketManager SocketManager { get; private set; }
public static IDataStore GetStore(bool currentTenant = true) public IDataStore GetStore(bool currentTenant = true)
{ {
return StorageFactory.GetStorage(currentTenant ? TenantProvider.CurrentTenantID.ToString() : string.Empty, FileConstant.StorageModule); return StorageFactory.GetStorage(currentTenant ? TenantManager.GetCurrentTenant().TenantId.ToString() : string.Empty, FileConstant.StorageModule);
} }
public static IDataStore GetStoreTemplate() public IDataStore GetStoreTemplate()
{ {
return StorageFactory.GetStorage(string.Empty, FileConstant.StorageTemplate); return StorageFactory.GetStorage(string.Empty, FileConstant.StorageTemplate);
} }
@ -363,20 +381,20 @@ namespace ASC.Web.Files.Classes
return InvalidTitleChars.Replace(title, "_"); return InvalidTitleChars.Replace(title, "_");
} }
public static string GetUserName(Guid userId, bool alive = false) public string GetUserName(Guid userId, bool alive = false)
{ {
if (userId.Equals(SecurityContext.CurrentAccount.ID)) return FilesCommonResource.Author_Me; if (userId.Equals(AuthContext.CurrentAccount.ID)) return FilesCommonResource.Author_Me;
if (userId.Equals(Constants.Guest.ID)) return FilesCommonResource.Guest; if (userId.Equals(Constants.Guest.ID)) return FilesCommonResource.Guest;
var userInfo = CoreContext.UserManager.GetUsers(userId); var userInfo = UserManager.GetUsers(userId);
if (userInfo.Equals(ASC.Core.Users.Constants.LostUser)) return alive ? FilesCommonResource.Guest : CustomNamingPeople.Substitute<FilesCommonResource>("ProfileRemoved"); if (userInfo.Equals(ASC.Core.Users.Constants.LostUser)) return alive ? FilesCommonResource.Guest : CustomNamingPeople.Substitute<FilesCommonResource>("ProfileRemoved");
return userInfo.DisplayUserName(false); return userInfo.DisplayUserName(false, DisplayUserSettingsHelper);
} }
#region Generate start documents #region Generate start documents
private static object GetFolderIdAndProccessFirstVisit(bool my) private object GetFolderIdAndProccessFirstVisit(bool my)
{ {
using (var folderDao = DaoFactory.GetFolderDao()) using (var folderDao = DaoFactory.GetFolderDao())
using (var fileDao = DaoFactory.GetFileDao()) using (var fileDao = DaoFactory.GetFileDao())
@ -388,13 +406,13 @@ namespace ASC.Web.Files.Classes
id = my ? folderDao.GetFolderIDUser(true) : folderDao.GetFolderIDCommon(true); id = my ? folderDao.GetFolderIDUser(true) : folderDao.GetFolderIDCommon(true);
//Copy start document //Copy start document
if (AdditionalWhiteLabelSettings.Instance.StartDocsEnabled) if (AdditionalWhiteLabelSettings.Instance(SettingsManager).StartDocsEnabled)
{ {
try try
{ {
var storeTemplate = GetStoreTemplate(); var storeTemplate = GetStoreTemplate();
var culture = my ? CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).GetCulture() : CoreContext.TenantManager.GetCurrentTenant().GetCulture(); var culture = my ? UserManager.GetUsers(AuthContext.CurrentAccount.ID).GetCulture() : TenantManager.GetCurrentTenant().GetCulture();
var path = FileConstant.StartDocPath + culture + "/"; var path = FileConstant.StartDocPath + culture + "/";
if (!storeTemplate.IsDirectory(path)) if (!storeTemplate.IsDirectory(path))
@ -462,12 +480,12 @@ namespace ASC.Web.Files.Classes
#endregion #endregion
public static long GetUserUsedSpace() public long GetUserUsedSpace()
{ {
return GetUserUsedSpace(SecurityContext.CurrentAccount.ID); return GetUserUsedSpace(AuthContext.CurrentAccount.ID);
} }
public static long GetUserUsedSpace(Guid userId) public long GetUserUsedSpace(Guid userId)
{ {
var spaceUsageManager = new FilesSpaceUsageStatManager() as IUserSpaceUsage; var spaceUsageManager = new FilesSpaceUsageStatManager() as IUserSpaceUsage;

View File

@ -24,6 +24,14 @@
*/ */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;
using System.Threading;
using ASC.Core;
using ASC.Core.Users; using ASC.Core.Users;
using ASC.Files.Core; using ASC.Files.Core;
using ASC.MessagingSystem; using ASC.MessagingSystem;
@ -32,25 +40,50 @@ using ASC.Web.Files.Classes;
using ASC.Web.Files.Helpers; using ASC.Web.Files.Helpers;
using ASC.Web.Files.Resources; using ASC.Web.Files.Resources;
using ASC.Web.Studio.Core; using ASC.Web.Studio.Core;
using System; using ASC.Web.Studio.UserControls.Statistics;
using System.Collections.Generic; using ASC.Web.Studio.Utility;
using System.IO;
using System.Linq;
using System.Security;
using System.Threading;
using File = ASC.Files.Core.File; using File = ASC.Files.Core.File;
using SecurityContext = ASC.Core.SecurityContext;
namespace ASC.Web.Files.Utils namespace ASC.Web.Files.Utils
{ {
public static class FileUploader public class FileUploader
{ {
public static File Exec(string folderId, string title, long contentLength, Stream data) public FilesSettingsHelper FilesSettingsHelper { get; }
public FileUtility FileUtility { get; }
public UserManager UserManager { get; }
public TenantManager TenantManager { get; }
public AuthContext AuthContext { get; }
public SetupInfo SetupInfo { get; }
public TenantExtra TenantExtra { get; }
public TenantStatisticsProvider TenantStatisticsProvider { get; }
public FileUploader(
FilesSettingsHelper filesSettingsHelper,
FileUtility fileUtility,
UserManager userManager,
TenantManager tenantManager,
AuthContext authContext,
SetupInfo setupInfo,
TenantExtra tenantExtra,
TenantStatisticsProvider tenantStatisticsProvider)
{ {
return Exec(folderId, title, contentLength, data, !FilesSettings.UpdateIfExist); FilesSettingsHelper = filesSettingsHelper;
FileUtility = fileUtility;
UserManager = userManager;
TenantManager = tenantManager;
AuthContext = authContext;
SetupInfo = setupInfo;
TenantExtra = tenantExtra;
TenantStatisticsProvider = tenantStatisticsProvider;
} }
public static File Exec(string folderId, string title, long contentLength, Stream data, bool createNewIfExist, bool deleteConvertStatus = true) public File Exec(string folderId, string title, long contentLength, Stream data)
{
return Exec(folderId, title, contentLength, data, !FilesSettingsHelper.UpdateIfExist);
}
public File Exec(string folderId, string title, long contentLength, Stream data, bool createNewIfExist, bool deleteConvertStatus = true)
{ {
if (contentLength <= 0) if (contentLength <= 0)
throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile); throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile);
@ -70,7 +103,7 @@ namespace ASC.Web.Files.Utils
return file; return file;
} }
public static File VerifyFileUpload(string folderId, string fileName, bool updateIfExists, string relativePath = null) public File VerifyFileUpload(string folderId, string fileName, bool updateIfExists, string relativePath = null)
{ {
fileName = Global.ReplaceInvalidCharsAndTruncate(fileName); fileName = Global.ReplaceInvalidCharsAndTruncate(fileName);
@ -99,7 +132,7 @@ namespace ASC.Web.Files.Utils
return new File { FolderID = folderId, Title = fileName }; return new File { FolderID = folderId, Title = fileName };
} }
public static File VerifyFileUpload(string folderId, string fileName, long fileSize, bool updateIfExists) public File VerifyFileUpload(string folderId, string fileName, long fileSize, bool updateIfExists)
{ {
if (fileSize <= 0) if (fileSize <= 0)
throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile); throw new Exception(FilesCommonResource.ErrorMassage_EmptyFile);
@ -114,11 +147,11 @@ namespace ASC.Web.Files.Utils
return file; return file;
} }
private static bool CanEdit(File file) private bool CanEdit(File file)
{ {
return file != null return file != null
&& Global.GetFilesSecurity().CanEdit(file) && Global.GetFilesSecurity().CanEdit(file)
&& !CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor() && !UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsVisitor(UserManager)
&& !EntryManager.FileLockedForMe(file.ID) && !EntryManager.FileLockedForMe(file.ID)
&& !FileTracker.IsEditing(file.ID) && !FileTracker.IsEditing(file.ID)
&& file.RootFolderType != FolderType.TRASH && file.RootFolderType != FolderType.TRASH
@ -166,7 +199,7 @@ namespace ASC.Web.Files.Utils
#region chunked upload #region chunked upload
public static File VerifyChunkedUpload(string folderId, string fileName, long fileSize, bool updateIfExists, string relativePath = null) public File VerifyChunkedUpload(string folderId, string fileName, long fileSize, bool updateIfExists, string relativePath = null)
{ {
var maxUploadSize = GetMaxFileSize(folderId, true); var maxUploadSize = GetMaxFileSize(folderId, true);
@ -179,7 +212,7 @@ namespace ASC.Web.Files.Utils
return file; return file;
} }
public static ChunkedUploadSession InitiateUpload(string folderId, string fileId, string fileName, long contentLength, bool encrypted) public ChunkedUploadSession InitiateUpload(string folderId, string fileId, string fileName, long contentLength, bool encrypted)
{ {
if (string.IsNullOrEmpty(folderId)) if (string.IsNullOrEmpty(folderId))
folderId = null; folderId = null;
@ -201,8 +234,8 @@ namespace ASC.Web.Files.Utils
uploadSession.Expired = uploadSession.Created + ChunkedUploadSessionHolder.SlidingExpiration; uploadSession.Expired = uploadSession.Created + ChunkedUploadSessionHolder.SlidingExpiration;
uploadSession.Location = FilesLinkUtility.GetUploadChunkLocationUrl(uploadSession.Id); uploadSession.Location = FilesLinkUtility.GetUploadChunkLocationUrl(uploadSession.Id);
uploadSession.TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId; uploadSession.TenantId = TenantManager.GetCurrentTenant().TenantId;
uploadSession.UserId = SecurityContext.CurrentAccount.ID; uploadSession.UserId = AuthContext.CurrentAccount.ID;
uploadSession.FolderId = folderId; uploadSession.FolderId = folderId;
uploadSession.CultureName = Thread.CurrentThread.CurrentUICulture.Name; uploadSession.CultureName = Thread.CurrentThread.CurrentUICulture.Name;
uploadSession.Encrypted = encrypted; uploadSession.Encrypted = encrypted;
@ -213,7 +246,7 @@ namespace ASC.Web.Files.Utils
} }
} }
public static ChunkedUploadSession UploadChunk(string uploadId, Stream stream, long chunkLength) public ChunkedUploadSession UploadChunk(string uploadId, Stream stream, long chunkLength)
{ {
var uploadSession = ChunkedUploadSessionHolder.GetSession(uploadId); var uploadSession = ChunkedUploadSessionHolder.GetSession(uploadId);
uploadSession.Expired = DateTime.UtcNow + ChunkedUploadSessionHolder.SlidingExpiration; uploadSession.Expired = DateTime.UtcNow + ChunkedUploadSessionHolder.SlidingExpiration;
@ -225,7 +258,7 @@ namespace ASC.Web.Files.Utils
if (chunkLength > SetupInfo.ChunkUploadSize) if (chunkLength > SetupInfo.ChunkUploadSize)
{ {
throw FileSizeComment.GetFileSizeException(SetupInfo.MaxUploadSize); throw FileSizeComment.GetFileSizeException(SetupInfo.MaxUploadSize(TenantExtra, TenantStatisticsProvider));
} }
var maxUploadSize = GetMaxFileSize(uploadSession.FolderId, uploadSession.BytesTotal > 0); var maxUploadSize = GetMaxFileSize(uploadSession.FolderId, uploadSession.BytesTotal > 0);