Merge pull request #2340 from bluewave-labs/hotfix/validation
remove showURL from validation
This commit is contained in:
2 files changed
+70
-69
No files matched your search
@@ -58,6 +58,11 @@ const Settings = () => {
|
|||||||
const handleChange = async (e) => {
|
const handleChange = async (e) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
|
|
||||||
|
// Special case for showURL until handled properly in the backend
|
||||||
|
if (name === "showURL") {
|
||||||
|
dispatch(setShowURL(value));
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Build next state early
|
// Build next state early
|
||||||
const newSettingsData = {
|
const newSettingsData = {
|
||||||
...settingsData,
|
...settingsData,
|
||||||
@@ -86,10 +91,6 @@ const Settings = () => {
|
|||||||
dispatch(setMode(value));
|
dispatch(setMode(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name === "showURL") {
|
|
||||||
dispatch(setShowURL(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name === "language") {
|
if (name === "language") {
|
||||||
dispatch(setLanguage(value));
|
dispatch(setLanguage(value));
|
||||||
i18n.changeLanguage(value);
|
i18n.changeLanguage(value);
|
||||||
@@ -132,6 +133,7 @@ const Settings = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
console.log(settingsData.settings);
|
||||||
const { error } = settingsValidation.validate(settingsData.settings, {
|
const { error } = settingsValidation.validate(settingsData.settings, {
|
||||||
abortEarly: false,
|
abortEarly: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ const lastnameSchema = joi
|
|||||||
.messages({
|
.messages({
|
||||||
"string.empty": "Surname is required",
|
"string.empty": "Surname is required",
|
||||||
"string.max": "Surname must be less than 50 characters",
|
"string.max": "Surname must be less than 50 characters",
|
||||||
"string.pattern.base": "Surname must contain only letters, spaces, apostrophes, or hyphens"
|
"string.pattern.base":
|
||||||
|
"Surname must contain only letters, spaces, apostrophes, or hyphens",
|
||||||
});
|
});
|
||||||
|
|
||||||
const passwordSchema = joi
|
const passwordSchema = joi
|
||||||
@@ -103,70 +104,69 @@ const credentials = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const monitorValidation = joi.object({
|
const monitorValidation = joi.object({
|
||||||
url: joi
|
url: joi.when("type", {
|
||||||
.when("type", {
|
is: "docker",
|
||||||
is: "docker",
|
then: joi
|
||||||
then: joi
|
.string()
|
||||||
.string()
|
.trim()
|
||||||
.trim()
|
.regex(/^[a-z0-9]{64}$/)
|
||||||
.regex(/^[a-z0-9]{64}$/)
|
.messages({
|
||||||
.messages({
|
"string.empty": "This field is required.",
|
||||||
"string.empty": "This field is required.",
|
"string.pattern.base": "Please enter a valid 64-character Docker container ID.",
|
||||||
"string.pattern.base": "Please enter a valid 64-character Docker container ID.",
|
}),
|
||||||
}),
|
otherwise: joi
|
||||||
otherwise: joi
|
.string()
|
||||||
.string()
|
.trim()
|
||||||
.trim()
|
.custom((value, helpers) => {
|
||||||
.custom((value, helpers) => {
|
// Regex from https://gist.github.com/dperini/729294
|
||||||
// Regex from https://gist.github.com/dperini/729294
|
var urlRegex = new RegExp(
|
||||||
var urlRegex = new RegExp(
|
"^" +
|
||||||
"^" +
|
// protocol identifier (optional)
|
||||||
// protocol identifier (optional)
|
// short syntax // still required
|
||||||
// short syntax // still required
|
"(?:(?:https?|ftp):\\/\\/)?" +
|
||||||
"(?:(?:https?|ftp):\\/\\/)?" +
|
// user:pass BasicAuth (optional)
|
||||||
// user:pass BasicAuth (optional)
|
"(?:" +
|
||||||
"(?:" +
|
// IP address dotted notation octets
|
||||||
// IP address dotted notation octets
|
// excludes loopback network 0.0.0.0
|
||||||
// excludes loopback network 0.0.0.0
|
// excludes reserved space >= 224.0.0.0
|
||||||
// excludes reserved space >= 224.0.0.0
|
// excludes network & broadcast addresses
|
||||||
// excludes network & broadcast addresses
|
// (first & last IP address of each class)
|
||||||
// (first & last IP address of each class)
|
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
"|" +
|
||||||
"|" +
|
// host & domain names, may end with dot
|
||||||
// host & domain names, may end with dot
|
// can be replaced by a shortest alternative
|
||||||
// can be replaced by a shortest alternative
|
// (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+
|
||||||
// (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+
|
"(?:" +
|
||||||
"(?:" +
|
"(?:" +
|
||||||
"(?:" +
|
"[a-z0-9\\u00a1-\\uffff]" +
|
||||||
"[a-z0-9\\u00a1-\\uffff]" +
|
"[a-z0-9\\u00a1-\\uffff_-]{0,62}" +
|
||||||
"[a-z0-9\\u00a1-\\uffff_-]{0,62}" +
|
")?" +
|
||||||
")?" +
|
"[a-z0-9\\u00a1-\\uffff]\\." +
|
||||||
"[a-z0-9\\u00a1-\\uffff]\\." +
|
")+" +
|
||||||
")+" +
|
// TLD identifier name, may end with dot
|
||||||
// TLD identifier name, may end with dot
|
"(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" +
|
||||||
"(?:[a-z\\u00a1-\\uffff]{2,}\\.?)" +
|
")" +
|
||||||
")" +
|
// port number (optional)
|
||||||
// port number (optional)
|
"(?::\\d{2,5})?" +
|
||||||
"(?::\\d{2,5})?" +
|
// resource path (optional)
|
||||||
// resource path (optional)
|
"(?:[/?#]\\S*)?" +
|
||||||
"(?:[/?#]\\S*)?" +
|
"$",
|
||||||
"$",
|
"i"
|
||||||
"i"
|
);
|
||||||
);
|
if (!urlRegex.test(value)) {
|
||||||
if (!urlRegex.test(value)) {
|
return helpers.error("string.invalidUrl");
|
||||||
return helpers.error("string.invalidUrl");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
})
|
})
|
||||||
.messages({
|
.messages({
|
||||||
"string.empty": "This field is required.",
|
"string.empty": "This field is required.",
|
||||||
"string.uri": "The URL you provided is not valid.",
|
"string.uri": "The URL you provided is not valid.",
|
||||||
"string.invalidUrl": "Please enter a valid URL with optional port",
|
"string.invalidUrl": "Please enter a valid URL with optional port",
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
port: joi
|
port: joi
|
||||||
.number()
|
.number()
|
||||||
.integer()
|
.integer()
|
||||||
@@ -277,7 +277,6 @@ const settingsValidation = joi.object({
|
|||||||
}),
|
}),
|
||||||
pagespeedApiKey: joi.string().allow("").optional(),
|
pagespeedApiKey: joi.string().allow("").optional(),
|
||||||
language: joi.string().required(),
|
language: joi.string().required(),
|
||||||
showURL: joi.bool().required(),
|
|
||||||
systemEmailHost: joi.string().allow(""),
|
systemEmailHost: joi.string().allow(""),
|
||||||
systemEmailPort: joi.number().allow(null, ""),
|
systemEmailPort: joi.number().allow(null, ""),
|
||||||
systemEmailAddress: joi.string().allow(""),
|
systemEmailAddress: joi.string().allow(""),
|
||||||
|
|||||||
Reference in new issue
Block a user