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 1 commit
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
Prev Previous commit
Feedback
hishamco committed Sep 12, 2023
commit 6f8f5ead39851f31ad3c254ff22b3c85f1e5f5cd
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public DefaultSiteSettingsDisplayDriver(

public override Task<IDisplayResult> EditAsync(ISite site, BuildEditorContext context)
{
if (!IsGeneralSettings(context))
if (!IsGeneralGroup(context))
{
return Task.FromResult<IDisplayResult>(null);
}
@@ -54,45 +54,47 @@ public override Task<IDisplayResult> EditAsync(ISite site, BuildEditorContext co

public override async Task<IDisplayResult> UpdateAsync(ISite site, UpdateEditorContext context)
{
if (IsGeneralSettings(context))
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 (!String.IsNullOrEmpty(site.BaseUrl) && !Uri.TryCreate(site.BaseUrl, UriKind.Absolute, out _))
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.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);
}

@@ -110,7 +112,7 @@ private static void PopulateProperties(ISite site, SiteSettingsViewModel model)
model.CacheMode = site.CacheMode;
}

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