From 16af78a2a28a2ee0fd98a2d5b259f28746d62bbb Mon Sep 17 00:00:00 2001 From: SuhorukovAnton Date: Fri, 14 Oct 2022 23:59:18 +0300 Subject: [PATCH] fix is default --- .../Api/Settings/SettingsController.cs | 4 +- .../Api/Settings/WhitelabelController.cs | 13 ++- .../AdditionalWhiteLabelSettingsDto.cs | 3 +- .../CompanyWhiteLabelSettingsDto.cs | 3 +- .../AdditionalWhiteLabelSettingsConverter.cs | 70 +++++++++++++++ .../CompanyWhiteLabelSettingsConverter.cs | 51 +++++++++++ .../Notify/NotifyConfiguration.cs | 4 +- web/ASC.Web.Core/Notify/StudioNotifyHelper.cs | 2 +- web/ASC.Web.Core/Utility/CommonLinkUtility.cs | 2 +- .../AdditionalWhiteLabelSettings.cs | 86 +++++++++++-------- .../WhiteLabel/CompanyWhiteLabelSettings.cs | 61 +++++++------ 11 files changed, 225 insertions(+), 74 deletions(-) create mode 100644 web/ASC.Web.Api/Mapping/AdditionalWhiteLabelSettingsConverter.cs create mode 100644 web/ASC.Web.Api/Mapping/CompanyWhiteLabelSettingsConverter.cs diff --git a/web/ASC.Web.Api/Api/Settings/SettingsController.cs b/web/ASC.Web.Api/Api/Settings/SettingsController.cs index 2db5d3987f..dcde7e773e 100644 --- a/web/ASC.Web.Api/Api/Settings/SettingsController.cs +++ b/web/ASC.Web.Api/Api/Settings/SettingsController.cs @@ -57,7 +57,7 @@ public class SettingsController : BaseSettingsController private readonly ILogger _log; private readonly TelegramHelper _telegramHelper; private readonly DnsSettings _dnsSettings; - private readonly AdditionalWhiteLabelSettingsHelper _additionalWhiteLabelSettingsHelper; + private readonly AdditionalWhiteLabelSettingsHelperInit _additionalWhiteLabelSettingsHelper; private readonly CustomColorThemesSettingsHelper _customColorThemesSettingsHelper; private readonly QuotaUsageManager _quotaUsageManager; private readonly QuotaSyncOperation _quotaSyncOperation; @@ -93,7 +93,7 @@ public class SettingsController : BaseSettingsController PasswordHasher passwordHasher, IHttpContextAccessor httpContextAccessor, DnsSettings dnsSettings, - AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper, + AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelper, CustomColorThemesSettingsHelper customColorThemesSettingsHelper, QuotaSyncOperation quotaSyncOperation, QuotaUsageManager quotaUsageManager diff --git a/web/ASC.Web.Api/Api/Settings/WhitelabelController.cs b/web/ASC.Web.Api/Api/Settings/WhitelabelController.cs index e9c533282a..86c4e35524 100644 --- a/web/ASC.Web.Api/Api/Settings/WhitelabelController.cs +++ b/web/ASC.Web.Api/Api/Settings/WhitelabelController.cs @@ -37,7 +37,9 @@ public class WhitelabelController : BaseSettingsController private readonly TenantLogoManager _tenantLogoManager; private readonly CoreBaseSettings _coreBaseSettings; private readonly CommonLinkUtility _commonLinkUtility; - private readonly IMapper _mapper; + private readonly IMapper _mapper; + private readonly CompanyWhiteLabelSettingsHelper _companyWhiteLabelSettingsHelper; + private readonly AdditionalWhiteLabelSettingsHelper _additionalWhiteLabelSettingsHelper; public WhitelabelController( ApiContext apiContext, @@ -51,7 +53,8 @@ public class WhitelabelController : BaseSettingsController CommonLinkUtility commonLinkUtility, IMemoryCache memoryCache, IHttpContextAccessor httpContextAccessor, - IMapper mapper) : base(apiContext, memoryCache, webItemManager, httpContextAccessor) + IMapper mapper, + CompanyWhiteLabelSettingsHelper companyWhiteLabelSettingsHelper, AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper) : base(apiContext, memoryCache, webItemManager, httpContextAccessor) { _permissionContext = permissionContext; _settingsManager = settingsManager; @@ -61,6 +64,8 @@ public class WhitelabelController : BaseSettingsController _coreBaseSettings = coreBaseSettings; _commonLinkUtility = commonLinkUtility; _mapper = mapper; + _companyWhiteLabelSettingsHelper = companyWhiteLabelSettingsHelper; + _additionalWhiteLabelSettingsHelper = additionalWhiteLabelSettingsHelper; } ///false @@ -198,11 +203,11 @@ public class WhitelabelController : BaseSettingsController { var result = new List(); - var instance = CompanyWhiteLabelSettings.Instance(_settingsManager); + var instance = _companyWhiteLabelSettingsHelper.Instance(); result.Add(instance); - if (!instance.IsDefault && !instance.IsLicensor) + if (!_companyWhiteLabelSettingsHelper.IsDefault(instance) && !instance.IsLicensor) { result.Add(_settingsManager.GetDefault()); } diff --git a/web/ASC.Web.Api/ApiModels/ResponseDto/AdditionalWhiteLabelSettingsDto.cs b/web/ASC.Web.Api/ApiModels/ResponseDto/AdditionalWhiteLabelSettingsDto.cs index 470edbd4e4..b05665cc0f 100644 --- a/web/ASC.Web.Api/ApiModels/ResponseDto/AdditionalWhiteLabelSettingsDto.cs +++ b/web/ASC.Web.Api/ApiModels/ResponseDto/AdditionalWhiteLabelSettingsDto.cs @@ -56,6 +56,7 @@ public class AdditionalWhiteLabelSettingsDto: IMapFrom(); + profile.CreateMap() + .ConvertUsing(); } } diff --git a/web/ASC.Web.Api/ApiModels/ResponseDto/CompanyWhiteLabelSettingsDto.cs b/web/ASC.Web.Api/ApiModels/ResponseDto/CompanyWhiteLabelSettingsDto.cs index ca7a4d4a99..0688243f67 100644 --- a/web/ASC.Web.Api/ApiModels/ResponseDto/CompanyWhiteLabelSettingsDto.cs +++ b/web/ASC.Web.Api/ApiModels/ResponseDto/CompanyWhiteLabelSettingsDto.cs @@ -44,6 +44,7 @@ public class CompanyWhiteLabelSettingsDto: IMapFrom public void Mapping(Profile profile) { - profile.CreateMap(); + profile.CreateMap() + .ConvertUsing(); } } diff --git a/web/ASC.Web.Api/Mapping/AdditionalWhiteLabelSettingsConverter.cs b/web/ASC.Web.Api/Mapping/AdditionalWhiteLabelSettingsConverter.cs new file mode 100644 index 0000000000..1fceaba3d5 --- /dev/null +++ b/web/ASC.Web.Api/Mapping/AdditionalWhiteLabelSettingsConverter.cs @@ -0,0 +1,70 @@ +// (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 + +namespace ASC.Web.Api.Mapping; + + +[Scope(Additional = typeof(AdditionalWhiteLabelSettingsConverterExtension))] +public class AdditionalWhiteLabelSettingsConverter : ITypeConverter +{ + private readonly AdditionalWhiteLabelSettingsHelper _additionalWhiteLabelSettingsHelper; + + public AdditionalWhiteLabelSettingsConverter(AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper) + { + _additionalWhiteLabelSettingsHelper = additionalWhiteLabelSettingsHelper; + } + + public AdditionalWhiteLabelSettingsDto Convert(AdditionalWhiteLabelSettings source, AdditionalWhiteLabelSettingsDto destination, ResolutionContext context) + { + var result = new AdditionalWhiteLabelSettingsDto() + { + BuyUrl = source.BuyUrl, + FeedbackAndSupportEnabled = source.FeedbackAndSupportEnabled, + FeedbackAndSupportUrl = source.FeedbackAndSupportUrl, + HelpCenterEnabled = source.HelpCenterEnabled, + IsDefault = _additionalWhiteLabelSettingsHelper.IsDefault(source), + LicenseAgreementsEnabled = source.LicenseAgreementsEnabled, + LicenseAgreementsUrl = source.LicenseAgreementsUrl, + SalesEmail = source.SalesEmail, + StartDocsEnabled = source.StartDocsEnabled, + UserForumEnabled = source.UserForumEnabled, + UserForumUrl = source.UserForumUrl, + VideoGuidesEnabled = source.VideoGuidesEnabled, + VideoGuidesUrl = source.VideoGuidesUrl + }; + + return result; + } +} + +public static class AdditionalWhiteLabelSettingsConverterExtension +{ + public static void Register(DIHelper dIHelper) + { + dIHelper.TryAdd(); + } +} + diff --git a/web/ASC.Web.Api/Mapping/CompanyWhiteLabelSettingsConverter.cs b/web/ASC.Web.Api/Mapping/CompanyWhiteLabelSettingsConverter.cs new file mode 100644 index 0000000000..c11343f4c9 --- /dev/null +++ b/web/ASC.Web.Api/Mapping/CompanyWhiteLabelSettingsConverter.cs @@ -0,0 +1,51 @@ +// (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 + +namespace ASC.Web.Api.Mapping; + +[Scope] +public class CompanyWhiteLabelSettingsConverter : ITypeConverter +{ + private readonly CompanyWhiteLabelSettingsHelper _companyWhiteLabelSettingsHelper; + public CompanyWhiteLabelSettingsConverter(CompanyWhiteLabelSettingsHelper companyWhiteLabelSettingsHelper) + { + _companyWhiteLabelSettingsHelper = companyWhiteLabelSettingsHelper; + } + public CompanyWhiteLabelSettingsDto Convert(CompanyWhiteLabelSettings source, CompanyWhiteLabelSettingsDto destination, ResolutionContext context) + { + var result = new CompanyWhiteLabelSettingsDto() + { + Address = source.Address, + CompanyName = source.CompanyName, + Email = source.Email, + IsDefault = _companyWhiteLabelSettingsHelper.IsDefault(source), + IsLicensor = source.IsLicensor, + Phone = source.Phone, + Site = source.Site + }; + return result; + } +} diff --git a/web/ASC.Web.Core/Notify/NotifyConfiguration.cs b/web/ASC.Web.Core/Notify/NotifyConfiguration.cs index d4c129f17a..970ff7fec7 100644 --- a/web/ASC.Web.Core/Notify/NotifyConfiguration.cs +++ b/web/ASC.Web.Core/Notify/NotifyConfiguration.cs @@ -272,7 +272,7 @@ public class NotifyTransferRequest : INotifyEngineAction private readonly TenantExtra _tenantExtra; private readonly WebItemManager _webItemManager; private readonly TenantLogoManager _tenantLogoManager; - private readonly AdditionalWhiteLabelSettingsHelper _additionalWhiteLabelSettingsHelper; + private readonly AdditionalWhiteLabelSettingsHelperInit _additionalWhiteLabelSettingsHelper; private readonly TenantUtil _tenantUtil; private readonly CoreBaseSettings _coreBaseSettings; private readonly CommonLinkUtility _commonLinkUtility; @@ -289,7 +289,7 @@ public class NotifyTransferRequest : INotifyEngineAction TenantExtra tenantExtra, WebItemManager webItemManager, TenantLogoManager tenantLogoManager, - AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper, + AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelper, TenantUtil tenantUtil, CoreBaseSettings coreBaseSettings, CommonLinkUtility commonLinkUtility, diff --git a/web/ASC.Web.Core/Notify/StudioNotifyHelper.cs b/web/ASC.Web.Core/Notify/StudioNotifyHelper.cs index 72f2c155bc..3b94268e8f 100644 --- a/web/ASC.Web.Core/Notify/StudioNotifyHelper.cs +++ b/web/ASC.Web.Core/Notify/StudioNotifyHelper.cs @@ -51,7 +51,7 @@ public class StudioNotifyHelper StudioNotifySource studioNotifySource, UserManager userManager, SettingsManager settingsManager, - AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper, + AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelper, CommonLinkUtility commonLinkUtility, TenantManager tenantManager, TenantExtra tenantExtra, diff --git a/web/ASC.Web.Core/Utility/CommonLinkUtility.cs b/web/ASC.Web.Core/Utility/CommonLinkUtility.cs index f692718aca..76d7d4a8f3 100644 --- a/web/ASC.Web.Core/Utility/CommonLinkUtility.cs +++ b/web/ASC.Web.Core/Utility/CommonLinkUtility.cs @@ -496,7 +496,7 @@ public class CommonLinkUtility : BaseCommonLinkUtility #region Help Centr - public string GetHelpLink(SettingsManager settingsManager, AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper, bool inCurrentCulture = true) + public string GetHelpLink(SettingsManager settingsManager, AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelper, bool inCurrentCulture = true) { if (!settingsManager.LoadForDefaultTenant().HelpCenterEnabled) { diff --git a/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs b/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs index a5335bbf5e..642ed33ae9 100644 --- a/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs +++ b/web/ASC.Web.Core/WhiteLabel/AdditionalWhiteLabelSettings.cs @@ -34,7 +34,7 @@ public class AdditionalWhiteLabelSettingsWrapper [Serializable] public class AdditionalWhiteLabelSettings : ISettings { - private readonly AdditionalWhiteLabelSettingsHelper _additionalWhiteLabelSettingsHelper; + public AdditionalWhiteLabelSettingsHelperInit AdditionalWhiteLabelSettingsHelper; public bool StartDocsEnabled { get; set; } @@ -60,54 +60,33 @@ public class AdditionalWhiteLabelSettings : ISettings { - private CoreSettings _coreSettings; + public CoreSettings CoreSettings; public string CompanyName { get; set; } @@ -51,7 +51,7 @@ public class CompanyWhiteLabelSettings : ISettings public CompanyWhiteLabelSettings(CoreSettings coreSettings) { - _coreSettings = coreSettings; + CoreSettings = coreSettings; } public CompanyWhiteLabelSettings() @@ -59,21 +59,6 @@ public class CompanyWhiteLabelSettings : ISettings } - public bool IsDefault - { - get - { - var defaultSettings = GetDefault(); - - return CompanyName == defaultSettings.CompanyName && - Site == defaultSettings.Site && - Email == defaultSettings.Email && - Address == defaultSettings.Address && - Phone == defaultSettings.Phone && - IsLicensor == defaultSettings.IsLicensor; - } - } - #region ISettings Members [JsonIgnore] @@ -85,19 +70,45 @@ public class CompanyWhiteLabelSettings : ISettings public CompanyWhiteLabelSettings GetDefault() { - var settings = _coreSettings.GetSetting("CompanyWhiteLabelSettings"); + var settings = CoreSettings.GetSetting("CompanyWhiteLabelSettings"); - var result = string.IsNullOrEmpty(settings) ? new CompanyWhiteLabelSettings(_coreSettings) : JsonConvert.DeserializeObject(settings); + var result = string.IsNullOrEmpty(settings) ? new CompanyWhiteLabelSettings(CoreSettings) : JsonConvert.DeserializeObject(settings); - result._coreSettings = _coreSettings; + result.CoreSettings = CoreSettings; return result; } #endregion - - public static CompanyWhiteLabelSettings Instance(SettingsManager settingsManager) - { - return settingsManager.LoadForDefaultTenant(); - } } + +[Scope] +public class CompanyWhiteLabelSettingsHelper +{ + private readonly CoreSettings _coreSettings; + private readonly SettingsManager _settingsManager; + + public CompanyWhiteLabelSettingsHelper(CoreSettings coreSettings, SettingsManager settingsManager) + { + _coreSettings = coreSettings; + _settingsManager = settingsManager; + } + + public CompanyWhiteLabelSettings Instance() + { + return _settingsManager.LoadForDefaultTenant(); + } + + public bool IsDefault(CompanyWhiteLabelSettings settings) + { + settings.CoreSettings = _coreSettings; + var defaultSettings = settings.GetDefault(); + + return settings.CompanyName == defaultSettings.CompanyName && + settings.Site == defaultSettings.Site && + settings.Email == defaultSettings.Email && + settings.Address == defaultSettings.Address && + settings.Phone == defaultSettings.Phone && + settings.IsLicensor == defaultSettings.IsLicensor; + } +} \ No newline at end of file