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

113 lines
4.0 KiB
C#
Raw Normal View History

2019-06-07 08:59:07 +00:00
/*
*
* (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.
*
*/
2020-07-08 15:30:23 +00:00
using System;
2020-09-18 07:59:23 +00:00
using System.Text.Json.Serialization;
2020-07-08 15:30:23 +00:00
2019-06-07 08:59:07 +00:00
using ASC.Core;
2019-08-15 12:04:42 +00:00
using ASC.Core.Common.Settings;
2020-07-08 15:30:23 +00:00
2019-10-31 13:54:43 +00:00
using Microsoft.Extensions.DependencyInjection;
2020-09-18 07:59:23 +00:00
2019-06-07 08:59:07 +00:00
namespace ASC.Web.Core.WhiteLabel
{
public class CompanyWhiteLabelSettingsWrapper
{
public CompanyWhiteLabelSettings Settings { get; set; }
}
2019-06-07 08:59:07 +00:00
[Serializable]
2019-11-08 15:11:30 +00:00
public class CompanyWhiteLabelSettings : ISettings
2019-06-07 08:59:07 +00:00
{
public string CompanyName { get; set; }
public string Site { get; set; }
public string Email { get; set; }
public string Address { get; set; }
2020-09-18 07:59:23 +00:00
public string Phone { get; set; }
[JsonPropertyName("IsLicensor")]
public bool IsLicensorSetting { get; set; }
public bool GetIsLicensor(TenantManager tenantManager, CoreSettings coreSettings)
{
return IsLicensorSetting
&& (IsDefault(coreSettings) || tenantManager.GetTenantQuota(tenantManager.GetCurrentTenant().TenantId).Branding);
}
2019-06-07 08:59:07 +00:00
public bool IsDefault(CoreSettings coreSettings)
2019-06-07 08:59:07 +00:00
{
if (!(GetDefault(coreSettings) is CompanyWhiteLabelSettings defaultSettings)) return false;
return CompanyName == defaultSettings.CompanyName &&
Site == defaultSettings.Site &&
Email == defaultSettings.Email &&
Address == defaultSettings.Address &&
Phone == defaultSettings.Phone &&
2020-09-18 07:59:23 +00:00
IsLicensorSetting == defaultSettings.IsLicensorSetting;
2019-09-13 11:18:27 +00:00
}
2019-06-07 08:59:07 +00:00
#region ISettings Members
public Guid ID
2019-06-07 08:59:07 +00:00
{
get { return new Guid("{C3C5A846-01A3-476D-A962-1CFD78C04ADB}"); }
}
2019-11-08 15:11:30 +00:00
private static CompanyWhiteLabelSettings _default;
public ISettings GetDefault(IServiceProvider serviceProvider)
{
if (_default != null) return _default;
return GetDefault(serviceProvider.GetService<CoreSettings>());
}
public ISettings GetDefault(CoreSettings coreSettings)
2019-06-07 08:59:07 +00:00
{
if (_default != null) return _default;
var settings = coreSettings.GetSetting("CompanyWhiteLabelSettings");
2019-06-07 08:59:07 +00:00
2020-09-18 07:59:23 +00:00
_default = string.IsNullOrEmpty(settings) ? new CompanyWhiteLabelSettings() : Newtonsoft.Json.JsonConvert.DeserializeObject<CompanyWhiteLabelSettings>(settings);
2019-06-07 08:59:07 +00:00
return _default;
}
#endregion
public static CompanyWhiteLabelSettings Instance(SettingsManager settingsManager)
2019-06-07 08:59:07 +00:00
{
return settingsManager.LoadForDefaultTenant<CompanyWhiteLabelSettings>();
2019-10-31 13:54:43 +00:00
}
2019-06-07 08:59:07 +00:00
}
}