fix is default

This commit is contained in:
Anton Suhorukov 2022-10-14 23:59:18 +03:00
parent d82f3b81ef
commit 16af78a2a2
11 changed files with 225 additions and 74 deletions

View File

@ -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

View File

@ -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;
}
///<visible>false</visible>
@ -198,11 +203,11 @@ public class WhitelabelController : BaseSettingsController
{
var result = new List<CompanyWhiteLabelSettings>();
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<CompanyWhiteLabelSettings>());
}

View File

@ -56,6 +56,7 @@ public class AdditionalWhiteLabelSettingsDto: IMapFrom<AdditionalWhiteLabelSetti
public void Mapping(Profile profile)
{
profile.CreateMap<AdditionalWhiteLabelSettings, AdditionalWhiteLabelSettingsDto>();
profile.CreateMap<AdditionalWhiteLabelSettings, AdditionalWhiteLabelSettingsDto>()
.ConvertUsing<AdditionalWhiteLabelSettingsConverter>();
}
}

View File

@ -44,6 +44,7 @@ public class CompanyWhiteLabelSettingsDto: IMapFrom<CompanyWhiteLabelSettings>
public void Mapping(Profile profile)
{
profile.CreateMap<CompanyWhiteLabelSettings, CompanyWhiteLabelSettingsDto>();
profile.CreateMap<CompanyWhiteLabelSettings, CompanyWhiteLabelSettingsDto>()
.ConvertUsing<CompanyWhiteLabelSettingsConverter>();
}
}

View File

@ -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<AdditionalWhiteLabelSettings, AdditionalWhiteLabelSettingsDto>
{
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<AdditionalWhiteLabelSettingsHelper>();
}
}

View File

@ -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<CompanyWhiteLabelSettings, CompanyWhiteLabelSettingsDto>
{
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;
}
}

View File

@ -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,

View File

@ -51,7 +51,7 @@ public class StudioNotifyHelper
StudioNotifySource studioNotifySource,
UserManager userManager,
SettingsManager settingsManager,
AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper,
AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelper,
CommonLinkUtility commonLinkUtility,
TenantManager tenantManager,
TenantExtra tenantExtra,

View File

