DocSpace-client/web/ASC.Web.Core/Utility/TenantExtra.cs

241 lines
8.8 KiB
C#
Raw Normal View History

/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
namespace ASC.Web.Studio.Utility
{
2020-10-19 15:53:15 +00:00
[Scope]
2019-09-09 12:56:33 +00:00
public class TenantExtra
{
2020-08-12 09:58:08 +00:00
private UserManager UserManager { get; }
private TenantStatisticsProvider TenantStatisticsProvider { get; }
private AuthContext AuthContext { get; }
private TenantManager TenantManager { get; }
private PaymentManager PaymentManager { get; }
private CoreBaseSettings CoreBaseSettings { get; }
private LicenseReader LicenseReader { get; }
private SetupInfo SetupInfo { get; }
private SettingsManager SettingsManager { get; }
2019-09-09 12:56:33 +00:00
2019-09-16 14:51:39 +00:00
public TenantExtra(
2019-10-31 11:28:30 +00:00
UserManager userManager,
TenantStatisticsProvider tenantStatisticsProvider,
AuthContext authContext,
TenantManager tenantManager,
2019-09-18 15:19:30 +00:00
PaymentManager paymentManager,
2019-09-20 15:08:45 +00:00
CoreBaseSettings coreBaseSettings,
2019-09-23 12:20:08 +00:00
LicenseReader licenseReader,
SetupInfo setupInfo,
SettingsManager settingsManager)
2019-09-09 12:56:33 +00:00
{
UserManager = userManager;
TenantStatisticsProvider = tenantStatisticsProvider;
AuthContext = authContext;
2019-09-16 14:51:39 +00:00
TenantManager = tenantManager;
PaymentManager = paymentManager;
2019-09-18 15:19:30 +00:00
CoreBaseSettings = coreBaseSettings;
2019-09-20 15:08:45 +00:00
LicenseReader = licenseReader;
2019-09-23 12:20:08 +00:00
SetupInfo = setupInfo;
SettingsManager = settingsManager;
2019-09-09 12:56:33 +00:00
}
2021-05-27 17:13:24 +00:00
public bool EnableTariffSettings
{
get
{
return
SetupInfo.IsVisibleSettings<TariffSettings>()
&& !SettingsManager.Load<TenantAccessSettings>().Anyone
2020-12-28 13:22:08 +00:00
&& (!CoreBaseSettings.Standalone || !string.IsNullOrEmpty(LicenseReader.LicensePath))
&& string.IsNullOrEmpty(SetupInfo.AmiMetaUrl);
}
}
2019-09-09 12:56:33 +00:00
public bool Saas
{
2019-09-18 15:19:30 +00:00
get { return !CoreBaseSettings.Standalone; }
}
2019-09-09 12:56:33 +00:00
public bool Enterprise
{
2020-09-17 12:04:28 +00:00
get { return CoreBaseSettings.Standalone && !string.IsNullOrEmpty(LicenseReader.LicensePath); }
}
2019-09-09 12:56:33 +00:00
public bool Opensource
{
2020-09-17 12:04:28 +00:00
get { return CoreBaseSettings.Standalone && string.IsNullOrEmpty(LicenseReader.LicensePath); }
}
2019-09-09 12:56:33 +00:00
public bool EnterprisePaid
{
2020-09-17 12:04:28 +00:00
get { return Enterprise && GetCurrentTariff().State < TariffState.NotPaid; }
}
2019-09-09 12:56:33 +00:00
public bool EnableControlPanel
{
2019-08-15 12:04:42 +00:00
get
{
2020-09-17 12:04:28 +00:00
return CoreBaseSettings.Standalone &&
!string.IsNullOrEmpty(SetupInfo.ControlPanelUrl) &&
2019-08-15 12:04:42 +00:00
GetTenantQuota().ControlPanel &&
GetCurrentTariff().State < TariffState.NotPaid &&
UserManager.GetUsers(AuthContext.CurrentAccount.ID).IsAdmin(UserManager);
2019-08-09 12:28:19 +00:00
}
}
2019-09-09 12:56:33 +00:00
public bool EnableDocbuilder
{
get { return !Opensource; }
}
2019-09-09 12:56:33 +00:00
public string GetAppsPageLink()
{
2020-09-17 12:04:28 +00:00
return VirtualPathUtility.ToAbsolute("~/AppInstall.aspx");
}
2019-09-09 12:56:33 +00:00
public string GetTariffPageLink()
{
2020-09-17 12:04:28 +00:00
return VirtualPathUtility.ToAbsolute("~/Tariffs.aspx");
}
2019-09-09 12:56:33 +00:00
public Tariff GetCurrentTariff()
{
return PaymentManager.GetTariff(TenantManager.GetCurrentTenant().TenantId);
}
2019-09-09 12:56:33 +00:00
public TenantQuota GetTenantQuota()
{
2019-09-16 14:51:39 +00:00
return GetTenantQuota(TenantManager.GetCurrentTenant().TenantId);
}
2019-09-09 12:56:33 +00:00
public TenantQuota GetTenantQuota(int tenant)
{
2019-09-16 14:51:39 +00:00
return TenantManager.GetTenantQuota(tenant);
}
2019-09-09 12:56:33 +00:00
public IEnumerable<TenantQuota> GetTenantQuotas()
{
2019-09-16 14:51:39 +00:00
return TenantManager.GetTenantQuotas();
}
2019-09-09 12:56:33 +00:00
private TenantQuota GetPrevQuota(TenantQuota curQuota)
{
TenantQuota prev = null;
foreach (var quota in GetTenantQuotas().OrderBy(r => r.ActiveUsers).Where(r => r.Year == curQuota.Year && r.Year3 == curQuota.Year3))
{
if (quota.Id == curQuota.Id)
return prev;
prev = quota;
}
return null;
}
2019-09-09 12:56:33 +00:00
public int GetPrevUsersCount(TenantQuota quota)
{
var prevQuota = GetPrevQuota(quota);
if (prevQuota == null || prevQuota.Trial)
return 1;
return prevQuota.ActiveUsers + 1;
}
public int GetRightQuotaId()
{
var q = GetRightQuota();
return q != null ? q.Id : 0;
}
public TenantQuota GetRightQuota()
{
var usedSpace = TenantStatisticsProvider.GetUsedSize();
var needUsersCount = TenantStatisticsProvider.GetUsersCount();
var quotas = GetTenantQuotas();
return quotas.OrderBy(q => q.ActiveUsers)
.ThenBy(q => q.Year)
.FirstOrDefault(q =>
q.ActiveUsers > needUsersCount
&& q.MaxTotalSize > usedSpace
&& !q.Free
&& !q.Trial);
}
public int GetRemainingCountUsers()
{
return GetTenantQuota().ActiveUsers - TenantStatisticsProvider.GetUsersCount();
}
2019-09-09 12:56:33 +00:00
public bool UpdatedWithoutLicense
{
get
{
DateTime licenseDay;
2019-09-18 15:19:30 +00:00
return CoreBaseSettings.Standalone
&& (licenseDay = GetCurrentTariff().LicenseDate.Date) < DateTime.Today
&& licenseDay < LicenseReader.VersionReleaseDate;
}
}
2019-09-09 12:56:33 +00:00
2020-09-17 12:04:28 +00:00
public void DemandControlPanelPermission()
{
if (!CoreBaseSettings.Standalone || SettingsManager.Load<TenantControlPanelSettings>().LimitedAccess)
{
throw new System.Security.SecurityException(Resource.ErrorAccessDenied);
}
}
2019-09-09 12:56:33 +00:00
public bool IsNotPaid()
{
Tariff tariff;
2021-05-27 17:13:24 +00:00
return EnableTariffSettings
2019-09-09 12:56:33 +00:00
&& ((tariff = GetCurrentTariff()).State >= TariffState.NotPaid
|| Enterprise && !EnterprisePaid && tariff.LicenseDate == DateTime.MaxValue);
}
/// <summary>
/// Max possible file size for not chunked upload. Less or equal than 100 mb.
/// </summary>
public long MaxUploadSize
{
get { return Math.Min(SetupInfo.AvailableFileSize, MaxChunkedUploadSize); }
}
/// <summary>
/// Max possible file size for chunked upload.
/// </summary>
public long MaxChunkedUploadSize
{
get
{
var diskQuota = GetTenantQuota();
if (diskQuota != null)
{
var usedSize = TenantStatisticsProvider.GetUsedSize();
var freeSize = Math.Max(diskQuota.MaxTotalSize - usedSize, 0);
return Math.Min(freeSize, diskQuota.MaxFileSize);
}
return SetupInfo.ChunkUploadSize;
}
}
}
}