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

Remove extra warning alert from SmtpSettings.Edit #14299

Merged
merged 6 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}