@ -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<AdditionalWhiteLabelSettings>().HelpCenterEnabled)
{

View File

@ -34,7 +34,7 @@ public class AdditionalWhiteLabelSettingsWrapper
[Serializable]
public class AdditionalWhiteLabelSettings : ISettings<AdditionalWhiteLabelSettings>
{
private readonly AdditionalWhiteLabelSettingsHelper _additionalWhiteLabelSettingsHelper;
public AdditionalWhiteLabelSettingsHelperInit AdditionalWhiteLabelSettingsHelper;
public bool StartDocsEnabled { get; set; }
@ -60,54 +60,33 @@ public class AdditionalWhiteLabelSettings : ISettings<AdditionalWhiteLabelSettin
public string LicenseAgreementsUrl { get; set; }
public bool IsDefault
{
get
{
var defaultSettings = GetDefault();
return StartDocsEnabled == defaultSettings.StartDocsEnabled &&
HelpCenterEnabled == defaultSettings.HelpCenterEnabled &&
FeedbackAndSupportEnabled == defaultSettings.FeedbackAndSupportEnabled &&
FeedbackAndSupportUrl == defaultSettings.FeedbackAndSupportUrl &&
UserForumEnabled == defaultSettings.UserForumEnabled &&
UserForumUrl == defaultSettings.UserForumUrl &&
VideoGuidesEnabled == defaultSettings.VideoGuidesEnabled &&
VideoGuidesUrl == defaultSettings.VideoGuidesUrl &&
SalesEmail == defaultSettings.SalesEmail &&
BuyUrl == defaultSettings.BuyUrl &&
LicenseAgreementsEnabled == defaultSettings.LicenseAgreementsEnabled &&
LicenseAgreementsUrl == defaultSettings.LicenseAgreementsUrl;
}
}
[JsonIgnore]
public Guid ID
{
get { return new Guid("{0108422F-C05D-488E-B271-30C4032494DA}"); }
}
public AdditionalWhiteLabelSettings(AdditionalWhiteLabelSettingsHelper additionalWhiteLabelSettingsHelper)
public AdditionalWhiteLabelSettings(AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelper)
{
_additionalWhiteLabelSettingsHelper = additionalWhiteLabelSettingsHelper;
this.AdditionalWhiteLabelSettingsHelper = additionalWhiteLabelSettingsHelper;
}
public AdditionalWhiteLabelSettings() { }
public AdditionalWhiteLabelSettings GetDefault()
{
return new AdditionalWhiteLabelSettings(_additionalWhiteLabelSettingsHelper)
return new AdditionalWhiteLabelSettings(AdditionalWhiteLabelSettingsHelper)
{
StartDocsEnabled = true,
HelpCenterEnabled = _additionalWhiteLabelSettingsHelper?.DefaultHelpCenterUrl != null,
FeedbackAndSupportEnabled = _additionalWhiteLabelSettingsHelper?.DefaultFeedbackAndSupportUrl != null,
FeedbackAndSupportUrl = _additionalWhiteLabelSettingsHelper?.DefaultFeedbackAndSupportUrl,
UserForumEnabled = _additionalWhiteLabelSettingsHelper?.DefaultUserForumUrl != null,
UserForumUrl = _additionalWhiteLabelSettingsHelper?.DefaultUserForumUrl,
VideoGuidesEnabled = _additionalWhiteLabelSettingsHelper?.DefaultVideoGuidesUrl != null,
VideoGuidesUrl = _additionalWhiteLabelSettingsHelper?.DefaultVideoGuidesUrl,
SalesEmail = _additionalWhiteLabelSettingsHelper?.DefaultMailSalesEmail,
BuyUrl = _additionalWhiteLabelSettingsHelper?.DefaultBuyUrl,
HelpCenterEnabled = AdditionalWhiteLabelSettingsHelper?.DefaultHelpCenterUrl != null,
FeedbackAndSupportEnabled = AdditionalWhiteLabelSettingsHelper?.DefaultFeedbackAndSupportUrl != null,
FeedbackAndSupportUrl = AdditionalWhiteLabelSettingsHelper?.DefaultFeedbackAndSupportUrl,
UserForumEnabled = AdditionalWhiteLabelSettingsHelper?.DefaultUserForumUrl != null,
UserForumUrl = AdditionalWhiteLabelSettingsHelper?.DefaultUserForumUrl,
VideoGuidesEnabled = AdditionalWhiteLabelSettingsHelper?.DefaultVideoGuidesUrl != null,
VideoGuidesUrl = AdditionalWhiteLabelSettingsHelper?.DefaultVideoGuidesUrl,
SalesEmail = AdditionalWhiteLabelSettingsHelper?.DefaultMailSalesEmail,
BuyUrl = AdditionalWhiteLabelSettingsHelper?.DefaultBuyUrl,
LicenseAgreementsEnabled = true,
LicenseAgreementsUrl = DefaultLicenseAgreements
};
@ -122,12 +101,45 @@ public class AdditionalWhiteLabelSettings : ISettings<AdditionalWhiteLabelSettin
}
}
[Singletone]
[Scope]
public class AdditionalWhiteLabelSettingsHelper
{
private readonly AdditionalWhiteLabelSettingsHelperInit _additionalWhiteLabelSettingsHelperInit;
public AdditionalWhiteLabelSettingsHelper(AdditionalWhiteLabelSettingsHelperInit additionalWhiteLabelSettingsHelperInit)
{
_additionalWhiteLabelSettingsHelperInit = additionalWhiteLabelSettingsHelperInit;
}
public bool IsDefault(AdditionalWhiteLabelSettings settings)
{
if (settings.AdditionalWhiteLabelSettingsHelper == null)
{
settings.AdditionalWhiteLabelSettingsHelper = _additionalWhiteLabelSettingsHelperInit;
}
var defaultSettings = settings.GetDefault();
return settings.StartDocsEnabled == defaultSettings.StartDocsEnabled &&
settings.HelpCenterEnabled == defaultSettings.HelpCenterEnabled &&
settings.FeedbackAndSupportEnabled == defaultSettings.FeedbackAndSupportEnabled &&
settings.FeedbackAndSupportUrl == defaultSettings.FeedbackAndSupportUrl &&
settings.UserForumEnabled == defaultSettings.UserForumEnabled &&
settings.UserForumUrl == defaultSettings.UserForumUrl &&
settings.VideoGuidesEnabled == defaultSettings.VideoGuidesEnabled &&
settings.VideoGuidesUrl == defaultSettings.VideoGuidesUrl &&
settings.SalesEmail == defaultSettings.SalesEmail &&
settings.BuyUrl == defaultSettings.BuyUrl &&
settings.LicenseAgreementsEnabled == defaultSettings.LicenseAgreementsEnabled &&
settings.LicenseAgreementsUrl == defaultSettings.LicenseAgreementsUrl;
}
}
[Singletone]
public class AdditionalWhiteLabelSettingsHelperInit
{
private readonly IConfiguration _configuration;
public AdditionalWhiteLabelSettingsHelper(IConfiguration configuration)
public AdditionalWhiteLabelSettingsHelperInit(IConfiguration configuration)
{
_configuration = configuration;
}
@ -185,4 +197,4 @@ public class AdditionalWhiteLabelSettingsHelper
return !string.IsNullOrEmpty(site) ? site + "/post.ashx?type=buyenterprise" : "";
}
}
}
}

View File

@ -34,7 +34,7 @@ public class CompanyWhiteLabelSettingsWrapper
[Serializable]
public class CompanyWhiteLabelSettings : ISettings<CompanyWhiteLabelSettings>
{
private CoreSettings _coreSettings;
public CoreSettings CoreSettings;
public string CompanyName { get; set; }
@ -51,7 +51,7 @@ public class CompanyWhiteLabelSettings : ISettings<CompanyWhiteLabelSettings>
public CompanyWhiteLabelSettings(CoreSettings coreSettings)
{
_coreSettings = coreSettings;
CoreSettings = coreSettings;
}
public CompanyWhiteLabelSettings()
@ -59,21 +59,6 @@ public class CompanyWhiteLabelSettings : ISettings<CompanyWhiteLabelSettings>
}
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<CompanyWhiteLabelSettings>
public CompanyWhiteLabelSettings GetDefault()
{
var settings = _coreSettings.GetSetting("CompanyWhiteLabelSettings");
var settings = CoreSettings.GetSetting("CompanyWhiteLabelSettings");
var result = string.IsNullOrEmpty(settings) ? new CompanyWhiteLabelSettings(_coreSettings) : JsonConvert.DeserializeObject<CompanyWhiteLabelSettings>(settings);
var result = string.IsNullOrEmpty(settings) ? new CompanyWhiteLabelSettings(CoreSettings) : JsonConvert.DeserializeObject<CompanyWhiteLabelSettings>(settings);
result._coreSettings = _coreSettings;
result.CoreSettings = CoreSettings;
return result;
}
#endregion
public static CompanyWhiteLabelSettings Instance(SettingsManager settingsManager)
{
return settingsManager.LoadForDefaultTenant<CompanyWhiteLabelSettings>();
}
}
[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<CompanyWhiteLabelSettings>();
}
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;
}
}