Skip to content

Commit

Permalink
fix issue #4900 - created and used overloads that take the portalId a…
Browse files Browse the repository at this point in the history
…s parameter (#4901)

Co-authored-by: Brian Dukes <bdukes@engagesoftware.com>
  • Loading branch information
robsiera and bdukes authored Nov 9, 2021
1 parent 2784c12 commit eed6166
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
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.10.3. Use overload taking portalId. Scheduled removal in v11.0.0.")]
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.10.3. Use overload taking portalId. Scheduled removal in v11.0.0.")]
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)
{
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,12 +171,12 @@ 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)
{
int? globalVersion = new ClientResourceSettings().GetVersion();
int? globalVersion = new ClientResourceSettings().GetVersion(portalSettings.PortalId);
crmVersion = globalVersion ?? default(int);
}
else
Expand Down

0 comments on commit eed6166

Please sign in to comment.