add validation logic to ensure page theme martches site theme

This commit is contained in:
sbwalker 2023-06-23 07:38:33 -04:00
parent a7c5841e76
commit 6126624631
3 changed files with 15 additions and 3 deletions

View File

@ -355,7 +355,7 @@
// appearance // appearance
_title = _page.Title; _title = _page.Title;
_themetype = _page.ThemeType; _themetype = _page.ThemeType;
if (string.IsNullOrEmpty(_themetype)) if (string.IsNullOrEmpty(_themetype) || ThemeService.GetTheme(PageState.Site.Themes, _themetype)?.ThemeName != ThemeService.GetTheme(PageState.Site.Themes, PageState.Site.DefaultThemeType)?.ThemeName)
{ {
_themetype = PageState.Site.DefaultThemeType; _themetype = PageState.Site.DefaultThemeType;
} }

View File

@ -24,6 +24,13 @@ namespace Oqtane.Services
/// <returns></returns> /// <returns></returns>
Task<Theme> GetThemeAsync(int themeId, int siteId); Task<Theme> GetThemeAsync(int themeId, int siteId);
/// <summary>
/// Returns a theme <see cref="ThemeControl"/>s containing a theme control type
/// </summary>
/// <param name="themes"></param>
/// <returns></returns>
Theme GetTheme(List<Theme> themes, string themeType);
/// <summary> /// <summary>
/// Returns a list of <see cref="ThemeControl"/>s from the given themes /// Returns a list of <see cref="ThemeControl"/>s from the given themes
/// </summary> /// </summary>

View File

@ -26,6 +26,11 @@ namespace Oqtane.Services
return await GetJsonAsync<Theme>($"{ApiUrl}/{themeId}?siteid={siteId}"); return await GetJsonAsync<Theme>($"{ApiUrl}/{themeId}?siteid={siteId}");
} }
public Theme GetTheme(List<Theme> themes, string themeType)
{
return themes.FirstOrDefault(item => item.Themes.Any(item => item.TypeName == themeType));
}
public List<ThemeControl> GetThemeControls(List<Theme> themes) public List<ThemeControl> GetThemeControls(List<Theme> themes)
{ {
return themes.SelectMany(item => item.Themes).OrderBy(item => item.Name).ToList(); return themes.SelectMany(item => item.Themes).OrderBy(item => item.Name).ToList();
@ -33,13 +38,13 @@ namespace Oqtane.Services
public List<ThemeControl> GetThemeControls(List<Theme> themes, string themeType) public List<ThemeControl> GetThemeControls(List<Theme> themes, string themeType)
{ {
return themes.First(item => item.Themes.Any(item => item.TypeName == themeType)).Themes.OrderBy(item => item.Name).ToList(); return GetTheme(themes, themeType)?.Themes.OrderBy(item => item.Name).ToList();
} }
public List<ThemeControl> GetContainerControls(List<Theme> themes, string themeType) public List<ThemeControl> GetContainerControls(List<Theme> themes, string themeType)
{ {
return themes.First(item => item.Themes.Any(item => item.TypeName == themeType)).Containers.OrderBy(item => item.Name).ToList(); return GetTheme(themes, themeType)?.Containers.OrderBy(item => item.Name).ToList();
} }
public async Task UpdateThemeAsync(Theme theme) public async Task UpdateThemeAsync(Theme theme)