Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #4900 - created and used overloads that take the portalId as parameter #4901

Merged
merged 7 commits into from
Nov 9, 2021
60 changes: 36 additions & 24 deletions DNN Platform/DotNetNuke.Web.Client/ClientResourceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,34 @@ private UpgradeStatus Status
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
[Obsolete("Deprecated in DotNetNuke 9.11.0. Use overload taking portalId. Scheduled removal in v11.0.0.")]
bdukes marked this conversation as resolved.
Show resolved Hide resolved
public bool IsOverridingDefaultSettingsEnabled()
{
var portalVersion = GetIntegerSetting(PortalSettingsDictionaryKey, VersionKey);
var overrideDefaultSettings = GetBooleanSetting(PortalSettingsDictionaryKey, OverrideDefaultSettingsKey);
int? portalId = GetPortalIdThroughReflection();
return this.IsOverridingDefaultSettingsEnabled(portalId);
}

public bool IsOverridingDefaultSettingsEnabled(int? portalId)
{
var portalVersion = GetIntegerSetting(portalId, PortalSettingsDictionaryKey, VersionKey);
var overrideDefaultSettings = GetBooleanSetting(portalId, PortalSettingsDictionaryKey, OverrideDefaultSettingsKey);

// if portal version is set
// and the portal "override default settings" flag is set and set to true
return portalVersion.HasValue && overrideDefaultSettings.HasValue && overrideDefaultSettings.Value;
}

[Obsolete("Deprecated in DotNetNuke 9.11.0. Use overload taking portalId. Scheduled removal in v11.0.0.")]
bdukes marked this conversation as resolved.
Show resolved Hide resolved
public int? GetVersion()
{
var portalVersion = GetIntegerSetting(PortalSettingsDictionaryKey, VersionKey);
var overrideDefaultSettings = GetBooleanSetting(PortalSettingsDictionaryKey, OverrideDefaultSettingsKey);
int? portalId = GetPortalIdThroughReflection();
return this.GetVersion(portalId);
}

public int? GetVersion(int? portalId)
{
var portalVersion = GetIntegerSetting(portalId, PortalSettingsDictionaryKey, VersionKey);
var overrideDefaultSettings = GetBooleanSetting(portalId, PortalSettingsDictionaryKey, OverrideDefaultSettingsKey);

// if portal version is set
// and the portal "override default settings" flag is set and set to true
Expand All @@ -117,7 +127,7 @@ public bool IsOverridingDefaultSettingsEnabled()
}

// otherwise return the host setting
var hostVersion = GetIntegerSetting(HostSettingsDictionaryKey, VersionKey);
var hostVersion = GetIntegerSetting(portalId, HostSettingsDictionaryKey, VersionKey);
if (hostVersion.HasValue)
{
return hostVersion.Value;
Expand All @@ -129,22 +139,25 @@ public bool IsOverridingDefaultSettingsEnabled()

public bool? AreCompositeFilesEnabled()
{
return this.IsBooleanSettingEnabled(EnableCompositeFilesKey);
int? portalId = GetPortalIdThroughReflection();
return this.IsBooleanSettingEnabled(portalId, EnableCompositeFilesKey);
}

public bool? EnableCssMinification()
{
return this.IsBooleanSettingEnabled(MinifyCssKey);
int? portalId = GetPortalIdThroughReflection();
return this.IsBooleanSettingEnabled(portalId, MinifyCssKey);
}

public bool? EnableJsMinification()
{
return this.IsBooleanSettingEnabled(MinifyJsKey);
int? portalId = GetPortalIdThroughReflection();
return this.IsBooleanSettingEnabled(portalId, MinifyJsKey);
}

private static bool? GetBooleanSetting(string dictionaryKey, string settingKey)
private static bool? GetBooleanSetting(int? portalId, string dictionaryKey, string settingKey)
{
var setting = GetSetting(dictionaryKey, settingKey);
var setting = GetSetting(portalId, dictionaryKey, settingKey);
bool result;
if (setting != null && bool.TryParse(setting, out result))
{
Expand All @@ -154,9 +167,9 @@ public bool IsOverridingDefaultSettingsEnabled()
return null;
}

private static int? GetIntegerSetting(string dictionaryKey, string settingKey)
private static int? GetIntegerSetting(int? portalId, string dictionaryKey, string settingKey)
{
var setting = GetSetting(dictionaryKey, settingKey);
var setting = GetSetting(portalId, dictionaryKey, settingKey);
int version;
if (setting != null && int.TryParse(setting, out version))
{
Expand All @@ -169,7 +182,7 @@ public bool IsOverridingDefaultSettingsEnabled()
return null;
}

private static string GetSetting(string dictionaryKey, string settingKey)
private static string GetSetting(int? portalId, string dictionaryKey, string settingKey)
{
bool isHttpContext = HttpContext.Current != null && HttpContext.Current.Items.Contains(dictionaryKey);
var settings = isHttpContext ? HttpContext.Current.Items[dictionaryKey] : null;
Expand All @@ -180,7 +193,7 @@ private static string GetSetting(string dictionaryKey, string settingKey)
return GetHostSettingThroughReflection(settingKey);
}

return GetPortalSettingThroughReflection(settingKey);
return GetPortalSettingThroughReflection(portalId, settingKey);
}

string value;
Expand All @@ -194,11 +207,10 @@ private static string GetSetting(string dictionaryKey, string settingKey)
return null;
}

private static string GetPortalSettingThroughReflection(string settingKey)
private static string GetPortalSettingThroughReflection(int? portalId, string settingKey)
valadas marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
int? portalId = GetPortalIdThroughReflection();
if (portalId.HasValue)
{
var method = _portalControllerType.GetMethod("GetPortalSettingsDictionary");
Expand Down Expand Up @@ -260,15 +272,15 @@ private static string GetHostSettingThroughReflection(string settingKey)
return null;
}

private bool? IsBooleanSettingEnabled(string settingKey)
private bool? IsBooleanSettingEnabled(int? portalId, string settingKey)
{
if (this.Status != UpgradeStatus.None)
{
return false;
}

var portalEnabled = GetBooleanSetting(PortalSettingsDictionaryKey, settingKey);
var overrideDefaultSettings = GetBooleanSetting(PortalSettingsDictionaryKey, OverrideDefaultSettingsKey);
var portalEnabled = GetBooleanSetting(portalId, PortalSettingsDictionaryKey, settingKey);
var overrideDefaultSettings = GetBooleanSetting(portalId, PortalSettingsDictionaryKey, OverrideDefaultSettingsKey);

// if portal version is set
// and the portal "override default settings" flag is set and set to true
Expand All @@ -278,7 +290,7 @@ private static string GetHostSettingThroughReflection(string settingKey)
}

// otherwise return the host setting
var hostEnabled = GetBooleanSetting(HostSettingsDictionaryKey, settingKey);
var hostEnabled = GetBooleanSetting(portalId, HostSettingsDictionaryKey, settingKey);
if (hostEnabled.HasValue)
{
return hostEnabled.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public virtual void LoadPortalSettings(PortalSettings portalSettings)
portalSettings.Registration = new RegistrationSettings(settings);

var clientResourcesSettings = new ClientResourceSettings();
bool overridingDefaultSettings = clientResourcesSettings.IsOverridingDefaultSettingsEnabled();
bool overridingDefaultSettings = clientResourcesSettings.IsOverridingDefaultSettingsEnabled(portalSettings.PortalId);

int crmVersion;
if (overridingDefaultSettings)
Expand Down