Skip to content

Commit

Permalink
Remove duplicate alert in settings (#14299)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Sep 12, 2023
1 parent 2586eb3 commit 808a1e6
Showing 1 changed file with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public DefaultSiteSettingsDisplayDriver(

public override Task<IDisplayResult> EditAsync(ISite site, BuildEditorContext context)
{
if (!IsGeneralGroup(context))
{
return Task.FromResult<IDisplayResult>(null);
}

context.Shape.Metadata.Wrappers.Add("Settings_Wrapper__General");

var result = Combine(
Expand All @@ -49,45 +54,47 @@ public override Task<IDisplayResult> EditAsync(ISite site, BuildEditorContext co

public override async Task<IDisplayResult> UpdateAsync(ISite site, UpdateEditorContext context)
{
if (context.GroupId.Equals(GroupId, StringComparison.OrdinalIgnoreCase))
if (!IsGeneralGroup(context))
{
var model = new SiteSettingsViewModel();
return null;
}

if (await context.Updater.TryUpdateModelAsync(model, Prefix))
{
site.SiteName = model.SiteName;
site.PageTitleFormat = model.PageTitleFormat;
site.BaseUrl = model.BaseUrl;
site.TimeZoneId = model.TimeZone;
site.PageSize = model.PageSize.Value;
site.UseCdn = model.UseCdn;
site.CdnBaseUrl = model.CdnBaseUrl;
site.ResourceDebugMode = model.ResourceDebugMode;
site.AppendVersion = model.AppendVersion;
site.CacheMode = model.CacheMode;

if (model.PageSize.Value < 1)
{
context.Updater.ModelState.AddModelError(Prefix, nameof(model.PageSize), S["The page size must be greater than zero."]);
}

if (site.MaxPageSize > 0 && model.PageSize.Value > site.MaxPageSize)
{
context.Updater.ModelState.AddModelError(Prefix, nameof(model.PageSize), S["The page size must be less than or equal to {0}.", site.MaxPageSize]);
}
}
var model = new SiteSettingsViewModel();

if (await context.Updater.TryUpdateModelAsync(model, Prefix))
{
site.SiteName = model.SiteName;
site.PageTitleFormat = model.PageTitleFormat;
site.BaseUrl = model.BaseUrl;
site.TimeZoneId = model.TimeZone;
site.PageSize = model.PageSize.Value;
site.UseCdn = model.UseCdn;
site.CdnBaseUrl = model.CdnBaseUrl;
site.ResourceDebugMode = model.ResourceDebugMode;
site.AppendVersion = model.AppendVersion;
site.CacheMode = model.CacheMode;

if (!String.IsNullOrEmpty(site.BaseUrl) && !Uri.TryCreate(site.BaseUrl, UriKind.Absolute, out _))
if (model.PageSize.Value < 1)
{
context.Updater.ModelState.AddModelError(Prefix, nameof(model.BaseUrl), S["The Base url must be a fully qualified URL."]);
context.Updater.ModelState.AddModelError(Prefix, nameof(model.PageSize), S["The page size must be greater than zero."]);
}

if (context.Updater.ModelState.IsValid)
if (site.MaxPageSize > 0 && model.PageSize.Value > site.MaxPageSize)
{
await _shellHost.ReleaseShellContextAsync(_shellSettings);
context.Updater.ModelState.AddModelError(Prefix, nameof(model.PageSize), S["The page size must be less than or equal to {0}.", site.MaxPageSize]);
}
}

if (!String.IsNullOrEmpty(site.BaseUrl) && !Uri.TryCreate(site.BaseUrl, UriKind.Absolute, out _))
{
context.Updater.ModelState.AddModelError(Prefix, nameof(model.BaseUrl), S["The Base url must be a fully qualified URL."]);
}

if (context.Updater.ModelState.IsValid)
{
await _shellHost.ReleaseShellContextAsync(_shellSettings);
}

return await EditAsync(site, context);
}

Expand All @@ -104,5 +111,8 @@ private static void PopulateProperties(ISite site, SiteSettingsViewModel model)
model.AppendVersion = site.AppendVersion;
model.CacheMode = site.CacheMode;
}

private static bool IsGeneralGroup(BuildEditorContext context)
=> context.GroupId.Equals(GroupId, StringComparison.OrdinalIgnoreCase);
}
}

0 comments on commit 808a1e6

Please sign in to comment.