Removed hard-coded email validation for healthcheck fix value. (#5557)

Made validation for healthchcls more flexible, supporting none, email and regex.

Co-authored-by: Nathan Woulfe <nathan@nathanw.com.au>
This commit is contained in:
Andy Butland
2021-06-02 04:54:11 +02:00
committed by GitHub
parent 57f7776848
commit cd53d7a294
7 changed files with 53 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
(function () {
"use strict";
function HealthCheckController($scope, healthCheckResource) {
function HealthCheckController(healthCheckResource) {
var SUCCESS = 0;
var WARNING = 1;
var ERROR = 2;
@@ -19,6 +19,7 @@
vm.checkAllInGroup = checkAllInGroup;
vm.openGroup = openGroup;
vm.setViewState = setViewState;
vm.parseRegex = parseRegex;
// Get a (grouped) list of all health checks
healthCheckResource.getAllChecks()
@@ -131,6 +132,10 @@
}
}
}
function parseRegex(regexAsString) {
return new RegExp(regexAsString);
}
}
angular.module("umbraco").controller("Umbraco.Dashboard.HealthCheckController", HealthCheckController);

View File

@@ -133,7 +133,12 @@
<div ng-if="action.valueRequired">
<div><label class="bold">Set new value:</label></div>
<input name="providedValue" type="text" ng-model="action.providedValue" required val-email />
<div ng-switch on="action.providedValueValidation">
<input ng-switch-when="email" name="providedValue" type="text" ng-model="action.providedValue" required val-email />
<input ng-switch-when="regex" name="providedValue" type="text" ng-model="action.providedValue" required ng-pattern="vm.parseRegex(action.providedValueValidationRegex)" />
<input ng-switch-default name="providedValue" type="text" ng-model="action.providedValue" required />
</div>
</div>
<umb-button type="button"

View File

@@ -43,13 +43,20 @@ namespace Umbraco.Web.HealthCheck.Checks.Config
/// </summary>
public abstract ValueComparisonType ValueComparisonType { get; }
/// <summary>
/// Indicates validation method for provided value
/// </summary>
public virtual ProvidedValueValidation ProvidedValueValidation => ProvidedValueValidation.None;
/// <summary>
/// If provided value validation requires a regex, it's provided here
/// </summary>
public virtual string ProvidedValueValidationRegex => string.Empty;
/// <summary>
/// Gets the flag indicating if the check is considered successful if the config value is missing (defaults to false - an error - if missing)
/// </summary>
public virtual bool ValidIfConfigMissing
{
get { return false; }
}
public virtual bool ValidIfConfigMissing => false;
protected AbstractConfigCheck(ILocalizedTextService textService)
{
@@ -160,6 +167,12 @@ namespace Umbraco.Web.HealthCheck.Checks.Config
ValueRequired = CanRectifyWithValue,
};
if (rectifyAction.ValueRequired)
{
rectifyAction.ProvidedValueValidation = ProvidedValueValidation.ToString().ToLower();
rectifyAction.ProvidedValueValidationRegex = ProvidedValueValidationRegex;
}
var resultMessage = string.Format(CheckErrorMessage, FileName, XPath, Values, CurrentValue);
return new[]
{

View File

@@ -20,6 +20,8 @@ namespace Umbraco.Web.HealthCheck.Checks.Config
public override ValueComparisonType ValueComparisonType => ValueComparisonType.ShouldNotEqual;
public override ProvidedValueValidation ProvidedValueValidation => ProvidedValueValidation.Email;
public override IEnumerable<AcceptableConfiguration> Values => new List<AcceptableConfiguration>
{
new AcceptableConfiguration { IsRecommended = false, Value = DefaultFromEmail }

View File

@@ -0,0 +1,9 @@
namespace Umbraco.Web.HealthCheck.Checks.Config
{
public enum ProvidedValueValidation
{
None = 1,
Email = 2,
Regex = 3
}
}

View File

@@ -70,6 +70,18 @@ namespace Umbraco.Web.HealthCheck
[DataMember(Name = "valueRequired")]
public bool ValueRequired { get; set; }
/// <summary>
/// Indicates if a value required, how it is validated
/// </summary>
[DataMember(Name = "providedValueValidation")]
public string ProvidedValueValidation { get; set; }
/// <summary>
/// Indicates if a value required, and is validated by a regex, what the regex to use is
/// </summary>
[DataMember(Name = "providedValueValidationRegex")]
public string ProvidedValueValidationRegex { get; set; }
/// <summary>
/// Provides a value to rectify the issue
/// </summary>

View File

@@ -167,6 +167,7 @@
<Compile Include="Editors\KeepAliveController.cs" />
<Compile Include="Editors\MacrosController.cs" />
<Compile Include="Editors\RelationTypeController.cs" />
<Compile Include="HealthCheck\Checks\Config\ProvidedValueValidation.cs" />
<Compile Include="Editors\TinyMceController.cs" />
<Compile Include="HealthCheck\Checks\Data\DatabaseIntegrityCheck.cs" />
<Compile Include="ImageCropperTemplateCoreExtensions.cs" />