DocSpace-buildtools/web/ASC.Web.Core/WhiteLabel/TenantLogoManager.cs

210 lines
7.8 KiB
C#
Raw Normal View History

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
{
get { return "letterlogodata" + TenantManager.GetCurrentTenant().Id; }
}
2022-03-17 15:13:38 +00:00
public bool WhiteLabelEnabled
{
get;
private set;
}
2022-03-17 15:13:38 +00:00
private ICache Cache { get; }
private ICacheNotify<TenantLogoCacheItem> CacheNotify { get; }
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)
{
TenantWhiteLabelSettingsHelper = tenantWhiteLabelSettingsHelper;
SettingsManager = settingsManager;
TenantInfoSettingsHelper = tenantInfoSettingsHelper;
TenantManager = tenantManager;
AuthContext = authContext;
Configuration = configuration;
var hideSettings = (Configuration["web:hide-settings"] ?? "").Split(new[] { ',', ';', ' ' });
WhiteLabelEnabled = !hideSettings.Contains("WhiteLabel", StringComparer.CurrentCultureIgnoreCase);
Cache = cache;
CacheNotify = cacheNotify;
}
2022-03-17 15:13:38 +00:00
public string GetFavicon(bool general, bool timeParam)
{
string faviconPath;
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
if (WhiteLabelEnabled)
{
faviconPath = TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Favicon, general);
if (timeParam)
{
var now = DateTime.Now;
faviconPath = string.Format("{0}?t={1}", faviconPath, now.Ticks);
}
}
else
{
faviconPath = TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Favicon, general);
}
2022-03-17 15:13:38 +00:00
return faviconPath;
}
2022-03-17 15:13:38 +00:00
public string GetTopLogo(bool general)//LogoLightSmall
{
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
2022-03-17 15:13:38 +00:00
if (WhiteLabelEnabled)
{
return TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.LightSmall, general);
}
return TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.LightSmall, general);
}
2022-03-17 15:13:38 +00:00
public string GetLogoDark(bool general)
{
if (WhiteLabelEnabled)
{
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
return TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Dark, general);
}
2022-03-17 15:13:38 +00:00
/*** simple scheme ***/
return TenantInfoSettingsHelper.GetAbsoluteCompanyLogoPath(SettingsManager.Load<TenantInfoSettings>());
/***/
}
2022-03-17 15:13:38 +00:00
public string GetLogoDocsEditor(bool general)
{
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
2022-03-17 15:13:38 +00:00
if (WhiteLabelEnabled)
{
return TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.DocsEditor, general);
2021-12-07 13:56:16 +00:00
}
2022-03-17 15:13:38 +00:00
return TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, general);
}
public string GetLogoDocsEditorEmbed(bool general)
{
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
2021-12-07 13:56:16 +00:00
2022-03-17 15:13:38 +00:00
if (WhiteLabelEnabled)
{
return TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.DocsEditorEmbed, general);
}
return TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditorEmbed, general);
}
2022-03-17 15:13:38 +00:00
public string GetLogoText()
{
if (WhiteLabelEnabled)
2021-12-07 13:56:16 +00:00
{
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
2022-03-17 15:13:38 +00:00
return tenantWhiteLabelSettings.GetLogoText(SettingsManager) ?? TenantWhiteLabelSettings.DefaultLogoText;
}
return TenantWhiteLabelSettings.DefaultLogoText;
}
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-17 15:13:38 +00:00
return !AuthContext.IsAuthenticated;
}
2022-03-17 15:13:38 +00:00
public bool WhiteLabelPaid
{
get
{
return TenantManager.GetTenantQuota(TenantManager.GetCurrentTenant().Id).WhiteLabel;
}
}
2022-03-17 15:13:38 +00:00
private TenantWhiteLabelSettingsHelper TenantWhiteLabelSettingsHelper { get; }
private SettingsManager SettingsManager { get; }
private TenantInfoSettingsHelper TenantInfoSettingsHelper { get; }
private TenantManager TenantManager { get; }
private AuthContext AuthContext { get; }
private IConfiguration Configuration { get; }
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)
{
var tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
return TenantWhiteLabelSettingsHelper.GetWhitelabelLogoData(tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Dark, true);
}
2022-03-17 15:13:38 +00:00
/*** simple scheme ***/
return TenantInfoSettingsHelper.GetStorageLogoData(SettingsManager.Load<TenantInfoSettings>());
/***/
}
2022-03-17 15:13:38 +00:00
public byte[] GetMailLogoDataFromCache()
{
return Cache.Get<byte[]>(CacheKey);
}
2022-03-17 15:13:38 +00:00
public void InsertMailLogoDataToCache(byte[] data)
{
Cache.Insert(CacheKey, data, DateTime.UtcNow.Add(TimeSpan.FromDays(1)));
}
2019-06-07 08:59:07 +00:00
2022-03-17 15:13:38 +00:00
public void RemoveMailLogoDataFromCache()
{
CacheNotify.Publish(new TenantLogoCacheItem() { Key = CacheKey }, Common.Caching.CacheNotifyAction.Remove);
}
}