2022-03-15 18:00:53 +00:00
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
//
|
|
|
|
// This program is a free software product.
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL 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 details, see
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
//
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
//
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
//
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
//
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
namespace ASC.Web.Core.WhiteLabel;
|
|
|
|
|
|
|
|
[Scope]
|
|
|
|
public class TenantLogoManager
|
2020-10-19 15:53:15 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
private string CacheKey
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
get { return "letterlogodata" + _tenantManager.GetCurrentTenant().Id; }
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-22 10:31:41 +00:00
|
|
|
public bool WhiteLabelEnabled { get; private set; }
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-22 10:31:41 +00:00
|
|
|
private readonly ICache _cache;
|
|
|
|
private readonly ICacheNotify<TenantLogoCacheItem> _cacheNotify;
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public TenantLogoManager(
|
|
|
|
TenantWhiteLabelSettingsHelper tenantWhiteLabelSettingsHelper,
|
|
|
|
SettingsManager settingsManager,
|
|
|
|
TenantInfoSettingsHelper tenantInfoSettingsHelper,
|
|
|
|
TenantManager tenantManager,
|
|
|
|
AuthContext authContext,
|
|
|
|
IConfiguration configuration,
|
|
|
|
ICacheNotify<TenantLogoCacheItem> cacheNotify,
|
|
|
|
ICache cache)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
_tenantWhiteLabelSettingsHelper = tenantWhiteLabelSettingsHelper;
|
|
|
|
_settingsManager = settingsManager;
|
|
|
|
_tenantInfoSettingsHelper = tenantInfoSettingsHelper;
|
|
|
|
_tenantManager = tenantManager;
|
|
|
|
_authContext = authContext;
|
|
|
|
_configuration = configuration;
|
|
|
|
var hideSettings = (_configuration["web:hide-settings"] ?? "").Split(new[] { ',', ';', ' ' });
|
2022-03-17 15:13:38 +00:00
|
|
|
WhiteLabelEnabled = !hideSettings.Contains("WhiteLabel", StringComparer.CurrentCultureIgnoreCase);
|
2022-03-22 10:31:41 +00:00
|
|
|
_cache = cache;
|
|
|
|
_cacheNotify = cacheNotify;
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string GetFavicon(bool general, bool timeParam)
|
|
|
|
{
|
|
|
|
string faviconPath;
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
2022-03-17 15:13:38 +00:00
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
faviconPath = _tenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Favicon, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
if (timeParam)
|
|
|
|
{
|
|
|
|
var now = DateTime.Now;
|
|
|
|
faviconPath = string.Format("{0}?t={1}", faviconPath, now.Ticks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
faviconPath = _tenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Favicon, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return faviconPath;
|
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string GetTopLogo(bool general)//LogoLightSmall
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.LightSmall, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.LightSmall, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string GetLogoDark(bool general)
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Dark, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
/*** simple scheme ***/
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantInfoSettingsHelper.GetAbsoluteCompanyLogoPath(_settingsManager.Load<TenantInfoSettings>());
|
2022-03-17 15:13:38 +00:00
|
|
|
/***/
|
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string GetLogoDocsEditor(bool general)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.DocsEditor, general);
|
2021-12-07 13:56:16 +00:00
|
|
|
}
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string GetLogoDocsEditorEmbed(bool general)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
2021-12-07 13:56:16 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.DocsEditorEmbed, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditorEmbed, general);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string GetLogoText()
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
2021-12-07 13:56:16 +00:00
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-22 10:31:41 +00:00
|
|
|
return tenantWhiteLabelSettings.GetLogoText(_settingsManager) ?? TenantWhiteLabelSettings.DefaultLogoText;
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
return TenantWhiteLabelSettings.DefaultLogoText;
|
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public bool IsRetina(HttpRequest request)
|
|
|
|
{
|
|
|
|
if (request != null)
|
|
|
|
{
|
|
|
|
var cookie = request.Cookies["is_retina"];
|
|
|
|
if (cookie != null && !string.IsNullOrEmpty(cookie))
|
2021-12-07 13:56:16 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
if (bool.TryParse(cookie, out var result))
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
2021-12-07 13:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 10:31:41 +00:00
|
|
|
return !_authContext.IsAuthenticated;
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public bool WhiteLabelPaid
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).WhiteLabel;
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-22 10:31:41 +00:00
|
|
|
private readonly TenantWhiteLabelSettingsHelper _tenantWhiteLabelSettingsHelper;
|
|
|
|
private readonly SettingsManager _settingsManager;
|
|
|
|
private readonly TenantInfoSettingsHelper _tenantInfoSettingsHelper;
|
|
|
|
private readonly TenantManager _tenantManager;
|
|
|
|
private readonly AuthContext _authContext;
|
|
|
|
private readonly IConfiguration _configuration;
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Get logo stream or null in case of default logo
|
|
|
|
/// </summary>
|
|
|
|
public Stream GetWhitelabelMailLogo()
|
|
|
|
{
|
|
|
|
if (WhiteLabelEnabled)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
var tenantWhiteLabelSettings = _settingsManager.Load<TenantWhiteLabelSettings>();
|
|
|
|
return _tenantWhiteLabelSettingsHelper.GetWhitelabelLogoData(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Dark, true);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
/*** simple scheme ***/
|
2022-03-22 10:31:41 +00:00
|
|
|
return _tenantInfoSettingsHelper.GetStorageLogoData(_settingsManager.Load<TenantInfoSettings>());
|
2022-03-17 15:13:38 +00:00
|
|
|
/***/
|
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public byte[] GetMailLogoDataFromCache()
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
return _cache.Get<byte[]>(CacheKey);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2022-03-22 10:20:43 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void InsertMailLogoDataToCache(byte[] data)
|
|
|
|
{
|
2022-03-22 10:31:41 +00:00
|
|
|
_cache.Insert(CacheKey, data, DateTime.UtcNow.Add(TimeSpan.FromDays(1)));
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void RemoveMailLogoDataFromCache()
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
_cacheNotify.Publish(new TenantLogoCacheItem() { Key = CacheKey }, CacheNotifyAction.Remove);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
}
|